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() {
std::swap(helpers, helpers_);
for (auto itr = helpers.begin(); itr != helpers.end(); ++itr) {
delete itr->first;
itr->second.Run();
std::move(itr->second).Run();
}
}
......
......@@ -34,48 +34,48 @@ FolderCreator::FolderCreator(drive::DriveServiceInterface* drive_service,
FolderCreator::~FolderCreator() {
}
void FolderCreator::Run(const FileIDCallback& callback) {
void FolderCreator::Run(FileIDCallback callback) {
drive::AddNewDirectoryOptions options;
options.visibility = google_apis::drive::FILE_VISIBILITY_PRIVATE;
drive_service_->AddNewDirectory(
parent_folder_id_, title_, options,
base::BindOnce(&FolderCreator::DidCreateFolder,
weak_ptr_factory_.GetWeakPtr(), callback));
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void FolderCreator::DidCreateFolder(
const FileIDCallback& callback,
FileIDCallback callback,
google_apis::DriveApiErrorCode error,
std::unique_ptr<google_apis::FileResource> entry) {
SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error);
if (status != SYNC_STATUS_OK) {
callback.Run(std::string(), status);
std::move(callback).Run(std::string(), status);
return;
}
drive_service_->SearchByTitle(
title_, parent_folder_id_,
base::Bind(
base::BindOnce(
&FolderCreator::DidListFolders, weak_ptr_factory_.GetWeakPtr(),
callback,
base::Passed(
std::vector<std::unique_ptr<google_apis::FileResource>>())));
std::move(callback),
std::vector<std::unique_ptr<google_apis::FileResource>>()));
}
void FolderCreator::DidListFolders(
const FileIDCallback& callback,
FileIDCallback callback,
std::vector<std::unique_ptr<google_apis::FileResource>> candidates,
google_apis::DriveApiErrorCode error,
std::unique_ptr<google_apis::FileList> file_list) {
SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error);
if (status != SYNC_STATUS_OK) {
callback.Run(std::string(), status);
std::move(callback).Run(std::string(), status);
return;
}
if (!file_list) {
NOTREACHED();
callback.Run(std::string(), SYNC_STATUS_FAILED);
std::move(callback).Run(std::string(), SYNC_STATUS_FAILED);
return;
}
......@@ -87,9 +87,9 @@ void FolderCreator::DidListFolders(
if (!file_list->next_link().is_empty()) {
drive_service_->GetRemainingFileList(
file_list->next_link(),
base::Bind(&FolderCreator::DidListFolders,
weak_ptr_factory_.GetWeakPtr(), callback,
base::Passed(&candidates)));
base::BindOnce(&FolderCreator::DidListFolders,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(candidates)));
return;
}
......@@ -104,7 +104,7 @@ void FolderCreator::DidListFolders(
}
if (!oldest) {
callback.Run(std::string(), SYNC_FILE_ERROR_NOT_FOUND);
std::move(callback).Run(std::string(), SYNC_FILE_ERROR_NOT_FOUND);
return;
}
......@@ -112,17 +112,17 @@ void FolderCreator::DidListFolders(
status = metadata_database_->UpdateByFileResourceList(std::move(candidates));
if (status != SYNC_STATUS_OK) {
callback.Run(std::string(), status);
std::move(callback).Run(std::string(), status);
return;
}
DCHECK(!file_id.empty());
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;
}
callback.Run(file_id, status);
std::move(callback).Run(file_id, status);
}
} // namespace drive_backend
......
......@@ -29,8 +29,8 @@ class MetadataDatabase;
class FolderCreator {
public:
typedef base::Callback<void(const std::string& file_id,
SyncStatusCode status)> FileIDCallback;
using FileIDCallback = base::OnceCallback<void(const std::string& file_id,
SyncStatusCode status)>;
FolderCreator(drive::DriveServiceInterface* drive_service,
MetadataDatabase* metadata_database,
......@@ -38,14 +38,14 @@ class FolderCreator {
const std::string& title);
~FolderCreator();
void Run(const FileIDCallback& callback);
void Run(FileIDCallback callback);
private:
void DidCreateFolder(const FileIDCallback& callback,
void DidCreateFolder(FileIDCallback callback,
google_apis::DriveApiErrorCode error,
std::unique_ptr<google_apis::FileResource> entry);
void DidListFolders(
const FileIDCallback& callback,
FileIDCallback callback,
std::vector<std::unique_ptr<google_apis::FileResource>> candidates,
google_apis::DriveApiErrorCode error,
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