Sync: Refactoring DataTypeController to make the design
shareable with USS datatypes.
1) Moved the code that activates and deactivates datatypes from
DataTypeManager to DataTypeController. This should allow controllers
to implement the activation differently from directory based and USS
datatypes.
2) Removed any directory specific code from DataTypeManager and
DataTypeController and made theme generic enough to work for
USS datatypes. More specifically:
- GetChangeProcessor() and model_safe_group() are moved to
DirectoryDataTypeController - see below.
- OnUserShareChanged(), user_share() are not needed anymore.
3) Introduced new base class for directory based DTC - DirectoryDataTypeController.
This class provides directory specific implementation for the datatype
activation/deactivation and declares some directory specific virtual
functions that formerly were in DataTypeController.
4) Changed the mechanism how some specific DTC get the user share.
Instead of being pushed to each DTC, user share can now be accessed
via SyncClient which is already passed to each controller. I had to fix
some mock classes and test code to make it work for all tests.
BUG=515962
Review URL: https://codereview.chromium.org/1314903004
Cr-Commit-Position: refs/heads/master@{#347111}
diff --git a/chrome/browser/sync/glue/bookmark_model_associator.cc b/chrome/browser/sync/glue/bookmark_model_associator.cc
index 2d79268..9955676 100644
--- a/chrome/browser/sync/glue/bookmark_model_associator.cc
+++ b/chrome/browser/sync/glue/bookmark_model_associator.cc
@@ -26,6 +26,7 @@
#include "components/undo/bookmark_undo_utils.h"
#include "content/public/browser/browser_thread.h"
#include "sync/api/sync_error.h"
+#include "sync/api/sync_merge_result.h"
#include "sync/internal_api/public/delete_journal.h"
#include "sync/internal_api/public/read_node.h"
#include "sync/internal_api/public/read_transaction.h"
diff --git a/chrome/browser/sync/glue/bookmark_model_associator.h b/chrome/browser/sync/glue/bookmark_model_associator.h
index bcfc39b..33d08c9 100644
--- a/chrome/browser/sync/glue/bookmark_model_associator.h
+++ b/chrome/browser/sync/glue/bookmark_model_associator.h
@@ -9,12 +9,12 @@
#include <set>
#include <stack>
#include <string>
+#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/hash.h"
#include "base/memory/weak_ptr.h"
-#include "components/sync_driver/data_type_controller.h"
#include "components/sync_driver/data_type_error_handler.h"
#include "components/sync_driver/model_associator.h"
#include "sync/internal_api/public/util/unrecoverable_error_handler.h"
diff --git a/chrome/browser/sync/glue/non_frontend_data_type_controller.cc b/chrome/browser/sync/glue/non_frontend_data_type_controller.cc
index 584a4c3..b213c09 100644
--- a/chrome/browser/sync/glue/non_frontend_data_type_controller.cc
+++ b/chrome/browser/sync/glue/non_frontend_data_type_controller.cc
@@ -157,10 +157,10 @@
NonFrontendDataTypeController::AssociationResult::~AssociationResult() {}
NonFrontendDataTypeController::NonFrontendDataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
const base::Closure& error_callback,
sync_driver::SyncClient* sync_client)
- : DataTypeController(ui_thread, error_callback),
+ : DirectoryDataTypeController(ui_thread, error_callback),
state_(NOT_RUNNING),
sync_client_(sync_client),
model_associator_(NULL),
@@ -293,13 +293,13 @@
}
NonFrontendDataTypeController::NonFrontendDataTypeController()
- : DataTypeController(base::ThreadTaskRunnerHandle::Get(), base::Closure()),
+ : DirectoryDataTypeController(base::ThreadTaskRunnerHandle::Get(),
+ base::Closure()),
state_(NOT_RUNNING),
sync_client_(NULL),
model_associator_(NULL),
change_processor_(NULL),
- weak_ptr_factory_(this) {
-}
+ weak_ptr_factory_(this) {}
NonFrontendDataTypeController::~NonFrontendDataTypeController() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
diff --git a/chrome/browser/sync/glue/non_frontend_data_type_controller.h b/chrome/browser/sync/glue/non_frontend_data_type_controller.h
index e6e5252..d630eba 100644
--- a/chrome/browser/sync/glue/non_frontend_data_type_controller.h
+++ b/chrome/browser/sync/glue/non_frontend_data_type_controller.h
@@ -13,8 +13,8 @@
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h"
-#include "components/sync_driver/data_type_controller.h"
#include "components/sync_driver/data_type_error_handler.h"
+#include "components/sync_driver/directory_data_type_controller.h"
#include "components/sync_driver/sync_api_component_factory.h"
class Profile;
@@ -45,13 +45,14 @@
// model_safe_group()
// PostTaskOnBackendThread()
// CreateSyncComponents()
-class NonFrontendDataTypeController : public sync_driver::DataTypeController {
+class NonFrontendDataTypeController
+ : public sync_driver::DirectoryDataTypeController {
public:
// For creating non-frontend processor/associator and associating on backend.
class BackendComponentsContainer;
NonFrontendDataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
const base::Closure& error_callback,
sync_driver::SyncClient* sync_client);
diff --git a/chrome/browser/sync/profile_sync_components_factory_impl.h b/chrome/browser/sync/profile_sync_components_factory_impl.h
index 76c75167..f3e99ca 100644
--- a/chrome/browser/sync/profile_sync_components_factory_impl.h
+++ b/chrome/browser/sync/profile_sync_components_factory_impl.h
@@ -96,10 +96,7 @@
// being explicitly enabled/disabled by the command line.
void RegisterCommonDataTypes(syncer::ModelTypeSet disabled_types,
syncer::ModelTypeSet enabled_types);
- // Used to bind a callback to give to DataTypeControllers to disable
- // data types.
- sync_driver::DataTypeController::DisableTypeCallback
- MakeDisableCallbackFor(syncer::ModelType type);
+
void DisableBrokenType(syncer::ModelType type,
const tracked_objects::Location& from_here,
const std::string& message);
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index 1fd4b36..323c25f 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -1158,14 +1158,6 @@
DVLOG(1) << "Setting preferred types for non-blocking DTM";
non_blocking_data_type_manager_.SetPreferredTypes(GetPreferredDataTypes());
- // Give the DataTypeControllers a handle to the now initialized backend
- // as a UserShare.
- for (DataTypeController::TypeMap::iterator it =
- directory_data_type_controllers_.begin();
- it != directory_data_type_controllers_.end(); ++it) {
- it->second->OnUserShareReady(GetUserShare());
- }
-
if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK)
ConfigureDataTypeManager();
else
diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h
index 3a24ff13..620f831d 100644
--- a/chrome/browser/sync/profile_sync_service.h
+++ b/chrome/browser/sync/profile_sync_service.h
@@ -338,6 +338,8 @@
// ProfileSyncService. It declares that this sync type may be activated at
// some point in the future. This function call does not enable or activate
// the syncing of this type
+ // TODO(stanisc): crbug.com/515962: this should merge with
+ // RegisterDataTypeController.
void RegisterNonBlockingType(syncer::ModelType type);
// Called by a component that supports non-blocking sync when it is ready to
@@ -347,6 +349,7 @@
// should result in a message to enable syncing for this type when the sync
// backend is available. If the type is not to be synced, this should result
// in a message that allows the component to delete its local sync state.
+ // TODO(stanisc): crbug.com/515962: review usage of this.
void InitializeNonBlockingType(
syncer::ModelType type,
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
index f49b9667b2..90a7711 100644
--- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
@@ -150,6 +150,7 @@
TestSyncClient(PersonalDataManager* pdm,
const scoped_refptr<AutofillWebDataService>& web_data_service)
: pdm_(pdm),
+ sync_service_(nullptr),
web_data_service_(web_data_service) {}
~TestSyncClient() override {}
@@ -157,6 +158,10 @@
autofill::PersonalDataManager* GetPersonalDataManager() override {
return pdm_;
}
+ sync_driver::SyncService* GetSyncService() override {
+ DCHECK(sync_service_);
+ return sync_service_;
+ }
scoped_refptr<autofill::AutofillWebDataService> GetWebDataService() override {
return web_data_service_;
}
@@ -172,8 +177,13 @@
}
}
+ void SetSyncService(sync_driver::SyncService* sync_service) {
+ sync_service_ = sync_service;
+ }
+
private:
PersonalDataManager* pdm_;
+ sync_driver::SyncService* sync_service_;
scoped_refptr<AutofillWebDataService> web_data_service_;
};
@@ -499,6 +509,7 @@
signin->SetAuthenticatedAccountInfo("12345", "test_user@gmail.com");
sync_service_ = TestProfileSyncService::BuildAutoStartAsyncInit(profile_,
callback);
+ sync_client_->SetSyncService(sync_service_);
ProfileSyncComponentsFactoryMock* components =
sync_service_->components_factory_mock();
diff --git a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
index 412a3bd..3908917 100644
--- a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
@@ -39,6 +39,7 @@
#include "components/sync_driver/data_type_error_handler_mock.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "sync/api/sync_error.h"
+#include "sync/api/sync_merge_result.h"
#include "sync/internal_api/public/change_record.h"
#include "sync/internal_api/public/read_node.h"
#include "sync/internal_api/public/read_transaction.h"
diff --git a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc
index 3b41120..2f4b4b0 100644
--- a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc
+++ b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc
@@ -29,7 +29,6 @@
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "components/sync_driver/about_sync_util.h"
-#include "components/sync_driver/data_type_controller.h"
#include "google_apis/gaia/gaia_constants.h"
#include "sync/internal_api/public/base/progress_marker_map.h"
#include "sync/internal_api/public/util/sync_string_conversions.h"
diff --git a/components/sync_driver.gypi b/components/sync_driver.gypi
index 6f48b25..2abb5ca 100644
--- a/components/sync_driver.gypi
+++ b/components/sync_driver.gypi
@@ -54,6 +54,8 @@
'sync_driver/device_info_sync_service.cc',
'sync_driver/device_info_sync_service.h',
'sync_driver/device_info_tracker.h',
+ 'sync_driver/directory_data_type_controller.cc',
+ 'sync_driver/directory_data_type_controller.h',
'sync_driver/favicon_cache.cc',
'sync_driver/favicon_cache.h',
'sync_driver/frontend_data_type_controller.cc',
diff --git a/components/sync_driver/BUILD.gn b/components/sync_driver/BUILD.gn
index 77f1914..262af6ff 100644
--- a/components/sync_driver/BUILD.gn
+++ b/components/sync_driver/BUILD.gn
@@ -33,6 +33,8 @@
"device_info_sync_service.cc",
"device_info_sync_service.h",
"device_info_tracker.h",
+ "directory_data_type_controller.cc",
+ "directory_data_type_controller.h",
"favicon_cache.cc",
"favicon_cache.h",
"frontend_data_type_controller.cc",
diff --git a/components/sync_driver/data_type_controller.cc b/components/sync_driver/data_type_controller.cc
index dc91999d..0e4bc4f 100644
--- a/components/sync_driver/data_type_controller.cc
+++ b/components/sync_driver/data_type_controller.cc
@@ -11,12 +11,10 @@
namespace sync_driver {
DataTypeController::DataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
const base::Closure& error_callback)
: base::RefCountedDeleteOnMessageLoop<DataTypeController>(ui_thread),
- error_callback_(error_callback),
- user_share_(NULL) {
-}
+ error_callback_(error_callback) {}
DataTypeController::~DataTypeController() {
}
@@ -41,14 +39,6 @@
type);
}
-void DataTypeController::OnUserShareReady(syncer::UserShare* share) {
- user_share_ = share;
-}
-
-syncer::UserShare* DataTypeController::user_share() const {
- return user_share_;
-}
-
bool DataTypeController::ReadyForStart() const {
return true;
}
diff --git a/components/sync_driver/data_type_controller.h b/components/sync_driver/data_type_controller.h
index ab6a517f..d9635d695 100644
--- a/components/sync_driver/data_type_controller.h
+++ b/components/sync_driver/data_type_controller.h
@@ -14,9 +14,7 @@
#include "base/memory/ref_counted_delete_on_message_loop.h"
#include "base/sequenced_task_runner_helpers.h"
#include "components/sync_driver/data_type_error_handler.h"
-#include "sync/api/sync_merge_result.h"
#include "sync/internal_api/public/base/model_type.h"
-#include "sync/internal_api/public/engine/model_safe_worker.h"
#include "sync/internal_api/public/util/unrecoverable_error_handler.h"
namespace base {
@@ -25,12 +23,11 @@
namespace syncer {
class SyncError;
-struct UserShare;
+class SyncMergeResult;
}
namespace sync_driver {
-
-class ChangeProcessor;
+class BackendDataTypeConfigurer;
// Data type controllers need to be refcounted threadsafe, as they may
// need to run model associator or change processor on other threads.
@@ -78,9 +75,6 @@
typedef base::Callback<void(syncer::ModelType,
syncer::SyncError)> ModelLoadCallback;
- typedef base::Callback<void(const tracked_objects::Location& location,
- const std::string&)> DisableTypeCallback;
-
typedef std::map<syncer::ModelType,
scoped_refptr<DataTypeController> > TypeMap;
typedef std::map<syncer::ModelType, DataTypeController::State> StateMap;
@@ -104,6 +98,16 @@
// be invoked.
virtual void StartAssociating(const StartCallback& start_callback) = 0;
+ // Called by DataTypeManager to activate the controlled data type using
+ // one of the implementation specific methods provided by the |configurer|.
+ // This is called (on UI thread) after the data type configuration has
+ // completed successfully.
+ virtual void ActivateDataType(BackendDataTypeConfigurer* configurer) = 0;
+
+ // Called by DataTypeManager to deactivate the controlled data type.
+ // See comments for ModelAssociationManager::OnSingleDataTypeWillStop.
+ virtual void DeactivateDataType(BackendDataTypeConfigurer* configurer) = 0;
+
// Synchronously stops the data type. If StartAssociating has already been
// called but is not done yet it will be aborted. Similarly if LoadModels
// has not completed it will also be aborted.
@@ -120,15 +124,6 @@
// Name of this data type. For logging purposes only.
virtual std::string name() const = 0;
- // The model safe group of this data type. This should reflect the
- // thread that should be used to modify the data type's native
- // model.
- virtual syncer::ModelSafeGroup model_safe_group() const = 0;
-
- // Access to the ChangeProcessor for the type being controlled by |this|.
- // Returns NULL if the ChangeProcessor isn't created or connected.
- virtual ChangeProcessor* GetChangeProcessor() const = 0;
-
// Current state of the data type controller.
virtual State state() const = 0;
@@ -139,10 +134,6 @@
const std::string& message,
syncer::ModelType type) override;
- // Called when the sync backend has initialized. |share| is the
- // UserShare handle to associate model data with.
- void OnUserShareReady(syncer::UserShare* share);
-
// Whether the DataTypeController is ready to start. This is useful if the
// datatype itself must make the decision about whether it should be enabled
// at all (and therefore whether the initial download of the sync data for
@@ -154,8 +145,9 @@
friend class base::RefCountedDeleteOnMessageLoop<DataTypeController>;
friend class base::DeleteHelper<DataTypeController>;
- DataTypeController(scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
- const base::Closure& error_callback);
+ DataTypeController(
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
+ const base::Closure& error_callback);
// If the DTC is waiting for models to load, once the models are
// loaded the datatype service will call this function on DTC to let
@@ -164,14 +156,9 @@
~DataTypeController() override;
- syncer::UserShare* user_share() const;
-
// The callback that will be invoked when an unrecoverable error occurs.
// TODO(sync): protected for use by legacy controllers.
base::Closure error_callback_;
-
- private:
- syncer::UserShare* user_share_;
};
} // namespace sync_driver
diff --git a/components/sync_driver/data_type_controller_mock.h b/components/sync_driver/data_type_controller_mock.h
index acc54b9..a5274530 100644
--- a/components/sync_driver/data_type_controller_mock.h
+++ b/components/sync_driver/data_type_controller_mock.h
@@ -7,6 +7,7 @@
#include "components/sync_driver/data_type_controller.h"
#include "sync/api/sync_error.h"
+#include "sync/api/sync_merge_result.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace sync_driver {
diff --git a/components/sync_driver/data_type_error_handler_mock.h b/components/sync_driver/data_type_error_handler_mock.h
index a5cd6d4..2bb66f5 100644
--- a/components/sync_driver/data_type_error_handler_mock.h
+++ b/components/sync_driver/data_type_error_handler_mock.h
@@ -4,7 +4,7 @@
#ifndef COMPONENTS_SYNC_DRIVER_DATA_TYPE_ERROR_HANDLER_MOCK_H__
#define COMPONENTS_SYNC_DRIVER_DATA_TYPE_ERROR_HANDLER_MOCK_H__
-#include "components/sync_driver/data_type_controller.h"
+#include "components/sync_driver/data_type_error_handler.h"
#include "sync/internal_api/public/base/model_type.h"
#include "testing/gmock/include/gmock/gmock.h"
diff --git a/components/sync_driver/data_type_manager_impl.cc b/components/sync_driver/data_type_manager_impl.cc
index 91e81fe..c16e3438 100644
--- a/components/sync_driver/data_type_manager_impl.cc
+++ b/components/sync_driver/data_type_manager_impl.cc
@@ -16,7 +16,6 @@
#include "base/profiler/scoped_tracker.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/trace_event.h"
-#include "components/sync_driver/data_type_controller.h"
#include "components/sync_driver/data_type_encryption_handler.h"
#include "components/sync_driver/data_type_manager_observer.h"
#include "components/sync_driver/data_type_status_table.h"
@@ -496,7 +495,11 @@
void DataTypeManagerImpl::OnSingleDataTypeWillStop(
syncer::ModelType type,
const syncer::SyncError& error) {
- configurer_->DeactivateDataType(type);
+ DataTypeController::TypeMap::const_iterator c_it = controllers_->find(type);
+ DCHECK(c_it != controllers_->end());
+ // Delegate deactivation to the controller.
+ c_it->second->DeactivateDataType(configurer_);
+
if (error.IsSet()) {
DataTypeStatusTable::TypeErrorMap failed_types;
failed_types[type] = error;
@@ -520,10 +523,8 @@
DataTypeController::TypeMap::const_iterator c_it = controllers_->find(type);
DCHECK(c_it != controllers_->end());
if (c_it->second->state() == DataTypeController::RUNNING) {
- // Tell the backend about the change processor for this type so it can
- // begin routing changes to it.
- configurer_->ActivateDataType(type, c_it->second->model_safe_group(),
- c_it->second->GetChangeProcessor());
+ // Delegate activation to the controller.
+ c_it->second->ActivateDataType(configurer_);
}
if (!debug_info_listener_.IsInitialized())
diff --git a/components/sync_driver/data_type_manager_impl_unittest.cc b/components/sync_driver/data_type_manager_impl_unittest.cc
index 0c511dc..fcb14f4 100644
--- a/components/sync_driver/data_type_manager_impl_unittest.cc
+++ b/components/sync_driver/data_type_manager_impl_unittest.cc
@@ -7,7 +7,6 @@
#include "base/compiler_specific.h"
#include "base/message_loop/message_loop.h"
#include "components/sync_driver/backend_data_type_configurer.h"
-#include "components/sync_driver/data_type_controller.h"
#include "components/sync_driver/data_type_encryption_handler.h"
#include "components/sync_driver/data_type_manager_observer.h"
#include "components/sync_driver/data_type_status_table.h"
diff --git a/components/sync_driver/directory_data_type_controller.cc b/components/sync_driver/directory_data_type_controller.cc
new file mode 100644
index 0000000..ce67b4f8
--- /dev/null
+++ b/components/sync_driver/directory_data_type_controller.cc
@@ -0,0 +1,31 @@
+// Copyright (c) 2015 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/directory_data_type_controller.h"
+
+#include "components/sync_driver/backend_data_type_configurer.h"
+
+namespace sync_driver {
+
+DirectoryDataTypeController::DirectoryDataTypeController(
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
+ const base::Closure& error_callback)
+ : DataTypeController(ui_thread, error_callback) {}
+
+DirectoryDataTypeController::~DirectoryDataTypeController() {}
+
+void DirectoryDataTypeController::ActivateDataType(
+ BackendDataTypeConfigurer* configurer) {
+ // Tell the backend about the change processor for this type so it can
+ // begin routing changes to it.
+ configurer->ActivateDataType(type(), model_safe_group(),
+ GetChangeProcessor());
+}
+
+void DirectoryDataTypeController::DeactivateDataType(
+ BackendDataTypeConfigurer* configurer) {
+ configurer->DeactivateDataType(type());
+}
+
+} // namespace sync_driver
diff --git a/components/sync_driver/directory_data_type_controller.h b/components/sync_driver/directory_data_type_controller.h
new file mode 100644
index 0000000..0ec3081
--- /dev/null
+++ b/components/sync_driver/directory_data_type_controller.h
@@ -0,0 +1,51 @@
+// Copyright 2015 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_DIRECTORY_DATA_TYPE_CONTROLLER_H__
+#define COMPONENTS_SYNC_DRIVER_DIRECTORY_DATA_TYPE_CONTROLLER_H__
+
+#include "components/sync_driver/data_type_controller.h"
+
+#include "sync/internal_api/public/engine/model_safe_worker.h"
+
+namespace sync_driver {
+class ChangeProcessor;
+
+// Base class for Directory based Data type controllers.
+class DirectoryDataTypeController : public DataTypeController {
+ public:
+ // Directory specific implementation of ActivateDataType with the
+ // type specific ChangeProcessor and ModelSafeGroup.
+ // Activates change processing on the controlled data type.
+ // This is called by DataTypeManager, synchronously with data type's
+ // model association.
+ // See BackendDataTypeConfigurer::ActivateDataType for more details.
+ void ActivateDataType(BackendDataTypeConfigurer* configurer) override;
+
+ // Directory specific implementation of DeactivateDataType.
+ // Deactivates change processing on the controlled data type (by removing
+ // the data type's ChangeProcessor registration with the backend).
+ // See BackendDataTypeConfigurer::DeactivateDataType for more details.
+ void DeactivateDataType(BackendDataTypeConfigurer* configurer) override;
+
+ protected:
+ // The model safe group of this data type. This should reflect the
+ // thread that should be used to modify the data type's native
+ // model.
+ virtual syncer::ModelSafeGroup model_safe_group() const = 0;
+
+ // Access to the ChangeProcessor for the type being controlled by |this|.
+ // Returns NULL if the ChangeProcessor isn't created or connected.
+ virtual ChangeProcessor* GetChangeProcessor() const = 0;
+
+ DirectoryDataTypeController(
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
+ const base::Closure& error_callback);
+
+ ~DirectoryDataTypeController() override;
+};
+
+} // namespace sync_driver
+
+#endif // COMPONENTS_SYNC_DRIVER_DIRECTORY_DATA_TYPE_CONTROLLER_H__
diff --git a/components/sync_driver/fake_data_type_controller.cc b/components/sync_driver/fake_data_type_controller.cc
index 093dba92..f4a3499 100644
--- a/components/sync_driver/fake_data_type_controller.cc
+++ b/components/sync_driver/fake_data_type_controller.cc
@@ -5,6 +5,7 @@
#include "components/sync_driver/fake_data_type_controller.h"
#include "base/thread_task_runner_handle.h"
+#include "sync/api/sync_merge_result.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -13,12 +14,12 @@
namespace sync_driver {
FakeDataTypeController::FakeDataTypeController(ModelType type)
- : DataTypeController(base::ThreadTaskRunnerHandle::Get(),
- base::Closure()),
- state_(NOT_RUNNING),
- model_load_delayed_(false),
- type_(type),
- ready_for_start_(true) {}
+ : DirectoryDataTypeController(base::ThreadTaskRunnerHandle::Get(),
+ base::Closure()),
+ state_(NOT_RUNNING),
+ model_load_delayed_(false),
+ type_(type),
+ ready_for_start_(true) {}
FakeDataTypeController::~FakeDataTypeController() {
}
diff --git a/components/sync_driver/fake_data_type_controller.h b/components/sync_driver/fake_data_type_controller.h
index 20b8204..eff5068 100644
--- a/components/sync_driver/fake_data_type_controller.h
+++ b/components/sync_driver/fake_data_type_controller.h
@@ -5,8 +5,8 @@
#ifndef COMPONENTS_SYNC_DRIVER_FAKE_DATA_TYPE_CONTROLLER_H__
#define COMPONENTS_SYNC_DRIVER_FAKE_DATA_TYPE_CONTROLLER_H__
-#include "components/sync_driver/data_type_controller.h"
#include "components/sync_driver/data_type_manager.h"
+#include "components/sync_driver/directory_data_type_controller.h"
namespace sync_driver {
@@ -19,7 +19,7 @@
// behavior of controllers. (It would be easier of the above classes
// used delegation instead of subclassing for per-data-type
// functionality.)
-class FakeDataTypeController : public DataTypeController {
+class FakeDataTypeController : public DirectoryDataTypeController {
public:
explicit FakeDataTypeController(syncer::ModelType type);
diff --git a/components/sync_driver/fake_sync_client.cc b/components/sync_driver/fake_sync_client.cc
index 5b2aa8de..048c7e6 100644
--- a/components/sync_driver/fake_sync_client.cc
+++ b/components/sync_driver/fake_sync_client.cc
@@ -6,18 +6,22 @@
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/password_manager/core/browser/password_store.h"
+#include "components/sync_driver/fake_sync_service.h"
namespace sync_driver {
-FakeSyncClient::FakeSyncClient() : factory_(nullptr) {}
+FakeSyncClient::FakeSyncClient()
+ : factory_(nullptr),
+ sync_service_(make_scoped_ptr(new FakeSyncService())) {}
FakeSyncClient::FakeSyncClient(SyncApiComponentFactory* factory)
- : factory_(factory) {}
+ : factory_(factory),
+ sync_service_(make_scoped_ptr(new FakeSyncService())) {}
FakeSyncClient::~FakeSyncClient() {}
SyncService* FakeSyncClient::GetSyncService() {
- return nullptr;
+ return sync_service_.get();
}
PrefService* FakeSyncClient::GetPrefService() {
diff --git a/components/sync_driver/fake_sync_client.h b/components/sync_driver/fake_sync_client.h
index 6afa4fc..eadeef2 100644
--- a/components/sync_driver/fake_sync_client.h
+++ b/components/sync_driver/fake_sync_client.h
@@ -8,6 +8,7 @@
#include "components/sync_driver/sync_client.h"
namespace sync_driver {
+class FakeSyncService;
// Fake implementation of SyncClient interface for tests.
class FakeSyncClient : public SyncClient {
@@ -29,6 +30,7 @@
private:
SyncApiComponentFactory* factory_;
+ scoped_ptr<FakeSyncService> sync_service_;
DISALLOW_COPY_AND_ASSIGN(FakeSyncClient);
};
diff --git a/components/sync_driver/fake_sync_service.cc b/components/sync_driver/fake_sync_service.cc
index 371d735f..2635f37f 100644
--- a/components/sync_driver/fake_sync_service.cc
+++ b/components/sync_driver/fake_sync_service.cc
@@ -11,8 +11,9 @@
namespace sync_driver {
-FakeSyncService::FakeSyncService() : error_(GoogleServiceAuthError::NONE) {
-}
+FakeSyncService::FakeSyncService()
+ : error_(GoogleServiceAuthError::NONE),
+ user_share_(make_scoped_ptr(new syncer::UserShare())) {}
FakeSyncService::~FakeSyncService() {
}
@@ -132,7 +133,7 @@
}
syncer::UserShare* FakeSyncService::GetUserShare() const {
- return new syncer::UserShare();
+ return user_share_.get();
}
LocalDeviceInfoProvider* FakeSyncService::GetLocalDeviceInfoProvider() const {
diff --git a/components/sync_driver/fake_sync_service.h b/components/sync_driver/fake_sync_service.h
index 67bda39..436487e7 100644
--- a/components/sync_driver/fake_sync_service.h
+++ b/components/sync_driver/fake_sync_service.h
@@ -82,6 +82,7 @@
GoogleServiceAuthError error_;
GURL sync_service_url_;
std::string unrecoverable_error_message_;
+ scoped_ptr<syncer::UserShare> user_share_;
};
} // namespace sync_driver
diff --git a/components/sync_driver/frontend_data_type_controller.cc b/components/sync_driver/frontend_data_type_controller.cc
index 5fe0a86..1312c33 100644
--- a/components/sync_driver/frontend_data_type_controller.cc
+++ b/components/sync_driver/frontend_data_type_controller.cc
@@ -11,16 +11,17 @@
#include "components/sync_driver/sync_client.h"
#include "components/sync_driver/sync_service.h"
#include "sync/api/sync_error.h"
+#include "sync/api/sync_merge_result.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/util/data_type_histogram.h"
namespace browser_sync {
FrontendDataTypeController::FrontendDataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
const base::Closure& error_callback,
sync_driver::SyncClient* sync_client)
- : DataTypeController(ui_thread, error_callback),
+ : DirectoryDataTypeController(ui_thread, error_callback),
sync_client_(sync_client),
state_(NOT_RUNNING) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -136,10 +137,10 @@
}
FrontendDataTypeController::FrontendDataTypeController()
- : DataTypeController(base::ThreadTaskRunnerHandle::Get(), base::Closure()),
+ : DirectoryDataTypeController(base::ThreadTaskRunnerHandle::Get(),
+ base::Closure()),
sync_client_(NULL),
- state_(NOT_RUNNING) {
-}
+ state_(NOT_RUNNING) {}
FrontendDataTypeController::~FrontendDataTypeController() {
DCHECK(thread_checker_.CalledOnValidThread());
diff --git a/components/sync_driver/frontend_data_type_controller.h b/components/sync_driver/frontend_data_type_controller.h
index fdbb96a..8bf4f7d 100644
--- a/components/sync_driver/frontend_data_type_controller.h
+++ b/components/sync_driver/frontend_data_type_controller.h
@@ -11,8 +11,8 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread_checker.h"
-#include "components/sync_driver/data_type_controller.h"
#include "components/sync_driver/data_type_error_handler.h"
+#include "components/sync_driver/directory_data_type_controller.h"
namespace base {
class SingleThreadTaskRunner;
@@ -41,10 +41,11 @@
// NOTE: This class is deprecated! New sync datatypes should be using the
// syncer::SyncableService API and the UIDataTypeController instead.
// TODO(zea): Delete this once all types are on the new API.
-class FrontendDataTypeController : public sync_driver::DataTypeController {
+class FrontendDataTypeController
+ : public sync_driver::DirectoryDataTypeController {
public:
FrontendDataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
const base::Closure& error_callback,
sync_driver::SyncClient* sync_client);
diff --git a/components/sync_driver/generic_change_processor.h b/components/sync_driver/generic_change_processor.h
index b149ba5..40c391c 100644
--- a/components/sync_driver/generic_change_processor.h
+++ b/components/sync_driver/generic_change_processor.h
@@ -11,7 +11,6 @@
#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "components/sync_driver/change_processor.h"
-#include "components/sync_driver/data_type_controller.h"
#include "components/sync_driver/data_type_error_handler.h"
#include "sync/api/attachments/attachment_store.h"
#include "sync/api/sync_change_processor.h"
diff --git a/components/sync_driver/model_association_manager.cc b/components/sync_driver/model_association_manager.cc
index 6924712f..7602385 100644
--- a/components/sync_driver/model_association_manager.cc
+++ b/components/sync_driver/model_association_manager.cc
@@ -11,6 +11,7 @@
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram_macros.h"
#include "base/trace_event/trace_event.h"
+#include "sync/api/sync_merge_result.h"
#include "sync/internal_api/public/base/model_type.h"
using syncer::ModelTypeSet;
diff --git a/components/sync_driver/non_ui_data_type_controller.cc b/components/sync_driver/non_ui_data_type_controller.cc
index ac180f61..bf339fa 100644
--- a/components/sync_driver/non_ui_data_type_controller.cc
+++ b/components/sync_driver/non_ui_data_type_controller.cc
@@ -10,7 +10,10 @@
#include "components/sync_driver/generic_change_processor_factory.h"
#include "components/sync_driver/shared_change_processor_ref.h"
#include "components/sync_driver/sync_api_component_factory.h"
+#include "components/sync_driver/sync_client.h"
+#include "components/sync_driver/sync_service.h"
#include "sync/api/sync_error.h"
+#include "sync/api/sync_merge_result.h"
#include "sync/api/syncable_service.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/util/data_type_histogram.h"
@@ -23,14 +26,13 @@
}
NonUIDataTypeController::NonUIDataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
const base::Closure& error_callback,
SyncClient* sync_client)
- : DataTypeController(ui_thread, error_callback),
+ : DirectoryDataTypeController(ui_thread, error_callback),
sync_client_(sync_client),
state_(NOT_RUNNING),
- ui_thread_(ui_thread) {
-}
+ ui_thread_(ui_thread) {}
void NonUIDataTypeController::LoadModels(
const ModelLoadCallback& model_load_callback) {
@@ -172,7 +174,8 @@
}
NonUIDataTypeController::NonUIDataTypeController()
- : DataTypeController(base::ThreadTaskRunnerHandle::Get(), base::Closure()),
+ : DirectoryDataTypeController(base::ThreadTaskRunnerHandle::Get(),
+ base::Closure()),
sync_client_(NULL) {}
NonUIDataTypeController::~NonUIDataTypeController() {}
@@ -305,13 +308,10 @@
// disconnected at this point, so all our accesses to the syncer from this
// point on are through it.
GenericChangeProcessorFactory factory;
+ DCHECK(sync_client_->GetSyncService());
local_service_ = shared_change_processor->Connect(
- sync_client_,
- &factory,
- user_share(),
- this,
- type(),
- weak_ptr_factory.GetWeakPtr());
+ sync_client_, &factory, sync_client_->GetSyncService()->GetUserShare(),
+ this, type(), weak_ptr_factory.GetWeakPtr());
if (!local_service_.get()) {
syncer::SyncError error(FROM_HERE,
syncer::SyncError::DATATYPE_ERROR,
diff --git a/components/sync_driver/non_ui_data_type_controller.h b/components/sync_driver/non_ui_data_type_controller.h
index 09bee6a6..5bf93ef 100644
--- a/components/sync_driver/non_ui_data_type_controller.h
+++ b/components/sync_driver/non_ui_data_type_controller.h
@@ -11,7 +11,7 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
-#include "components/sync_driver/data_type_controller.h"
+#include "components/sync_driver/directory_data_type_controller.h"
#include "components/sync_driver/shared_change_processor.h"
namespace syncer {
@@ -22,10 +22,10 @@
class SyncClient;
-class NonUIDataTypeController : public DataTypeController {
+class NonUIDataTypeController : public DirectoryDataTypeController {
public:
NonUIDataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
const base::Closure& error_callback,
SyncClient* sync_client);
diff --git a/components/sync_driver/non_ui_data_type_controller_unittest.cc b/components/sync_driver/non_ui_data_type_controller_unittest.cc
index 6c86ae56..ec10a53 100644
--- a/components/sync_driver/non_ui_data_type_controller_unittest.cc
+++ b/components/sync_driver/non_ui_data_type_controller_unittest.cc
@@ -17,6 +17,7 @@
#include "base/threading/thread.h"
#include "base/tracked_objects.h"
#include "components/sync_driver/data_type_controller_mock.h"
+#include "components/sync_driver/fake_sync_client.h"
#include "components/sync_driver/generic_change_processor_factory.h"
#include "components/sync_driver/non_ui_data_type_controller_mock.h"
#include "sync/api/fake_syncable_service.h"
@@ -178,7 +179,8 @@
scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner_;
};
-class SyncNonUIDataTypeControllerTest : public testing::Test {
+class SyncNonUIDataTypeControllerTest : public testing::Test,
+ public FakeSyncClient {
public:
SyncNonUIDataTypeControllerTest()
: backend_thread_("dbthread") {}
@@ -189,7 +191,7 @@
// All of these are refcounted, so don't need to be released.
dtc_mock_ = new StrictMock<NonUIDataTypeControllerMock>();
non_ui_dtc_ = new NonUIDataTypeControllerFake(
- NULL, dtc_mock_.get(), change_processor_.get(),
+ this, dtc_mock_.get(), change_processor_.get(),
backend_thread_.task_runner());
}
diff --git a/components/sync_driver/proxy_data_type_controller.cc b/components/sync_driver/proxy_data_type_controller.cc
index e9b87326..8b4ca03d 100644
--- a/components/sync_driver/proxy_data_type_controller.cc
+++ b/components/sync_driver/proxy_data_type_controller.cc
@@ -4,10 +4,12 @@
#include "components/sync_driver/proxy_data_type_controller.h"
+#include "sync/api/sync_merge_result.h"
+
namespace sync_driver {
ProxyDataTypeController::ProxyDataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
syncer::ModelType type)
: DataTypeController(ui_thread, base::Closure()),
state_(NOT_RUNNING),
@@ -43,15 +45,6 @@
return type_;
}
-syncer::ModelSafeGroup ProxyDataTypeController::model_safe_group() const {
- DCHECK(syncer::ProxyTypes().Has(type_));
- return syncer::GROUP_PASSIVE;
-}
-
-ChangeProcessor* ProxyDataTypeController::GetChangeProcessor() const {
- return NULL;
-}
-
std::string ProxyDataTypeController::name() const {
// For logging only.
return syncer::ModelTypeToString(type());
@@ -70,4 +63,10 @@
NOTIMPLEMENTED();
}
+void ProxyDataTypeController::ActivateDataType(
+ BackendDataTypeConfigurer* configurer) {}
+
+void ProxyDataTypeController::DeactivateDataType(
+ BackendDataTypeConfigurer* configurer) {}
+
} // namespace sync_driver
diff --git a/components/sync_driver/proxy_data_type_controller.h b/components/sync_driver/proxy_data_type_controller.h
index 97a49e5..8aaa902 100644
--- a/components/sync_driver/proxy_data_type_controller.h
+++ b/components/sync_driver/proxy_data_type_controller.h
@@ -18,7 +18,7 @@
class ProxyDataTypeController : public DataTypeController {
public:
explicit ProxyDataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
syncer::ModelType type);
// DataTypeController interface.
@@ -26,10 +26,10 @@
void StartAssociating(const StartCallback& start_callback) override;
void Stop() override;
syncer::ModelType type() const override;
- syncer::ModelSafeGroup model_safe_group() const override;
- ChangeProcessor* GetChangeProcessor() const override;
std::string name() const override;
State state() const override;
+ void ActivateDataType(BackendDataTypeConfigurer* configurer) override;
+ void DeactivateDataType(BackendDataTypeConfigurer* configurer) override;
// DataTypeErrorHandler interface.
void OnSingleDataTypeUnrecoverableError(
diff --git a/components/sync_driver/ui_data_type_controller.cc b/components/sync_driver/ui_data_type_controller.cc
index 1d0aca7..17eee9b 100644
--- a/components/sync_driver/ui_data_type_controller.cc
+++ b/components/sync_driver/ui_data_type_controller.cc
@@ -13,7 +13,9 @@
#include "components/sync_driver/generic_change_processor_factory.h"
#include "components/sync_driver/shared_change_processor_ref.h"
#include "components/sync_driver/sync_client.h"
+#include "components/sync_driver/sync_service.h"
#include "sync/api/sync_error.h"
+#include "sync/api/sync_merge_result.h"
#include "sync/api/syncable_service.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/util/data_type_histogram.h"
@@ -21,19 +23,18 @@
namespace sync_driver {
UIDataTypeController::UIDataTypeController()
- : DataTypeController(base::ThreadTaskRunnerHandle::Get(),
- base::Closure()),
+ : DirectoryDataTypeController(base::ThreadTaskRunnerHandle::Get(),
+ base::Closure()),
sync_client_(NULL),
state_(NOT_RUNNING),
- type_(syncer::UNSPECIFIED) {
-}
+ type_(syncer::UNSPECIFIED) {}
UIDataTypeController::UIDataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
const base::Closure& error_callback,
syncer::ModelType type,
SyncClient* sync_client)
- : DataTypeController(ui_thread, error_callback),
+ : DirectoryDataTypeController(ui_thread, error_callback),
sync_client_(sync_client),
state_(NOT_RUNNING),
type_(type),
@@ -131,12 +132,10 @@
// Connect |shared_change_processor_| to the syncer and get the
// syncer::SyncableService associated with type().
+ DCHECK(sync_client_->GetSyncService());
local_service_ = shared_change_processor_->Connect(
- sync_client_,
- processor_factory_.get(),
- user_share(),
- this,
- type(),
+ sync_client_, processor_factory_.get(),
+ sync_client_->GetSyncService()->GetUserShare(), this, type(),
weak_ptr_factory.GetWeakPtr());
if (!local_service_.get()) {
syncer::SyncError error(FROM_HERE,
diff --git a/components/sync_driver/ui_data_type_controller.h b/components/sync_driver/ui_data_type_controller.h
index a1e086a..9ebc6a3 100644
--- a/components/sync_driver/ui_data_type_controller.h
+++ b/components/sync_driver/ui_data_type_controller.h
@@ -11,7 +11,7 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
-#include "components/sync_driver/data_type_controller.h"
+#include "components/sync_driver/directory_data_type_controller.h"
#include "components/sync_driver/shared_change_processor.h"
namespace base {
@@ -30,10 +30,10 @@
// thread we perform initialization on, so we don't have to worry about thread
// safety. The main start/stop funtionality is implemented by default.
// Note: RefCountedThreadSafe by way of DataTypeController.
-class UIDataTypeController : public DataTypeController {
+class UIDataTypeController : public DirectoryDataTypeController {
public:
UIDataTypeController(
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
const base::Closure& error_callback,
syncer::ModelType type,
SyncClient* sync_client);