| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/chrome_sync_client.h" | 5 #include "chrome/browser/sync/chrome_sync_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 8 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 9 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 10 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 11 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 11 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" | 12 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" |
| 12 #include "chrome/browser/favicon/favicon_service_factory.h" | 13 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 13 #include "chrome/browser/history/history_service_factory.h" | 14 #include "chrome/browser/history/history_service_factory.h" |
| 14 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 15 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 15 #include "chrome/browser/password_manager/password_store_factory.h" | 16 #include "chrome/browser/password_manager/password_store_factory.h" |
| 16 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 17 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/search_engines/template_url_service_factory.h" | 19 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 19 #include "chrome/browser/sync/glue/sync_start_util.h" | 20 #include "chrome/browser/sync/glue/sync_start_util.h" |
| 21 #include "chrome/browser/sync/glue/theme_data_type_controller.h" |
| 20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 21 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" | 23 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" |
| 22 #include "chrome/browser/themes/theme_service.h" | 24 #include "chrome/browser/themes/theme_service.h" |
| 23 #include "chrome/browser/themes/theme_service_factory.h" | 25 #include "chrome/browser/themes/theme_service_factory.h" |
| 24 #include "chrome/browser/themes/theme_syncable_service.h" | 26 #include "chrome/browser/themes/theme_syncable_service.h" |
| 25 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" | 27 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" |
| 26 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | 28 #include "chrome/browser/undo/bookmark_undo_service_factory.h" |
| 27 #include "chrome/browser/web_data_service_factory.h" | 29 #include "chrome/browser/web_data_service_factory.h" |
| 30 #include "chrome/common/channel_info.h" |
| 28 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 29 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service
.h" | 32 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service
.h" |
| 30 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser
vice.h" | 33 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser
vice.h" |
| 31 #include "components/autofill/core/browser/webdata/autofill_wallet_metadata_sync
able_service.h" | 34 #include "components/autofill/core/browser/webdata/autofill_wallet_metadata_sync
able_service.h" |
| 32 #include "components/autofill/core/browser/webdata/autofill_wallet_syncable_serv
ice.h" | 35 #include "components/autofill/core/browser/webdata/autofill_wallet_syncable_serv
ice.h" |
| 33 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 36 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 34 #include "components/browser_sync/browser/profile_sync_service.h" | 37 #include "components/browser_sync/browser/profile_sync_service.h" |
| 38 #include "components/browser_sync/common/browser_sync_switches.h" |
| 35 #include "components/dom_distiller/core/dom_distiller_service.h" | 39 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 36 #include "components/history/core/browser/history_model_worker.h" | 40 #include "components/history/core/browser/history_model_worker.h" |
| 37 #include "components/history/core/browser/history_service.h" | 41 #include "components/history/core/browser/history_service.h" |
| 38 #include "components/invalidation/impl/profile_invalidation_provider.h" | 42 #include "components/invalidation/impl/profile_invalidation_provider.h" |
| 39 #include "components/password_manager/core/browser/password_store.h" | 43 #include "components/password_manager/core/browser/password_store.h" |
| 40 #include "components/password_manager/sync/browser/password_model_worker.h" | 44 #include "components/password_manager/sync/browser/password_model_worker.h" |
| 45 #include "components/search_engines/search_engine_data_type_controller.h" |
| 41 #include "components/sync_driver/glue/browser_thread_model_worker.h" | 46 #include "components/sync_driver/glue/browser_thread_model_worker.h" |
| 47 #include "components/sync_driver/glue/chrome_report_unrecoverable_error.h" |
| 42 #include "components/sync_driver/glue/ui_model_worker.h" | 48 #include "components/sync_driver/glue/ui_model_worker.h" |
| 43 #include "components/sync_driver/sync_api_component_factory.h" | 49 #include "components/sync_driver/sync_api_component_factory.h" |
| 50 #include "components/sync_driver/ui_data_type_controller.h" |
| 44 #include "components/sync_sessions/sync_sessions_client.h" | 51 #include "components/sync_sessions/sync_sessions_client.h" |
| 45 #include "components/syncable_prefs/pref_service_syncable.h" | 52 #include "components/syncable_prefs/pref_service_syncable.h" |
| 46 #include "content/public/browser/browser_thread.h" | 53 #include "content/public/browser/browser_thread.h" |
| 47 #include "sync/internal_api/public/engine/passive_model_worker.h" | 54 #include "sync/internal_api/public/engine/passive_model_worker.h" |
| 48 | 55 |
| 49 #if defined(ENABLE_APP_LIST) | 56 #if defined(ENABLE_APP_LIST) |
| 50 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 57 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 51 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 58 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
| 52 #include "ui/app_list/app_list_switches.h" | 59 #include "ui/app_list/app_list_switches.h" |
| 53 #endif | 60 #endif |
| (...skipping 26 matching lines...) Expand all Loading... |
| 80 #if defined(OS_ANDROID) | 87 #if defined(OS_ANDROID) |
| 81 #include "chrome/browser/sync/glue/synced_window_delegates_getter_android.h" | 88 #include "chrome/browser/sync/glue/synced_window_delegates_getter_android.h" |
| 82 #endif | 89 #endif |
| 83 | 90 |
| 84 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
| 85 #include "components/wifi_sync/wifi_credential_syncable_service.h" | 92 #include "components/wifi_sync/wifi_credential_syncable_service.h" |
| 86 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h" | 93 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h" |
| 87 #endif | 94 #endif |
| 88 | 95 |
| 89 using content::BrowserThread; | 96 using content::BrowserThread; |
| 97 #if defined(ENABLE_EXTENSIONS) |
| 98 using browser_sync::ExtensionDataTypeController; |
| 99 using browser_sync::ExtensionSettingDataTypeController; |
| 100 #endif |
| 101 using browser_sync::SearchEngineDataTypeController; |
| 102 using sync_driver::UIDataTypeController; |
| 90 | 103 |
| 91 namespace browser_sync { | 104 namespace browser_sync { |
| 92 | 105 |
| 93 // Chrome implementation of SyncSessionsClient. Needs to be in a separate class | 106 // Chrome implementation of SyncSessionsClient. Needs to be in a separate class |
| 94 // due to possible multiple inheritance issues, wherein ChromeSyncClient might | 107 // due to possible multiple inheritance issues, wherein ChromeSyncClient might |
| 95 // inherit from other interfaces with same methods. | 108 // inherit from other interfaces with same methods. |
| 96 class SyncSessionsClientImpl : public sync_sessions::SyncSessionsClient { | 109 class SyncSessionsClientImpl : public sync_sessions::SyncSessionsClient { |
| 97 public: | 110 public: |
| 98 explicit SyncSessionsClientImpl(Profile* profile) : profile_(profile) { | 111 explicit SyncSessionsClientImpl(Profile* profile) : profile_(profile) { |
| 99 window_delegates_getter_.reset( | 112 window_delegates_getter_.reset( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 new NotificationServiceSessionsRouter(profile_, this, flare)); | 157 new NotificationServiceSessionsRouter(profile_, this, flare)); |
| 145 } | 158 } |
| 146 | 159 |
| 147 private: | 160 private: |
| 148 Profile* profile_; | 161 Profile* profile_; |
| 149 scoped_ptr<SyncedWindowDelegatesGetter> window_delegates_getter_; | 162 scoped_ptr<SyncedWindowDelegatesGetter> window_delegates_getter_; |
| 150 | 163 |
| 151 DISALLOW_COPY_AND_ASSIGN(SyncSessionsClientImpl); | 164 DISALLOW_COPY_AND_ASSIGN(SyncSessionsClientImpl); |
| 152 }; | 165 }; |
| 153 | 166 |
| 154 ChromeSyncClient::ChromeSyncClient( | 167 ChromeSyncClient::ChromeSyncClient(Profile* profile) |
| 155 Profile* profile, | |
| 156 scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory) | |
| 157 : profile_(profile), | 168 : profile_(profile), |
| 158 component_factory_(component_factory.Pass()), | |
| 159 sync_sessions_client_(new SyncSessionsClientImpl(profile)), | 169 sync_sessions_client_(new SyncSessionsClientImpl(profile)), |
| 160 browsing_data_remover_observer_(NULL) {} | 170 browsing_data_remover_observer_(NULL), |
| 171 weak_ptr_factory_(this) {} |
| 161 | 172 |
| 162 ChromeSyncClient::~ChromeSyncClient() { | 173 ChromeSyncClient::~ChromeSyncClient() { |
| 163 } | 174 } |
| 164 | 175 |
| 165 void ChromeSyncClient::Initialize(sync_driver::SyncService* sync_service) { | 176 void ChromeSyncClient::Initialize( |
| 177 scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory, |
| 178 sync_driver::SyncService* sync_service) { |
| 166 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 179 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 180 component_factory_ = component_factory.Pass(); |
| 167 sync_service_ = sync_service; | 181 sync_service_ = sync_service; |
| 168 web_data_service_ = GetWebDataService(); | 182 web_data_service_ = GetWebDataService(); |
| 169 password_store_ = GetPasswordStore(); | 183 password_store_ = GetPasswordStore(); |
| 170 component_factory_->RegisterDataTypes(this); | |
| 171 } | 184 } |
| 172 | 185 |
| 173 sync_driver::SyncService* ChromeSyncClient::GetSyncService() { | 186 sync_driver::SyncService* ChromeSyncClient::GetSyncService() { |
| 174 // TODO(zea): bring back this DCHECK after Typed URLs are converted to | 187 // TODO(zea): bring back this DCHECK after Typed URLs are converted to |
| 175 // SyncableService. | 188 // SyncableService. |
| 176 // DCHECK_CURRENTLY_ON(BrowserThread::UI); | 189 // DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 177 return sync_service_; | 190 return sync_service_; |
| 178 } | 191 } |
| 179 | 192 |
| 180 PrefService* ChromeSyncClient::GetPrefService() { | 193 PrefService* ChromeSyncClient::GetPrefService() { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 PasswordStoreFactory::GetForProfile(profile_, | 447 PasswordStoreFactory::GetForProfile(profile_, |
| 435 ServiceAccessType::EXPLICIT_ACCESS); | 448 ServiceAccessType::EXPLICIT_ACCESS); |
| 436 password->RemoveLoginsSyncedBetween(start, end); | 449 password->RemoveLoginsSyncedBetween(start, end); |
| 437 } | 450 } |
| 438 | 451 |
| 439 void ChromeSyncClient::SetBrowsingDataRemoverObserverForTesting( | 452 void ChromeSyncClient::SetBrowsingDataRemoverObserverForTesting( |
| 440 BrowsingDataRemover::Observer* observer) { | 453 BrowsingDataRemover::Observer* observer) { |
| 441 browsing_data_remover_observer_ = observer; | 454 browsing_data_remover_observer_ = observer; |
| 442 } | 455 } |
| 443 | 456 |
| 457 sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod |
| 458 ChromeSyncClient::GetRegisterPlatformTypesCallback() { |
| 459 return base::Bind( |
| 460 #ifdef OS_ANDROID |
| 461 &ChromeSyncClient::RegisterAndroidDataTypes, |
| 462 #else |
| 463 &ChromeSyncClient::RegisterDesktopDataTypes, |
| 464 #endif // OS_ANDROID |
| 465 weak_ptr_factory_.GetWeakPtr()); |
| 466 } |
| 467 |
| 468 void ChromeSyncClient::RegisterDesktopDataTypes( |
| 469 syncer::ModelTypeSet disabled_types, |
| 470 syncer::ModelTypeSet enabled_types) { |
| 471 sync_driver::SyncService* sync_service = GetSyncService(); |
| 472 base::Closure error_callback = |
| 473 base::Bind(&ChromeReportUnrecoverableError, chrome::GetChannel()); |
| 474 const scoped_refptr<base::SingleThreadTaskRunner> ui_thread = |
| 475 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 476 |
| 477 #if defined(ENABLE_EXTENSIONS) |
| 478 // App sync is enabled by default. Register unless explicitly |
| 479 // disabled. |
| 480 if (!disabled_types.Has(syncer::APPS)) { |
| 481 sync_service->RegisterDataTypeController(new ExtensionDataTypeController( |
| 482 syncer::APPS, error_callback, this, profile_)); |
| 483 } |
| 484 |
| 485 // Extension sync is enabled by default. Register unless explicitly |
| 486 // disabled. |
| 487 if (!disabled_types.Has(syncer::EXTENSIONS)) { |
| 488 sync_service->RegisterDataTypeController(new ExtensionDataTypeController( |
| 489 syncer::EXTENSIONS, error_callback, this, profile_)); |
| 490 } |
| 491 #endif |
| 492 |
| 493 // Preference sync is enabled by default. Register unless explicitly |
| 494 // disabled. |
| 495 if (!disabled_types.Has(syncer::PREFERENCES)) { |
| 496 sync_service->RegisterDataTypeController(new UIDataTypeController( |
| 497 ui_thread, error_callback, syncer::PREFERENCES, this)); |
| 498 } |
| 499 |
| 500 #if defined(ENABLE_THEMES) |
| 501 // Theme sync is enabled by default. Register unless explicitly disabled. |
| 502 if (!disabled_types.Has(syncer::THEMES)) { |
| 503 sync_service->RegisterDataTypeController( |
| 504 new ThemeDataTypeController(error_callback, this, profile_)); |
| 505 } |
| 506 #endif |
| 507 |
| 508 // Search Engine sync is enabled by default. Register unless explicitly |
| 509 // disabled. |
| 510 if (!disabled_types.Has(syncer::SEARCH_ENGINES)) { |
| 511 sync_service->RegisterDataTypeController(new SearchEngineDataTypeController( |
| 512 ui_thread, error_callback, this, |
| 513 TemplateURLServiceFactory::GetForProfile(profile_))); |
| 514 } |
| 515 |
| 516 #if defined(ENABLE_EXTENSIONS) |
| 517 // Extension setting sync is enabled by default. Register unless explicitly |
| 518 // disabled. |
| 519 if (!disabled_types.Has(syncer::EXTENSION_SETTINGS)) { |
| 520 sync_service->RegisterDataTypeController( |
| 521 new ExtensionSettingDataTypeController(syncer::EXTENSION_SETTINGS, |
| 522 error_callback, this, profile_)); |
| 523 } |
| 524 |
| 525 // App setting sync is enabled by default. Register unless explicitly |
| 526 // disabled. |
| 527 if (!disabled_types.Has(syncer::APP_SETTINGS)) { |
| 528 sync_service->RegisterDataTypeController( |
| 529 new ExtensionSettingDataTypeController(syncer::APP_SETTINGS, |
| 530 error_callback, this, profile_)); |
| 531 } |
| 532 #endif |
| 533 |
| 534 #if defined(ENABLE_APP_LIST) |
| 535 if (app_list::switches::IsAppListSyncEnabled()) { |
| 536 sync_service->RegisterDataTypeController(new UIDataTypeController( |
| 537 ui_thread, error_callback, syncer::APP_LIST, this)); |
| 538 } |
| 539 #endif |
| 540 |
| 541 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) |
| 542 // Dictionary sync is enabled by default. |
| 543 if (!disabled_types.Has(syncer::DICTIONARY)) { |
| 544 sync_service->RegisterDataTypeController(new UIDataTypeController( |
| 545 ui_thread, error_callback, syncer::DICTIONARY, this)); |
| 546 } |
| 547 #endif |
| 548 |
| 549 #if defined(ENABLE_SUPERVISED_USERS) |
| 550 sync_service->RegisterDataTypeController( |
| 551 new SupervisedUserSyncDataTypeController(syncer::SUPERVISED_USER_SETTINGS, |
| 552 error_callback, this, profile_)); |
| 553 sync_service->RegisterDataTypeController( |
| 554 new SupervisedUserSyncDataTypeController( |
| 555 syncer::SUPERVISED_USER_WHITELISTS, error_callback, this, profile_)); |
| 556 sync_service->RegisterDataTypeController( |
| 557 new SupervisedUserSyncDataTypeController(syncer::SUPERVISED_USERS, |
| 558 error_callback, this, profile_)); |
| 559 sync_service->RegisterDataTypeController( |
| 560 new SupervisedUserSyncDataTypeController( |
| 561 syncer::SUPERVISED_USER_SHARED_SETTINGS, error_callback, this, |
| 562 profile_)); |
| 563 #endif |
| 564 |
| 565 #if defined(OS_CHROMEOS) |
| 566 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 567 switches::kEnableWifiCredentialSync) && |
| 568 !disabled_types.Has(syncer::WIFI_CREDENTIALS)) { |
| 569 sync_service->RegisterDataTypeController(new UIDataTypeController( |
| 570 ui_thread, error_callback, syncer::WIFI_CREDENTIALS, this)); |
| 571 } |
| 572 #endif |
| 573 } |
| 574 |
| 575 void ChromeSyncClient::RegisterAndroidDataTypes( |
| 576 syncer::ModelTypeSet disabled_types, |
| 577 syncer::ModelTypeSet enabled_types) { |
| 578 sync_driver::SyncService* sync_service = GetSyncService(); |
| 579 base::Closure error_callback = |
| 580 base::Bind(&ChromeReportUnrecoverableError, chrome::GetChannel()); |
| 581 #if defined(ENABLE_SUPERVISED_USERS) |
| 582 sync_service->RegisterDataTypeController( |
| 583 new SupervisedUserSyncDataTypeController(syncer::SUPERVISED_USER_SETTINGS, |
| 584 error_callback, this, profile_)); |
| 585 sync_service->RegisterDataTypeController( |
| 586 new SupervisedUserSyncDataTypeController( |
| 587 syncer::SUPERVISED_USER_WHITELISTS, error_callback, this, profile_)); |
| 588 #endif |
| 589 } |
| 590 |
| 444 } // namespace browser_sync | 591 } // namespace browser_sync |
| OLD | NEW |