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.h"
11 #include "chrome/browser/history/history_service_factory.h"
12 #include "chrome/browser/password_manager/password_store_factory.h"
13 #include "chrome/browser/pref_service_flags_storage.h"
14 #include "chrome/browser/prefs/pref_model_associator.h"
15 #include "chrome/browser/prefs/pref_service_syncable.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/browser/signin/signin_manager_factory.h"
19 #include "chrome/browser/sync/glue/autofill_data_type_controller.h"
20 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h"
21 #include "chrome/browser/sync/glue/autofill_wallet_data_type_controller.h"
22 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
23 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h"
24 #include "chrome/browser/sync/glue/bookmark_model_associator.h"
25 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
26 #include "chrome/browser/sync/glue/history_delete_directives_data_type_controller.h"
27 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h"
28 #include "chrome/browser/sync/glue/password_data_type_controller.h"
29 #include "chrome/browser/sync/glue/search_engine_data_type_controller.h"
30 #include "chrome/browser/sync/glue/sync_backend_host.h"
31 #include "chrome/browser/sync/glue/sync_backend_host_impl.h"
32 #include "chrome/browser/sync/glue/theme_data_type_controller.h"
33 #include "chrome/browser/sync/glue/typed_url_change_processor.h"
34 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
35 #include "chrome/browser/sync/glue/typed_url_model_associator.h"
36 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
37 #include "chrome/browser/sync/profile_sync_service.h"
38 #include "chrome/browser/sync/profile_sync_service_factory.h"
39 #include "chrome/browser/sync/sessions/session_data_type_controller.h"
40 #include "chrome/browser/themes/theme_service.h"
41 #include "chrome/browser/themes/theme_service_factory.h"
42 #include "chrome/browser/themes/theme_syncable_service.h"
43 #include "chrome/browser/webdata/web_data_service_factory.h"
44 #include "chrome/common/chrome_switches.h"
45 #include "chrome/common/chrome_version_info.h"
46 #include "chrome/common/pref_names.h"
47 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service.h"
48 #include "components/autofill/core/browser/webdata/autofill_profile_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/password_manager/core/browser/password_store.h"
55 #include "components/search_engines/template_url_service.h"
56 #include "components/signin/core/browser/signin_manager.h"
57 #include "components/sync_driver/data_type_manager_impl.h"
58 #include "components/sync_driver/data_type_manager_observer.h"
59 #include "components/sync_driver/device_info_data_type_controller.h"
60 #include "components/sync_driver/generic_change_processor.h"
61 #include "components/sync_driver/proxy_data_type_controller.h"
62 #include "components/sync_driver/shared_change_processor.h"
63 #include "components/sync_driver/ui_data_type_controller.h"
64 #include "content/public/browser/browser_thread.h"
65 #include "google_apis/gaia/oauth2_token_service_request.h"
66 #include "net/url_request/url_request_context_getter.h"
67 #include "sync/api/syncable_service.h"
68 #include "sync/internal_api/public/attachments/attachment_downloader.h"
69 #include "sync/internal_api/public/attachments/attachment_service.h"
70 #include "sync/internal_api/public/attachments/attachment_service_impl.h"
71 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h"
73 #if defined(ENABLE_APP_LIST)
74 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
75 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
76 #include "ui/app_list/app_list_switches.h"
79 #if defined(ENABLE_EXTENSIONS)
80 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
81 #include "chrome/browser/extensions/extension_sync_service.h"
82 #include "chrome/browser/sync/glue/extension_backed_data_type_controller.h"
83 #include "chrome/browser/sync/glue/extension_data_type_controller.h"
84 #include "chrome/browser/sync/glue/extension_setting_data_type_controller.h"
87 #if defined(ENABLE_SUPERVISED_USERS)
88 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service.h"
89 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service_factory.h"
90 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h"
91 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_factory.h"
92 #include "chrome/browser/supervised_user/supervised_user_service.h"
93 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
94 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
95 #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
96 #include "chrome/browser/supervised_user/supervised_user_sync_data_type_controller.h"
97 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h"
100 #if defined(ENABLE_SPELLCHECK)
101 #include "chrome/browser/spellchecker/spellcheck_factory.h"
102 #include "chrome/browser/spellchecker/spellcheck_service.h"
105 #if defined(OS_CHROMEOS)
106 #include "components/wifi_sync/wifi_credential_syncable_service.h"
107 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h"
110 using bookmarks::BookmarkModel
;
111 using browser_sync::AutofillDataTypeController
;
112 using browser_sync::AutofillProfileDataTypeController
;
113 using browser_sync::BookmarkChangeProcessor
;
114 using browser_sync::BookmarkDataTypeController
;
115 using browser_sync::BookmarkModelAssociator
;
116 using browser_sync::ChromeReportUnrecoverableError
;
117 #if defined(ENABLE_EXTENSIONS)
118 using browser_sync::ExtensionBackedDataTypeController
;
119 using browser_sync::ExtensionDataTypeController
;
120 using browser_sync::ExtensionSettingDataTypeController
;
122 using browser_sync::HistoryDeleteDirectivesDataTypeController
;
123 using browser_sync::PasswordDataTypeController
;
124 using browser_sync::SearchEngineDataTypeController
;
125 using browser_sync::SessionDataTypeController
;
126 using browser_sync::SyncBackendHost
;
127 using browser_sync::ThemeDataTypeController
;
128 using browser_sync::TypedUrlChangeProcessor
;
129 using browser_sync::TypedUrlDataTypeController
;
130 using browser_sync::TypedUrlModelAssociator
;
131 using content::BrowserThread
;
132 using sync_driver::DataTypeController
;
133 using sync_driver::DataTypeErrorHandler
;
134 using sync_driver::DataTypeManager
;
135 using sync_driver::DataTypeManagerImpl
;
136 using sync_driver::DataTypeManagerObserver
;
137 using sync_driver::DeviceInfoDataTypeController
;
138 using sync_driver::ProxyDataTypeController
;
139 using sync_driver::SharedChangeProcessor
;
140 using sync_driver::UIDataTypeController
;
144 syncer::ModelTypeSet
GetDisabledTypesFromCommandLine(
145 const base::CommandLine
& command_line
) {
146 syncer::ModelTypeSet disabled_types
;
147 std::string disabled_types_str
=
148 command_line
.GetSwitchValueASCII(switches::kDisableSyncTypes
);
149 disabled_types
= syncer::ModelTypeSetFromString(disabled_types_str
);
150 return disabled_types
;
153 syncer::ModelTypeSet
GetEnabledTypesFromCommandLine(
154 const base::CommandLine
& command_line
) {
155 syncer::ModelTypeSet enabled_types
;
156 return enabled_types
;
161 ProfileSyncComponentsFactoryImpl::ProfileSyncComponentsFactoryImpl(
163 base::CommandLine
* command_line
,
164 const GURL
& sync_service_url
,
165 OAuth2TokenService
* token_service
,
166 net::URLRequestContextGetter
* url_request_context_getter
)
168 command_line_(command_line
),
169 web_data_service_(WebDataServiceFactory::GetAutofillWebDataForProfile(
171 ServiceAccessType::EXPLICIT_ACCESS
)),
172 sync_service_url_(sync_service_url
),
173 token_service_(token_service
),
174 url_request_context_getter_(url_request_context_getter
),
175 weak_factory_(this) {
176 DCHECK(token_service_
);
177 DCHECK(url_request_context_getter_
);
180 ProfileSyncComponentsFactoryImpl::~ProfileSyncComponentsFactoryImpl() {
183 void ProfileSyncComponentsFactoryImpl::RegisterDataTypes(
184 ProfileSyncService
* pss
) {
185 syncer::ModelTypeSet disabled_types
=
186 GetDisabledTypesFromCommandLine(*command_line_
);
187 syncer::ModelTypeSet enabled_types
=
188 GetEnabledTypesFromCommandLine(*command_line_
);
189 RegisterCommonDataTypes(disabled_types
, enabled_types
, pss
);
190 #if !defined(OS_ANDROID)
191 RegisterDesktopDataTypes(disabled_types
, enabled_types
, pss
);
195 void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes(
196 syncer::ModelTypeSet disabled_types
,
197 syncer::ModelTypeSet enabled_types
,
198 ProfileSyncService
* pss
) {
199 // TODO(stanisc): can DEVICE_INFO be one of disabled datatypes?
200 pss
->RegisterDataTypeController(new DeviceInfoDataTypeController(
201 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
202 base::Bind(&ChromeReportUnrecoverableError
),
204 pss
->GetLocalDeviceInfoProvider()));
206 // Autofill sync is enabled by default. Register unless explicitly
208 if (!disabled_types
.Has(syncer::AUTOFILL
)) {
209 pss
->RegisterDataTypeController(
210 new AutofillDataTypeController(this, profile_
));
213 // Autofill profile sync is enabled by default. Register unless explicitly
215 if (!disabled_types
.Has(syncer::AUTOFILL_PROFILE
)) {
216 pss
->RegisterDataTypeController(
217 new AutofillProfileDataTypeController(this, profile_
));
220 if (profile_
->GetPrefs()->GetBoolean(
221 autofill::prefs::kAutofillWalletSyncExperimentEnabled
) &&
222 !disabled_types
.Has(syncer::AUTOFILL_WALLET_DATA
)) {
223 // The feature can be enabled by sync experiment *or* command line flag,
224 // and additionally the sync type must be enabled.
225 pss
->RegisterDataTypeController(
226 new browser_sync::AutofillWalletDataTypeController(this, profile_
));
229 // Bookmark sync is enabled by default. Register unless explicitly
231 if (!disabled_types
.Has(syncer::BOOKMARKS
)) {
232 pss
->RegisterDataTypeController(
233 new BookmarkDataTypeController(this, profile_
, pss
));
236 const bool history_disabled
=
237 profile_
->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled
);
238 // TypedUrl sync is enabled by default. Register unless explicitly disabled,
239 // or if saving history is disabled.
240 if (!disabled_types
.Has(syncer::TYPED_URLS
) && !history_disabled
) {
241 pss
->RegisterDataTypeController(
242 new TypedUrlDataTypeController(this, profile_
, pss
));
245 // Delete directive sync is enabled by default. Register unless full history
247 if (!disabled_types
.Has(syncer::HISTORY_DELETE_DIRECTIVES
) &&
249 pss
->RegisterDataTypeController(
250 new HistoryDeleteDirectivesDataTypeController(this, pss
));
253 // Session sync is enabled by default. Register unless explicitly disabled.
254 // This is also disabled if the browser history is disabled, because the
255 // tab sync data is added to the web history on the server.
256 if (!disabled_types
.Has(syncer::PROXY_TABS
) && !history_disabled
) {
257 pss
->RegisterDataTypeController(new ProxyDataTypeController(
258 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
259 syncer::PROXY_TABS
));
260 pss
->RegisterDataTypeController(
261 new SessionDataTypeController(this,
263 pss
->GetSyncedWindowDelegatesGetter(),
264 pss
->GetLocalDeviceInfoProvider()));
267 // Favicon sync is enabled by default. Register unless explicitly disabled.
268 if (!disabled_types
.Has(syncer::FAVICON_IMAGES
) &&
269 !disabled_types
.Has(syncer::FAVICON_TRACKING
) &&
271 // crbug/384552. We disable error uploading for this data types for now.
272 pss
->RegisterDataTypeController(
273 new UIDataTypeController(
274 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
276 syncer::FAVICON_IMAGES
,
278 pss
->RegisterDataTypeController(
279 new UIDataTypeController(
280 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
282 syncer::FAVICON_TRACKING
,
286 // Password sync is enabled by default. Register unless explicitly
288 if (!disabled_types
.Has(syncer::PASSWORDS
)) {
289 pss
->RegisterDataTypeController(
290 new PasswordDataTypeController(this, profile_
));
293 // Article sync is disabled by default. Register only if explicitly enabled.
294 if (IsEnableSyncArticlesSet()) {
295 pss
->RegisterDataTypeController(
296 new UIDataTypeController(
297 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
298 base::Bind(&ChromeReportUnrecoverableError
),
303 #if defined(ENABLE_SUPERVISED_USERS)
304 pss
->RegisterDataTypeController(
305 new SupervisedUserSyncDataTypeController(
306 syncer::SUPERVISED_USER_SETTINGS
,
309 pss
->RegisterDataTypeController(
310 new SupervisedUserSyncDataTypeController(
311 syncer::SUPERVISED_USER_WHITELISTS
,
317 void ProfileSyncComponentsFactoryImpl::RegisterDesktopDataTypes(
318 syncer::ModelTypeSet disabled_types
,
319 syncer::ModelTypeSet enabled_types
,
320 ProfileSyncService
* pss
) {
321 #if defined(ENABLE_EXTENSIONS)
322 // App sync is enabled by default. Register unless explicitly
324 if (!disabled_types
.Has(syncer::APPS
)) {
325 pss
->RegisterDataTypeController(
326 new ExtensionDataTypeController(syncer::APPS
, this, profile_
));
329 // Extension sync is enabled by default. Register unless explicitly
331 if (!disabled_types
.Has(syncer::EXTENSIONS
)) {
332 pss
->RegisterDataTypeController(
333 new ExtensionDataTypeController(syncer::EXTENSIONS
, this, profile_
));
337 // Preference sync is enabled by default. Register unless explicitly
339 if (!disabled_types
.Has(syncer::PREFERENCES
)) {
340 pss
->RegisterDataTypeController(
341 new UIDataTypeController(
342 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
343 base::Bind(&ChromeReportUnrecoverableError
),
348 if (!disabled_types
.Has(syncer::PRIORITY_PREFERENCES
)) {
349 pss
->RegisterDataTypeController(
350 new UIDataTypeController(
351 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
352 base::Bind(&ChromeReportUnrecoverableError
),
353 syncer::PRIORITY_PREFERENCES
,
357 #if defined(ENABLE_THEMES)
358 // Theme sync is enabled by default. Register unless explicitly disabled.
359 if (!disabled_types
.Has(syncer::THEMES
)) {
360 pss
->RegisterDataTypeController(
361 new ThemeDataTypeController(this, profile_
));
365 // Search Engine sync is enabled by default. Register unless explicitly
367 if (!disabled_types
.Has(syncer::SEARCH_ENGINES
)) {
368 pss
->RegisterDataTypeController(
369 new SearchEngineDataTypeController(this, profile_
));
372 #if defined(ENABLE_EXTENSIONS)
373 // Extension setting sync is enabled by default. Register unless explicitly
375 if (!disabled_types
.Has(syncer::EXTENSION_SETTINGS
)) {
376 pss
->RegisterDataTypeController(new ExtensionSettingDataTypeController(
377 syncer::EXTENSION_SETTINGS
, this, profile_
));
380 // App setting sync is enabled by default. Register unless explicitly
382 if (!disabled_types
.Has(syncer::APP_SETTINGS
)) {
383 pss
->RegisterDataTypeController(new ExtensionSettingDataTypeController(
384 syncer::APP_SETTINGS
, this, profile_
));
388 #if defined(ENABLE_APP_LIST)
389 if (app_list::switches::IsAppListSyncEnabled()) {
390 pss
->RegisterDataTypeController(
391 new UIDataTypeController(
392 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
393 base::Bind(&ChromeReportUnrecoverableError
),
399 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS)
400 // Dictionary sync is enabled by default.
401 if (!disabled_types
.Has(syncer::DICTIONARY
)) {
402 pss
->RegisterDataTypeController(
403 new UIDataTypeController(
404 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
405 base::Bind(&ChromeReportUnrecoverableError
),
411 #if defined(ENABLE_SUPERVISED_USERS)
412 pss
->RegisterDataTypeController(
413 new SupervisedUserSyncDataTypeController(
414 syncer::SUPERVISED_USERS
,
417 pss
->RegisterDataTypeController(
418 new SupervisedUserSyncDataTypeController(
419 syncer::SUPERVISED_USER_SHARED_SETTINGS
,
424 #if defined(OS_CHROMEOS)
425 if (command_line_
->HasSwitch(switches::kEnableWifiCredentialSync
) &&
426 !disabled_types
.Has(syncer::WIFI_CREDENTIALS
)) {
427 pss
->RegisterDataTypeController(
428 new UIDataTypeController(
429 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
430 base::Bind(&ChromeReportUnrecoverableError
),
431 syncer::WIFI_CREDENTIALS
,
437 DataTypeManager
* ProfileSyncComponentsFactoryImpl::CreateDataTypeManager(
438 const syncer::WeakHandle
<syncer::DataTypeDebugInfoListener
>&
440 const DataTypeController::TypeMap
* controllers
,
441 const sync_driver::DataTypeEncryptionHandler
* encryption_handler
,
442 SyncBackendHost
* backend
,
443 DataTypeManagerObserver
* observer
) {
444 return new DataTypeManagerImpl(base::Bind(ChromeReportUnrecoverableError
),
452 browser_sync::SyncBackendHost
*
453 ProfileSyncComponentsFactoryImpl::CreateSyncBackendHost(
454 const std::string
& name
,
456 invalidation::InvalidationService
* invalidator
,
457 const base::WeakPtr
<sync_driver::SyncPrefs
>& sync_prefs
,
458 const base::FilePath
& sync_folder
) {
459 return new browser_sync::SyncBackendHostImpl(name
, profile
, invalidator
,
460 sync_prefs
, sync_folder
);
463 scoped_ptr
<sync_driver::LocalDeviceInfoProvider
>
464 ProfileSyncComponentsFactoryImpl::CreateLocalDeviceInfoProvider() {
465 return scoped_ptr
<sync_driver::LocalDeviceInfoProvider
>(
466 new browser_sync::LocalDeviceInfoProviderImpl());
469 base::WeakPtr
<syncer::SyncableService
> ProfileSyncComponentsFactoryImpl::
470 GetSyncableServiceForType(syncer::ModelType type
) {
471 if (!profile_
) { // For tests.
472 return base::WeakPtr
<syncer::SyncableService
>();
475 case syncer::DEVICE_INFO
:
476 return ProfileSyncServiceFactory::GetForProfile(profile_
)
477 ->GetDeviceInfoSyncableService()
479 case syncer::PREFERENCES
:
480 return PrefServiceSyncable::FromProfile(
481 profile_
)->GetSyncableService(syncer::PREFERENCES
)->AsWeakPtr();
482 case syncer::PRIORITY_PREFERENCES
:
483 return PrefServiceSyncable::FromProfile(profile_
)->GetSyncableService(
484 syncer::PRIORITY_PREFERENCES
)->AsWeakPtr();
485 case syncer::AUTOFILL
:
486 case syncer::AUTOFILL_PROFILE
:
487 case syncer::AUTOFILL_WALLET_DATA
: {
488 if (!web_data_service_
.get())
489 return base::WeakPtr
<syncer::SyncableService
>();
490 if (type
== syncer::AUTOFILL
) {
491 return autofill::AutocompleteSyncableService::FromWebDataService(
492 web_data_service_
.get())->AsWeakPtr();
493 } else if (type
== syncer::AUTOFILL_PROFILE
) {
494 return autofill::AutofillProfileSyncableService::FromWebDataService(
495 web_data_service_
.get())->AsWeakPtr();
497 return autofill::AutofillWalletSyncableService::FromWebDataService(
498 web_data_service_
.get())->AsWeakPtr();
500 case syncer::SEARCH_ENGINES
:
501 return TemplateURLServiceFactory::GetForProfile(profile_
)->AsWeakPtr();
502 #if defined(ENABLE_EXTENSIONS)
504 case syncer::EXTENSIONS
:
505 return ExtensionSyncService::Get(profile_
)->AsWeakPtr();
506 case syncer::APP_SETTINGS
:
507 case syncer::EXTENSION_SETTINGS
:
508 return extensions::settings_sync_util::GetSyncableService(profile_
, type
)
511 #if defined(ENABLE_APP_LIST)
512 case syncer::APP_LIST
:
513 return app_list::AppListSyncableServiceFactory::GetForProfile(profile_
)->
516 #if defined(ENABLE_THEMES)
518 return ThemeServiceFactory::GetForProfile(profile_
)->
519 GetThemeSyncableService()->AsWeakPtr();
521 case syncer::HISTORY_DELETE_DIRECTIVES
: {
522 HistoryService
* history
= HistoryServiceFactory::GetForProfile(
523 profile_
, ServiceAccessType::EXPLICIT_ACCESS
);
524 return history
? history
->AsWeakPtr() : base::WeakPtr
<HistoryService
>();
526 #if defined(ENABLE_SPELLCHECK)
527 case syncer::DICTIONARY
:
528 return SpellcheckServiceFactory::GetForContext(profile_
)->
529 GetCustomDictionary()->AsWeakPtr();
531 case syncer::FAVICON_IMAGES
:
532 case syncer::FAVICON_TRACKING
: {
533 browser_sync::FaviconCache
* favicons
=
534 ProfileSyncServiceFactory::GetForProfile(profile_
)->
536 return favicons
? favicons
->AsWeakPtr()
537 : base::WeakPtr
<syncer::SyncableService
>();
539 #if defined(ENABLE_SUPERVISED_USERS)
540 case syncer::SUPERVISED_USER_SETTINGS
:
541 return SupervisedUserSettingsServiceFactory::GetForProfile(profile_
)->
543 case syncer::SUPERVISED_USERS
:
544 return SupervisedUserSyncServiceFactory::GetForProfile(profile_
)->
546 case syncer::SUPERVISED_USER_SHARED_SETTINGS
:
547 return SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
548 profile_
)->AsWeakPtr();
549 case syncer::SUPERVISED_USER_WHITELISTS
:
550 return SupervisedUserServiceFactory::GetForProfile(profile_
)
551 ->GetWhitelistService()
554 case syncer::ARTICLES
: {
555 dom_distiller::DomDistillerService
* service
=
556 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext(
559 return service
->GetSyncableService()->AsWeakPtr();
560 return base::WeakPtr
<syncer::SyncableService
>();
562 case syncer::SESSIONS
: {
563 return ProfileSyncServiceFactory::GetForProfile(profile_
)->
564 GetSessionsSyncableService()->AsWeakPtr();
566 case syncer::PASSWORDS
: {
567 #if defined(PASSWORD_MANAGER_ENABLE_SYNC)
568 scoped_refptr
<password_manager::PasswordStore
> password_store
=
569 PasswordStoreFactory::GetForProfile(
570 profile_
, ServiceAccessType::EXPLICIT_ACCESS
);
571 return password_store
.get() ? password_store
->GetPasswordSyncableService()
572 : base::WeakPtr
<syncer::SyncableService
>();
574 return base::WeakPtr
<syncer::SyncableService
>();
577 #if defined(OS_CHROMEOS)
578 case syncer::WIFI_CREDENTIALS
:
579 return wifi_sync::WifiCredentialSyncableServiceFactory::
580 GetForBrowserContext(profile_
)->AsWeakPtr();
583 // The following datatypes still need to be transitioned to the
584 // syncer::SyncableService API:
588 return base::WeakPtr
<syncer::SyncableService
>();
592 class TokenServiceProvider
593 : public OAuth2TokenServiceRequest::TokenServiceProvider
{
595 TokenServiceProvider(
596 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
597 OAuth2TokenService
* token_service
);
599 // OAuth2TokenServiceRequest::TokenServiceProvider implementation.
600 scoped_refptr
<base::SingleThreadTaskRunner
> GetTokenServiceTaskRunner()
602 OAuth2TokenService
* GetTokenService() override
;
605 ~TokenServiceProvider() override
;
607 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
608 OAuth2TokenService
* token_service_
;
611 TokenServiceProvider::TokenServiceProvider(
612 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
613 OAuth2TokenService
* token_service
)
614 : task_runner_(task_runner
), token_service_(token_service
) {
617 TokenServiceProvider::~TokenServiceProvider() {
620 scoped_refptr
<base::SingleThreadTaskRunner
>
621 TokenServiceProvider::GetTokenServiceTaskRunner() {
625 OAuth2TokenService
* TokenServiceProvider::GetTokenService() {
626 return token_service_
;
629 scoped_ptr
<syncer::AttachmentService
>
630 ProfileSyncComponentsFactoryImpl::CreateAttachmentService(
631 const scoped_refptr
<syncer::AttachmentStore
>& attachment_store
,
632 const syncer::UserShare
& user_share
,
633 const std::string
& store_birthday
,
634 syncer::ModelType model_type
,
635 syncer::AttachmentService::Delegate
* delegate
) {
636 scoped_ptr
<syncer::AttachmentUploader
> attachment_uploader
;
637 scoped_ptr
<syncer::AttachmentDownloader
> attachment_downloader
;
638 // Only construct an AttachmentUploader and AttachmentDownload if we have sync
639 // credentials. We may not have sync credentials because there may not be a
640 // signed in sync user (e.g. sync is running in "backup" mode).
641 if (!user_share
.sync_credentials
.email
.empty() &&
642 !user_share
.sync_credentials
.scope_set
.empty()) {
643 scoped_refptr
<OAuth2TokenServiceRequest::TokenServiceProvider
>
644 token_service_provider(new TokenServiceProvider(
645 content::BrowserThread::GetMessageLoopProxyForThread(
646 content::BrowserThread::UI
),
648 // TODO(maniscalco): Use shared (one per profile) thread-safe instances of
649 // AttachmentUploader and AttachmentDownloader instead of creating a new one
650 // per AttachmentService (bug 369536).
651 attachment_uploader
.reset(new syncer::AttachmentUploaderImpl(
652 sync_service_url_
, url_request_context_getter_
,
653 user_share
.sync_credentials
.email
,
654 user_share
.sync_credentials
.scope_set
, token_service_provider
,
655 store_birthday
, model_type
));
657 token_service_provider
= new TokenServiceProvider(
658 content::BrowserThread::GetMessageLoopProxyForThread(
659 content::BrowserThread::UI
),
661 attachment_downloader
= syncer::AttachmentDownloader::Create(
662 sync_service_url_
, url_request_context_getter_
,
663 user_share
.sync_credentials
.email
,
664 user_share
.sync_credentials
.scope_set
, token_service_provider
,
665 store_birthday
, model_type
);
668 // It is important that the initial backoff delay is relatively large. For
669 // whatever reason, the server may fail all requests for a short period of
670 // time. When this happens we don't want to overwhelm the server with
671 // requests so we use a large initial backoff.
672 const base::TimeDelta initial_backoff_delay
=
673 base::TimeDelta::FromMinutes(30);
674 const base::TimeDelta max_backoff_delay
= base::TimeDelta::FromHours(4);
675 scoped_ptr
<syncer::AttachmentService
> attachment_service(
676 new syncer::AttachmentServiceImpl(attachment_store
,
677 attachment_uploader
.Pass(),
678 attachment_downloader
.Pass(),
680 initial_backoff_delay
,
682 return attachment_service
.Pass();
685 ProfileSyncComponentsFactory::SyncComponents
686 ProfileSyncComponentsFactoryImpl::CreateBookmarkSyncComponents(
687 ProfileSyncService
* profile_sync_service
,
688 sync_driver::DataTypeErrorHandler
* error_handler
) {
689 BookmarkModel
* bookmark_model
=
690 BookmarkModelFactory::GetForProfile(profile_sync_service
->profile());
691 syncer::UserShare
* user_share
= profile_sync_service
->GetUserShare();
692 // TODO(akalin): We may want to propagate this switch up eventually.
693 #if defined(OS_ANDROID)
694 const bool kExpectMobileBookmarksFolder
= true;
696 const bool kExpectMobileBookmarksFolder
= false;
698 BookmarkModelAssociator
* model_associator
=
699 new BookmarkModelAssociator(bookmark_model
,
700 profile_sync_service
->profile(),
703 kExpectMobileBookmarksFolder
);
704 BookmarkChangeProcessor
* change_processor
=
705 new BookmarkChangeProcessor(profile_sync_service
->profile(),
708 return SyncComponents(model_associator
, change_processor
);
711 ProfileSyncComponentsFactory::SyncComponents
712 ProfileSyncComponentsFactoryImpl::CreateTypedUrlSyncComponents(
713 ProfileSyncService
* profile_sync_service
,
714 history::HistoryBackend
* history_backend
,
715 sync_driver::DataTypeErrorHandler
* error_handler
) {
716 TypedUrlModelAssociator
* model_associator
=
717 new TypedUrlModelAssociator(profile_sync_service
,
720 TypedUrlChangeProcessor
* change_processor
=
721 new TypedUrlChangeProcessor(profile_
,
725 return SyncComponents(model_associator
, change_processor
);