From 14693e1b149daad671fca474b438c01359bf48c7 Mon Sep 17 00:00:00 2001 From: "tzik@chromium.org" Date: Mon, 30 Jun 2014 16:01:50 +0000 Subject: [PATCH] [SyncFS] Convert RemoteToLocalSyncer to SyncTask BUG=344769 TEST=./unit_tests --gtest_filter='RemoteToLocalSyncerTest.*' Review URL: https://codereview.chromium.org/351793003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280604 0039d316-1c4b-4281-b951-d872f2087c98 --- .../drive_backend/conflict_resolver_unittest.cc | 3 ++- .../drive_backend/local_to_remote_syncer_unittest.cc | 3 ++- .../drive_backend/remote_to_local_syncer.cc | 16 +++++++++++++++- .../drive_backend/remote_to_local_syncer.h | 5 +++-- .../drive_backend/remote_to_local_syncer_unittest.cc | 4 +++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/chrome/browser/sync_file_system/drive_backend/conflict_resolver_unittest.cc b/chrome/browser/sync_file_system/drive_backend/conflict_resolver_unittest.cc index 27459263809d..93dbbc229750 100644 --- a/chrome/browser/sync_file_system/drive_backend/conflict_resolver_unittest.cc +++ b/chrome/browser/sync_file_system/drive_backend/conflict_resolver_unittest.cc @@ -183,7 +183,8 @@ class ConflictResolverTest : public testing::Test { SyncStatusCode status = SYNC_STATUS_UNKNOWN; scoped_ptr syncer( new RemoteToLocalSyncer(context_.get())); - syncer->RunExclusive(CreateResultReceiver(&status)); + syncer->RunPreflight(SyncTaskToken::CreateForTesting( + CreateResultReceiver(&status))); base::RunLoop().RunUntilIdle(); return status; } diff --git a/chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer_unittest.cc b/chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer_unittest.cc index 50a196a83d1a..555c56990833 100644 --- a/chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer_unittest.cc +++ b/chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer_unittest.cc @@ -195,7 +195,8 @@ class LocalToRemoteSyncerTest : public testing::Test { SyncStatusCode status = SYNC_STATUS_UNKNOWN; scoped_ptr syncer(new RemoteToLocalSyncer(context_.get())); - syncer->RunExclusive(CreateResultReceiver(&status)); + syncer->RunPreflight(SyncTaskToken::CreateForTesting( + CreateResultReceiver(&status))); base::RunLoop().RunUntilIdle(); return status; } diff --git a/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.cc b/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.cc index 80f261624629..e9c4f94f9046 100644 --- a/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.cc +++ b/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.cc @@ -17,6 +17,9 @@ #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" +#include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" +#include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" +#include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.h" #include "chrome/browser/sync_file_system/logger.h" #include "chrome/browser/sync_file_system/syncable_file_system_util.h" #include "extensions/common/extension.h" @@ -87,7 +90,18 @@ RemoteToLocalSyncer::RemoteToLocalSyncer(SyncEngineContext* sync_context) RemoteToLocalSyncer::~RemoteToLocalSyncer() { } -void RemoteToLocalSyncer::RunExclusive(const SyncStatusCallback& callback) { +void RemoteToLocalSyncer::RunPreflight(scoped_ptr token) { + scoped_ptr blocking_factor(new BlockingFactor); + blocking_factor->exclusive = true; + SyncTaskManager::UpdateBlockingFactor( + token.Pass(), blocking_factor.Pass(), + base::Bind(&RemoteToLocalSyncer::RunExclusive, + weak_ptr_factory_.GetWeakPtr())); +} + +void RemoteToLocalSyncer::RunExclusive(scoped_ptr token) { + SyncStatusCallback callback = SyncTaskToken::WrapToCallback(token.Pass()); + if (!drive_service() || !metadata_database() || !remote_change_processor()) { util::Log(logging::LOG_VERBOSE, FROM_HERE, "[Remote -> Local] Context not ready."); diff --git a/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h b/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h index fdcba1e464d2..2e5876c8c360 100644 --- a/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h +++ b/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h @@ -39,14 +39,15 @@ namespace drive_backend { class MetadataDatabase; class SyncEngineContext; -class RemoteToLocalSyncer : public ExclusiveTask { +class RemoteToLocalSyncer : public SyncTask { public: // Conflicting trackers will have low priority for RemoteToLocalSyncer so that // it should be resolved by LocatToRemoteSyncer. explicit RemoteToLocalSyncer(SyncEngineContext* sync_context); virtual ~RemoteToLocalSyncer(); - virtual void RunExclusive(const SyncStatusCallback& callback) OVERRIDE; + virtual void RunPreflight(scoped_ptr token) OVERRIDE; + void RunExclusive(scoped_ptr token); const fileapi::FileSystemURL& url() const { return url_; } SyncAction sync_action() const { return sync_action_; } diff --git a/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer_unittest.cc b/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer_unittest.cc index a0f8038ae0a7..92551e535cdf 100644 --- a/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer_unittest.cc +++ b/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer_unittest.cc @@ -21,6 +21,7 @@ #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" #include "chrome/browser/sync_file_system/drive_backend/sync_engine_initializer.h" #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" +#include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" #include "chrome/browser/sync_file_system/fake_remote_change_processor.h" #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" #include "chrome/browser/sync_file_system/syncable_file_system_util.h" @@ -182,7 +183,8 @@ class RemoteToLocalSyncerTest : public testing::Test { SyncStatusCode status = SYNC_STATUS_UNKNOWN; scoped_ptr syncer(new RemoteToLocalSyncer(context_.get())); - syncer->RunExclusive(CreateResultReceiver(&status)); + syncer->RunPreflight(SyncTaskToken::CreateForTesting( + CreateResultReceiver(&status))); base::RunLoop().RunUntilIdle(); return status; } -- 2.11.4.GIT