Commit 109a4b56 authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Chromium LUCI CQ

Convert PrepareChangeCallback to OnceCallback

This CL converts RemoteChangeProcessor::PrepareChangeCallback from
base::Callback to base::OnceCallback.

Bug: 1152272
Change-Id: I3c0ff1e629ed476c8a5f2258f129258d13c7797c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2606666
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Auto-Submit: Thomas Guilbert <tguilbert@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841203}
parent 8f581691
......@@ -32,7 +32,7 @@ RemoteChangeProcessorOnWorker::~RemoteChangeProcessorOnWorker() {
void RemoteChangeProcessorOnWorker::PrepareForProcessRemoteChange(
const storage::FileSystemURL& url,
const PrepareChangeCallback& callback) {
PrepareChangeCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
ui_task_runner_->PostTask(
......@@ -41,7 +41,7 @@ void RemoteChangeProcessorOnWorker::PrepareForProcessRemoteChange(
&RemoteChangeProcessorWrapper::PrepareForProcessRemoteChange,
wrapper_, url,
RelayCallbackToTaskRunner(worker_task_runner_.get(), FROM_HERE,
callback)));
std::move(callback))));
}
void RemoteChangeProcessorOnWorker::ApplyRemoteChange(
......
......@@ -33,9 +33,8 @@ class RemoteChangeProcessorOnWorker : public RemoteChangeProcessor {
base::SequencedTaskRunner* worker_task_runner);
~RemoteChangeProcessorOnWorker() override;
void PrepareForProcessRemoteChange(
const storage::FileSystemURL& url,
const PrepareChangeCallback& callback) override;
void PrepareForProcessRemoteChange(const storage::FileSystemURL& url,
PrepareChangeCallback callback) override;
void ApplyRemoteChange(const FileChange& change,
const base::FilePath& local_path,
const storage::FileSystemURL& url,
......
......@@ -17,9 +17,10 @@ RemoteChangeProcessorWrapper::RemoteChangeProcessorWrapper(
void RemoteChangeProcessorWrapper::PrepareForProcessRemoteChange(
const storage::FileSystemURL& url,
const RemoteChangeProcessor::PrepareChangeCallback& callback) {
RemoteChangeProcessor::PrepareChangeCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
remote_change_processor_->PrepareForProcessRemoteChange(url, callback);
remote_change_processor_->PrepareForProcessRemoteChange(url,
std::move(callback));
}
void RemoteChangeProcessorWrapper::ApplyRemoteChange(
......
......@@ -25,7 +25,7 @@ class RemoteChangeProcessorWrapper
void PrepareForProcessRemoteChange(
const storage::FileSystemURL& url,
const RemoteChangeProcessor::PrepareChangeCallback& callback);
RemoteChangeProcessor::PrepareChangeCallback callback);
void ApplyRemoteChange(const FileChange& change,
const base::FilePath& local_path,
......
......@@ -28,7 +28,7 @@ FakeRemoteChangeProcessor::~FakeRemoteChangeProcessor() {
void FakeRemoteChangeProcessor::PrepareForProcessRemoteChange(
const storage::FileSystemURL& url,
const PrepareChangeCallback& callback) {
PrepareChangeCallback callback) {
SyncFileMetadata local_metadata;
if (storage::VirtualPath::IsRootPath(url.path())) {
......@@ -60,8 +60,8 @@ void FakeRemoteChangeProcessor::PrepareForProcessRemoteChange(
change_list = found_list->second;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(callback, SYNC_STATUS_OK, local_metadata, change_list));
FROM_HERE, base::BindOnce(std::move(callback), SYNC_STATUS_OK,
local_metadata, change_list));
}
void FakeRemoteChangeProcessor::ApplyRemoteChange(
......
......@@ -42,9 +42,8 @@ class FakeRemoteChangeProcessor : public RemoteChangeProcessor {
~FakeRemoteChangeProcessor() override;
// RemoteChangeProcessor overrides.
void PrepareForProcessRemoteChange(
const storage::FileSystemURL& url,
const PrepareChangeCallback& callback) override;
void PrepareForProcessRemoteChange(const storage::FileSystemURL& url,
PrepareChangeCallback callback) override;
void ApplyRemoteChange(const FileChange& change,
const base::FilePath& local_path,
const storage::FileSystemURL& url,
......
......@@ -38,11 +38,12 @@ namespace sync_file_system {
namespace {
void PrepareForProcessRemoteChangeCallbackAdapter(
const RemoteChangeProcessor::PrepareChangeCallback& callback,
RemoteChangeProcessor::PrepareChangeCallback callback,
SyncStatusCode status,
const LocalFileSyncInfo& sync_file_info,
storage::ScopedFile snapshot) {
callback.Run(status, sync_file_info.metadata, sync_file_info.changes);
std::move(callback).Run(status, sync_file_info.metadata,
sync_file_info.changes);
}
void InvokeCallbackOnNthInvocation(int* count, const base::Closure& callback) {
......@@ -117,8 +118,7 @@ std::unique_ptr<LocalFileSyncService> LocalFileSyncService::Create(
std::unique_ptr<LocalFileSyncService> LocalFileSyncService::CreateForTesting(
Profile* profile,
leveldb::Env* env) {
std::unique_ptr<LocalFileSyncService> sync_service(
new LocalFileSyncService(profile, env));
auto sync_service = base::WrapUnique(new LocalFileSyncService(profile, env));
sync_service->sync_context_->set_mock_notify_changes_duration_in_sec(0);
return sync_service;
}
......@@ -224,7 +224,7 @@ void LocalFileSyncService::GetLocalFileMetadata(
void LocalFileSyncService::PrepareForProcessRemoteChange(
const FileSystemURL& url,
const PrepareChangeCallback& callback) {
PrepareChangeCallback callback) {
DVLOG(1) << "PrepareForProcessRemoteChange: " << url.DebugString();
if (!base::Contains(origin_to_contexts_, url.origin().GetURL())) {
......@@ -244,8 +244,8 @@ void LocalFileSyncService::PrepareForProcessRemoteChange(
// The extension has been uninstalled and this method is called
// before the remote changes for the origin are removed.
callback.Run(SYNC_STATUS_NO_CHANGE_TO_SYNC,
SyncFileMetadata(), FileChangeList());
std::move(callback).Run(SYNC_STATUS_NO_CHANGE_TO_SYNC, SyncFileMetadata(),
FileChangeList());
return;
}
scoped_refptr<storage::FileSystemContext> file_system_context =
......@@ -254,9 +254,9 @@ void LocalFileSyncService::PrepareForProcessRemoteChange(
->GetFileSystemContext();
MaybeInitializeFileSystemContext(
url.origin().GetURL(), file_system_context.get(),
base::Bind(&LocalFileSyncService::DidInitializeForRemoteSync,
AsWeakPtr(), url, base::RetainedRef(file_system_context),
callback));
base::BindOnce(&LocalFileSyncService::DidInitializeForRemoteSync,
AsWeakPtr(), url, base::RetainedRef(file_system_context),
std::move(callback)));
return;
}
......@@ -264,7 +264,8 @@ void LocalFileSyncService::PrepareForProcessRemoteChange(
sync_context_->PrepareForSync(
origin_to_contexts_[url.origin().GetURL()], url,
LocalFileSyncContext::SYNC_EXCLUSIVE,
base::Bind(&PrepareForProcessRemoteChangeCallbackAdapter, callback));
base::BindOnce(&PrepareForProcessRemoteChangeCallbackAdapter,
std::move(callback)));
}
void LocalFileSyncService::ApplyRemoteChange(const FileChange& change,
......@@ -279,8 +280,8 @@ void LocalFileSyncService::ApplyRemoteChange(const FileChange& change,
sync_context_->ApplyRemoteChange(
origin_to_contexts_[url.origin().GetURL()], change, local_path, url,
base::Bind(&LocalFileSyncService::DidApplyRemoteChange, AsWeakPtr(),
base::Passed(&callback)));
base::BindOnce(&LocalFileSyncService::DidApplyRemoteChange, AsWeakPtr(),
std::move(callback)));
}
void LocalFileSyncService::FinalizeRemoteSync(
......@@ -382,17 +383,17 @@ void LocalFileSyncService::DidInitializeFileSystemContext(
void LocalFileSyncService::DidInitializeForRemoteSync(
const FileSystemURL& url,
storage::FileSystemContext* file_system_context,
const PrepareChangeCallback& callback,
PrepareChangeCallback callback,
SyncStatusCode status) {
if (status != SYNC_STATUS_OK) {
DVLOG(1) << "FileSystemContext initialization failed for remote sync:"
<< url.DebugString() << " status=" << status
<< " (" << SyncStatusCodeToString(status) << ")";
callback.Run(status, SyncFileMetadata(), FileChangeList());
std::move(callback).Run(status, SyncFileMetadata(), FileChangeList());
return;
}
origin_to_contexts_[url.origin().GetURL()] = file_system_context;
PrepareForProcessRemoteChange(url, callback);
PrepareForProcessRemoteChange(url, std::move(callback));
}
void LocalFileSyncService::DidApplyRemoteChange(SyncStatusCallback callback,
......
......@@ -132,9 +132,8 @@ class LocalFileSyncService
SyncFileMetadataCallback callback);
// RemoteChangeProcessor overrides.
void PrepareForProcessRemoteChange(
const storage::FileSystemURL& url,
const PrepareChangeCallback& callback) override;
void PrepareForProcessRemoteChange(const storage::FileSystemURL& url,
PrepareChangeCallback callback) override;
void ApplyRemoteChange(const FileChange& change,
const base::FilePath& local_path,
const storage::FileSystemURL& url,
......@@ -196,7 +195,7 @@ class LocalFileSyncService
void DidInitializeForRemoteSync(
const storage::FileSystemURL& url,
storage::FileSystemContext* file_system_context,
const PrepareChangeCallback& callback,
PrepareChangeCallback callback,
SyncStatusCode status);
// Callback for ApplyRemoteChange.
......
......@@ -30,7 +30,7 @@ class MockRemoteChangeProcessor : public RemoteChangeProcessor {
// RemoteChangeProcessor overrides.
MOCK_METHOD2(PrepareForProcessRemoteChange,
void(const storage::FileSystemURL& url,
const PrepareChangeCallback& callback));
PrepareChangeCallback callback));
MOCK_METHOD4(ApplyRemoteChange,
void(const FileChange& change,
const base::FilePath& local_path,
......
......@@ -34,10 +34,10 @@ class RemoteChangeProcessor {
// URL in the local filesystem. If the target URL does not exist it is
// set to SYNC_FILE_TYPE_UNKNOWN.
// |changes| indicates a set of pending changes for the target URL.
typedef base::Callback<void(
SyncStatusCode status,
const SyncFileMetadata& metadata,
const FileChangeList& changes)> PrepareChangeCallback;
using PrepareChangeCallback =
base::OnceCallback<void(SyncStatusCode status,
const SyncFileMetadata& metadata,
const FileChangeList& changes)>;
RemoteChangeProcessor() {}
virtual ~RemoteChangeProcessor() {}
......@@ -49,7 +49,7 @@ class RemoteChangeProcessor {
// which is supposed to be done by LocalChangeProcessor)
virtual void PrepareForProcessRemoteChange(
const storage::FileSystemURL& url,
const PrepareChangeCallback& callback) = 0;
PrepareChangeCallback callback) = 0;
// This is called to apply the remote |change|. If the change type is
// ADD_OR_UPDATE for a file, |local_path| needs to point to a
......
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