diff options
author | loyso <loyso@chromium.org> | 2015-11-16 19:25:41 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-17 03:26:14 +0000 |
commit | 958471f62fe440dbde14ac8ad0292f0af5da83b3 (patch) | |
tree | b336f9fd4a936ced8fcd0b60070f5464784f857f | |
parent | a2e8a4030fc3da64a9d3c261fc5402213dcc443d (diff) | |
download | chromium_src-958471f62fe440dbde14ac8ad0292f0af5da83b3.zip chromium_src-958471f62fe440dbde14ac8ad0292f0af5da83b3.tar.gz chromium_src-958471f62fe440dbde14ac8ad0292f0af5da83b3.tar.bz2 |
Revert of [Sync] Componentize ProfileSyncComponentsFactoryImpl (patchset #8 id:180001 of https://codereview.chromium.org/1421003007/ )
Reason for revert:
Fails unit tests on Android builds:
ProfileSyncServiceFactoryTest.CreatePSSDisableOne
ProfileSyncServiceFactoryTest.CreatePSSDisableMultiple
ProfileSyncServiceFactoryTest.CreatePSSDefault
Original issue's description:
> [Sync] Componentize ProfileSyncComponentsFactoryImpl
>
> Componentize ProfileSyncComponentsFactoryImpl into browser_sync component.
> As part of this, pull out RegisterDesktopDatatypes method into ChromeSyncClient.
> Similarly, a RegisterAndroidDataTypes is created instead for Android
> platforms.
>
> Because profile_sync_components_factory_impl_unittest.cc was really duplicating
> and testing the logic from ProfileSyncServiceFactory, went ahead and moved the
> test cases over into profile_sync_service_factory_unittest.cc.
>
> BUG=512768
> TBR=rdevlin.cronin@chromium.org
>
> Committed: https://crrev.com/7db382299ca33ffb369f9c79a5331bbfbab259bc
> Cr-Commit-Position: refs/heads/master@{#359916}
TBR=blundell@chromium.org,rdevlin.cronin@chromium.org,zea@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=512768
Review URL: https://codereview.chromium.org/1451023005
Cr-Commit-Position: refs/heads/master@{#359988}
28 files changed, 583 insertions, 577 deletions
diff --git a/chrome/browser/extensions/api/preferences_private/preferences_private_apitest.cc b/chrome/browser/extensions/api/preferences_private/preferences_private_apitest.cc index 57c7350..8393421 100644 --- a/chrome/browser/extensions/api/preferences_private/preferences_private_apitest.cc +++ b/chrome/browser/extensions/api/preferences_private/preferences_private_apitest.cc @@ -49,7 +49,9 @@ class FakeProfileSyncService : public ProfileSyncService { public: explicit FakeProfileSyncService(Profile* profile) : ProfileSyncService( - make_scoped_ptr(new browser_sync::ChromeSyncClient(profile)), + make_scoped_ptr(new browser_sync::ChromeSyncClient( + profile, + make_scoped_ptr(new SyncApiComponentFactoryMock()))), make_scoped_ptr<SigninManagerWrapper>(NULL), ProfileOAuth2TokenServiceFactory::GetForProfile(profile), browser_sync::MANUAL_START, @@ -64,11 +66,7 @@ class FakeProfileSyncService : public ProfileSyncService { content::BrowserThread::FILE), content::BrowserThread::GetBlockingPool()), sync_initialized_(true), - initialized_state_violation_(false) { - static_cast<browser_sync::ChromeSyncClient*>(GetSyncClient()) - ->SetSyncApiComponentFactoryForTesting( - make_scoped_ptr(new SyncApiComponentFactoryMock())); - } + initialized_state_violation_(false) {} ~FakeProfileSyncService() override {} diff --git a/chrome/browser/extensions/api/sessions/sessions_apitest.cc b/chrome/browser/extensions/api/sessions/sessions_apitest.cc index c53b02b..2999003 100644 --- a/chrome/browser/extensions/api/sessions/sessions_apitest.cc +++ b/chrome/browser/extensions/api/sessions/sessions_apitest.cc @@ -137,12 +137,10 @@ scoped_ptr<KeyedService> ExtensionSessionsTest::BuildProfileSyncService( sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id"))); - Profile* profile = static_cast<Profile*>(context); - ProfileSyncServiceMock* sync_service = new ProfileSyncServiceMock( - make_scoped_ptr(new browser_sync::ChromeSyncClient(profile)), profile); - static_cast<browser_sync::ChromeSyncClient*>(sync_service->GetSyncClient()) - ->SetSyncApiComponentFactoryForTesting(factory.Pass()); - return make_scoped_ptr(sync_service); + return make_scoped_ptr(new ProfileSyncServiceMock( + make_scoped_ptr(new browser_sync::ChromeSyncClient( + static_cast<Profile*>(context), factory.Pass())), + static_cast<Profile*>(context))); } void ExtensionSessionsTest::CreateTestProfileSyncService() { diff --git a/chrome/browser/sync/chrome_sync_client.cc b/chrome/browser/sync/chrome_sync_client.cc index 7c5e70d2..78e18831 100644 --- a/chrome/browser/sync/chrome_sync_client.cc +++ b/chrome/browser/sync/chrome_sync_client.cc @@ -5,7 +5,6 @@ #include "chrome/browser/sync/chrome_sync_client.h" #include "base/bind.h" -#include "base/command_line.h" #include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/browsing_data/browsing_data_helper.h" @@ -17,9 +16,7 @@ #include "chrome/browser/prefs/pref_service_syncable_util.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/sync/glue/sync_start_util.h" -#include "chrome/browser/sync/glue/theme_data_type_controller.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" #include "chrome/browser/themes/theme_service.h" @@ -28,36 +25,26 @@ #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" #include "chrome/browser/undo/bookmark_undo_service_factory.h" #include "chrome/browser/web_data_service_factory.h" -#include "chrome/common/channel_info.h" -#include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "components/autofill/core/browser/webdata/autocomplete_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" -#include "components/browser_sync/browser/profile_sync_components_factory_impl.h" #include "components/browser_sync/browser/profile_sync_service.h" -#include "components/browser_sync/common/browser_sync_switches.h" #include "components/dom_distiller/core/dom_distiller_service.h" #include "components/history/core/browser/history_model_worker.h" #include "components/history/core/browser/history_service.h" #include "components/invalidation/impl/profile_invalidation_provider.h" #include "components/password_manager/core/browser/password_store.h" #include "components/password_manager/sync/browser/password_model_worker.h" -#include "components/search_engines/search_engine_data_type_controller.h" -#include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/sync_driver/glue/browser_thread_model_worker.h" -#include "components/sync_driver/glue/chrome_report_unrecoverable_error.h" #include "components/sync_driver/glue/ui_model_worker.h" #include "components/sync_driver/sync_api_component_factory.h" -#include "components/sync_driver/sync_util.h" -#include "components/sync_driver/ui_data_type_controller.h" #include "components/sync_sessions/sync_sessions_client.h" #include "components/syncable_prefs/pref_service_syncable.h" #include "content/public/browser/browser_thread.h" #include "sync/internal_api/public/engine/passive_model_worker.h" -#include "ui/base/device_form_factor.h" #if defined(ENABLE_APP_LIST) #include "chrome/browser/ui/app_list/app_list_syncable_service.h" @@ -100,12 +87,6 @@ #endif using content::BrowserThread; -#if defined(ENABLE_EXTENSIONS) -using browser_sync::ExtensionDataTypeController; -using browser_sync::ExtensionSettingDataTypeController; -#endif -using browser_sync::SearchEngineDataTypeController; -using sync_driver::UIDataTypeController; namespace browser_sync { @@ -170,40 +151,23 @@ class SyncSessionsClientImpl : public sync_sessions::SyncSessionsClient { DISALLOW_COPY_AND_ASSIGN(SyncSessionsClientImpl); }; -ChromeSyncClient::ChromeSyncClient(Profile* profile) +ChromeSyncClient::ChromeSyncClient( + Profile* profile, + scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory) : profile_(profile), + component_factory_(component_factory.Pass()), sync_sessions_client_(new SyncSessionsClientImpl(profile)), - browsing_data_remover_observer_(NULL), - weak_ptr_factory_(this) {} + browsing_data_remover_observer_(NULL) {} ChromeSyncClient::~ChromeSyncClient() { } void ChromeSyncClient::Initialize(sync_driver::SyncService* sync_service) { DCHECK_CURRENTLY_ON(BrowserThread::UI); - // Component factory may already be set in tests. - if (!GetSyncApiComponentFactory()) { - const GURL sync_service_url = GetSyncServiceURL( - *base::CommandLine::ForCurrentProcess(), chrome::GetChannel()); - ProfileOAuth2TokenService* token_service = - ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); - net::URLRequestContextGetter* url_request_context_getter = - profile_->GetRequestContext(); - - component_factory_.reset(new ProfileSyncComponentsFactoryImpl( - this, chrome::GetChannel(), chrome::GetVersionString(), - ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET, - *base::CommandLine::ForCurrentProcess(), - prefs::kSavingBrowserHistoryDisabled, sync_service_url, - content::BrowserThread::GetMessageLoopProxyForThread( - content::BrowserThread::UI), - content::BrowserThread::GetMessageLoopProxyForThread( - content::BrowserThread::DB), - token_service, url_request_context_getter)); - } sync_service_ = sync_service; web_data_service_ = GetWebDataService(); password_store_ = GetPasswordStore(); + component_factory_->RegisterDataTypes(this); } sync_driver::SyncService* ChromeSyncClient::GetSyncService() { @@ -259,17 +223,6 @@ base::Closure ChromeSyncClient::GetPasswordStateChangedCallback() { base::Unretained(profile_)); } -sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod -ChromeSyncClient::GetRegisterPlatformTypesCallback() { - return base::Bind( -#ifdef OS_ANDROID - &ChromeSyncClient::RegisterAndroidDataTypes, -#else - &ChromeSyncClient::RegisterDesktopDataTypes, -#endif // OS_ANDROID - weak_ptr_factory_.GetWeakPtr()); -} - scoped_refptr<autofill::AutofillWebDataService> ChromeSyncClient::GetWebDataService() { DCHECK_CURRENTLY_ON(BrowserThread::UI); @@ -488,132 +441,4 @@ void ChromeSyncClient::SetBrowsingDataRemoverObserverForTesting( browsing_data_remover_observer_ = observer; } -void ChromeSyncClient::SetSyncApiComponentFactoryForTesting( - scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory) { - component_factory_ = component_factory.Pass(); -} - -void ChromeSyncClient::RegisterDesktopDataTypes( - syncer::ModelTypeSet disabled_types, - syncer::ModelTypeSet enabled_types) { - sync_driver::SyncService* sync_service = GetSyncService(); - base::Closure error_callback = - base::Bind(&ChromeReportUnrecoverableError, chrome::GetChannel()); - const scoped_refptr<base::SingleThreadTaskRunner> ui_thread = - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); - -#if defined(ENABLE_EXTENSIONS) - // App sync is enabled by default. Register unless explicitly - // disabled. - if (!disabled_types.Has(syncer::APPS)) { - sync_service->RegisterDataTypeController(new ExtensionDataTypeController( - syncer::APPS, error_callback, this, profile_)); - } - - // Extension sync is enabled by default. Register unless explicitly - // disabled. - if (!disabled_types.Has(syncer::EXTENSIONS)) { - sync_service->RegisterDataTypeController(new ExtensionDataTypeController( - syncer::EXTENSIONS, error_callback, this, profile_)); - } -#endif - - // Preference sync is enabled by default. Register unless explicitly - // disabled. - if (!disabled_types.Has(syncer::PREFERENCES)) { - sync_service->RegisterDataTypeController(new UIDataTypeController( - ui_thread, error_callback, syncer::PREFERENCES, this)); - } - -#if defined(ENABLE_THEMES) - // Theme sync is enabled by default. Register unless explicitly disabled. - if (!disabled_types.Has(syncer::THEMES)) { - sync_service->RegisterDataTypeController( - new ThemeDataTypeController(error_callback, this, profile_)); - } -#endif - - // Search Engine sync is enabled by default. Register unless explicitly - // disabled. - if (!disabled_types.Has(syncer::SEARCH_ENGINES)) { - sync_service->RegisterDataTypeController(new SearchEngineDataTypeController( - ui_thread, error_callback, this, - TemplateURLServiceFactory::GetForProfile(profile_))); - } - -#if defined(ENABLE_EXTENSIONS) - // Extension setting sync is enabled by default. Register unless explicitly - // disabled. - if (!disabled_types.Has(syncer::EXTENSION_SETTINGS)) { - sync_service->RegisterDataTypeController( - new ExtensionSettingDataTypeController(syncer::EXTENSION_SETTINGS, - error_callback, this, profile_)); - } - - // App setting sync is enabled by default. Register unless explicitly - // disabled. - if (!disabled_types.Has(syncer::APP_SETTINGS)) { - sync_service->RegisterDataTypeController( - new ExtensionSettingDataTypeController(syncer::APP_SETTINGS, - error_callback, this, profile_)); - } -#endif - -#if defined(ENABLE_APP_LIST) - if (app_list::switches::IsAppListSyncEnabled()) { - sync_service->RegisterDataTypeController(new UIDataTypeController( - ui_thread, error_callback, syncer::APP_LIST, this)); - } -#endif - -#if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) - // Dictionary sync is enabled by default. - if (!disabled_types.Has(syncer::DICTIONARY)) { - sync_service->RegisterDataTypeController(new UIDataTypeController( - ui_thread, error_callback, syncer::DICTIONARY, this)); - } -#endif - -#if defined(ENABLE_SUPERVISED_USERS) - sync_service->RegisterDataTypeController( - new SupervisedUserSyncDataTypeController(syncer::SUPERVISED_USER_SETTINGS, - error_callback, this, profile_)); - sync_service->RegisterDataTypeController( - new SupervisedUserSyncDataTypeController( - syncer::SUPERVISED_USER_WHITELISTS, error_callback, this, profile_)); - sync_service->RegisterDataTypeController( - new SupervisedUserSyncDataTypeController(syncer::SUPERVISED_USERS, - error_callback, this, profile_)); - sync_service->RegisterDataTypeController( - new SupervisedUserSyncDataTypeController( - syncer::SUPERVISED_USER_SHARED_SETTINGS, error_callback, this, - profile_)); -#endif - -#if defined(OS_CHROMEOS) - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableWifiCredentialSync) && - !disabled_types.Has(syncer::WIFI_CREDENTIALS)) { - sync_service->RegisterDataTypeController(new UIDataTypeController( - ui_thread, error_callback, syncer::WIFI_CREDENTIALS, this)); - } -#endif -} - -void ChromeSyncClient::RegisterAndroidDataTypes( - syncer::ModelTypeSet disabled_types, - syncer::ModelTypeSet enabled_types) { - sync_driver::SyncService* sync_service = GetSyncService(); - base::Closure error_callback = - base::Bind(&ChromeReportUnrecoverableError, chrome::GetChannel()); -#if defined(ENABLE_SUPERVISED_USERS) - sync_service->RegisterDataTypeController( - new SupervisedUserSyncDataTypeController(syncer::SUPERVISED_USER_SETTINGS, - error_callback, this, profile_)); - sync_service->RegisterDataTypeController( - new SupervisedUserSyncDataTypeController( - syncer::SUPERVISED_USER_WHITELISTS, error_callback, this, profile_)); -#endif -} - } // namespace browser_sync diff --git a/chrome/browser/sync/chrome_sync_client.h b/chrome/browser/sync/chrome_sync_client.h index f43249e..7d16e8a 100644 --- a/chrome/browser/sync/chrome_sync_client.h +++ b/chrome/browser/sync/chrome_sync_client.h @@ -21,7 +21,9 @@ namespace browser_sync { class ChromeSyncClient : public sync_driver::SyncClient { public: - explicit ChromeSyncClient(Profile* profile); + ChromeSyncClient( + Profile* profile, + scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory); ~ChromeSyncClient() override; // SyncClient implementation. @@ -35,8 +37,6 @@ class ChromeSyncClient : public sync_driver::SyncClient { sync_driver::ClearBrowsingDataCallback GetClearBrowsingDataCallback() override; base::Closure GetPasswordStateChangedCallback() override; - sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod - GetRegisterPlatformTypesCallback() override; autofill::PersonalDataManager* GetPersonalDataManager() override; invalidation::InvalidationService* GetInvalidationService() override; scoped_refptr<autofill::AutofillWebDataService> GetWebDataService() override; @@ -50,29 +50,15 @@ class ChromeSyncClient : public sync_driver::SyncClient { syncer::WorkerLoopDestructionObserver* observer) override; sync_driver::SyncApiComponentFactory* GetSyncApiComponentFactory() override; - // Helpers for overriding getters in tests. + // Helper for testing rollback. void SetBrowsingDataRemoverObserverForTesting( BrowsingDataRemover::Observer* observer); - void SetSyncApiComponentFactoryForTesting( - scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory); private: - // Register data types which are enabled on desktop platforms only. - // |disabled_types| and |enabled_types| correspond only to those types - // being explicitly disabled/enabled by the command line. - void RegisterDesktopDataTypes(syncer::ModelTypeSet disabled_types, - syncer::ModelTypeSet enabled_types); - - // Register data types which are enabled on Android platforms only. - // |disabled_types| and |enabled_types| correspond only to those types - // being explicitly disabled/enabled by the command line. - void RegisterAndroidDataTypes(syncer::ModelTypeSet disabled_types, - syncer::ModelTypeSet enabled_types); + Profile* const profile_; void ClearBrowsingData(base::Time start, base::Time end); - Profile* const profile_; - // The sync api component factory in use by this client. scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory_; @@ -95,8 +81,6 @@ class ChromeSyncClient : public sync_driver::SyncClient { // Used in integration tests. BrowsingDataRemover::Observer* browsing_data_remover_observer_; - base::WeakPtrFactory<ChromeSyncClient> weak_ptr_factory_; - DISALLOW_COPY_AND_ASSIGN(ChromeSyncClient); }; diff --git a/components/browser_sync/browser/profile_sync_components_factory_impl.cc b/chrome/browser/sync/profile_sync_components_factory_impl.cc index 88599ae..a482550 100644 --- a/components/browser_sync/browser/profile_sync_components_factory_impl.cc +++ b/chrome/browser/sync/profile_sync_components_factory_impl.cc @@ -2,12 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/browser_sync/browser/profile_sync_components_factory_impl.h" +#include "chrome/browser/sync/profile_sync_components_factory_impl.h" #include "base/command_line.h" #include "base/memory/ref_counted.h" #include "base/prefs/pref_service.h" #include "build/build_config.h" +#include "chrome/browser/bookmarks/bookmark_model_factory.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" +#include "chrome/browser/sync/glue/theme_data_type_controller.h" +#include "chrome/common/channel_info.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" #include "components/autofill/core/browser/autofill_wallet_data_type_controller.h" #include "components/autofill/core/browser/webdata/autofill_data_type_controller.h" #include "components/autofill/core/browser/webdata/autofill_profile_data_type_controller.h" @@ -21,6 +28,7 @@ #include "components/history/core/browser/typed_url_data_type_controller.h" #include "components/history/core/browser/typed_url_model_associator.h" #include "components/password_manager/sync/browser/password_data_type_controller.h" +#include "components/search_engines/search_engine_data_type_controller.h" #include "components/sync_bookmarks/bookmark_change_processor.h" #include "components/sync_bookmarks/bookmark_data_type_controller.h" #include "components/sync_bookmarks/bookmark_model_associator.h" @@ -34,6 +42,7 @@ #include "components/sync_driver/sync_client.h" #include "components/sync_driver/ui_data_type_controller.h" #include "components/sync_sessions/session_data_type_controller.h" +#include "content/public/browser/browser_thread.h" #include "google_apis/gaia/oauth2_token_service.h" #include "google_apis/gaia/oauth2_token_service_request.h" #include "net/url_request/url_request_context_getter.h" @@ -41,6 +50,20 @@ #include "sync/internal_api/public/attachments/attachment_service.h" #include "sync/internal_api/public/attachments/attachment_service_impl.h" #include "sync/internal_api/public/attachments/attachment_uploader_impl.h" +#include "ui/base/device_form_factor.h" + +#if defined(ENABLE_APP_LIST) +#include "ui/app_list/app_list_switches.h" +#endif + +#if defined(ENABLE_EXTENSIONS) +#include "chrome/browser/sync/glue/extension_data_type_controller.h" +#include "chrome/browser/sync/glue/extension_setting_data_type_controller.h" +#endif + +#if defined(ENABLE_SUPERVISED_USERS) +#include "chrome/browser/supervised_user/supervised_user_sync_data_type_controller.h" +#endif using bookmarks::BookmarkModel; using browser_sync::AutofillDataTypeController; @@ -49,13 +72,20 @@ using browser_sync::BookmarkChangeProcessor; using browser_sync::BookmarkDataTypeController; using browser_sync::BookmarkModelAssociator; using browser_sync::ChromeReportUnrecoverableError; +#if defined(ENABLE_EXTENSIONS) +using browser_sync::ExtensionDataTypeController; +using browser_sync::ExtensionSettingDataTypeController; +#endif using browser_sync::HistoryDeleteDirectivesDataTypeController; using browser_sync::PasswordDataTypeController; +using browser_sync::SearchEngineDataTypeController; using browser_sync::SessionDataTypeController; using browser_sync::SyncBackendHost; +using browser_sync::ThemeDataTypeController; using browser_sync::TypedUrlChangeProcessor; using browser_sync::TypedUrlDataTypeController; using browser_sync::TypedUrlModelAssociator; +using content::BrowserThread; using sync_driver::DataTypeController; using sync_driver::DataTypeErrorHandler; using sync_driver::DataTypeManager; @@ -89,26 +119,14 @@ syncer::ModelTypeSet GetEnabledTypesFromCommandLine( } // namespace ProfileSyncComponentsFactoryImpl::ProfileSyncComponentsFactoryImpl( - sync_driver::SyncClient* sync_client, - version_info::Channel channel, - const std::string& version, - bool is_tablet, - const base::CommandLine& command_line, - const char* history_disabled_pref, + Profile* profile, + base::CommandLine* command_line, const GURL& sync_service_url, - const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, - const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, OAuth2TokenService* token_service, net::URLRequestContextGetter* url_request_context_getter) - : sync_client_(sync_client), - channel_(channel), - version_(version), - is_tablet_(is_tablet), + : profile_(profile), command_line_(command_line), - history_disabled_pref_(history_disabled_pref), sync_service_url_(sync_service_url), - ui_thread_(ui_thread), - db_thread_(db_thread), token_service_(token_service), url_request_context_getter_(url_request_context_getter), weak_factory_(this) { @@ -116,44 +134,51 @@ ProfileSyncComponentsFactoryImpl::ProfileSyncComponentsFactoryImpl( DCHECK(url_request_context_getter_); } -ProfileSyncComponentsFactoryImpl::~ProfileSyncComponentsFactoryImpl() {} +ProfileSyncComponentsFactoryImpl::~ProfileSyncComponentsFactoryImpl() { +} void ProfileSyncComponentsFactoryImpl::RegisterDataTypes( - const RegisterDataTypesMethod& register_platform_types_method) { + sync_driver::SyncClient* sync_client) { syncer::ModelTypeSet disabled_types = - GetDisabledTypesFromCommandLine(command_line_); + GetDisabledTypesFromCommandLine(*command_line_); syncer::ModelTypeSet enabled_types = - GetEnabledTypesFromCommandLine(command_line_); - RegisterCommonDataTypes(disabled_types, enabled_types); - if (!register_platform_types_method.is_null()) - register_platform_types_method.Run(disabled_types, enabled_types); + GetEnabledTypesFromCommandLine(*command_line_); + RegisterCommonDataTypes(disabled_types, enabled_types, sync_client); +#if !defined(OS_ANDROID) + RegisterDesktopDataTypes(disabled_types, enabled_types, sync_client); +#endif } void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes( syncer::ModelTypeSet disabled_types, - syncer::ModelTypeSet enabled_types) { - sync_driver::SyncService* sync_service = sync_client_->GetSyncService(); + syncer::ModelTypeSet enabled_types, + sync_driver::SyncClient* sync_client) { + sync_driver::SyncService* sync_service = sync_client->GetSyncService(); base::Closure error_callback = - base::Bind(&ChromeReportUnrecoverableError, channel_); + base::Bind(&ChromeReportUnrecoverableError, chrome::GetChannel()); + const scoped_refptr<base::SingleThreadTaskRunner> ui_thread = + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); + const scoped_refptr<base::SingleThreadTaskRunner> db_thread = + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB); // TODO(stanisc): can DEVICE_INFO be one of disabled datatypes? sync_service->RegisterDataTypeController(new DeviceInfoDataTypeController( - ui_thread_, error_callback, sync_client_, + ui_thread, error_callback, sync_client, sync_service->GetLocalDeviceInfoProvider())); // Autofill sync is enabled by default. Register unless explicitly // disabled. if (!disabled_types.Has(syncer::AUTOFILL)) { sync_service->RegisterDataTypeController(new AutofillDataTypeController( - ui_thread_, db_thread_, error_callback, sync_client_)); + ui_thread, db_thread, error_callback, sync_client)); } // Autofill profile sync is enabled by default. Register unless explicitly // disabled. if (!disabled_types.Has(syncer::AUTOFILL_PROFILE)) { sync_service->RegisterDataTypeController( - new AutofillProfileDataTypeController(ui_thread_, db_thread_, - error_callback, sync_client_)); + new AutofillProfileDataTypeController(ui_thread, db_thread, + error_callback, sync_client)); } // Wallet data sync is enabled by default, but behind a syncer experiment @@ -162,7 +187,7 @@ void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes( if (!wallet_disabled) { sync_service->RegisterDataTypeController( new browser_sync::AutofillWalletDataTypeController( - ui_thread_, db_thread_, error_callback, sync_client_, + ui_thread, db_thread, error_callback, sync_client, syncer::AUTOFILL_WALLET_DATA)); } @@ -172,24 +197,25 @@ void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes( if (!wallet_disabled && enabled_types.Has(syncer::AUTOFILL_WALLET_METADATA)) { sync_service->RegisterDataTypeController( new browser_sync::AutofillWalletDataTypeController( - ui_thread_, db_thread_, error_callback, sync_client_, + ui_thread, db_thread, error_callback, sync_client, syncer::AUTOFILL_WALLET_METADATA)); } // Bookmark sync is enabled by default. Register unless explicitly // disabled. if (!disabled_types.Has(syncer::BOOKMARKS)) { - sync_service->RegisterDataTypeController(new BookmarkDataTypeController( - ui_thread_, error_callback, sync_client_)); + sync_service->RegisterDataTypeController( + new BookmarkDataTypeController(ui_thread, error_callback, sync_client)); } const bool history_disabled = - sync_client_->GetPrefService()->GetBoolean(history_disabled_pref_); + profile_->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled); // TypedUrl sync is enabled by default. Register unless explicitly disabled, // or if saving history is disabled. if (!disabled_types.Has(syncer::TYPED_URLS) && !history_disabled) { - sync_service->RegisterDataTypeController(new TypedUrlDataTypeController( - ui_thread_, error_callback, sync_client_, history_disabled_pref_)); + sync_service->RegisterDataTypeController( + new TypedUrlDataTypeController(ui_thread, error_callback, sync_client, + prefs::kSavingBrowserHistoryDisabled)); } // Delete directive sync is enabled by default. Register unless full history @@ -197,8 +223,8 @@ void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes( if (!disabled_types.Has(syncer::HISTORY_DELETE_DIRECTIVES) && !history_disabled) { sync_service->RegisterDataTypeController( - new HistoryDeleteDirectivesDataTypeController( - ui_thread_, error_callback, sync_client_)); + new HistoryDeleteDirectivesDataTypeController(ui_thread, error_callback, + sync_client)); } // Session sync is enabled by default. Register unless explicitly disabled. @@ -206,46 +232,159 @@ void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes( // tab sync data is added to the web history on the server. if (!disabled_types.Has(syncer::PROXY_TABS) && !history_disabled) { sync_service->RegisterDataTypeController( - new ProxyDataTypeController(ui_thread_, syncer::PROXY_TABS)); + new ProxyDataTypeController(ui_thread, syncer::PROXY_TABS)); // TODO(zea): remove this once SyncedWindowDelegateGetter is componentized. // For now, we know that the implementation of SyncService is always a // ProfileSyncService at this level. ProfileSyncService* pss = static_cast<ProfileSyncService*>(sync_service); sync_service->RegisterDataTypeController(new SessionDataTypeController( - ui_thread_, error_callback, sync_client_, + ui_thread, error_callback, sync_client, pss->GetSyncedWindowDelegatesGetter(), - sync_service->GetLocalDeviceInfoProvider(), history_disabled_pref_)); + sync_service->GetLocalDeviceInfoProvider(), + prefs::kSavingBrowserHistoryDisabled)); } // Favicon sync is enabled by default. Register unless explicitly disabled. if (!disabled_types.Has(syncer::FAVICON_IMAGES) && - !disabled_types.Has(syncer::FAVICON_TRACKING) && !history_disabled) { + !disabled_types.Has(syncer::FAVICON_TRACKING) && + !history_disabled) { // crbug/384552. We disable error uploading for this data types for now. sync_service->RegisterDataTypeController(new UIDataTypeController( - ui_thread_, base::Closure(), syncer::FAVICON_IMAGES, sync_client_)); + ui_thread, base::Closure(), syncer::FAVICON_IMAGES, sync_client)); sync_service->RegisterDataTypeController(new UIDataTypeController( - ui_thread_, base::Closure(), syncer::FAVICON_TRACKING, sync_client_)); + ui_thread, base::Closure(), syncer::FAVICON_TRACKING, sync_client)); } // Password sync is enabled by default. Register unless explicitly // disabled. if (!disabled_types.Has(syncer::PASSWORDS)) { sync_service->RegisterDataTypeController(new PasswordDataTypeController( - ui_thread_, error_callback, sync_client_, - sync_client_->GetPasswordStateChangedCallback())); + ui_thread, error_callback, sync_client, + sync_client->GetPasswordStateChangedCallback())); } if (!disabled_types.Has(syncer::PRIORITY_PREFERENCES)) { - sync_service->RegisterDataTypeController( - new UIDataTypeController(ui_thread_, error_callback, - syncer::PRIORITY_PREFERENCES, sync_client_)); + sync_service->RegisterDataTypeController(new UIDataTypeController( + ui_thread, error_callback, syncer::PRIORITY_PREFERENCES, sync_client)); } // Article sync is disabled by default. Register only if explicitly enabled. if (dom_distiller::IsEnableSyncArticlesSet()) { sync_service->RegisterDataTypeController(new UIDataTypeController( - ui_thread_, error_callback, syncer::ARTICLES, sync_client_)); + ui_thread, error_callback, syncer::ARTICLES, sync_client)); } + +#if defined(ENABLE_SUPERVISED_USERS) + sync_service->RegisterDataTypeController( + new SupervisedUserSyncDataTypeController(syncer::SUPERVISED_USER_SETTINGS, + error_callback, sync_client, + profile_)); + sync_service->RegisterDataTypeController( + new SupervisedUserSyncDataTypeController( + syncer::SUPERVISED_USER_WHITELISTS, error_callback, sync_client, + profile_)); +#endif +} + +void ProfileSyncComponentsFactoryImpl::RegisterDesktopDataTypes( + syncer::ModelTypeSet disabled_types, + syncer::ModelTypeSet enabled_types, + sync_driver::SyncClient* sync_client) { + sync_driver::SyncService* sync_service = sync_client->GetSyncService(); + base::Closure error_callback = + base::Bind(&ChromeReportUnrecoverableError, chrome::GetChannel()); + const scoped_refptr<base::SingleThreadTaskRunner> ui_thread = + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); + +#if defined(ENABLE_EXTENSIONS) + // App sync is enabled by default. Register unless explicitly + // disabled. + if (!disabled_types.Has(syncer::APPS)) { + sync_service->RegisterDataTypeController(new ExtensionDataTypeController( + syncer::APPS, error_callback, sync_client, profile_)); + } + + // Extension sync is enabled by default. Register unless explicitly + // disabled. + if (!disabled_types.Has(syncer::EXTENSIONS)) { + sync_service->RegisterDataTypeController(new ExtensionDataTypeController( + syncer::EXTENSIONS, error_callback, sync_client, profile_)); + } +#endif + + // Preference sync is enabled by default. Register unless explicitly + // disabled. + if (!disabled_types.Has(syncer::PREFERENCES)) { + sync_service->RegisterDataTypeController(new UIDataTypeController( + ui_thread, error_callback, syncer::PREFERENCES, sync_client)); + } + +#if defined(ENABLE_THEMES) + // Theme sync is enabled by default. Register unless explicitly disabled. + if (!disabled_types.Has(syncer::THEMES)) { + sync_service->RegisterDataTypeController( + new ThemeDataTypeController(error_callback, sync_client, profile_)); + } +#endif + + // Search Engine sync is enabled by default. Register unless explicitly + // disabled. + if (!disabled_types.Has(syncer::SEARCH_ENGINES)) { + sync_service->RegisterDataTypeController(new SearchEngineDataTypeController( + ui_thread, error_callback, sync_client, + TemplateURLServiceFactory::GetForProfile(profile_))); + } + +#if defined(ENABLE_EXTENSIONS) + // Extension setting sync is enabled by default. Register unless explicitly + // disabled. + if (!disabled_types.Has(syncer::EXTENSION_SETTINGS)) { + sync_service->RegisterDataTypeController( + new ExtensionSettingDataTypeController( + syncer::EXTENSION_SETTINGS, error_callback, sync_client, profile_)); + } + + // App setting sync is enabled by default. Register unless explicitly + // disabled. + if (!disabled_types.Has(syncer::APP_SETTINGS)) { + sync_service->RegisterDataTypeController( + new ExtensionSettingDataTypeController( + syncer::APP_SETTINGS, error_callback, sync_client, profile_)); + } +#endif + +#if defined(ENABLE_APP_LIST) + if (app_list::switches::IsAppListSyncEnabled()) { + sync_service->RegisterDataTypeController(new UIDataTypeController( + ui_thread, error_callback, syncer::APP_LIST, sync_client)); + } +#endif + +#if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) + // Dictionary sync is enabled by default. + if (!disabled_types.Has(syncer::DICTIONARY)) { + sync_service->RegisterDataTypeController(new UIDataTypeController( + ui_thread, error_callback, syncer::DICTIONARY, sync_client)); + } +#endif + +#if defined(ENABLE_SUPERVISED_USERS) + sync_service->RegisterDataTypeController( + new SupervisedUserSyncDataTypeController( + syncer::SUPERVISED_USERS, error_callback, sync_client, profile_)); + sync_service->RegisterDataTypeController( + new SupervisedUserSyncDataTypeController( + syncer::SUPERVISED_USER_SHARED_SETTINGS, error_callback, sync_client, + profile_)); +#endif + +#if defined(OS_CHROMEOS) + if (command_line_->HasSwitch(switches::kEnableWifiCredentialSync) && + !disabled_types.Has(syncer::WIFI_CREDENTIALS)) { + sync_service->RegisterDataTypeController(new UIDataTypeController( + ui_thread, error_callback, syncer::WIFI_CREDENTIALS, sync_client)); + } +#endif } DataTypeManager* ProfileSyncComponentsFactoryImpl::CreateDataTypeManager( @@ -262,18 +401,23 @@ DataTypeManager* ProfileSyncComponentsFactoryImpl::CreateDataTypeManager( browser_sync::SyncBackendHost* ProfileSyncComponentsFactoryImpl::CreateSyncBackendHost( const std::string& name, + sync_driver::SyncClient* sync_client, invalidation::InvalidationService* invalidator, const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, const base::FilePath& sync_folder) { return new browser_sync::SyncBackendHostImpl( - name, sync_client_, ui_thread_, invalidator, sync_prefs, sync_folder); + name, sync_client, + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), + invalidator, sync_prefs, sync_folder); } scoped_ptr<sync_driver::LocalDeviceInfoProvider> ProfileSyncComponentsFactoryImpl::CreateLocalDeviceInfoProvider() { return scoped_ptr<sync_driver::LocalDeviceInfoProvider>( - new browser_sync::LocalDeviceInfoProviderImpl(channel_, version_, - is_tablet_)); + new browser_sync::LocalDeviceInfoProviderImpl( + chrome::GetChannel(), + chrome::GetVersionString(), + ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET)); } class TokenServiceProvider @@ -298,9 +442,11 @@ class TokenServiceProvider TokenServiceProvider::TokenServiceProvider( const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, OAuth2TokenService* token_service) - : task_runner_(task_runner), token_service_(token_service) {} + : task_runner_(task_runner), token_service_(token_service) { +} -TokenServiceProvider::~TokenServiceProvider() {} +TokenServiceProvider::~TokenServiceProvider() { +} scoped_refptr<base::SingleThreadTaskRunner> TokenServiceProvider::GetTokenServiceTaskRunner() { @@ -325,9 +471,12 @@ ProfileSyncComponentsFactoryImpl::CreateAttachmentService( // signed in sync user (e.g. sync is running in "backup" mode). if (!user_share.sync_credentials.email.empty() && !user_share.sync_credentials.scope_set.empty()) { + const scoped_refptr<base::SingleThreadTaskRunner> ui_thread = + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); + scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> token_service_provider( - new TokenServiceProvider(ui_thread_, token_service_)); + new TokenServiceProvider(ui_thread, token_service_)); // TODO(maniscalco): Use shared (one per profile) thread-safe instances of // AttachmentUploader and AttachmentDownloader instead of creating a new one // per AttachmentService (bug 369536). @@ -338,7 +487,7 @@ ProfileSyncComponentsFactoryImpl::CreateAttachmentService( store_birthday, model_type)); token_service_provider = - new TokenServiceProvider(ui_thread_, token_service_); + new TokenServiceProvider(ui_thread, token_service_); attachment_downloader = syncer::AttachmentDownloader::Create( sync_service_url_, url_request_context_getter_, user_share.sync_credentials.email, @@ -362,14 +511,14 @@ ProfileSyncComponentsFactoryImpl::CreateAttachmentService( } sync_driver::SyncApiComponentFactory::SyncComponents -ProfileSyncComponentsFactoryImpl::CreateBookmarkSyncComponents( - sync_driver::SyncService* sync_service, - sync_driver::DataTypeErrorHandler* error_handler) { + ProfileSyncComponentsFactoryImpl::CreateBookmarkSyncComponents( + sync_driver::SyncService* sync_service, + sync_driver::DataTypeErrorHandler* error_handler) { BookmarkModel* bookmark_model = - sync_service->GetSyncClient()->GetBookmarkModel(); + BookmarkModelFactory::GetForProfile(profile_); syncer::UserShare* user_share = sync_service->GetUserShare(); -// TODO(akalin): We may want to propagate this switch up eventually. -#if defined(OS_ANDROID) || defined(OS_IOS) + // TODO(akalin): We may want to propagate this switch up eventually. +#if defined(OS_ANDROID) const bool kExpectMobileBookmarksFolder = true; #else const bool kExpectMobileBookmarksFolder = false; @@ -383,18 +532,23 @@ ProfileSyncComponentsFactoryImpl::CreateBookmarkSyncComponents( } sync_driver::SyncApiComponentFactory::SyncComponents -ProfileSyncComponentsFactoryImpl::CreateTypedUrlSyncComponents( - sync_driver::SyncService* sync_service, - history::HistoryBackend* history_backend, - sync_driver::DataTypeErrorHandler* error_handler) { - DCHECK(!ui_thread_->BelongsToCurrentThread()); + ProfileSyncComponentsFactoryImpl::CreateTypedUrlSyncComponents( + sync_driver::SyncService* sync_service, + history::HistoryBackend* history_backend, + sync_driver::DataTypeErrorHandler* error_handler) { + DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); + + const scoped_refptr<base::SingleThreadTaskRunner> ui_thread = + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); // TODO(zea): Once TypedURLs are converted to SyncableService, remove // |sync_service_| member, and make GetSyncService require it be called on // the UI thread. TypedUrlModelAssociator* model_associator = - new TypedUrlModelAssociator(sync_service, history_backend, error_handler); + new TypedUrlModelAssociator(sync_service, + history_backend, + error_handler); TypedUrlChangeProcessor* change_processor = new TypedUrlChangeProcessor( - model_associator, history_backend, error_handler, ui_thread_); + model_associator, history_backend, error_handler, ui_thread); return SyncComponents(model_associator, change_processor); } diff --git a/components/browser_sync/browser/profile_sync_components_factory_impl.h b/chrome/browser/sync/profile_sync_components_factory_impl.h index 579d1b9..0e7ede7 100644 --- a/components/browser_sync/browser/profile_sync_components_factory_impl.h +++ b/chrome/browser/sync/profile_sync_components_factory_impl.h @@ -2,23 +2,25 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMPONENTS_BROWSER_SYNC_BROWSER_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ -#define COMPONENTS_BROWSER_SYNC_BROWSER_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ +#ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ +#define CHROME_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ #include <string> #include "base/basictypes.h" -#include "base/command_line.h" #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" #include "components/sync_driver/sync_api_component_factory.h" -#include "components/version_info/version_info.h" #include "sync/internal_api/public/base/model_type.h" #include "url/gurl.h" class OAuth2TokenService; class Profile; +namespace base { +class CommandLine; +} + namespace net { class URLRequestContextGetter; } @@ -35,22 +37,15 @@ class ProfileSyncComponentsFactoryImpl // |url_request_context_getter| must outlive the // ProfileSyncComponentsFactoryImpl. ProfileSyncComponentsFactoryImpl( - sync_driver::SyncClient* sync_client, - version_info::Channel channel, - const std::string& version, - bool is_tablet, - const base::CommandLine& command_line, - const char* history_disabled_pref, + Profile* profile, + base::CommandLine* command_line, const GURL& sync_service_url, - const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, - const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, OAuth2TokenService* token_service, net::URLRequestContextGetter* url_request_context_getter); ~ProfileSyncComponentsFactoryImpl() override; - // SyncApiComponentFactory implementation: - void RegisterDataTypes( - const RegisterDataTypesMethod& register_platform_types_method) override; + void RegisterDataTypes(sync_driver::SyncClient* sync_client) override; + sync_driver::DataTypeManager* CreateDataTypeManager( const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& debug_info_listener, @@ -58,19 +53,25 @@ class ProfileSyncComponentsFactoryImpl const sync_driver::DataTypeEncryptionHandler* encryption_handler, browser_sync::SyncBackendHost* backend, sync_driver::DataTypeManagerObserver* observer) override; + browser_sync::SyncBackendHost* CreateSyncBackendHost( const std::string& name, + sync_driver::SyncClient* sync_client, invalidation::InvalidationService* invalidator, const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, const base::FilePath& sync_folder) override; + scoped_ptr<sync_driver::LocalDeviceInfoProvider> CreateLocalDeviceInfoProvider() override; + scoped_ptr<syncer::AttachmentService> CreateAttachmentService( scoped_ptr<syncer::AttachmentStoreForSync> attachment_store, const syncer::UserShare& user_share, const std::string& store_birthday, syncer::ModelType model_type, syncer::AttachmentService::Delegate* delegate) override; + + // Legacy datatypes that need to be converted to the SyncableService API. sync_driver::SyncApiComponentFactory::SyncComponents CreateBookmarkSyncComponents( sync_driver::SyncService* sync_service, @@ -82,26 +83,28 @@ class ProfileSyncComponentsFactoryImpl sync_driver::DataTypeErrorHandler* error_handler) override; private: + // Register data types which are enabled on desktop platforms only. + // |disabled_types| and |enabled_types| correspond only to those types + // being explicitly enabled/disabled by the command line. + void RegisterDesktopDataTypes(syncer::ModelTypeSet disabled_types, + syncer::ModelTypeSet enabled_types, + sync_driver::SyncClient* sync_client); + // Register data types which are enabled on both desktop and mobile. // |disabled_types| and |enabled_types| correspond only to those types // being explicitly enabled/disabled by the command line. void RegisterCommonDataTypes(syncer::ModelTypeSet disabled_types, - syncer::ModelTypeSet enabled_types); + syncer::ModelTypeSet enabled_types, + sync_driver::SyncClient* sync_client); void DisableBrokenType(syncer::ModelType type, const tracked_objects::Location& from_here, const std::string& message); - // Client/platform specific members. - sync_driver::SyncClient* const sync_client_; - const version_info::Channel channel_; - const std::string version_; - const bool is_tablet_; - const base::CommandLine command_line_; - const char* history_disabled_pref_; + Profile* profile_; + base::CommandLine* command_line_; + const GURL sync_service_url_; - const scoped_refptr<base::SingleThreadTaskRunner> ui_thread_; - const scoped_refptr<base::SingleThreadTaskRunner> db_thread_; OAuth2TokenService* const token_service_; net::URLRequestContextGetter* const url_request_context_getter_; @@ -110,4 +113,4 @@ class ProfileSyncComponentsFactoryImpl DISALLOW_COPY_AND_ASSIGN(ProfileSyncComponentsFactoryImpl); }; -#endif // COMPONENTS_BROWSER_SYNC_BROWSER_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ +#endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ diff --git a/chrome/browser/sync/profile_sync_components_factory_impl_unittest.cc b/chrome/browser/sync/profile_sync_components_factory_impl_unittest.cc new file mode 100644 index 0000000..a2f2f1f --- /dev/null +++ b/chrome/browser/sync/profile_sync_components_factory_impl_unittest.cc @@ -0,0 +1,181 @@ +// Copyright (c) 2012 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 <vector> + +#include "base/command_line.h" +#include "base/files/file_path.h" +#include "base/memory/scoped_ptr.h" +#include "base/message_loop/message_loop.h" +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" +#include "chrome/browser/sync/chrome_sync_client.h" +#include "chrome/browser/sync/profile_sync_components_factory_impl.h" +#include "chrome/browser/sync/profile_sync_service_factory.h" +#include "chrome/browser/sync/profile_sync_test_util.h" +#include "chrome/common/channel_info.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/test/base/testing_profile.h" +#include "components/browser_sync/browser/profile_sync_service.h" +#include "components/browser_sync/common/browser_sync_switches.h" +#include "components/signin/core/browser/profile_oauth2_token_service.h" +#include "components/sync_driver/data_type_controller.h" +#include "components/sync_driver/signin_manager_wrapper.h" +#include "components/sync_driver/sync_util.h" +#include "content/public/test/test_browser_thread_bundle.h" +#include "google_apis/gaia/gaia_constants.h" +#include "google_apis/gaia/oauth2_token_service.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/app_list/app_list_switches.h" + +using sync_driver::DataTypeController; + +class ProfileSyncComponentsFactoryImplTest : public testing::Test { + protected: + ProfileSyncComponentsFactoryImplTest() + : thread_bundle_(content::TestBrowserThreadBundle::DEFAULT) {} + + void SetUp() override { + profile_.reset(new TestingProfile()); + base::FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); + command_line_.reset(new base::CommandLine(program_path)); + scope_set_.insert(GaiaConstants::kChromeSyncOAuth2Scope); + } + + // Returns the collection of default datatypes. + static std::vector<syncer::ModelType> DefaultDatatypes() { + std::vector<syncer::ModelType> datatypes; + datatypes.push_back(syncer::APPS); +#if defined(ENABLE_APP_LIST) + if (app_list::switches::IsAppListSyncEnabled()) + datatypes.push_back(syncer::APP_LIST); +#endif + datatypes.push_back(syncer::APP_SETTINGS); + datatypes.push_back(syncer::AUTOFILL); + datatypes.push_back(syncer::AUTOFILL_PROFILE); + datatypes.push_back(syncer::AUTOFILL_WALLET_DATA); + datatypes.push_back(syncer::BOOKMARKS); + datatypes.push_back(syncer::DEVICE_INFO); +#if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) + datatypes.push_back(syncer::DICTIONARY); +#endif + datatypes.push_back(syncer::EXTENSIONS); + datatypes.push_back(syncer::EXTENSION_SETTINGS); + datatypes.push_back(syncer::HISTORY_DELETE_DIRECTIVES); + datatypes.push_back(syncer::PASSWORDS); + datatypes.push_back(syncer::PREFERENCES); + datatypes.push_back(syncer::PRIORITY_PREFERENCES); + datatypes.push_back(syncer::SEARCH_ENGINES); + datatypes.push_back(syncer::SESSIONS); + datatypes.push_back(syncer::PROXY_TABS); + datatypes.push_back(syncer::THEMES); + datatypes.push_back(syncer::TYPED_URLS); + datatypes.push_back(syncer::FAVICON_TRACKING); + datatypes.push_back(syncer::FAVICON_IMAGES); + datatypes.push_back(syncer::SUPERVISED_USERS); + datatypes.push_back(syncer::SUPERVISED_USER_SETTINGS); + datatypes.push_back(syncer::SUPERVISED_USER_SHARED_SETTINGS); + datatypes.push_back(syncer::SUPERVISED_USER_WHITELISTS); + + return datatypes; + } + + // Returns the number of default datatypes. + static size_t DefaultDatatypesCount() { + return DefaultDatatypes().size(); + } + + // Asserts that all the default datatypes are in |map|, except + // for |exception_type|, which unless it is UNDEFINED, is asserted to + // not be in |map|. + static void CheckDefaultDatatypesInMapExcept( + DataTypeController::StateMap* map, + syncer::ModelTypeSet exception_types) { + std::vector<syncer::ModelType> defaults = DefaultDatatypes(); + std::vector<syncer::ModelType>::iterator iter; + for (iter = defaults.begin(); iter != defaults.end(); ++iter) { + if (exception_types.Has(*iter)) + EXPECT_EQ(0U, map->count(*iter)) + << *iter << " found in dataypes map, shouldn't be there."; + else + EXPECT_EQ(1U, map->count(*iter)) + << *iter << " not found in datatypes map"; + } + } + + // Asserts that if you disable types via the command line, all other types + // are enabled. + void TestSwitchDisablesType(syncer::ModelTypeSet types) { + command_line_->AppendSwitchASCII(switches::kDisableSyncTypes, + syncer::ModelTypeSetToString(types)); + GURL sync_service_url = + GetSyncServiceURL(*command_line_, chrome::GetChannel()); + ProfileOAuth2TokenService* token_service = + ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); + scoped_ptr<sync_driver::SyncApiComponentFactory> factory( + new ProfileSyncComponentsFactoryImpl( + profile_.get(), command_line_.get(), + GetSyncServiceURL(*command_line_, chrome::GetChannel()), + token_service, profile_->GetRequestContext())); + scoped_ptr<sync_driver::SyncClient> sync_client( + new browser_sync::ChromeSyncClient(profile_.get(), factory.Pass())); + scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( + sync_client.Pass(), + make_scoped_ptr<SigninManagerWrapper>(NULL), token_service, + browser_sync::MANUAL_START, base::Bind(&EmptyNetworkTimeUpdate), + profile_->GetPath(), profile_->GetRequestContext(), + profile_->GetDebugName(), chrome::GetChannel(), + content::BrowserThread::GetMessageLoopProxyForThread( + content::BrowserThread::DB), + content::BrowserThread::GetMessageLoopProxyForThread( + content::BrowserThread::FILE), + content::BrowserThread::GetBlockingPool())); + pss->GetSyncClient()->Initialize(pss.get()); + DataTypeController::StateMap controller_states; + pss->GetDataTypeControllerStates(&controller_states); + EXPECT_EQ(DefaultDatatypesCount() - types.Size(), controller_states.size()); + CheckDefaultDatatypesInMapExcept(&controller_states, types); + } + + content::TestBrowserThreadBundle thread_bundle_; + scoped_ptr<Profile> profile_; + scoped_ptr<base::CommandLine> command_line_; + OAuth2TokenService::ScopeSet scope_set_; +}; + +TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { + ProfileOAuth2TokenService* token_service = + ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); + scoped_ptr<sync_driver::SyncApiComponentFactory> factory( + new ProfileSyncComponentsFactoryImpl( + profile_.get(), command_line_.get(), + GetSyncServiceURL(*command_line_, chrome::GetChannel()), + token_service, profile_->GetRequestContext())); + scoped_ptr<sync_driver::SyncClient> sync_client( + new browser_sync::ChromeSyncClient(profile_.get(), factory.Pass())); + scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( + sync_client.Pass(), + make_scoped_ptr<SigninManagerWrapper>(NULL), token_service, + browser_sync::MANUAL_START, base::Bind(&EmptyNetworkTimeUpdate), + profile_->GetPath(), profile_->GetRequestContext(), + profile_->GetDebugName(), chrome::GetChannel(), + content::BrowserThread::GetMessageLoopProxyForThread( + content::BrowserThread::DB), + content::BrowserThread::GetMessageLoopProxyForThread( + content::BrowserThread::FILE), + content::BrowserThread::GetBlockingPool())); + pss->GetSyncClient()->Initialize(pss.get()); + DataTypeController::StateMap controller_states; + pss->GetDataTypeControllerStates(&controller_states); + EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); + CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet()); +} + +TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableOne) { + TestSwitchDisablesType(syncer::ModelTypeSet(syncer::AUTOFILL)); +} + +TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableMultiple) { + TestSwitchDisablesType( + syncer::ModelTypeSet(syncer::AUTOFILL_PROFILE, syncer::BOOKMARKS)); +} diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc index e334815..f4d7f4f 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc @@ -6,6 +6,7 @@ #include "base/command_line.h" #include "base/memory/singleton.h" +#include "base/prefs/pref_service.h" #include "base/time/time.h" #include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" @@ -24,11 +25,11 @@ #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/sync/chrome_sync_client.h" +#include "chrome/browser/sync/profile_sync_components_factory_impl.h" #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/web_data_service_factory.h" #include "chrome/common/channel_info.h" -#include "components/browser_sync/browser/profile_sync_components_factory_impl.h" #include "components/browser_sync/browser/profile_sync_service.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/network_time/network_time_tracker.h" @@ -147,11 +148,18 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( // once http://crbug.com/171406 has been fixed. AboutSigninInternalsFactory::GetForProfile(profile); + const GURL sync_service_url = GetSyncServiceURL( + *base::CommandLine::ForCurrentProcess(), chrome::GetChannel()); + scoped_ptr<SigninManagerWrapper> signin_wrapper( new SupervisedUserSigninManagerWrapper(profile, signin)); - + std::string account_id = signin_wrapper->GetAccountIdToUse(); + OAuth2TokenService::ScopeSet scope_set; + scope_set.insert(signin_wrapper->GetSyncScopeToUse()); ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile); + net::URLRequestContextGetter* url_request_context_getter = + profile->GetRequestContext(); // TODO(tim): Currently, AUTO/MANUAL settings refer to the *first* time sync // is set up and *not* a browser restart for a manual-start platform (where @@ -162,10 +170,14 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( browser_sync::ProfileSyncServiceStartBehavior behavior = browser_defaults::kSyncAutoStarts ? browser_sync::AUTO_START : browser_sync::MANUAL_START; - browser_sync::ChromeSyncClient* chrome_sync_client = - new browser_sync::ChromeSyncClient(profile); + scoped_ptr<sync_driver::SyncApiComponentFactory> sync_factory( + new ProfileSyncComponentsFactoryImpl( + profile, base::CommandLine::ForCurrentProcess(), sync_service_url, + token_service, url_request_context_getter)); + scoped_ptr<browser_sync::ChromeSyncClient> sync_client( + new browser_sync::ChromeSyncClient(profile, sync_factory.Pass())); ProfileSyncService* pss = new ProfileSyncService( - make_scoped_ptr(chrome_sync_client), signin_wrapper.Pass(), token_service, + sync_client.Pass(), signin_wrapper.Pass(), token_service, behavior, base::Bind(&UpdateNetworkTime), profile->GetPath(), profile->GetRequestContext(), profile->GetDebugName(), chrome::GetChannel(), @@ -174,8 +186,6 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( content::BrowserThread::GetMessageLoopProxyForThread( content::BrowserThread::FILE), content::BrowserThread::GetBlockingPool()); - - // Will also initialize the sync client. pss->Initialize(); return pss; } diff --git a/chrome/browser/sync/profile_sync_service_factory_unittest.cc b/chrome/browser/sync/profile_sync_service_factory_unittest.cc index 0e41583..963d824 100644 --- a/chrome/browser/sync/profile_sync_service_factory_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_factory_unittest.cc @@ -5,88 +5,20 @@ #include "base/command_line.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/sync/profile_sync_service_factory.h" +#include "chrome/common/chrome_switches.h" #include "chrome/test/base/testing_profile.h" -#include "components/browser_sync/browser/profile_sync_service.h" #include "components/browser_sync/common/browser_sync_switches.h" -#include "components/sync_driver/data_type_controller.h" #include "content/public/test/test_browser_thread_bundle.h" -#include "sync/internal_api/public/base/model_type.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/app_list/app_list_switches.h" - -using sync_driver::DataTypeController; class ProfileSyncServiceFactoryTest : public testing::Test { protected: - ProfileSyncServiceFactoryTest() : profile_(new TestingProfile()) {} - - // Returns the collection of default datatypes. - std::vector<syncer::ModelType> DefaultDatatypes() { - std::vector<syncer::ModelType> datatypes; - datatypes.push_back(syncer::APPS); -#if defined(ENABLE_APP_LIST) - if (app_list::switches::IsAppListSyncEnabled()) - datatypes.push_back(syncer::APP_LIST); -#endif - datatypes.push_back(syncer::APP_SETTINGS); - datatypes.push_back(syncer::AUTOFILL); - datatypes.push_back(syncer::AUTOFILL_PROFILE); - datatypes.push_back(syncer::AUTOFILL_WALLET_DATA); - datatypes.push_back(syncer::BOOKMARKS); - datatypes.push_back(syncer::DEVICE_INFO); -#if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) - datatypes.push_back(syncer::DICTIONARY); -#endif - datatypes.push_back(syncer::EXTENSIONS); - datatypes.push_back(syncer::EXTENSION_SETTINGS); - datatypes.push_back(syncer::HISTORY_DELETE_DIRECTIVES); - datatypes.push_back(syncer::PASSWORDS); - datatypes.push_back(syncer::PREFERENCES); - datatypes.push_back(syncer::PRIORITY_PREFERENCES); - datatypes.push_back(syncer::SEARCH_ENGINES); - datatypes.push_back(syncer::SESSIONS); - datatypes.push_back(syncer::PROXY_TABS); - datatypes.push_back(syncer::THEMES); - datatypes.push_back(syncer::TYPED_URLS); - datatypes.push_back(syncer::FAVICON_TRACKING); - datatypes.push_back(syncer::FAVICON_IMAGES); - datatypes.push_back(syncer::SUPERVISED_USERS); - datatypes.push_back(syncer::SUPERVISED_USER_SETTINGS); - datatypes.push_back(syncer::SUPERVISED_USER_SHARED_SETTINGS); - datatypes.push_back(syncer::SUPERVISED_USER_WHITELISTS); - - return datatypes; - } - - // Returns the number of default datatypes. - size_t DefaultDatatypesCount() { return DefaultDatatypes().size(); } - - // Asserts that all the default datatypes are in |map|, except - // for |exception_type|, which unless it is UNDEFINED, is asserted to - // not be in |map|. - void CheckDefaultDatatypesInMapExcept(DataTypeController::StateMap* map, - syncer::ModelTypeSet exception_types) { - std::vector<syncer::ModelType> defaults = DefaultDatatypes(); - std::vector<syncer::ModelType>::iterator iter; - for (iter = defaults.begin(); iter != defaults.end(); ++iter) { - if (exception_types.Has(*iter)) - EXPECT_EQ(0U, map->count(*iter)) - << *iter << " found in dataypes map, shouldn't be there."; - else - EXPECT_EQ(1U, map->count(*iter)) << *iter - << " not found in datatypes map"; - } - } + ProfileSyncServiceFactoryTest() {} - void SetDisabledTypes(syncer::ModelTypeSet disabled_types) { - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDisableSyncTypes, - syncer::ModelTypeSetToString(disabled_types)); + void SetUp() override { + profile_.reset(new TestingProfile()); } - Profile* profile() { return profile_.get(); } - - private: content::TestBrowserThreadBundle thread_bundle_; scoped_ptr<Profile> profile_; }; @@ -94,42 +26,5 @@ class ProfileSyncServiceFactoryTest : public testing::Test { // Verify that the disable sync flag disables creation of the sync service. TEST_F(ProfileSyncServiceFactoryTest, DisableSyncFlag) { base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); - EXPECT_EQ(nullptr, ProfileSyncServiceFactory::GetForProfile(profile())); -} - -// Verify that a normal (no command line flags) PSS can be created and -// properly initialized. -TEST_F(ProfileSyncServiceFactoryTest, CreatePSSDefault) { - ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile()); - DataTypeController::StateMap controller_states; - pss->GetDataTypeControllerStates(&controller_states); - EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); - CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet()); -} - -// Verify that a PSS with a disabled datatype can be created and properly -// initialized. -TEST_F(ProfileSyncServiceFactoryTest, CreatePSSDisableOne) { - syncer::ModelTypeSet disabled_types(syncer::AUTOFILL); - SetDisabledTypes(disabled_types); - ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile()); - DataTypeController::StateMap controller_states; - pss->GetDataTypeControllerStates(&controller_states); - EXPECT_EQ(DefaultDatatypesCount() - disabled_types.Size(), - controller_states.size()); - CheckDefaultDatatypesInMapExcept(&controller_states, disabled_types); -} - -// Verify that a PSS with multiple disabled datatypes can be created and -// properly initialized. -TEST_F(ProfileSyncServiceFactoryTest, CreatePSSDisableMultiple) { - syncer::ModelTypeSet disabled_types(syncer::AUTOFILL_PROFILE, - syncer::BOOKMARKS); - SetDisabledTypes(disabled_types); - ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile()); - DataTypeController::StateMap controller_states; - pss->GetDataTypeControllerStates(&controller_states); - EXPECT_EQ(DefaultDatatypesCount() - disabled_types.Size(), - controller_states.size()); - CheckDefaultDatatypesInMapExcept(&controller_states, disabled_types); + EXPECT_EQ(nullptr, ProfileSyncServiceFactory::GetForProfile(profile_.get())); } diff --git a/chrome/browser/sync/profile_sync_service_mock.cc b/chrome/browser/sync/profile_sync_service_mock.cc index e5c8a3f..209187a 100644 --- a/chrome/browser/sync/profile_sync_service_mock.cc +++ b/chrome/browser/sync/profile_sync_service_mock.cc @@ -21,12 +21,12 @@ ProfileSyncServiceMock::ProfileSyncServiceMock(Profile* profile) : ProfileSyncServiceMock( - make_scoped_ptr(new browser_sync::ChromeSyncClient(profile)), - profile) { - static_cast<browser_sync::ChromeSyncClient*>(GetSyncClient()) - ->SetSyncApiComponentFactoryForTesting( - make_scoped_ptr(new SyncApiComponentFactoryMock())); -} + make_scoped_ptr( + new browser_sync::ChromeSyncClient( + profile, + make_scoped_ptr(new SyncApiComponentFactoryMock()))) + .Pass(), + profile) {} ProfileSyncServiceMock::ProfileSyncServiceMock( scoped_ptr<sync_driver::SyncClient> sync_client, diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc index 7c3afc8..03160fd 100644 --- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc @@ -118,19 +118,20 @@ class ProfileSyncServiceStartupTest : public testing::Test { void SetUp() override { CHECK(profile_manager_.SetUp()); - TestingProfile::TestingFactories testing_factories; - testing_factories.push_back(std::make_pair( + TestingProfile::TestingFactories testing_facotries; + testing_facotries.push_back(std::make_pair( SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase)); - testing_factories.push_back( - std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), - BuildAutoIssuingFakeProfileOAuth2TokenService)); - testing_factories.push_back( - std::make_pair(ProfileSyncServiceFactory::GetInstance(), BuildService)); + testing_facotries.push_back( + std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), + BuildAutoIssuingFakeProfileOAuth2TokenService)); + testing_facotries.push_back( + std::make_pair(ProfileSyncServiceFactory::GetInstance(), + BuildService)); profile_ = profile_manager_.CreateTestingProfile( "sync-startup-test", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), base::UTF8ToUTF16("sync-startup-test"), 0, std::string(), - testing_factories); + testing_facotries); } void TearDown() override { sync_->RemoveObserver(&observer_); } @@ -139,9 +140,8 @@ class ProfileSyncServiceStartupTest : public testing::Test { content::BrowserContext* browser_context) { Profile* profile = static_cast<Profile*>(browser_context); scoped_ptr<browser_sync::ChromeSyncClient> sync_client( - new browser_sync::ChromeSyncClient(profile)); - sync_client->SetSyncApiComponentFactoryForTesting( - make_scoped_ptr(new SyncApiComponentFactoryMock())); + new browser_sync::ChromeSyncClient( + profile, make_scoped_ptr(new SyncApiComponentFactoryMock()))); return make_scoped_ptr(new TestProfileSyncServiceNoBackup( sync_client.Pass(), profile, make_scoped_ptr(new SigninManagerWrapper( @@ -212,7 +212,7 @@ class ProfileSyncServiceStartupTest : public testing::Test { browser_sync::SyncBackendHostMock* sync_backend_host = new browser_sync::SyncBackendHostMock(); EXPECT_CALL(*GetSyncApiComponentFactoryMock(), - CreateSyncBackendHost(_, _, _, _)) + CreateSyncBackendHost(_, _, _, _, _)) .WillOnce(Return(sync_backend_host)); return sync_backend_host; } @@ -246,9 +246,8 @@ class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { ProfileOAuth2TokenServiceFactory::GetForProfile(profile); EXPECT_TRUE(signin->IsAuthenticated()); scoped_ptr<browser_sync::ChromeSyncClient> sync_client( - new browser_sync::ChromeSyncClient(profile)); - sync_client->SetSyncApiComponentFactoryForTesting( - make_scoped_ptr(new SyncApiComponentFactoryMock())); + new browser_sync::ChromeSyncClient( + profile, make_scoped_ptr(new SyncApiComponentFactoryMock()))); return make_scoped_ptr(new TestProfileSyncServiceNoBackup( sync_client.Pass(), profile, make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, @@ -379,7 +378,7 @@ TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { CreateDataTypeManager(_, _, _, _, _)) .Times(0); EXPECT_CALL(*GetSyncApiComponentFactoryMock(), - CreateSyncBackendHost(_, _, _, _)) + CreateSyncBackendHost(_, _, _, _, _)) .Times(0); profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc index a3efd96..fe887df 100644 --- a/chrome/browser/sync/profile_sync_service_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_unittest.cc @@ -35,6 +35,7 @@ #include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" #include "components/signin/core/browser/signin_manager.h" +#include "components/signin/core/browser/signin_manager.h" #include "components/strings/grit/components_strings.h" #include "components/sync_driver/data_type_manager.h" #include "components/sync_driver/data_type_manager_observer.h" @@ -105,12 +106,11 @@ using testing::_; class TestChromeSyncClient : public ChromeSyncClient { public: TestChromeSyncClient( - scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory, Profile* profile, + scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory, sync_driver::ClearBrowsingDataCallback callback) - : ChromeSyncClient(profile), - callback_(callback), - component_factory_(component_factory.Pass()) {} + : ChromeSyncClient(profile, component_factory.Pass()), + callback_(callback) {} ~TestChromeSyncClient() override {} private: @@ -119,12 +119,8 @@ class TestChromeSyncClient : public ChromeSyncClient { override { return callback_; } - sync_driver::SyncApiComponentFactory* GetSyncApiComponentFactory() override { - return component_factory_.get(); - } sync_driver::ClearBrowsingDataCallback callback_; - scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory_; }; class TestSyncServiceObserver : public sync_driver::SyncServiceObserver { @@ -259,9 +255,7 @@ class ProfileSyncServiceTest : public ::testing::Test { protected: ProfileSyncServiceTest() : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), - profile_manager_(TestingBrowserProcess::GetGlobal()), - profile_(NULL), - components_factory_(NULL) {} + profile_manager_(TestingBrowserProcess::GetGlobal()) {} ~ProfileSyncServiceTest() override {} void SetUp() override { @@ -310,7 +304,7 @@ class ProfileSyncServiceTest : public ::testing::Test { new SyncApiComponentFactoryMock()); components_factory_ = components_factory.get(); scoped_ptr<ChromeSyncClient> sync_client(new TestChromeSyncClient( - components_factory.Pass(), profile_, + profile_, components_factory.Pass(), base::Bind(&ProfileSyncServiceTest::ClearBrowsingDataCallback, base::Unretained(this)))); service_.reset(new ProfileSyncService( @@ -397,14 +391,14 @@ class ProfileSyncServiceTest : public ::testing::Test { } void ExpectSyncBackendHostCreation(int times) { - EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _)) + EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _, _)) .Times(times) .WillRepeatedly(ReturnNewSyncBackendHostMock()); } void ExpectSyncBackendHostCreationCollectDeleteDir( int times, std::vector<bool> *delete_dir_param) { - EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _)) + EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _, _)) .Times(times) .WillRepeatedly( ReturnNewMockHostCollectDeleteDirParam(delete_dir_param)); @@ -412,13 +406,13 @@ class ProfileSyncServiceTest : public ::testing::Test { void ExpectSyncBackendHostCreationCaptureClearServerData( syncer::SyncManager::ClearServerDataCallback* captured_callback) { - EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _)) + EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _, _)) .Times(1) .WillOnce(ReturnNewMockHostCaptureClearServerData(captured_callback)); } void PrepareDelayedInitSyncBackendHost() { - EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _)) + EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _, _)) .WillOnce(ReturnNewSyncBackendHostNoReturn()); } diff --git a/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc b/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc index b4afe23..6f12001 100644 --- a/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc +++ b/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc @@ -277,7 +277,7 @@ class SessionsSyncManagerTest void SetUp() override { BrowserWithTestWindowTest::SetUp(); - sync_client_.reset(new browser_sync::ChromeSyncClient(profile())); + sync_client_.reset(new browser_sync::ChromeSyncClient(profile(), nullptr)); browser_sync::NotificationServiceSessionsRouter* router( new browser_sync::NotificationServiceSessionsRouter( profile(), GetSyncSessionsClient(), diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc index 2a724d8..ea7778b 100644 --- a/chrome/browser/sync/test_profile_sync_service.cc +++ b/chrome/browser/sync/test_profile_sync_service.cc @@ -126,24 +126,22 @@ TestProfileSyncService::TestProfileSyncService( SigninManagerBase* signin, ProfileOAuth2TokenService* oauth2_token_service, browser_sync::ProfileSyncServiceStartBehavior behavior) - : ProfileSyncService( - make_scoped_ptr(new browser_sync::ChromeSyncClient(profile)), - make_scoped_ptr(new SigninManagerWrapper(signin)), - oauth2_token_service, - behavior, - base::Bind(&EmptyNetworkTimeUpdate), - profile->GetPath(), - profile->GetRequestContext(), - profile->GetDebugName(), - chrome::GetChannel(), - content::BrowserThread::GetMessageLoopProxyForThread( - content::BrowserThread::DB), - content::BrowserThread::GetMessageLoopProxyForThread( - content::BrowserThread::FILE), - content::BrowserThread::GetBlockingPool()) { - static_cast<browser_sync::ChromeSyncClient*>(GetSyncClient()) - ->SetSyncApiComponentFactoryForTesting( - make_scoped_ptr(new SyncApiComponentFactoryMock)); + : ProfileSyncService(make_scoped_ptr(new browser_sync::ChromeSyncClient( + profile, + make_scoped_ptr(new SyncApiComponentFactoryMock))), + make_scoped_ptr(new SigninManagerWrapper(signin)), + oauth2_token_service, + behavior, + base::Bind(&EmptyNetworkTimeUpdate), + profile->GetPath(), + profile->GetRequestContext(), + profile->GetDebugName(), + chrome::GetChannel(), + content::BrowserThread::GetMessageLoopProxyForThread( + content::BrowserThread::DB), + content::BrowserThread::GetMessageLoopProxyForThread( + content::BrowserThread::FILE), + content::BrowserThread::GetBlockingPool()) { SetSyncSetupCompleted(); } @@ -171,8 +169,9 @@ TestProfileSyncService* TestProfileSyncService::BuildAutoStartAsyncInit( SyncApiComponentFactoryMock* components = sync_service->GetSyncApiComponentFactoryMock(); // TODO(tim): Convert to a fake instead of mock. - EXPECT_CALL(*components, CreateSyncBackendHost(testing::_, testing::_, - testing::_, testing::_)) + EXPECT_CALL(*components, + CreateSyncBackendHost(testing::_, testing::_, testing::_, + testing::_, testing::_)) .WillOnce( testing::Return(new browser_sync::SyncBackendHostForProfileSyncTest( profile, sync_service->GetSyncClient(), diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 0aee8e6..583eb16 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2908,6 +2908,8 @@ 'browser/sync/glue/synced_window_delegate_android.h', 'browser/sync/glue/synced_window_delegates_getter_android.cc', 'browser/sync/glue/synced_window_delegates_getter_android.h', + 'browser/sync/profile_sync_components_factory_impl.cc', + 'browser/sync/profile_sync_components_factory_impl.h', 'browser/sync/profile_sync_service_android.cc', 'browser/sync/profile_sync_service_android.h', 'browser/sync/profile_sync_service_factory.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 0bd7d33..eb28aa8 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -227,6 +227,7 @@ 'browser/sync/glue/search_engine_data_type_controller_unittest.cc', 'browser/sync/glue/sync_backend_host_impl_unittest.cc', 'browser/sync/profile_sync_auth_provider_unittest.cc', + 'browser/sync/profile_sync_components_factory_impl_unittest.cc', 'browser/sync/profile_sync_service_autofill_unittest.cc', 'browser/sync/profile_sync_service_bookmark_unittest.cc', 'browser/sync/profile_sync_service_factory_unittest.cc', diff --git a/components/browser_sync.gypi b/components/browser_sync.gypi index 03c178a..e67b03d 100644 --- a/components/browser_sync.gypi +++ b/components/browser_sync.gypi @@ -14,23 +14,18 @@ '../net/net.gyp:net', '../sync/sync.gyp:sync', '../ui/base/ui_base.gyp:ui_base', - 'autofill_core_browser', 'autofill_core_common', 'browser_sync_common', 'components_strings.gyp:components_strings', - 'dom_distiller_core', 'history_core_browser', 'invalidation_impl', 'invalidation_public', 'keyed_service_core', - 'password_manager_sync_browser', 'pref_registry', 'signin_core_browser', 'syncable_prefs', - 'sync_bookmarks', 'sync_driver', 'sync_sessions', - 'variations', 'version_info', ], 'include_dirs': [ @@ -38,8 +33,6 @@ ], 'sources': [ # Note: file list duplicated in GN build. - 'browser_sync/browser/profile_sync_components_factory_impl.cc', - 'browser_sync/browser/profile_sync_components_factory_impl.h', 'browser_sync/browser/profile_sync_service.cc', 'browser_sync/browser/profile_sync_service.h', 'browser_sync/browser/signin_confirmation_helper.cc', diff --git a/components/browser_sync/browser/BUILD.gn b/components/browser_sync/browser/BUILD.gn index e2123ce..0966e41 100644 --- a/components/browser_sync/browser/BUILD.gn +++ b/components/browser_sync/browser/BUILD.gn @@ -6,8 +6,6 @@ import("//build/config/features.gni") source_set("browser") { sources = [ - "profile_sync_components_factory_impl.cc", - "profile_sync_components_factory_impl.h", "profile_sync_service.cc", "profile_sync_service.h", "signin_confirmation_helper.cc", @@ -17,21 +15,16 @@ source_set("browser") { deps = [ "//base", "//base:prefs", - "//components/autofill/core/browser", - "//components/dom_distiller/core", "//components/history/core/browser", "//components/invalidation/impl", "//components/invalidation/public", "//components/keyed_service/core", - "//components/password_manager/sync/browser", "//components/pref_registry", "//components/signin/core/browser", "//components/strings", "//components/syncable_prefs", - "//components/sync_bookmarks", "//components/sync_driver", "//components/sync_sessions", - "//components/variations", "//components/version_info", "//components/version_info:generate_version_info", "//google_apis", diff --git a/components/browser_sync/browser/DEPS b/components/browser_sync/browser/DEPS index 23d2595..4cb7215 100644 --- a/components/browser_sync/browser/DEPS +++ b/components/browser_sync/browser/DEPS @@ -1,18 +1,14 @@ include_rules = [ - "+components/autofill/core", - "+components/dom_distiller/core", + "+components/autofill/core/common", "+components/history/core/browser", "+components/invalidation", "+components/keyed_service/core", - "+components/password_manager/sync/browser", "+components/pref_registry", "+components/signin/core/browser", "+components/syncable_prefs", - "+components/sync_bookmarks", "+components/sync_driver", "+components/sync_sessions", "+components/strings", - "+components/variations", "+components/version_info", "+google_apis", "+net", diff --git a/components/browser_sync/browser/profile_sync_service.cc b/components/browser_sync/browser/profile_sync_service.cc index dd6636b..3e5e0dc 100644 --- a/components/browser_sync/browser/profile_sync_service.cc +++ b/components/browser_sync/browser/profile_sync_service.cc @@ -211,7 +211,6 @@ ProfileSyncService::ProfileSyncService( connection_status_(syncer::CONNECTION_NOT_ATTEMPTED), last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()), network_resources_(new syncer::HttpBridgeNetworkResources), - start_behavior_(start_behavior), backend_mode_(IDLE), need_backup_(false), backup_finished_(false), @@ -221,6 +220,42 @@ ProfileSyncService::ProfileSyncService( startup_controller_weak_factory_(this) { DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(sync_client_); + startup_controller_.reset(new browser_sync::StartupController( + start_behavior, + oauth2_token_service, + &sync_prefs_, + signin_.get(), + base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, + startup_controller_weak_factory_.GetWeakPtr(), + SYNC))); + backup_rollback_controller_.reset(new sync_driver::BackupRollbackController( + &sync_prefs_, + signin_.get(), + base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, + startup_controller_weak_factory_.GetWeakPtr(), + BACKUP), + base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, + startup_controller_weak_factory_.GetWeakPtr(), + ROLLBACK))); + scoped_ptr<browser_sync::LocalSessionEventRouter> router( + sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); + local_device_ = sync_client_->GetSyncApiComponentFactory() + ->CreateLocalDeviceInfoProvider(); + sync_stopped_reporter_.reset(new browser_sync::SyncStoppedReporter( + sync_service_url_, local_device_->GetSyncUserAgent(), + url_request_context_, + browser_sync::SyncStoppedReporter::ResultCallback())); + sessions_sync_manager_.reset(new SessionsSyncManager( + sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), + router.Pass(), + base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, + weak_factory_.GetWeakPtr()), + base::Bind(&ProfileSyncService::TriggerRefresh, + weak_factory_.GetWeakPtr(), + syncer::ModelTypeSet(syncer::SESSIONS)))); + device_info_sync_service_.reset( + new DeviceInfoSyncService(local_device_.get())); + std::string last_version = sync_prefs_.GetLastRunVersion(); std::string current_version = PRODUCT_VERSION; sync_prefs_.SetLastRunVersion(current_version); @@ -254,41 +289,6 @@ bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { void ProfileSyncService::Initialize() { sync_client_->Initialize(this); - startup_controller_.reset(new browser_sync::StartupController( - start_behavior_, oauth2_token_service_, &sync_prefs_, signin_.get(), - base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, - startup_controller_weak_factory_.GetWeakPtr(), SYNC))); - backup_rollback_controller_.reset(new sync_driver::BackupRollbackController( - &sync_prefs_, signin_.get(), - base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, - startup_controller_weak_factory_.GetWeakPtr(), BACKUP), - base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, - startup_controller_weak_factory_.GetWeakPtr(), ROLLBACK))); - scoped_ptr<browser_sync::LocalSessionEventRouter> router( - sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); - local_device_ = sync_client_->GetSyncApiComponentFactory() - ->CreateLocalDeviceInfoProvider(); - sync_stopped_reporter_.reset(new browser_sync::SyncStoppedReporter( - sync_service_url_, local_device_->GetSyncUserAgent(), - url_request_context_, - browser_sync::SyncStoppedReporter::ResultCallback())); - sessions_sync_manager_.reset(new SessionsSyncManager( - sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), - router.Pass(), - base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, - weak_factory_.GetWeakPtr()), - base::Bind(&ProfileSyncService::TriggerRefresh, - weak_factory_.GetWeakPtr(), - syncer::ModelTypeSet(syncer::SESSIONS)))); - device_info_sync_service_.reset( - new DeviceInfoSyncService(local_device_.get())); - - sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod - register_platform_types_callback = - sync_client_->GetRegisterPlatformTypesCallback(); - sync_client_->GetSyncApiComponentFactory()->RegisterDataTypes( - register_platform_types_callback); - // We clear this here (vs Shutdown) because we want to remember that an error // happened on shutdown so we can display details (message, location) about it // in about:sync. @@ -672,8 +672,8 @@ void ProfileSyncService::StartUpSlowBackendComponents( backend_.reset( sync_client_->GetSyncApiComponentFactory()->CreateSyncBackendHost( - debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(), - directory_path_)); + debug_identifier_, sync_client_.get(), invalidator, + sync_prefs_.AsWeakPtr(), directory_path_)); // Initialize the backend. Every time we start up a new SyncBackendHost, // we'll want to start from a fresh SyncDB, so delete any old one that might diff --git a/components/browser_sync/browser/profile_sync_service.h b/components/browser_sync/browser/profile_sync_service.h index 32c998e..9909a29 100644 --- a/components/browser_sync/browser/profile_sync_service.h +++ b/components/browser_sync/browser/profile_sync_service.h @@ -230,6 +230,7 @@ class ProfileSyncService : public sync_driver::SyncService, ROLLBACK // Backend for rollback. }; + // Takes ownership of |factory| and |signin_wrapper|. ProfileSyncService( scoped_ptr<sync_driver::SyncClient> sync_client, scoped_ptr<SigninManagerWrapper> signin_wrapper, @@ -947,7 +948,6 @@ class ProfileSyncService : public sync_driver::SyncService, scoped_ptr<syncer::NetworkResources> network_resources_; - browser_sync::ProfileSyncServiceStartBehavior start_behavior_; scoped_ptr<browser_sync::StartupController> startup_controller_; scoped_ptr<sync_driver::BackupRollbackController> backup_rollback_controller_; diff --git a/components/sync_driver/fake_sync_client.cc b/components/sync_driver/fake_sync_client.cc index 8645c2d..51e2b38a 100644 --- a/components/sync_driver/fake_sync_client.cc +++ b/components/sync_driver/fake_sync_client.cc @@ -16,9 +16,6 @@ namespace { void DummyClearBrowsingDataCallback(base::Time start, base::Time end) {} -void DummyRegisterPlatformTypesCallback(syncer::ModelTypeSet, - syncer::ModelTypeSet) {} - } // namespace FakeSyncClient::FakeSyncClient() @@ -66,11 +63,6 @@ base::Closure FakeSyncClient::GetPasswordStateChangedCallback() { return base::Bind(&base::DoNothing); } -sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod -FakeSyncClient::GetRegisterPlatformTypesCallback() { - return base::Bind(&DummyRegisterPlatformTypesCallback); -} - autofill::PersonalDataManager* FakeSyncClient::GetPersonalDataManager() { return nullptr; } diff --git a/components/sync_driver/fake_sync_client.h b/components/sync_driver/fake_sync_client.h index 9a74ad3..dbe5376 100644 --- a/components/sync_driver/fake_sync_client.h +++ b/components/sync_driver/fake_sync_client.h @@ -27,8 +27,6 @@ class FakeSyncClient : public SyncClient { scoped_refptr<password_manager::PasswordStore> GetPasswordStore() override; ClearBrowsingDataCallback GetClearBrowsingDataCallback() override; base::Closure GetPasswordStateChangedCallback() override; - sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod - GetRegisterPlatformTypesCallback() override; autofill::PersonalDataManager* GetPersonalDataManager() override; scoped_refptr<autofill::AutofillWebDataService> GetWebDataService() override; BookmarkUndoService* GetBookmarkUndoServiceIfExists() override; diff --git a/components/sync_driver/generic_change_processor_unittest.cc b/components/sync_driver/generic_change_processor_unittest.cc index 63e6187..2524511 100644 --- a/components/sync_driver/generic_change_processor_unittest.cc +++ b/components/sync_driver/generic_change_processor_unittest.cc @@ -85,8 +85,7 @@ class MockSyncApiComponentFactory : public SyncApiComponentFactory { MockSyncApiComponentFactory() {} // SyncApiComponentFactory implementation. - void RegisterDataTypes( - const RegisterDataTypesMethod& register_platform_types_method) override {} + void RegisterDataTypes(sync_driver::SyncClient* sync_client) override {} sync_driver::DataTypeManager* CreateDataTypeManager( const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& debug_info_listener, @@ -98,6 +97,7 @@ class MockSyncApiComponentFactory : public SyncApiComponentFactory { }; browser_sync::SyncBackendHost* CreateSyncBackendHost( const std::string& name, + SyncClient* sync_client, invalidation::InvalidationService* invalidator, const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, const base::FilePath& sync_folder) override { diff --git a/components/sync_driver/shared_change_processor_unittest.cc b/components/sync_driver/shared_change_processor_unittest.cc index d277a3b..8a1a24e 100644 --- a/components/sync_driver/shared_change_processor_unittest.cc +++ b/components/sync_driver/shared_change_processor_unittest.cc @@ -42,8 +42,7 @@ class TestSyncApiComponentFactory : public SyncApiComponentFactory { ~TestSyncApiComponentFactory() override {} // SyncApiComponentFactory implementation. - void RegisterDataTypes( - const RegisterDataTypesMethod& register_platform_types_method) override {} + void RegisterDataTypes(sync_driver::SyncClient* sync_client) override {} sync_driver::DataTypeManager* CreateDataTypeManager( const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& debug_info_listener, @@ -55,6 +54,7 @@ class TestSyncApiComponentFactory : public SyncApiComponentFactory { } browser_sync::SyncBackendHost* CreateSyncBackendHost( const std::string& name, + SyncClient* sync_client, invalidation::InvalidationService* invalidator, const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, const base::FilePath& sync_folder) override { diff --git a/components/sync_driver/sync_api_component_factory.h b/components/sync_driver/sync_api_component_factory.h index d64bba1..937fd73 100644 --- a/components/sync_driver/sync_api_component_factory.h +++ b/components/sync_driver/sync_api_component_factory.h @@ -57,13 +57,6 @@ class SyncService; class SyncApiComponentFactory { public: virtual ~SyncApiComponentFactory() {} - // Callback to allow platform-specific datatypes to register themselves as - // data type controllers. - // |disabled_types| and |enabled_types| control the disable/enable state of - // types that are on or off by default (respectively). - typedef base::Callback<void(syncer::ModelTypeSet disabled_types, - syncer::ModelTypeSet enabled_types)> - RegisterDataTypesMethod; // The various factory methods for the data type model associators // and change processors all return this struct. This is needed @@ -87,8 +80,7 @@ class SyncApiComponentFactory { }; // Creates and registers enabled datatypes with the provided SyncClient. - virtual void RegisterDataTypes( - const RegisterDataTypesMethod& register_platform_types_method) = 0; + virtual void RegisterDataTypes(sync_driver::SyncClient* sync_client) = 0; // Instantiates a new DataTypeManager with a SyncBackendHost, a list of data // type controllers and a DataTypeManagerObserver. The return pointer is @@ -104,6 +96,7 @@ class SyncApiComponentFactory { // Creating this in the factory helps us mock it out in testing. virtual browser_sync::SyncBackendHost* CreateSyncBackendHost( const std::string& name, + SyncClient* sync_client, invalidation::InvalidationService* invalidator, const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, const base::FilePath& sync_folder) = 0; diff --git a/components/sync_driver/sync_api_component_factory_mock.h b/components/sync_driver/sync_api_component_factory_mock.h index f89e502..70899c5 100644 --- a/components/sync_driver/sync_api_component_factory_mock.h +++ b/components/sync_driver/sync_api_component_factory_mock.h @@ -29,7 +29,7 @@ class SyncApiComponentFactoryMock sync_driver::ChangeProcessor* change_processor); ~SyncApiComponentFactoryMock() override; - MOCK_METHOD1(RegisterDataTypes, void(const RegisterDataTypesMethod&)); + MOCK_METHOD1(RegisterDataTypes, void(sync_driver::SyncClient*)); MOCK_METHOD5(CreateDataTypeManager, sync_driver::DataTypeManager*( const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&, @@ -37,9 +37,10 @@ class SyncApiComponentFactoryMock const sync_driver::DataTypeEncryptionHandler*, browser_sync::SyncBackendHost*, sync_driver::DataTypeManagerObserver* observer)); - MOCK_METHOD4(CreateSyncBackendHost, + MOCK_METHOD5(CreateSyncBackendHost, browser_sync::SyncBackendHost*( const std::string& name, + sync_driver::SyncClient* sync_client, invalidation::InvalidationService* invalidator, const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, const base::FilePath& sync_folder)); diff --git a/components/sync_driver/sync_client.h b/components/sync_driver/sync_client.h index 5f44d1d..fda584d 100644 --- a/components/sync_driver/sync_client.h +++ b/components/sync_driver/sync_client.h @@ -10,7 +10,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" -#include "components/sync_driver/sync_api_component_factory.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/util/extensions_activity.h" @@ -54,6 +53,7 @@ class SyncSessionsClient; namespace sync_driver { +class SyncApiComponentFactory; class SyncService; typedef base::Callback<void(base::Time, base::Time)> ClearBrowsingDataCallback; @@ -69,7 +69,9 @@ class SyncClient { SyncClient(); virtual ~SyncClient(); - // Initializes the sync client with the specified sync service. + // Initializes the sync client with the specified sync service. This will also + // register data type controllers with |service| (via + // SyncApiComponentFactory::RegisterDataTypes). virtual void Initialize(SyncService* service) = 0; // Returns the current SyncService instance. @@ -88,11 +90,6 @@ class SyncClient { // have browsing data cleared. virtual ClearBrowsingDataCallback GetClearBrowsingDataCallback() = 0; - // Returns a callback that will register the types specific to the current - // platform. - virtual sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod - GetRegisterPlatformTypesCallback() = 0; - // Returns a callback that will be invoked when password sync state has // potentially been changed. virtual base::Closure GetPasswordStateChangedCallback() = 0; |