diff options
author | blundell <blundell@chromium.org> | 2015-08-27 02:06:02 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-27 09:07:01 +0000 |
commit | 5c45b203238decb5cb2b174f8e70c76a6a3601e4 (patch) | |
tree | 652c4ca1848d5e6e9bfab2bc8385bb6b775adf9b | |
parent | cf934a2f15606819f9d5f214f6b36c129fadb9ac (diff) | |
download | chromium_src-5c45b203238decb5cb2b174f8e70c76a6a3601e4.zip chromium_src-5c45b203238decb5cb2b174f8e70c76a6a3601e4.tar.gz chromium_src-5c45b203238decb5cb2b174f8e70c76a6a3601e4.tar.bz2 |
Componentize FrontendDataTypeController
As part of componentizing //chrome/browser/sync for sharing with iOS,
this CL componentizes FrontendDataTypeController. It does the following:
- Removes the unused dependency on Profile.
- Changes the dependency on ProfileSyncService to be on SyncService.
BUG=512033
Review URL: https://codereview.chromium.org/1319463002
Cr-Commit-Position: refs/heads/master@{#345821}
16 files changed, 63 insertions, 59 deletions
diff --git a/chrome/browser/sync/glue/bookmark_data_type_controller.cc b/chrome/browser/sync/glue/bookmark_data_type_controller.cc index 19d2d02..7bc6d8c 100644 --- a/chrome/browser/sync/glue/bookmark_data_type_controller.cc +++ b/chrome/browser/sync/glue/bookmark_data_type_controller.cc @@ -29,8 +29,8 @@ BookmarkDataTypeController::BookmarkDataTypeController( BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), base::Bind(&ChromeReportUnrecoverableError), profile_sync_factory, - profile, sync_service), + profile_(profile), history_service_observer_(this), bookmark_model_observer_(this) { } @@ -62,9 +62,12 @@ void BookmarkDataTypeController::CleanUpState() { } void BookmarkDataTypeController::CreateSyncComponents() { + // This cast is safe since |sync_service_| is the PSS that was passed in to + // this object's constructor. + // TODO(blundell): Remove this cast once it's no longer needed. + ProfileSyncService* pss = static_cast<ProfileSyncService*>(sync_service_); ProfileSyncComponentsFactory::SyncComponents sync_components = - profile_sync_factory_->CreateBookmarkSyncComponents(sync_service_, - this); + profile_sync_factory_->CreateBookmarkSyncComponents(pss, this); set_model_associator(sync_components.model_associator); set_change_processor(sync_components.change_processor); } diff --git a/chrome/browser/sync/glue/bookmark_data_type_controller.h b/chrome/browser/sync/glue/bookmark_data_type_controller.h index a6a4028..60e58df 100644 --- a/chrome/browser/sync/glue/bookmark_data_type_controller.h +++ b/chrome/browser/sync/glue/bookmark_data_type_controller.h @@ -9,9 +9,12 @@ #include "base/compiler_specific.h" #include "base/scoped_observer.h" -#include "chrome/browser/sync/glue/frontend_data_type_controller.h" #include "components/bookmarks/browser/base_bookmark_model_observer.h" #include "components/history/core/browser/history_service_observer.h" +#include "components/sync_driver/frontend_data_type_controller.h" + +class Profile; +class ProfileSyncService; namespace browser_sync { @@ -50,6 +53,7 @@ class BookmarkDataTypeController : public FrontendDataTypeController, void HistoryServiceBeingDeleted( history::HistoryService* history_service) override; + Profile* const profile_; ScopedObserver<history::HistoryService, history::HistoryServiceObserver> history_service_observer_; ScopedObserver<bookmarks::BookmarkModel, BaseBookmarkModelObserver> diff --git a/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc b/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc index e3b08bc..b2093b7 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc @@ -13,13 +13,13 @@ #include "base/single_thread_task_runner.h" #include "base/thread_task_runner_handle.h" #include "base/tracked_objects.h" -#include "chrome/browser/sync/glue/frontend_data_type_controller.h" -#include "chrome/browser/sync/glue/frontend_data_type_controller_mock.h" #include "chrome/browser/sync/profile_sync_components_factory_mock.h" #include "chrome/browser/sync/profile_sync_service_mock.h" #include "chrome/test/base/profile_mock.h" #include "components/sync_driver/change_processor_mock.h" #include "components/sync_driver/data_type_controller_mock.h" +#include "components/sync_driver/frontend_data_type_controller.h" +#include "components/sync_driver/frontend_data_type_controller_mock.h" #include "components/sync_driver/model_associator_mock.h" #include "content/public/test/test_browser_thread_bundle.h" @@ -41,22 +41,23 @@ class FrontendDataTypeControllerFake : public FrontendDataTypeController { public: FrontendDataTypeControllerFake( ProfileSyncComponentsFactory* profile_sync_factory, - Profile* profile, ProfileSyncService* sync_service, FrontendDataTypeControllerMock* mock) : FrontendDataTypeController(base::ThreadTaskRunnerHandle::Get(), base::Closure(), profile_sync_factory, - profile, sync_service), mock_(mock) {} syncer::ModelType type() const override { return syncer::BOOKMARKS; } private: void CreateSyncComponents() override { + // This cast is safe since |sync_service_| is the PSS that was passed in to + // this object's constructor. + // TODO(blundell): Remove this cast once it's no longer needed. + ProfileSyncService* pss = static_cast<ProfileSyncService*>(sync_service_); ProfileSyncComponentsFactory::SyncComponents sync_components = - profile_sync_factory_-> - CreateBookmarkSyncComponents(sync_service_, this); + profile_sync_factory_->CreateBookmarkSyncComponents(pss, this); model_associator_.reset(sync_components.model_associator); change_processor_.reset(sync_components.change_processor); } @@ -91,7 +92,6 @@ class SyncFrontendDataTypeControllerTest : public testing::Test { dtc_mock_ = new StrictMock<FrontendDataTypeControllerMock>(); frontend_dtc_ = new FrontendDataTypeControllerFake(profile_sync_factory_.get(), - &profile_, &service_, dtc_mock_.get()); } diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index c4c3f41..82e489d 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -279,6 +279,7 @@ class ProfileSyncService : public sync_driver::SyncService, syncer::ModelTypeSet GetPreferredDataTypes() const override; void OnUserChoseDatatypes(bool sync_everything, syncer::ModelTypeSet chosen_types) override; + void DeactivateDataType(syncer::ModelType type) override; void SetSyncSetupCompleted() override; bool FirstSetupInProgress() const override; void SetSetupInProgress(bool setup_in_progress) override; @@ -546,10 +547,6 @@ class ProfileSyncService : public sync_driver::SyncService, // it easier to iterate over its elements when constructing that page. base::Value* GetTypeStatusMap() const; - // Overridden by tests. - // TODO(zea): Remove these and have the dtc's call directly into the SBH. - virtual void DeactivateDataType(syncer::ModelType type); - // SyncPrefObserver implementation. void OnSyncManagedPrefChange(bool is_sync_managed) override; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index dc323e1..b590fcd 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2871,8 +2871,6 @@ 'browser/sync/glue/chrome_report_unrecoverable_error.h', 'browser/sync/glue/extensions_activity_monitor.cc', 'browser/sync/glue/extensions_activity_monitor.h', - 'browser/sync/glue/frontend_data_type_controller.cc', - 'browser/sync/glue/frontend_data_type_controller.h', 'browser/sync/glue/history_delete_directives_data_type_controller.cc', 'browser/sync/glue/history_delete_directives_data_type_controller.h', 'browser/sync/glue/history_model_worker.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index cb7086a..874eb25 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -239,8 +239,6 @@ 'browser/sync/glue/autofill_data_type_controller_unittest.cc', 'browser/sync/glue/bookmark_data_type_controller_unittest.cc', 'browser/sync/glue/browser_thread_model_worker_unittest.cc', - 'browser/sync/glue/frontend_data_type_controller_mock.cc', - 'browser/sync/glue/frontend_data_type_controller_mock.h', 'browser/sync/glue/frontend_data_type_controller_unittest.cc', 'browser/sync/glue/local_device_info_provider_unittest.cc', 'browser/sync/glue/non_frontend_data_type_controller_mock.cc', diff --git a/components/autofill/core/browser/options_util_unittest.cc b/components/autofill/core/browser/options_util_unittest.cc index 79361ec..968fbad 100644 --- a/components/autofill/core/browser/options_util_unittest.cc +++ b/components/autofill/core/browser/options_util_unittest.cc @@ -36,6 +36,7 @@ class SyncServiceMock : public sync_driver::SyncService { MOCK_CONST_METHOD0(GetPreferredDataTypes, syncer::ModelTypeSet()); MOCK_METHOD2(OnUserChoseDatatypes, void(bool sync_everything, syncer::ModelTypeSet chosen_types)); + MOCK_METHOD1(DeactivateDataType, void(syncer::ModelType type)); MOCK_METHOD0(SetSyncSetupCompleted, void()); MOCK_CONST_METHOD0(FirstSetupInProgress, bool()); MOCK_METHOD1(SetSetupInProgress, void(bool)); diff --git a/components/sync_driver.gypi b/components/sync_driver.gypi index 8a51bb1..9b814fc 100644 --- a/components/sync_driver.gypi +++ b/components/sync_driver.gypi @@ -53,6 +53,8 @@ 'sync_driver/device_info_tracker.h', 'sync_driver/favicon_cache.cc', 'sync_driver/favicon_cache.h', + 'sync_driver/frontend_data_type_controller.cc', + 'sync_driver/frontend_data_type_controller.h', 'sync_driver/generic_change_processor.cc', 'sync_driver/generic_change_processor.h', 'sync_driver/generic_change_processor_factory.cc', @@ -164,6 +166,8 @@ 'sync_driver/fake_generic_change_processor.h', 'sync_driver/fake_sync_service.cc', 'sync_driver/fake_sync_service.h', + 'sync_driver/frontend_data_type_controller_mock.cc', + 'sync_driver/frontend_data_type_controller_mock.h', 'sync_driver/local_device_info_provider_mock.cc', 'sync_driver/local_device_info_provider_mock.h', 'sync_driver/model_associator_mock.cc', diff --git a/components/sync_driver/BUILD.gn b/components/sync_driver/BUILD.gn index f1c8963..c642350 100644 --- a/components/sync_driver/BUILD.gn +++ b/components/sync_driver/BUILD.gn @@ -33,6 +33,8 @@ source_set("sync_driver") { "device_info_tracker.h", "favicon_cache.cc", "favicon_cache.h", + "frontend_data_type_controller.cc", + "frontend_data_type_controller.h", "generic_change_processor.cc", "generic_change_processor.h", "generic_change_processor_factory.cc", @@ -136,6 +138,8 @@ source_set("test_support") { "fake_data_type_controller.h", "fake_generic_change_processor.cc", "fake_generic_change_processor.h", + "frontend_data_type_controller_mock.cc", + "frontend_data_type_controller_mock.h", "local_device_info_provider_mock.cc", "local_device_info_provider_mock.h", "model_associator_mock.cc", diff --git a/components/sync_driver/fake_sync_service.cc b/components/sync_driver/fake_sync_service.cc index d502010..fc10ac7 100644 --- a/components/sync_driver/fake_sync_service.cc +++ b/components/sync_driver/fake_sync_service.cc @@ -63,6 +63,9 @@ void FakeSyncService::OnUserChoseDatatypes(bool sync_everything, syncer::ModelTypeSet chosen_types) { } +void FakeSyncService::DeactivateDataType(syncer::ModelType type) { +} + void FakeSyncService::SetSyncSetupCompleted() { } diff --git a/components/sync_driver/fake_sync_service.h b/components/sync_driver/fake_sync_service.h index a6b6c72..46023ee 100644 --- a/components/sync_driver/fake_sync_service.h +++ b/components/sync_driver/fake_sync_service.h @@ -38,6 +38,7 @@ class FakeSyncService : public sync_driver::SyncService { syncer::ModelTypeSet GetPreferredDataTypes() const override; void OnUserChoseDatatypes(bool sync_everything, syncer::ModelTypeSet chosen_types) override; + void DeactivateDataType(syncer::ModelType type) override; void SetSyncSetupCompleted() override; bool FirstSetupInProgress() const override; void SetSetupInProgress(bool setup_in_progress) override; diff --git a/chrome/browser/sync/glue/frontend_data_type_controller.cc b/components/sync_driver/frontend_data_type_controller.cc index 1a82baf..42500a2 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller.cc +++ b/components/sync_driver/frontend_data_type_controller.cc @@ -2,49 +2,37 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/sync/glue/frontend_data_type_controller.h" +#include "components/sync_driver/frontend_data_type_controller.h" #include "base/logging.h" #include "base/thread_task_runner_handle.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" -#include "chrome/browser/sync/profile_sync_service.h" #include "components/sync_driver/change_processor.h" #include "components/sync_driver/model_associator.h" #include "components/sync_driver/profile_sync_components_factory.h" -#include "content/public/browser/browser_thread.h" +#include "components/sync_driver/sync_service.h" #include "sync/api/sync_error.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/util/data_type_histogram.h" -using content::BrowserThread; - namespace browser_sync { -// TODO(tim): Legacy controllers are being left behind in componentization -// effort for now, hence passing null DisableTypeCallback and still having -// a dependency on ProfileSyncService. That dep can probably be removed -// without too much work. FrontendDataTypeController::FrontendDataTypeController( scoped_refptr<base::SingleThreadTaskRunner> ui_thread, const base::Closure& error_callback, ProfileSyncComponentsFactory* profile_sync_factory, - Profile* profile, - ProfileSyncService* sync_service) + sync_driver::SyncService* sync_service) : DataTypeController(ui_thread, error_callback), profile_sync_factory_(profile_sync_factory), - profile_(profile), sync_service_(sync_service), state_(NOT_RUNNING) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(profile_sync_factory); - DCHECK(profile); DCHECK(sync_service); } void FrontendDataTypeController::LoadModels( const ModelLoadCallback& model_load_callback) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(thread_checker_.CalledOnValidThread()); model_load_callback_ = model_load_callback; if (state_ != NOT_RUNNING) { @@ -69,7 +57,7 @@ void FrontendDataTypeController::LoadModels( } void FrontendDataTypeController::OnModelLoaded() { - DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(thread_checker_.CalledOnValidThread()); DCHECK_EQ(state_, MODEL_STARTING); state_ = MODEL_LOADED; @@ -78,7 +66,7 @@ void FrontendDataTypeController::OnModelLoaded() { void FrontendDataTypeController::StartAssociating( const StartCallback& start_callback) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(!start_callback.is_null()); DCHECK_EQ(state_, MODEL_LOADED); @@ -90,7 +78,7 @@ void FrontendDataTypeController::StartAssociating( } void FrontendDataTypeController::Stop() { - DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(thread_checker_.CalledOnValidThread()); if (state_ == NOT_RUNNING) return; @@ -153,13 +141,12 @@ void FrontendDataTypeController::OnSingleDataTypeUnrecoverableError( FrontendDataTypeController::FrontendDataTypeController() : DataTypeController(base::ThreadTaskRunnerHandle::Get(), base::Closure()), profile_sync_factory_(NULL), - profile_(NULL), sync_service_(NULL), state_(NOT_RUNNING) { } FrontendDataTypeController::~FrontendDataTypeController() { - DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(thread_checker_.CalledOnValidThread()); } bool FrontendDataTypeController::StartModels() { @@ -244,7 +231,7 @@ void FrontendDataTypeController::CleanUp() { } void FrontendDataTypeController::AbortModelLoad() { - DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(thread_checker_.CalledOnValidThread()); CleanUp(); state_ = NOT_RUNNING; } @@ -253,7 +240,7 @@ void FrontendDataTypeController::StartDone( ConfigureResult start_result, const syncer::SyncMergeResult& local_merge_result, const syncer::SyncMergeResult& syncer_merge_result) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(thread_checker_.CalledOnValidThread()); if (!IsSuccessfulResult(start_result)) { if (IsUnrecoverableResult(start_result)) RecordUnrecoverableError(FROM_HERE, "StartFailed"); @@ -271,7 +258,7 @@ void FrontendDataTypeController::StartDone( } void FrontendDataTypeController::RecordAssociationTime(base::TimeDelta time) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(thread_checker_.CalledOnValidThread()); #define PER_DATA_TYPE_MACRO(type_str) \ UMA_HISTOGRAM_TIMES("Sync." type_str "AssociationTime", time); SYNC_DATA_TYPE_HISTOGRAM(type()); @@ -279,7 +266,7 @@ void FrontendDataTypeController::RecordAssociationTime(base::TimeDelta time) { } void FrontendDataTypeController::RecordStartFailure(ConfigureResult result) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(thread_checker_.CalledOnValidThread()); UMA_HISTOGRAM_ENUMERATION("Sync.DataTypeStartFailures", ModelTypeToHistogramInt(type()), syncer::MODEL_TYPE_COUNT); diff --git a/chrome/browser/sync/glue/frontend_data_type_controller.h b/components/sync_driver/frontend_data_type_controller.h index 2bd7136..2443952 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller.h +++ b/components/sync_driver/frontend_data_type_controller.h @@ -2,19 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_H__ -#define CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_H__ +#ifndef COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_H__ +#define COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_H__ #include <string> #include "base/basictypes.h" #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" -class Profile; -class ProfileSyncService; class ProfileSyncComponentsFactory; namespace base { @@ -29,6 +28,7 @@ class SyncError; namespace sync_driver { class AssociatorInterface; class ChangeProcessor; +class SyncService; } namespace browser_sync { @@ -49,8 +49,7 @@ class FrontendDataTypeController : public sync_driver::DataTypeController { scoped_refptr<base::SingleThreadTaskRunner> ui_thread, const base::Closure& error_callback, ProfileSyncComponentsFactory* profile_sync_factory, - Profile* profile, - ProfileSyncService* sync_service); + sync_driver::SyncService* sync_service); // DataTypeController interface. void LoadModels(const ModelLoadCallback& model_load_callback) override; @@ -115,8 +114,7 @@ class FrontendDataTypeController : public sync_driver::DataTypeController { const std::string& message); ProfileSyncComponentsFactory* const profile_sync_factory_; - Profile* const profile_; - ProfileSyncService* const sync_service_; + sync_driver::SyncService* const sync_service_; State state_; @@ -138,9 +136,11 @@ class FrontendDataTypeController : public sync_driver::DataTypeController { // to a failure or abort or stop. void CleanUp(); + base::ThreadChecker thread_checker_; + DISALLOW_COPY_AND_ASSIGN(FrontendDataTypeController); }; } // namespace browser_sync -#endif // CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_H__ +#endif // COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_H__ diff --git a/chrome/browser/sync/glue/frontend_data_type_controller_mock.cc b/components/sync_driver/frontend_data_type_controller_mock.cc index 405d328..c2fcd03 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller_mock.cc +++ b/components/sync_driver/frontend_data_type_controller_mock.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/sync/glue/frontend_data_type_controller_mock.h" +#include "components/sync_driver/frontend_data_type_controller_mock.h" namespace browser_sync { diff --git a/chrome/browser/sync/glue/frontend_data_type_controller_mock.h b/components/sync_driver/frontend_data_type_controller_mock.h index 333cec2..b3479dc 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller_mock.h +++ b/components/sync_driver/frontend_data_type_controller_mock.h @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_MOCK_H__ -#define CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_MOCK_H__ +#ifndef COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_MOCK_H__ +#define COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_MOCK_H__ -#include "chrome/browser/sync/glue/frontend_data_type_controller.h" +#include "components/sync_driver/frontend_data_type_controller.h" #include "sync/api/sync_error.h" #include "testing/gmock/include/gmock/gmock.h" @@ -55,4 +55,4 @@ class FrontendDataTypeControllerMock : public FrontendDataTypeController { } // namespace browser_sync -#endif // CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_MOCK_H__ +#endif // COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_MOCK_H__ diff --git a/components/sync_driver/sync_service.h b/components/sync_driver/sync_service.h index 1e47a6c..2a65909 100644 --- a/components/sync_driver/sync_service.h +++ b/components/sync_driver/sync_service.h @@ -118,6 +118,10 @@ class SyncService : public DataTypeEncryptionHandler { virtual void OnUserChoseDatatypes(bool sync_everything, syncer::ModelTypeSet chosen_types) = 0; + // Overridden by tests. + // TODO(zea): Remove these and have the dtc's call directly into the SBH. + virtual void DeactivateDataType(syncer::ModelType type) = 0; + // Called whe Sync has been setup by the user and can be started. virtual void SetSyncSetupCompleted() = 0; |