diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-01 06:21:03 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-01 06:21:03 +0000 |
commit | 44eda8f2d61ea6c8785f3bd007dc644c26d543cd (patch) | |
tree | a6a2f053a72754c591615c66d230a33d62ffd98a /components/sync_driver | |
parent | 5c35c28f15bfb1291ddb7c34ce1252197d46ff94 (diff) | |
download | chromium_src-44eda8f2d61ea6c8785f3bd007dc644c26d543cd.zip chromium_src-44eda8f2d61ea6c8785f3bd007dc644c26d543cd.tar.gz chromium_src-44eda8f2d61ea6c8785f3bd007dc644c26d543cd.tar.bz2 |
sync: Add NonBlockingDataTypeManager
The new class manages the set of NonBlockingDataTypeControllers. Its
logic could have fit into the ProfileSyncService, but the code is a bit
cleaner if we factor it out into a separate class.
This CL does actually instantiate and make use of the
NonBlockingDataTypeManager, so it is not entirely a no-op. However,
without any registered non-blocking types, there will be no
NonBlockingDataTypeControllers for it to manage, so its functionality
will be limited.
BUG=351005
Review URL: https://codereview.chromium.org/251143003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267461 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/sync_driver')
3 files changed, 162 insertions, 1 deletions
diff --git a/components/sync_driver/non_blocking_data_type_controller_unittest.cc b/components/sync_driver/non_blocking_data_type_controller_unittest.cc index b695c0b..43c4fa4 100644 --- a/components/sync_driver/non_blocking_data_type_controller_unittest.cc +++ b/components/sync_driver/non_blocking_data_type_controller_unittest.cc @@ -27,7 +27,7 @@ class MockSyncCoreProxy : public syncer::SyncCoreProxy { scoped_refptr<base::SequencedTaskRunner>()); } - virtual scoped_ptr<SyncCoreProxy> Clone() OVERRIDE { + virtual scoped_ptr<SyncCoreProxy> Clone() const OVERRIDE { return scoped_ptr<SyncCoreProxy>(new MockSyncCoreProxy()); } }; diff --git a/components/sync_driver/non_blocking_data_type_manager.cc b/components/sync_driver/non_blocking_data_type_manager.cc new file mode 100644 index 0000000..7ab3497 --- /dev/null +++ b/components/sync_driver/non_blocking_data_type_manager.cc @@ -0,0 +1,78 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/sync_driver/non_blocking_data_type_manager.h" + +#include "base/sequenced_task_runner.h" +#include "components/sync_driver/non_blocking_data_type_controller.h" +#include "sync/internal_api/public/non_blocking_type_processor.h" + +namespace browser_sync { + +NonBlockingDataTypeManager::NonBlockingDataTypeManager() + : non_blocking_data_type_controllers_deleter_( + &non_blocking_data_type_controllers_) {} + +NonBlockingDataTypeManager::~NonBlockingDataTypeManager() {} + +void NonBlockingDataTypeManager::RegisterType( + syncer::ModelType type, + bool enabled) { + DCHECK_EQ(0U, non_blocking_data_type_controllers_.count(type)) + << "Duplicate registration of type " << ModelTypeToString(type); + + non_blocking_data_type_controllers_.insert(std::make_pair( + type, + new NonBlockingDataTypeController( + type, + enabled))); +} + +void NonBlockingDataTypeManager::InitializeTypeProcessor( + syncer::ModelType type, + const scoped_refptr<base::SequencedTaskRunner>& task_runner, + const base::WeakPtr<syncer::NonBlockingTypeProcessor>& processor) { + NonBlockingDataTypeControllerMap::iterator it = + non_blocking_data_type_controllers_.find(type); + DCHECK(it != non_blocking_data_type_controllers_.end()); + it->second->InitializeProcessor(task_runner, processor); +} + +void NonBlockingDataTypeManager::ConnectSyncBackend( + scoped_ptr<syncer::SyncCoreProxy> proxy) { + for (NonBlockingDataTypeControllerMap::iterator it = + non_blocking_data_type_controllers_.begin(); + it != non_blocking_data_type_controllers_.end(); ++it) { + it->second->InitializeSyncCoreProxy(proxy->Clone()); + } +} + +void NonBlockingDataTypeManager::DisconnectSyncBackend() { + for (NonBlockingDataTypeControllerMap::iterator it = + non_blocking_data_type_controllers_.begin(); + it != non_blocking_data_type_controllers_.end(); ++it) { + it->second->ClearSyncCoreProxy(); + } +} + +void NonBlockingDataTypeManager::SetPreferredTypes( + syncer::ModelTypeSet preferred_types) { + for (NonBlockingDataTypeControllerMap::iterator it = + non_blocking_data_type_controllers_.begin(); + it != non_blocking_data_type_controllers_.end(); ++it) { + it->second->SetIsPreferred(preferred_types.Has(it->first)); + } +} + +syncer::ModelTypeSet NonBlockingDataTypeManager::GetRegisteredTypes() const { + syncer::ModelTypeSet result; + for (NonBlockingDataTypeControllerMap::const_iterator it = + non_blocking_data_type_controllers_.begin(); + it != non_blocking_data_type_controllers_.end(); ++it) { + result.Put(it->first); + } + return result; +} + +} // namespace browser_sync diff --git a/components/sync_driver/non_blocking_data_type_manager.h b/components/sync_driver/non_blocking_data_type_manager.h new file mode 100644 index 0000000..49e85b3 --- /dev/null +++ b/components/sync_driver/non_blocking_data_type_manager.h @@ -0,0 +1,83 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_MANAGER_H_ +#define COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_MANAGER_H_ + +#include <map> + +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "base/stl_util.h" +#include "sync/internal_api/public/base/model_type.h" + +namespace base { +class SequencedTaskRunner; +} // namespace base + +namespace syncer { +class NonBlockingTypeProcessor; +class SyncCoreProxy; +} //namespace syncer + +namespace browser_sync { + +class NonBlockingDataTypeController; + +// Manages a set of NonBlockingDataTypeControllers. +// +// Each NonBlockingDataTypeController instance handles the logic around +// enabling and disabling sync for a particular non-blocking type. This class +// manages all the controllers. +class NonBlockingDataTypeManager { + public: + NonBlockingDataTypeManager(); + ~NonBlockingDataTypeManager(); + + // Declares |type| as a non-blocking type. Should be done early + // on during sync initialization. + // + // The |preferred| flag indicates whether or not this type should be synced. + void RegisterType(syncer::ModelType type, bool preferred); + + // Connects the NonBlockingTypeProcessor and associated model type + // thread to its NonBlockingDataTypeController on the UI thread. + void InitializeTypeProcessor( + syncer::ModelType type, + const scoped_refptr<base::SequencedTaskRunner>& task_runner, + const base::WeakPtr<syncer::NonBlockingTypeProcessor>& processor); + + // Connects the sync backend, as represented by a SyncCoreProxy, to the + // NonBlockingDataTypeController on the UI thread. + void ConnectSyncBackend(scoped_ptr<syncer::SyncCoreProxy> proxy); + + // Disconnects the sync backend from the UI thread. Should be called + // early on during shutdown, but the whole procedure is asynchronous so + // there's not much downside to calling it later. + void DisconnectSyncBackend(); + + // Updates the set of types the user wants to have synced. + void SetPreferredTypes(syncer::ModelTypeSet types); + + // Returns the list of all known non-blocking sync types that registered with + // RegisterType. + syncer::ModelTypeSet GetRegisteredTypes() const; + + private: + typedef + std::map<syncer::ModelType, browser_sync::NonBlockingDataTypeController*> + NonBlockingDataTypeControllerMap; + + // List of data type controllers for non-blocking types. + NonBlockingDataTypeControllerMap non_blocking_data_type_controllers_; + + // Deleter for elements of the non-blocking data types controller map. + STLValueDeleter<NonBlockingDataTypeControllerMap> + non_blocking_data_type_controllers_deleter_; +}; + +} // namespace browser_sync + +#endif // COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_MANAGER_H_ |