Commit 7711c50f authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Chromium LUCI CQ

Convert FileIDCallback to OnceCallback

This CL converts FolderCreator::FileIDCallback to OnceCallback.

Bug: 1152272
Change-Id: I03fd7a647e2b91e967a23f15b3fa4b4444c8c74a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586671
Auto-Submit: Thomas Guilbert <tguilbert@chromium.org>
Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836966}
parent bbb97e27
...@@ -21,7 +21,7 @@ void CallbackTracker::AbortAll() { ...@@ -21,7 +21,7 @@ void CallbackTracker::AbortAll() {
std::swap(helpers, helpers_); std::swap(helpers, helpers_);
for (auto itr = helpers.begin(); itr != helpers.end(); ++itr) { for (auto itr = helpers.begin(); itr != helpers.end(); ++itr) {
delete itr->first; delete itr->first;
itr->second.Run(); std::move(itr->second).Run();
} }
} }
......
...@@ -34,48 +34,48 @@ FolderCreator::FolderCreator(drive::DriveServiceInterface* drive_service, ...@@ -34,48 +34,48 @@ FolderCreator::FolderCreator(drive::DriveServiceInterface* drive_service,
FolderCreator::~FolderCreator() { FolderCreator::~FolderCreator() {
} }
void FolderCreator::Run(const FileIDCallback& callback) { void FolderCreator::Run(FileIDCallback callback) {
drive::AddNewDirectoryOptions options; drive::AddNewDirectoryOptions options;
options.visibility = google_apis::drive::FILE_VISIBILITY_PRIVATE; options.visibility = google_apis::drive::FILE_VISIBILITY_PRIVATE;
drive_service_->AddNewDirectory( drive_service_->AddNewDirectory(
parent_folder_id_, title_, options, parent_folder_id_, title_, options,
base::BindOnce(&FolderCreator::DidCreateFolder, base::BindOnce(&FolderCreator::DidCreateFolder,
weak_ptr_factory_.GetWeakPtr(), callback)); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
void FolderCreator::DidCreateFolder( void FolderCreator::DidCreateFolder(
const FileIDCallback& callback, FileIDCallback callback,
google_apis::DriveApiErrorCode error, google_apis::DriveApiErrorCode error,
std::unique_ptr<google_apis::FileResource> entry) { std::unique_ptr<google_apis::FileResource> entry) {
SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error);
if (status != SYNC_STATUS_OK) { if (status != SYNC_STATUS_OK) {
callback.Run(std::string(), status); std::move(callback).Run(std::string(), status);
return; return;
} }
drive_service_->SearchByTitle( drive_service_->SearchByTitle(
title_, parent_folder_id_, title_, parent_folder_id_,
base::Bind( base::BindOnce(
&FolderCreator::DidListFolders, weak_ptr_factory_.GetWeakPtr(), &FolderCreator::DidListFolders, weak_ptr_factory_.GetWeakPtr(),
callback, std::move(callback),
base::Passed(
std::vector<std::unique_ptr<google_apis::FileResource>>()))); std::vector<std::unique_ptr<google_apis::FileResource>>()));
} }
void FolderCreator::DidListFolders( void FolderCreator::DidListFolders(
const FileIDCallback& callback, FileIDCallback callback,
std::vector<std::unique_ptr<google_apis::FileResource>> candidates, std::vector<std::unique_ptr<google_apis::FileResource>> candidates,
google_apis::DriveApiErrorCode error, google_apis::DriveApiErrorCode error,
std::unique_ptr<google_apis::FileList> file_list) { std::unique_ptr<google_apis::FileList> file_list) {
SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error);
if (status != SYNC_STATUS_OK) { if (status != SYNC_STATUS_OK) {
callback.Run(std::string(), status); std::move(callback).Run(std::string(), status);
return; return;
} }
if (!file_list) { if (!file_list) {
NOTREACHED(); NOTREACHED();
callback.Run(std::string(), SYNC_STATUS_FAILED); std::move(callback).Run(std::string(), SYNC_STATUS_FAILED);
return; return;
} }
...@@ -87,9 +87,9 @@ void FolderCreator::DidListFolders( ...@@ -87,9 +87,9 @@ void FolderCreator::DidListFolders(
if (!file_list->next_link().is_empty()) { if (!file_list->next_link().is_empty()) {
drive_service_->GetRemainingFileList( drive_service_->GetRemainingFileList(
file_list->next_link(), file_list->next_link(),
base::Bind(&FolderCreator::DidListFolders, base::BindOnce(&FolderCreator::DidListFolders,
weak_ptr_factory_.GetWeakPtr(), callback, weak_ptr_factory_.GetWeakPtr(), std::move(callback),
base::Passed(&candidates))); std::move(candidates)));
return; return;
} }
...@@ -104,7 +104,7 @@ void FolderCreator::DidListFolders( ...@@ -104,7 +104,7 @@ void FolderCreator::DidListFolders(
} }
if (!oldest) { if (!oldest) {
callback.Run(std::string(), SYNC_FILE_ERROR_NOT_FOUND); std::move(callback).Run(std::string(), SYNC_FILE_ERROR_NOT_FOUND);
return; return;
} }
...@@ -112,17 +112,17 @@ void FolderCreator::DidListFolders( ...@@ -112,17 +112,17 @@ void FolderCreator::DidListFolders(
status = metadata_database_->UpdateByFileResourceList(std::move(candidates)); status = metadata_database_->UpdateByFileResourceList(std::move(candidates));
if (status != SYNC_STATUS_OK) { if (status != SYNC_STATUS_OK) {
callback.Run(std::string(), status); std::move(callback).Run(std::string(), status);
return; return;
} }
DCHECK(!file_id.empty()); DCHECK(!file_id.empty());
if (!metadata_database_->FindFileByFileID(file_id, nullptr)) { if (!metadata_database_->FindFileByFileID(file_id, nullptr)) {
callback.Run(std::string(), SYNC_FILE_ERROR_NOT_FOUND); std::move(callback).Run(std::string(), SYNC_FILE_ERROR_NOT_FOUND);
return; return;
} }
callback.Run(file_id, status); std::move(callback).Run(file_id, status);
} }
} // namespace drive_backend } // namespace drive_backend
......
...@@ -29,8 +29,8 @@ class MetadataDatabase; ...@@ -29,8 +29,8 @@ class MetadataDatabase;
class FolderCreator { class FolderCreator {
public: public:
typedef base::Callback<void(const std::string& file_id, using FileIDCallback = base::OnceCallback<void(const std::string& file_id,
SyncStatusCode status)> FileIDCallback; SyncStatusCode status)>;
FolderCreator(drive::DriveServiceInterface* drive_service, FolderCreator(drive::DriveServiceInterface* drive_service,
MetadataDatabase* metadata_database, MetadataDatabase* metadata_database,
...@@ -38,14 +38,14 @@ class FolderCreator { ...@@ -38,14 +38,14 @@ class FolderCreator {
const std::string& title); const std::string& title);
~FolderCreator(); ~FolderCreator();
void Run(const FileIDCallback& callback); void Run(FileIDCallback callback);
private: private:
void DidCreateFolder(const FileIDCallback& callback, void DidCreateFolder(FileIDCallback callback,
google_apis::DriveApiErrorCode error, google_apis::DriveApiErrorCode error,
std::unique_ptr<google_apis::FileResource> entry); std::unique_ptr<google_apis::FileResource> entry);
void DidListFolders( void DidListFolders(
const FileIDCallback& callback, FileIDCallback callback,
std::vector<std::unique_ptr<google_apis::FileResource>> candidates, std::vector<std::unique_ptr<google_apis::FileResource>> candidates,
google_apis::DriveApiErrorCode error, google_apis::DriveApiErrorCode error,
std::unique_ptr<google_apis::FileList> file_list); std::unique_ptr<google_apis::FileList> file_list);
......
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