Commit 90c0bb3a authored by Xida Chen's avatar Xida Chen Committed by Chromium LUCI CQ

[Code health] Convert GetFileInfoSuccessCallback to OnceCallback

As a result of this convert, the PendingTaskInfo::task is
converted to a base::OnceClosure.

This is a code health CL, no behaviour change is expected.

Bug: 1152278
Change-Id: I1bb1434f01b35818336a37bed6687ab71b1dfaf3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2593480
Commit-Queue: Xida Chen <xidachen@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837712}
parent 4e2e4686
......@@ -52,15 +52,15 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
PendingTaskInfo(const base::FilePath& path,
content::BrowserThread::ID thread_id,
const base::Location& location,
const base::Closure& task);
PendingTaskInfo(const PendingTaskInfo& other);
base::OnceClosure task);
PendingTaskInfo(PendingTaskInfo&& other);
~PendingTaskInfo();
base::FilePath path;
base::FilePath cached_path;
const content::BrowserThread::ID thread_id;
const base::Location location;
const base::Closure task;
base::OnceClosure task;
};
class MTPFileNode;
......@@ -84,7 +84,7 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
// MTPDeviceAsyncDelegate:
void GetFileInfo(const base::FilePath& file_path,
const GetFileInfoSuccessCallback& success_callback,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback) override;
void CreateDirectory(const base::FilePath& directory_path,
const bool exclusive,
......@@ -146,7 +146,7 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
// The internal methods correspond to the similarly named methods above.
// The |root_node_| cache should be filled at this point.
void GetFileInfoInternal(const base::FilePath& file_path,
const GetFileInfoSuccessCallback& success_callback,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback);
void CreateDirectoryInternal(
const std::vector<base::FilePath>& components,
......@@ -233,13 +233,13 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
// If the device is uninitialized, store the |task_info| in a pending task
// queue and runs the pending tasks in the queue once the device is
// successfully initialized.
void EnsureInitAndRunTask(const PendingTaskInfo& task_info);
void EnsureInitAndRunTask(PendingTaskInfo task_info);
// Runs a task. If |task_info.path| is empty, or if the path is cached, runs
// the task immediately.
// Otherwise, fills the cache first before running the task.
// |task_info.task| runs on the UI thread.
void RunTask(const PendingTaskInfo& task_info);
void RunTask(PendingTaskInfo task_info);
// Writes data from the device to the snapshot file path based on the
// parameters in |current_snapshot_request_info_| by doing a call-and-reply to
......@@ -263,7 +263,7 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
// Called when GetFileInfo() succeeds. |file_info| specifies the
// requested file details. |success_callback| is invoked to notify the caller
// about the requested file details.
void OnDidGetFileInfo(const GetFileInfoSuccessCallback& success_callback,
void OnDidGetFileInfo(GetFileInfoSuccessCallback success_callback,
const base::File::Info& file_info);
// Called when GetFileInfo() of |directory_path| succeeded at checking the
......
......@@ -106,7 +106,7 @@ void MTPDeviceTaskHelper::OpenStorage(const std::string& storage_name,
void MTPDeviceTaskHelper::GetFileInfo(
uint32_t file_id,
const GetFileInfoSuccessCallback& success_callback,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (device_handle_.empty())
......@@ -116,8 +116,8 @@ void MTPDeviceTaskHelper::GetFileInfo(
GetMediaTransferProtocolManager()->GetFileInfo(
device_handle_, file_ids,
base::BindOnce(&MTPDeviceTaskHelper::OnGetFileInfo,
weak_ptr_factory_.GetWeakPtr(), success_callback,
error_callback));
weak_ptr_factory_.GetWeakPtr(),
std::move(success_callback), error_callback));
}
void MTPDeviceTaskHelper::CreateDirectory(
......@@ -260,7 +260,7 @@ void MTPDeviceTaskHelper::OnDidOpenStorage(
}
void MTPDeviceTaskHelper::OnGetFileInfo(
const GetFileInfoSuccessCallback& success_callback,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback,
std::vector<device::mojom::MtpFileEntryPtr> entries,
bool error) const {
......@@ -271,8 +271,9 @@ void MTPDeviceTaskHelper::OnGetFileInfo(
}
content::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(success_callback, FileInfoFromMTPFileEntry(
std::move(entries[0]))));
FROM_HERE,
base::BindOnce(std::move(success_callback),
FileInfoFromMTPFileEntry(std::move(entries[0]))));
}
void MTPDeviceTaskHelper::OnCreateDirectory(
......
......@@ -86,7 +86,7 @@ class MTPDeviceTaskHelper {
// If there is an error, |error_callback| is invoked on the IO thread to
// notify the caller about the file error.
void GetFileInfo(uint32_t file_id,
const GetFileInfoSuccessCallback& success_callback,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback);
// Forwards CreateDirectory request to the MediaTransferProtocolManager.
......@@ -184,7 +184,7 @@ class MTPDeviceTaskHelper {
// When |entries| has a size other than 1, or if |error| is true, then an
// error has occurred. In this case, |error_callback| is invoked on the IO
// thread to notify the caller.
void OnGetFileInfo(const GetFileInfoSuccessCallback& success_callback,
void OnGetFileInfo(GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback,
std::vector<device::mojom::MtpFileEntryPtr> entries,
bool error) const;
......
......@@ -375,10 +375,10 @@ void DeviceMediaAsyncFileUtil::GetFileInfo(
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback));
delegate->GetFileInfo(
url.path(),
base::Bind(&DeviceMediaAsyncFileUtil::OnDidGetFileInfo,
weak_ptr_factory_.GetWeakPtr(),
base::RetainedRef(context->task_runner()), url.path(),
copyable_callback),
base::BindOnce(&DeviceMediaAsyncFileUtil::OnDidGetFileInfo,
weak_ptr_factory_.GetWeakPtr(),
base::RetainedRef(context->task_runner()), url.path(),
copyable_callback),
base::BindRepeating(&OnGetFileInfoError, copyable_callback));
}
......
......@@ -30,8 +30,8 @@ class IOBuffer;
class MTPDeviceAsyncDelegate {
public:
// A callback to be called when GetFileInfo method call succeeds.
typedef base::Callback<
void(const base::File::Info& file_info)> GetFileInfoSuccessCallback;
typedef base::OnceCallback<void(const base::File::Info& file_info)>
GetFileInfoSuccessCallback;
// A callback to be called when CreateDirectory method call succeeds.
typedef base::Closure CreateDirectorySuccessCallback;
......@@ -98,10 +98,9 @@ class MTPDeviceAsyncDelegate {
// Gets information about the given |file_path| and invokes the appropriate
// callback asynchronously when complete.
virtual void GetFileInfo(
const base::FilePath& file_path,
const GetFileInfoSuccessCallback& success_callback,
const ErrorCallback& error_callback) = 0;
virtual void GetFileInfo(const base::FilePath& file_path,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback) = 0;
// Creates a directory to |directory_path|. When |exclusive| is true, this
// returns base::File::FILE_ERROR_EXISTS if a directory already exists for
......
......@@ -91,8 +91,8 @@ int64_t MTPFileStreamReader::GetLength(
get_length_callback_ = std::move(callback);
delegate->GetFileInfo(
url_.path(),
base::Bind(&MTPFileStreamReader::FinishGetLength,
weak_factory_.GetWeakPtr()),
base::BindOnce(&MTPFileStreamReader::FinishGetLength,
weak_factory_.GetWeakPtr()),
base::BindRepeating(
&MTPFileStreamReader::CallGetLengthCallbackWithPlatformFileError,
weak_factory_.GetWeakPtr()));
......
......@@ -36,7 +36,7 @@ class MTPDeviceDelegateImplMac : public MTPDeviceAsyncDelegate {
// IO thread by the async filesystem file util. They forward to
// similarly-named methods on the UI thread.
void GetFileInfo(const base::FilePath& file_path,
const GetFileInfoSuccessCallback& success_callback,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback) override;
void CreateDirectory(const base::FilePath& directory_path,
......
......@@ -149,13 +149,12 @@ MTPDeviceDelegateImplMac::~MTPDeviceDelegateImplMac() {
namespace {
void ForwardGetFileInfo(
base::File::Info* info,
base::File::Error* error,
const GetFileInfoSuccessCallback& success_callback,
const ErrorCallback& error_callback) {
void ForwardGetFileInfo(base::File::Info* info,
base::File::Error* error,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback) {
if (*error == base::File::FILE_OK)
success_callback.Run(*info);
std::move(success_callback).Run(*info);
else
error_callback.Run(*error);
}
......@@ -164,7 +163,7 @@ void ForwardGetFileInfo(
void MTPDeviceDelegateImplMac::GetFileInfo(
const base::FilePath& file_path,
const GetFileInfoSuccessCallback& success_callback,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback) {
base::File::Info* info = new base::File::Info;
base::File::Error* error = new base::File::Error;
......@@ -173,8 +172,8 @@ void MTPDeviceDelegateImplMac::GetFileInfo(
FROM_HERE,
base::Bind(&MTPDeviceDelegateImplMac::GetFileInfoImpl,
base::Unretained(this), file_path, info, error),
base::Bind(&ForwardGetFileInfo, base::Owned(info), base::Owned(error),
success_callback, error_callback));
base::BindOnce(&ForwardGetFileInfo, base::Owned(info), base::Owned(error),
std::move(success_callback), error_callback));
}
void MTPDeviceDelegateImplMac::CreateDirectory(
......
......@@ -375,7 +375,7 @@ MTPDeviceDelegateImplWin::~MTPDeviceDelegateImplWin() {
void MTPDeviceDelegateImplWin::GetFileInfo(
const base::FilePath& file_path,
const GetFileInfoSuccessCallback& success_callback,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
DCHECK(!file_path.empty());
......@@ -385,8 +385,9 @@ void MTPDeviceDelegateImplWin::GetFileInfo(
base::BindOnce(&GetFileInfoOnBlockingPoolThread, storage_device_info_,
file_path, base::Unretained(file_info)),
base::BindOnce(&MTPDeviceDelegateImplWin::OnGetFileInfo,
weak_ptr_factory_.GetWeakPtr(), success_callback,
error_callback, base::Owned(file_info))));
weak_ptr_factory_.GetWeakPtr(),
std::move(success_callback), error_callback,
base::Owned(file_info))));
}
void MTPDeviceDelegateImplWin::CreateDirectory(
......@@ -584,14 +585,14 @@ void MTPDeviceDelegateImplWin::OnInitCompleted(bool succeeded) {
}
void MTPDeviceDelegateImplWin::OnGetFileInfo(
const GetFileInfoSuccessCallback& success_callback,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback,
base::File::Info* file_info,
base::File::Error error) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
DCHECK(file_info);
if (error == base::File::FILE_OK)
success_callback.Run(*file_info);
std::move(success_callback).Run(*file_info);
else
error_callback.Run(error);
task_in_progress_ = false;
......
......@@ -95,7 +95,7 @@ class MTPDeviceDelegateImplWin : public MTPDeviceAsyncDelegate {
// MTPDeviceAsyncDelegate:
void GetFileInfo(const base::FilePath& file_path,
const GetFileInfoSuccessCallback& success_callback,
GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback) override;
void CreateDirectory(
const base::FilePath& directory_path,
......@@ -189,7 +189,7 @@ class MTPDeviceDelegateImplWin : public MTPDeviceAsyncDelegate {
//
// If the GetFileInfo() fails, |file_info| is not set and |error_callback| is
// invoked to notify the caller about the platform file |error|.
void OnGetFileInfo(const GetFileInfoSuccessCallback& success_callback,
void OnGetFileInfo(GetFileInfoSuccessCallback success_callback,
const ErrorCallback& error_callback,
base::File::Info* file_info,
base::File::Error error);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment