1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "build/build_config.h"
7 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
8 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
9 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
10 #include "chrome/browser/history/history_service_factory.h"
11 #include "chrome/browser/password_manager/password_store_factory.h"
12 #include "chrome/browser/pref_service_flags_storage.h"
13 #include "chrome/browser/prefs/pref_model_associator.h"
14 #include "chrome/browser/prefs/pref_service_syncable.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search_engines/template_url_service_factory.h"
17 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chrome/browser/sync/glue/autofill_data_type_controller.h"
19 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h"
20 #include "chrome/browser/sync/glue/autofill_wallet_data_type_controller.h"
21 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
22 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h"
23 #include "chrome/browser/sync/glue/bookmark_model_associator.h"
24 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
25 #include "chrome/browser/sync/glue/history_delete_directives_data_type_controller.h"
26 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h"
27 #include "chrome/browser/sync/glue/password_data_type_controller.h"
28 #include "chrome/browser/sync/glue/search_engine_data_type_controller.h"
29 #include "chrome/browser/sync/glue/sync_backend_host.h"
30 #include "chrome/browser/sync/glue/sync_backend_host_impl.h"
31 #include "chrome/browser/sync/glue/theme_data_type_controller.h"
32 #include "chrome/browser/sync/glue/typed_url_change_processor.h"
33 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
34 #include "chrome/browser/sync/glue/typed_url_model_associator.h"
35 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
36 #include "chrome/browser/sync/profile_sync_service.h"
37 #include "chrome/browser/sync/profile_sync_service_factory.h"
38 #include "chrome/browser/sync/sessions/session_data_type_controller.h"
39 #include "chrome/browser/themes/theme_service.h"
40 #include "chrome/browser/themes/theme_service_factory.h"
41 #include "chrome/browser/themes/theme_syncable_service.h"
42 #include "chrome/browser/web_data_service_factory.h"
43 #include "chrome/common/chrome_switches.h"
44 #include "chrome/common/chrome_version_info.h"
45 #include "chrome/common/pref_names.h"
46 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service.h"
47 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h"
48 #include "components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h"
49 #include "components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h"
50 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
51 #include "components/autofill/core/common/autofill_pref_names.h"
52 #include "components/autofill/core/common/autofill_switches.h"
53 #include "components/dom_distiller/core/dom_distiller_service.h"
54 #include "components/history/core/browser/history_service.h"
55 #include "components/password_manager/core/browser/password_store.h"
56 #include "components/search_engines/template_url_service.h"
57 #include "components/signin/core/browser/signin_manager.h"
58 #include "components/sync_driver/data_type_manager_impl.h"
59 #include "components/sync_driver/data_type_manager_observer.h"
60 #include "components/sync_driver/device_info_data_type_controller.h"
61 #include "components/sync_driver/generic_change_processor.h"
62 #include "components/sync_driver/proxy_data_type_controller.h"
63 #include "components/sync_driver/shared_change_processor.h"
64 #include "components/sync_driver/ui_data_type_controller.h"
65 #include "content/public/browser/browser_thread.h"
66 #include "google_apis/gaia/oauth2_token_service_request.h"
67 #include "net/url_request/url_request_context_getter.h"
68 #include "sync/api/syncable_service.h"
69 #include "sync/internal_api/public/attachments/attachment_downloader.h"
70 #include "sync/internal_api/public/attachments/attachment_service.h"
71 #include "sync/internal_api/public/attachments/attachment_service_impl.h"
72 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h"
74 #if defined(ENABLE_APP_LIST)
75 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
76 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
77 #include "ui/app_list/app_list_switches.h"
80 #if defined(ENABLE_EXTENSIONS)
81 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
82 #include "chrome/browser/extensions/extension_sync_service.h"
83 #include "chrome/browser/sync/glue/extension_backed_data_type_controller.h"
84 #include "chrome/browser/sync/glue/extension_data_type_controller.h"
85 #include "chrome/browser/sync/glue/extension_setting_data_type_controller.h"
88 #if defined(ENABLE_SUPERVISED_USERS)
89 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service.h"
90 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service_factory.h"
91 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h"
92 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_factory.h"
93 #include "chrome/browser/supervised_user/supervised_user_service.h"
94 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
95 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
96 #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
97 #include "chrome/browser/supervised_user/supervised_user_sync_data_type_controller.h"
98 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h"
101 #if defined(ENABLE_SPELLCHECK)
102 #include "chrome/browser/spellchecker/spellcheck_factory.h"
103 #include "chrome/browser/spellchecker/spellcheck_service.h"
106 #if defined(OS_CHROMEOS)
107 #include "components/wifi_sync/wifi_credential_syncable_service.h"
108 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h"
111 using bookmarks::BookmarkModel
;
112 using browser_sync::AutofillDataTypeController
;
113 using browser_sync::AutofillProfileDataTypeController
;
114 using browser_sync::BookmarkChangeProcessor
;
115 using browser_sync::BookmarkDataTypeController
;
116 using browser_sync::BookmarkModelAssociator
;
117 using browser_sync::ChromeReportUnrecoverableError
;
118 #if defined(ENABLE_EXTENSIONS)
119 using browser_sync::ExtensionBackedDataTypeController
;
120 using browser_sync::ExtensionDataTypeController
;
121 using browser_sync::ExtensionSettingDataTypeController
;
123 using browser_sync::HistoryDeleteDirectivesDataTypeController
;
124 using browser_sync::PasswordDataTypeController
;
125 using browser_sync::SearchEngineDataTypeController
;
126 using browser_sync::SessionDataTypeController
;
127 using browser_sync::SyncBackendHost
;
128 using browser_sync::ThemeDataTypeController
;
129 using browser_sync::TypedUrlChangeProcessor
;
130 using browser_sync::TypedUrlDataTypeController
;
131 using browser_sync::TypedUrlModelAssociator
;
132 using content::BrowserThread
;
133 using sync_driver::DataTypeController
;
134 using sync_driver::DataTypeErrorHandler
;
135 using sync_driver::DataTypeManager
;
136 using sync_driver::DataTypeManagerImpl
;
137 using sync_driver::DataTypeManagerObserver
;
138 using sync_driver::DeviceInfoDataTypeController
;
139 using sync_driver::ProxyDataTypeController
;
140 using sync_driver::SharedChangeProcessor
;
141 using sync_driver::UIDataTypeController
;
145 syncer::ModelTypeSet
GetDisabledTypesFromCommandLine(
146 const base::CommandLine
& command_line
) {
147 syncer::ModelTypeSet disabled_types
;
148 std::string disabled_types_str
=
149 command_line
.GetSwitchValueASCII(switches::kDisableSyncTypes
);
151 // Disable sync types experimentally to measure impact on startup time.
152 // TODO(mlerman): Remove this after the experiment. crbug.com/454788
153 std::string disable_types_finch
=
154 variations::GetVariationParamValue("LightSpeed", "DisableSyncPart");
155 if (!disable_types_finch
.empty()) {
156 if (disabled_types_str
.empty())
157 disabled_types_str
= disable_types_finch
;
159 disabled_types_str
+= ", " + disable_types_finch
;
162 disabled_types
= syncer::ModelTypeSetFromString(disabled_types_str
);
163 return disabled_types
;
166 syncer::ModelTypeSet
GetEnabledTypesFromCommandLine(
167 const base::CommandLine
& command_line
) {
168 syncer::ModelTypeSet enabled_types
;
169 if (command_line
.HasSwitch(autofill::switches::kEnableWalletMetadataSync
))
170 enabled_types
.Put(syncer::AUTOFILL_WALLET_METADATA
);
172 return enabled_types
;
177 ProfileSyncComponentsFactoryImpl::ProfileSyncComponentsFactoryImpl(
179 base::CommandLine
* command_line
,
180 const GURL
& sync_service_url
,
181 OAuth2TokenService
* token_service
,
182 net::URLRequestContextGetter
* url_request_context_getter
)
184 command_line_(command_line
),
185 web_data_service_(WebDataServiceFactory::GetAutofillWebDataForProfile(
187 ServiceAccessType::EXPLICIT_ACCESS
)),
188 sync_service_url_(sync_service_url
),
189 token_service_(token_service
),
190 url_request_context_getter_(url_request_context_getter
),
191 weak_factory_(this) {
192 DCHECK(token_service_
);
193 DCHECK(url_request_context_getter_
);
196 ProfileSyncComponentsFactoryImpl::~ProfileSyncComponentsFactoryImpl() {
199 void ProfileSyncComponentsFactoryImpl::RegisterDataTypes(
200 ProfileSyncService
* pss
) {
201 syncer::ModelTypeSet disabled_types
=
202 GetDisabledTypesFromCommandLine(*command_line_
);
203 syncer::ModelTypeSet enabled_types
=
204 GetEnabledTypesFromCommandLine(*command_line_
);
205 RegisterCommonDataTypes(disabled_types
, enabled_types
, pss
);
206 #if !defined(OS_ANDROID)
207 RegisterDesktopDataTypes(disabled_types
, enabled_types
, pss
);
211 void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes(
212 syncer::ModelTypeSet disabled_types
,
213 syncer::ModelTypeSet enabled_types
,
214 ProfileSyncService
* pss
) {
215 // TODO(stanisc): can DEVICE_INFO be one of disabled datatypes?
216 pss
->RegisterDataTypeController(new DeviceInfoDataTypeController(
217 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
218 base::Bind(&ChromeReportUnrecoverableError
),
220 pss
->GetLocalDeviceInfoProvider()));
222 // Autofill sync is enabled by default. Register unless explicitly
224 if (!disabled_types
.Has(syncer::AUTOFILL
)) {
225 pss
->RegisterDataTypeController(
226 new AutofillDataTypeController(this, profile_
));
229 // Autofill profile sync is enabled by default. Register unless explicitly
231 if (!disabled_types
.Has(syncer::AUTOFILL_PROFILE
)) {
232 pss
->RegisterDataTypeController(
233 new AutofillProfileDataTypeController(this, profile_
));
236 // Wallet data sync is enabled by default, but behind a syncer experiment
237 // enforced by the datatype controller. Register unless explicitly disabled.
238 bool wallet_disabled
= disabled_types
.Has(syncer::AUTOFILL_WALLET_DATA
);
239 if (!wallet_disabled
) {
240 pss
->RegisterDataTypeController(
241 new browser_sync::AutofillWalletDataTypeController(
242 this, profile_
, syncer::AUTOFILL_WALLET_DATA
));
245 // Wallet metadata sync depends on Wallet data sync and is disabled by
246 // default. Register if Wallet data is syncing and metadata sync is explicitly
248 if (!wallet_disabled
&& enabled_types
.Has(syncer::AUTOFILL_WALLET_METADATA
)) {
249 pss
->RegisterDataTypeController(
250 new browser_sync::AutofillWalletDataTypeController(
251 this, profile_
, syncer::AUTOFILL_WALLET_METADATA
));
254 // Bookmark sync is enabled by default. Register unless explicitly
256 if (!disabled_types
.Has(syncer::BOOKMARKS
)) {
257 pss
->RegisterDataTypeController(
258 new BookmarkDataTypeController(this, profile_
, pss
));
261 const bool history_disabled
=
262 profile_
->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled
);
263 // TypedUrl sync is enabled by default. Register unless explicitly disabled,
264 // or if saving history is disabled.
265 if (!disabled_types
.Has(syncer::TYPED_URLS
) && !history_disabled
) {
266 pss
->RegisterDataTypeController(
267 new TypedUrlDataTypeController(this, profile_
, pss
));
270 // Delete directive sync is enabled by default. Register unless full history
272 if (!disabled_types
.Has(syncer::HISTORY_DELETE_DIRECTIVES
) &&
274 pss
->RegisterDataTypeController(
275 new HistoryDeleteDirectivesDataTypeController(this, pss
));
278 // Session sync is enabled by default. Register unless explicitly disabled.
279 // This is also disabled if the browser history is disabled, because the
280 // tab sync data is added to the web history on the server.
281 if (!disabled_types
.Has(syncer::PROXY_TABS
) && !history_disabled
) {
282 pss
->RegisterDataTypeController(new ProxyDataTypeController(
283 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
284 syncer::PROXY_TABS
));
285 pss
->RegisterDataTypeController(
286 new SessionDataTypeController(this,
288 pss
->GetSyncedWindowDelegatesGetter(),
289 pss
->GetLocalDeviceInfoProvider()));
292 // Favicon sync is enabled by default. Register unless explicitly disabled.
293 if (!disabled_types
.Has(syncer::FAVICON_IMAGES
) &&
294 !disabled_types
.Has(syncer::FAVICON_TRACKING
) &&
296 // crbug/384552. We disable error uploading for this data types for now.
297 pss
->RegisterDataTypeController(
298 new UIDataTypeController(
299 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
301 syncer::FAVICON_IMAGES
,
303 pss
->RegisterDataTypeController(
304 new UIDataTypeController(
305 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
307 syncer::FAVICON_TRACKING
,
311 // Password sync is enabled by default. Register unless explicitly
313 if (!disabled_types
.Has(syncer::PASSWORDS
)) {
314 pss
->RegisterDataTypeController(
315 new PasswordDataTypeController(this, profile_
));
318 if (!disabled_types
.Has(syncer::PRIORITY_PREFERENCES
)) {
319 pss
->RegisterDataTypeController(
320 new UIDataTypeController(
321 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
322 base::Bind(&ChromeReportUnrecoverableError
),
323 syncer::PRIORITY_PREFERENCES
,
327 // Article sync is disabled by default. Register only if explicitly enabled.
328 if (IsEnableSyncArticlesSet()) {
329 pss
->RegisterDataTypeController(
330 new UIDataTypeController(
331 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
332 base::Bind(&ChromeReportUnrecoverableError
),
337 #if defined(ENABLE_SUPERVISED_USERS)
338 pss
->RegisterDataTypeController(
339 new SupervisedUserSyncDataTypeController(
340 syncer::SUPERVISED_USER_SETTINGS
,
343 pss
->RegisterDataTypeController(
344 new SupervisedUserSyncDataTypeController(
345 syncer::SUPERVISED_USER_WHITELISTS
,
351 void ProfileSyncComponentsFactoryImpl::RegisterDesktopDataTypes(
352 syncer::ModelTypeSet disabled_types
,
353 syncer::ModelTypeSet enabled_types
,
354 ProfileSyncService
* pss
) {
355 #if defined(ENABLE_EXTENSIONS)
356 // App sync is enabled by default. Register unless explicitly
358 if (!disabled_types
.Has(syncer::APPS
)) {
359 pss
->RegisterDataTypeController(
360 new ExtensionDataTypeController(syncer::APPS
, this, profile_
));
363 // Extension sync is enabled by default. Register unless explicitly
365 if (!disabled_types
.Has(syncer::EXTENSIONS
)) {
366 pss
->RegisterDataTypeController(
367 new ExtensionDataTypeController(syncer::EXTENSIONS
, this, profile_
));
371 // Preference sync is enabled by default. Register unless explicitly
373 if (!disabled_types
.Has(syncer::PREFERENCES
)) {
374 pss
->RegisterDataTypeController(
375 new UIDataTypeController(
376 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
377 base::Bind(&ChromeReportUnrecoverableError
),
382 #if defined(ENABLE_THEMES)
383 // Theme sync is enabled by default. Register unless explicitly disabled.
384 if (!disabled_types
.Has(syncer::THEMES
)) {
385 pss
->RegisterDataTypeController(
386 new ThemeDataTypeController(this, profile_
));
390 // Search Engine sync is enabled by default. Register unless explicitly
392 if (!disabled_types
.Has(syncer::SEARCH_ENGINES
)) {
393 pss
->RegisterDataTypeController(
394 new SearchEngineDataTypeController(this, profile_
));
397 #if defined(ENABLE_EXTENSIONS)
398 // Extension setting sync is enabled by default. Register unless explicitly
400 if (!disabled_types
.Has(syncer::EXTENSION_SETTINGS
)) {
401 pss
->RegisterDataTypeController(new ExtensionSettingDataTypeController(
402 syncer::EXTENSION_SETTINGS
, this, profile_
));
405 // App setting sync is enabled by default. Register unless explicitly
407 if (!disabled_types
.Has(syncer::APP_SETTINGS
)) {
408 pss
->RegisterDataTypeController(new ExtensionSettingDataTypeController(
409 syncer::APP_SETTINGS
, this, profile_
));
413 #if defined(ENABLE_APP_LIST)
414 if (app_list::switches::IsAppListSyncEnabled()) {
415 pss
->RegisterDataTypeController(
416 new UIDataTypeController(
417 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
418 base::Bind(&ChromeReportUnrecoverableError
),
424 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS)
425 // Dictionary sync is enabled by default.
426 if (!disabled_types
.Has(syncer::DICTIONARY
)) {
427 pss
->RegisterDataTypeController(
428 new UIDataTypeController(
429 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
430 base::Bind(&ChromeReportUnrecoverableError
),
436 #if defined(ENABLE_SUPERVISED_USERS)
437 pss
->RegisterDataTypeController(
438 new SupervisedUserSyncDataTypeController(
439 syncer::SUPERVISED_USERS
,
442 pss
->RegisterDataTypeController(
443 new SupervisedUserSyncDataTypeController(
444 syncer::SUPERVISED_USER_SHARED_SETTINGS
,
449 #if defined(OS_CHROMEOS)
450 if (command_line_
->HasSwitch(switches::kEnableWifiCredentialSync
) &&
451 !disabled_types
.Has(syncer::WIFI_CREDENTIALS
)) {
452 pss
->RegisterDataTypeController(
453 new UIDataTypeController(
454 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
455 base::Bind(&ChromeReportUnrecoverableError
),
456 syncer::WIFI_CREDENTIALS
,
462 DataTypeManager
* ProfileSyncComponentsFactoryImpl::CreateDataTypeManager(
463 const syncer::WeakHandle
<syncer::DataTypeDebugInfoListener
>&
465 const DataTypeController::TypeMap
* controllers
,
466 const sync_driver::DataTypeEncryptionHandler
* encryption_handler
,
467 SyncBackendHost
* backend
,
468 DataTypeManagerObserver
* observer
) {
469 return new DataTypeManagerImpl(base::Bind(ChromeReportUnrecoverableError
),
477 browser_sync::SyncBackendHost
*
478 ProfileSyncComponentsFactoryImpl::CreateSyncBackendHost(
479 const std::string
& name
,
481 invalidation::InvalidationService
* invalidator
,
482 const base::WeakPtr
<sync_driver::SyncPrefs
>& sync_prefs
,
483 const base::FilePath
& sync_folder
) {
484 return new browser_sync::SyncBackendHostImpl(name
, profile
, invalidator
,
485 sync_prefs
, sync_folder
);
488 scoped_ptr
<sync_driver::LocalDeviceInfoProvider
>
489 ProfileSyncComponentsFactoryImpl::CreateLocalDeviceInfoProvider() {
490 return scoped_ptr
<sync_driver::LocalDeviceInfoProvider
>(
491 new browser_sync::LocalDeviceInfoProviderImpl());
494 base::WeakPtr
<syncer::SyncableService
> ProfileSyncComponentsFactoryImpl::
495 GetSyncableServiceForType(syncer::ModelType type
) {
496 if (!profile_
) { // For tests.
497 return base::WeakPtr
<syncer::SyncableService
>();
500 case syncer::DEVICE_INFO
:
501 return ProfileSyncServiceFactory::GetForProfile(profile_
)
502 ->GetDeviceInfoSyncableService()
504 case syncer::PREFERENCES
:
505 return PrefServiceSyncable::FromProfile(
506 profile_
)->GetSyncableService(syncer::PREFERENCES
)->AsWeakPtr();
507 case syncer::PRIORITY_PREFERENCES
:
508 return PrefServiceSyncable::FromProfile(profile_
)->GetSyncableService(
509 syncer::PRIORITY_PREFERENCES
)->AsWeakPtr();
510 case syncer::AUTOFILL
:
511 case syncer::AUTOFILL_PROFILE
:
512 case syncer::AUTOFILL_WALLET_DATA
:
513 case syncer::AUTOFILL_WALLET_METADATA
: {
514 if (!web_data_service_
.get())
515 return base::WeakPtr
<syncer::SyncableService
>();
516 if (type
== syncer::AUTOFILL
) {
517 return autofill::AutocompleteSyncableService::FromWebDataService(
518 web_data_service_
.get())->AsWeakPtr();
519 } else if (type
== syncer::AUTOFILL_PROFILE
) {
520 return autofill::AutofillProfileSyncableService::FromWebDataService(
521 web_data_service_
.get())->AsWeakPtr();
522 } else if (type
== syncer::AUTOFILL_WALLET_METADATA
) {
523 return autofill::AutofillWalletMetadataSyncableService::
524 FromWebDataService(web_data_service_
.get())->AsWeakPtr();
526 return autofill::AutofillWalletSyncableService::FromWebDataService(
527 web_data_service_
.get())->AsWeakPtr();
529 case syncer::SEARCH_ENGINES
:
530 return TemplateURLServiceFactory::GetForProfile(profile_
)->AsWeakPtr();
531 #if defined(ENABLE_EXTENSIONS)
533 case syncer::EXTENSIONS
:
534 return ExtensionSyncService::Get(profile_
)->AsWeakPtr();
535 case syncer::APP_SETTINGS
:
536 case syncer::EXTENSION_SETTINGS
:
537 return extensions::settings_sync_util::GetSyncableService(profile_
, type
)
540 #if defined(ENABLE_APP_LIST)
541 case syncer::APP_LIST
:
542 return app_list::AppListSyncableServiceFactory::GetForProfile(profile_
)->
545 #if defined(ENABLE_THEMES)
547 return ThemeServiceFactory::GetForProfile(profile_
)->
548 GetThemeSyncableService()->AsWeakPtr();
550 case syncer::HISTORY_DELETE_DIRECTIVES
: {
551 history::HistoryService
* history
= HistoryServiceFactory::GetForProfile(
552 profile_
, ServiceAccessType::EXPLICIT_ACCESS
);
553 return history
? history
->AsWeakPtr()
554 : base::WeakPtr
<history::HistoryService
>();
556 #if defined(ENABLE_SPELLCHECK)
557 case syncer::DICTIONARY
:
558 return SpellcheckServiceFactory::GetForContext(profile_
)->
559 GetCustomDictionary()->AsWeakPtr();
561 case syncer::FAVICON_IMAGES
:
562 case syncer::FAVICON_TRACKING
: {
563 browser_sync::FaviconCache
* favicons
=
564 ProfileSyncServiceFactory::GetForProfile(profile_
)->
566 return favicons
? favicons
->AsWeakPtr()
567 : base::WeakPtr
<syncer::SyncableService
>();
569 #if defined(ENABLE_SUPERVISED_USERS)
570 case syncer::SUPERVISED_USER_SETTINGS
:
571 return SupervisedUserSettingsServiceFactory::GetForProfile(profile_
)->
573 #if !defined(OS_ANDROID) && !defined(OS_IOS)
574 case syncer::SUPERVISED_USERS
:
575 return SupervisedUserSyncServiceFactory::GetForProfile(profile_
)->
577 case syncer::SUPERVISED_USER_SHARED_SETTINGS
:
578 return SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
579 profile_
)->AsWeakPtr();
581 case syncer::SUPERVISED_USER_WHITELISTS
:
582 return SupervisedUserServiceFactory::GetForProfile(profile_
)
583 ->GetWhitelistService()
586 case syncer::ARTICLES
: {
587 dom_distiller::DomDistillerService
* service
=
588 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext(
591 return service
->GetSyncableService()->AsWeakPtr();
592 return base::WeakPtr
<syncer::SyncableService
>();
594 case syncer::SESSIONS
: {
595 return ProfileSyncServiceFactory::GetForProfile(profile_
)->
596 GetSessionsSyncableService()->AsWeakPtr();
598 case syncer::PASSWORDS
: {
599 scoped_refptr
<password_manager::PasswordStore
> password_store
=
600 PasswordStoreFactory::GetForProfile(
601 profile_
, ServiceAccessType::EXPLICIT_ACCESS
);
602 return password_store
.get() ? password_store
->GetPasswordSyncableService()
603 : base::WeakPtr
<syncer::SyncableService
>();
605 #if defined(OS_CHROMEOS)
606 case syncer::WIFI_CREDENTIALS
:
607 return wifi_sync::WifiCredentialSyncableServiceFactory::
608 GetForBrowserContext(profile_
)->AsWeakPtr();
611 // The following datatypes still need to be transitioned to the
612 // syncer::SyncableService API:
616 return base::WeakPtr
<syncer::SyncableService
>();
620 class TokenServiceProvider
621 : public OAuth2TokenServiceRequest::TokenServiceProvider
{
623 TokenServiceProvider(
624 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
625 OAuth2TokenService
* token_service
);
627 // OAuth2TokenServiceRequest::TokenServiceProvider implementation.
628 scoped_refptr
<base::SingleThreadTaskRunner
> GetTokenServiceTaskRunner()
630 OAuth2TokenService
* GetTokenService() override
;
633 ~TokenServiceProvider() override
;
635 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
636 OAuth2TokenService
* token_service_
;
639 TokenServiceProvider::TokenServiceProvider(
640 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
641 OAuth2TokenService
* token_service
)
642 : task_runner_(task_runner
), token_service_(token_service
) {
645 TokenServiceProvider::~TokenServiceProvider() {
648 scoped_refptr
<base::SingleThreadTaskRunner
>
649 TokenServiceProvider::GetTokenServiceTaskRunner() {
653 OAuth2TokenService
* TokenServiceProvider::GetTokenService() {
654 return token_service_
;
657 scoped_ptr
<syncer::AttachmentService
>
658 ProfileSyncComponentsFactoryImpl::CreateAttachmentService(
659 scoped_ptr
<syncer::AttachmentStoreForSync
> attachment_store
,
660 const syncer::UserShare
& user_share
,
661 const std::string
& store_birthday
,
662 syncer::ModelType model_type
,
663 syncer::AttachmentService::Delegate
* delegate
) {
664 scoped_ptr
<syncer::AttachmentUploader
> attachment_uploader
;
665 scoped_ptr
<syncer::AttachmentDownloader
> attachment_downloader
;
666 // Only construct an AttachmentUploader and AttachmentDownload if we have sync
667 // credentials. We may not have sync credentials because there may not be a
668 // signed in sync user (e.g. sync is running in "backup" mode).
669 if (!user_share
.sync_credentials
.email
.empty() &&
670 !user_share
.sync_credentials
.scope_set
.empty()) {
671 scoped_refptr
<OAuth2TokenServiceRequest::TokenServiceProvider
>
672 token_service_provider(new TokenServiceProvider(
673 content::BrowserThread::GetMessageLoopProxyForThread(
674 content::BrowserThread::UI
),
676 // TODO(maniscalco): Use shared (one per profile) thread-safe instances of
677 // AttachmentUploader and AttachmentDownloader instead of creating a new one
678 // per AttachmentService (bug 369536).
679 attachment_uploader
.reset(new syncer::AttachmentUploaderImpl(
680 sync_service_url_
, url_request_context_getter_
,
681 user_share
.sync_credentials
.email
,
682 user_share
.sync_credentials
.scope_set
, token_service_provider
,
683 store_birthday
, model_type
));
685 token_service_provider
= new TokenServiceProvider(
686 content::BrowserThread::GetMessageLoopProxyForThread(
687 content::BrowserThread::UI
),
689 attachment_downloader
= syncer::AttachmentDownloader::Create(
690 sync_service_url_
, url_request_context_getter_
,
691 user_share
.sync_credentials
.email
,
692 user_share
.sync_credentials
.scope_set
, token_service_provider
,
693 store_birthday
, model_type
);
696 // It is important that the initial backoff delay is relatively large. For
697 // whatever reason, the server may fail all requests for a short period of
698 // time. When this happens we don't want to overwhelm the server with
699 // requests so we use a large initial backoff.
700 const base::TimeDelta initial_backoff_delay
=
701 base::TimeDelta::FromMinutes(30);
702 const base::TimeDelta max_backoff_delay
= base::TimeDelta::FromHours(4);
703 scoped_ptr
<syncer::AttachmentService
> attachment_service(
704 new syncer::AttachmentServiceImpl(
705 attachment_store
.Pass(), attachment_uploader
.Pass(),
706 attachment_downloader
.Pass(), delegate
, initial_backoff_delay
,
708 return attachment_service
.Pass();
711 ProfileSyncComponentsFactory::SyncComponents
712 ProfileSyncComponentsFactoryImpl::CreateBookmarkSyncComponents(
713 ProfileSyncService
* profile_sync_service
,
714 sync_driver::DataTypeErrorHandler
* error_handler
) {
715 BookmarkModel
* bookmark_model
=
716 BookmarkModelFactory::GetForProfile(profile_sync_service
->profile());
717 syncer::UserShare
* user_share
= profile_sync_service
->GetUserShare();
718 // TODO(akalin): We may want to propagate this switch up eventually.
719 #if defined(OS_ANDROID)
720 const bool kExpectMobileBookmarksFolder
= true;
722 const bool kExpectMobileBookmarksFolder
= false;
724 BookmarkModelAssociator
* model_associator
=
725 new BookmarkModelAssociator(bookmark_model
,
726 profile_sync_service
->profile(),
729 kExpectMobileBookmarksFolder
);
730 BookmarkChangeProcessor
* change_processor
=
731 new BookmarkChangeProcessor(profile_sync_service
->profile(),
734 return SyncComponents(model_associator
, change_processor
);
737 ProfileSyncComponentsFactory::SyncComponents
738 ProfileSyncComponentsFactoryImpl::CreateTypedUrlSyncComponents(
739 ProfileSyncService
* profile_sync_service
,
740 history::HistoryBackend
* history_backend
,
741 sync_driver::DataTypeErrorHandler
* error_handler
) {
742 TypedUrlModelAssociator
* model_associator
=
743 new TypedUrlModelAssociator(profile_sync_service
,
746 TypedUrlChangeProcessor
* change_processor
=
747 new TypedUrlChangeProcessor(profile_
,
751 return SyncComponents(model_associator
, change_processor
);