diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-26 09:57:48 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-26 09:57:48 +0000 |
commit | a74bfd94b772bd2fd2fb6a4c86ab7fa28bae5e09 (patch) | |
tree | cd65affbec838521ffaaa82797e59e9d0d5b3bfe /sync | |
parent | 599bdcf987a713e054225e9d9908374cd95c05c7 (diff) | |
download | chromium_src-a74bfd94b772bd2fd2fb6a4c86ab7fa28bae5e09.zip chromium_src-a74bfd94b772bd2fd2fb6a4c86ab7fa28bae5e09.tar.gz chromium_src-a74bfd94b772bd2fd2fb6a4c86ab7fa28bae5e09.tar.bz2 |
Introduce NonBlockingDataTypeController
The NonBlockingDataTypeController tracks the sync state of
a non-blocking data type and sends signals to its components from the UI
thread. It is responsible for enabling and disabling sync for a data
type according to user preference and the availbility of the sync
backend.
This CL also includes some changes to the NonBlockingDataTypeProcessor,
which is currently just a stub of what will eventually become
non-blocking sync's model thread component, so that it can be used in
testing NonBlockingDataTypeController.
BUG=351005
Review URL: https://codereview.chromium.org/249843002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266344 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r-- | sync/internal_api/non_blocking_type_processor.cc | 30 | ||||
-rw-r--r-- | sync/internal_api/public/non_blocking_type_processor.h | 29 | ||||
-rw-r--r-- | sync/internal_api/sync_core_proxy_impl_unittest.cc | 8 |
3 files changed, 51 insertions, 16 deletions
diff --git a/sync/internal_api/non_blocking_type_processor.cc b/sync/internal_api/non_blocking_type_processor.cc index 8fd0d27..d426443 100644 --- a/sync/internal_api/non_blocking_type_processor.cc +++ b/sync/internal_api/non_blocking_type_processor.cc @@ -11,14 +11,22 @@ namespace syncer { NonBlockingTypeProcessor::NonBlockingTypeProcessor(ModelType type) - : type_(type), enabled_(false), weak_ptr_factory_(this) {} + : type_(type), + is_preferred_(false), + is_connected_(false), + weak_ptr_factory_(this) {} NonBlockingTypeProcessor::~NonBlockingTypeProcessor() { } -bool NonBlockingTypeProcessor::IsEnabled() const { +bool NonBlockingTypeProcessor::IsPreferred() const { DCHECK(CalledOnValidThread()); - return enabled_; + return is_preferred_; +} + +bool NonBlockingTypeProcessor::IsConnected() const { + DCHECK(CalledOnValidThread()); + return is_connected_; } ModelType NonBlockingTypeProcessor::GetModelType() const { @@ -28,15 +36,19 @@ ModelType NonBlockingTypeProcessor::GetModelType() const { void NonBlockingTypeProcessor::Enable(SyncCoreProxy* core_proxy) { DCHECK(CalledOnValidThread()); - core_proxy->ConnectTypeToCore( - GetModelType(), - AsWeakPtr()); + is_preferred_ = true; + core_proxy->ConnectTypeToCore(GetModelType(), AsWeakPtr()); } void NonBlockingTypeProcessor::Disable() { DCHECK(CalledOnValidThread()); - enabled_ = false; - weak_ptr_factory_.InvalidateWeakPtrs(); + is_preferred_ = false; + Disconnect(); +} + +void NonBlockingTypeProcessor::Disconnect() { + DCHECK(CalledOnValidThread()); + is_connected_ = false; core_ = base::WeakPtr<NonBlockingTypeProcessorCore>(); sync_thread_ = scoped_refptr<base::SequencedTaskRunner>(); } @@ -50,7 +62,7 @@ void NonBlockingTypeProcessor::OnConnect( base::WeakPtr<NonBlockingTypeProcessorCore> core, scoped_refptr<base::SequencedTaskRunner> sync_thread) { DCHECK(CalledOnValidThread()); - enabled_ = true; + is_connected_ = true; core_ = core; sync_thread_ = sync_thread; } diff --git a/sync/internal_api/public/non_blocking_type_processor.h b/sync/internal_api/public/non_blocking_type_processor.h index 0198c27..3745088 100644 --- a/sync/internal_api/public/non_blocking_type_processor.h +++ b/sync/internal_api/public/non_blocking_type_processor.h @@ -24,8 +24,20 @@ class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe { NonBlockingTypeProcessor(ModelType type); virtual ~NonBlockingTypeProcessor(); + // Returns true if this object believes that sync is preferred for this type. + // + // By "preferred", we mean that a policy decision has been made that this + // type should be synced. Most of the time this is controlled by a user + // clicking a checkbox on the settings page. + // + // The canonical preferred state is based on SyncPrefs on the UI thread. At + // best, this value is stale and may lag behind the one set on the UI thread. + // Before this type has registered with the UI thread, it's mostly just an + // informed guess. + bool IsPreferred() const; + // Returns true if the handshake with sync thread is complete. - bool IsEnabled() const; + bool IsConnected() const; // Returns the model type handled by this processor. ModelType GetModelType() const; @@ -33,10 +45,14 @@ class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe { // Starts the handshake with the sync thread. void Enable(SyncCoreProxy* core_proxy); - // Severs all ties to the sync thread. + // Severs all ties to the sync thread and may delete local sync state. // Another call to Enable() can be used to re-establish this connection. void Disable(); + // Severs all ties to the sync thread. + // Another call to Enable() can be used to re-establish this connection. + void Disconnect(); + // Callback used to process the handshake response. void OnConnect(base::WeakPtr<NonBlockingTypeProcessorCore> core, scoped_refptr<base::SequencedTaskRunner> sync_thread); @@ -46,7 +62,14 @@ class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe { private: ModelType type_; sync_pb::DataTypeProgressMarker progress_marker_; - bool enabled_; + + // Whether or not sync is preferred for this type. This is a cached copy of + // the canonical copy information on the UI thread. + bool is_preferred_; + + // Whether or not this object has completed its initial handshake with the + // SyncCoreProxy. + bool is_connected_; base::WeakPtr<NonBlockingTypeProcessorCore> core_; scoped_refptr<base::SequencedTaskRunner> sync_thread_; diff --git a/sync/internal_api/sync_core_proxy_impl_unittest.cc b/sync/internal_api/sync_core_proxy_impl_unittest.cc index a3e228c..2e306ee 100644 --- a/sync/internal_api/sync_core_proxy_impl_unittest.cc +++ b/sync/internal_api/sync_core_proxy_impl_unittest.cc @@ -52,7 +52,7 @@ TEST_F(SyncCoreProxyImplTest, FailToConnect1) { base::RunLoop run_loop_; run_loop_.RunUntilIdle(); - EXPECT_FALSE(themes_processor.IsEnabled()); + EXPECT_FALSE(themes_processor.IsConnected()); } // Try to connect a type to a SyncCore as it shuts down. @@ -63,7 +63,7 @@ TEST_F(SyncCoreProxyImplTest, FailToConnect2) { base::RunLoop run_loop_; run_loop_.RunUntilIdle(); - EXPECT_FALSE(themes_processor.IsEnabled()); + EXPECT_FALSE(themes_processor.IsConnected()); } // Tests the case where the type's processor shuts down first. @@ -75,7 +75,7 @@ TEST_F(SyncCoreProxyImplTest, TypeDisconnectsFirst) { base::RunLoop run_loop_; run_loop_.RunUntilIdle(); - EXPECT_TRUE(themes_processor->IsEnabled()); + EXPECT_TRUE(themes_processor->IsConnected()); themes_processor.reset(); } @@ -88,7 +88,7 @@ TEST_F(SyncCoreProxyImplTest, SyncDisconnectsFirst) { base::RunLoop run_loop_; run_loop_.RunUntilIdle(); - EXPECT_TRUE(themes_processor->IsEnabled()); + EXPECT_TRUE(themes_processor->IsConnected()); DisableSync(); } |