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/notifications/sync_notifier/chrome_notifier_service.h"
13 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_factory.h"
14 #include "chrome/browser/password_manager/password_store_factory.h"
15 #include "chrome/browser/pref_service_flags_storage.h"
16 #include "chrome/browser/prefs/pref_model_associator.h"
17 #include "chrome/browser/prefs/pref_service_syncable.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/search_engines/template_url_service_factory.h"
20 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/sync/glue/autofill_data_type_controller.h"
22 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h"
23 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
24 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h"
25 #include "chrome/browser/sync/glue/bookmark_model_associator.h"
26 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
27 #include "chrome/browser/sync/glue/extension_backed_data_type_controller.h"
28 #include "chrome/browser/sync/glue/extension_data_type_controller.h"
29 #include "chrome/browser/sync/glue/extension_setting_data_type_controller.h"
30 #include "chrome/browser/sync/glue/history_delete_directives_data_type_controller.h"
31 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h"
32 #include "chrome/browser/sync/glue/password_data_type_controller.h"
33 #include "chrome/browser/sync/glue/search_engine_data_type_controller.h"
34 #include "chrome/browser/sync/glue/sync_backend_host.h"
35 #include "chrome/browser/sync/glue/sync_backend_host_impl.h"
36 #include "chrome/browser/sync/glue/theme_data_type_controller.h"
37 #include "chrome/browser/sync/glue/typed_url_change_processor.h"
38 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
39 #include "chrome/browser/sync/glue/typed_url_model_associator.h"
40 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
41 #include "chrome/browser/sync/profile_sync_service.h"
42 #include "chrome/browser/sync/profile_sync_service_factory.h"
43 #include "chrome/browser/sync/sessions/session_data_type_controller.h"
44 #include "chrome/browser/themes/theme_service.h"
45 #include "chrome/browser/themes/theme_service_factory.h"
46 #include "chrome/browser/themes/theme_syncable_service.h"
47 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
48 #include "chrome/browser/webdata/web_data_service_factory.h"
49 #include "chrome/common/chrome_switches.h"
50 #include "chrome/common/chrome_version_info.h"
51 #include "chrome/common/pref_names.h"
52 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h"
53 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
54 #include "components/dom_distiller/core/dom_distiller_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/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/attachments/fake_attachment_store.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/api/synced_notifications_private/synced_notifications_shim.h"
83 #include "chrome/browser/extensions/extension_sync_service.h"
86 #if defined(ENABLE_MANAGED_USERS)
87 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
88 #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
89 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service.h"
90 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service_factory.h"
91 #include "chrome/browser/supervised_user/supervised_user_sync_data_type_controller.h"
92 #include "chrome/browser/supervised_user/supervised_user_sync_service.h"
93 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h"
96 #if defined(ENABLE_SPELLCHECK)
97 #include "chrome/browser/spellchecker/spellcheck_factory.h"
98 #include "chrome/browser/spellchecker/spellcheck_service.h"
101 using browser_sync::AutofillDataTypeController
;
102 using browser_sync::AutofillProfileDataTypeController
;
103 using browser_sync::BookmarkChangeProcessor
;
104 using browser_sync::BookmarkDataTypeController
;
105 using browser_sync::BookmarkModelAssociator
;
106 using browser_sync::ChromeReportUnrecoverableError
;
107 using browser_sync::ExtensionBackedDataTypeController
;
108 using browser_sync::ExtensionDataTypeController
;
109 using browser_sync::ExtensionSettingDataTypeController
;
110 using browser_sync::HistoryDeleteDirectivesDataTypeController
;
111 using browser_sync::PasswordDataTypeController
;
112 using browser_sync::SearchEngineDataTypeController
;
113 using browser_sync::SessionDataTypeController
;
114 using browser_sync::SyncBackendHost
;
115 using browser_sync::ThemeDataTypeController
;
116 using browser_sync::TypedUrlChangeProcessor
;
117 using browser_sync::TypedUrlDataTypeController
;
118 using browser_sync::TypedUrlModelAssociator
;
119 using content::BrowserThread
;
120 using sync_driver::DataTypeController
;
121 using sync_driver::DataTypeErrorHandler
;
122 using sync_driver::DataTypeManager
;
123 using sync_driver::DataTypeManagerImpl
;
124 using sync_driver::DataTypeManagerObserver
;
125 using sync_driver::ProxyDataTypeController
;
126 using sync_driver::SharedChangeProcessor
;
127 using sync_driver::UIDataTypeController
;
131 syncer::ModelTypeSet
GetDisabledTypesFromCommandLine(
132 const CommandLine
& command_line
) {
133 syncer::ModelTypeSet disabled_types
;
134 std::string disabled_types_str
=
135 command_line
.GetSwitchValueASCII(switches::kDisableSyncTypes
);
136 disabled_types
= syncer::ModelTypeSetFromString(disabled_types_str
);
137 return disabled_types
;
140 syncer::ModelTypeSet
GetEnabledTypesFromCommandLine(
141 const CommandLine
& command_line
) {
142 syncer::ModelTypeSet enabled_types
;
143 if (command_line
.HasSwitch(switches::kEnableSyncSyncedNotifications
)) {
144 enabled_types
.Put(syncer::SYNCED_NOTIFICATIONS
);
146 return enabled_types
;
151 ProfileSyncComponentsFactoryImpl::ProfileSyncComponentsFactoryImpl(
153 CommandLine
* command_line
,
154 const GURL
& sync_service_url
,
155 OAuth2TokenService
* token_service
,
156 net::URLRequestContextGetter
* url_request_context_getter
)
158 command_line_(command_line
),
159 web_data_service_(WebDataServiceFactory::GetAutofillWebDataForProfile(
160 profile_
, Profile::EXPLICIT_ACCESS
)),
161 sync_service_url_(sync_service_url
),
162 token_service_(token_service
),
163 url_request_context_getter_(url_request_context_getter
),
164 weak_factory_(this) {
165 DCHECK(token_service_
);
166 DCHECK(url_request_context_getter_
);
169 ProfileSyncComponentsFactoryImpl::~ProfileSyncComponentsFactoryImpl() {
172 void ProfileSyncComponentsFactoryImpl::RegisterDataTypes(
173 ProfileSyncService
* pss
) {
174 syncer::ModelTypeSet disabled_types
=
175 GetDisabledTypesFromCommandLine(*command_line_
);
176 syncer::ModelTypeSet enabled_types
=
177 GetEnabledTypesFromCommandLine(*command_line_
);
178 RegisterCommonDataTypes(disabled_types
, enabled_types
, pss
);
179 #if !defined(OS_ANDROID)
180 RegisterDesktopDataTypes(disabled_types
, enabled_types
, pss
);
184 void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes(
185 syncer::ModelTypeSet disabled_types
,
186 syncer::ModelTypeSet enabled_types
,
187 ProfileSyncService
* pss
) {
188 // Autofill sync is enabled by default. Register unless explicitly
190 if (!disabled_types
.Has(syncer::AUTOFILL
)) {
191 pss
->RegisterDataTypeController(
192 new AutofillDataTypeController(this, profile_
));
195 // Autofill profile sync is enabled by default. Register unless explicitly
197 if (!disabled_types
.Has(syncer::AUTOFILL_PROFILE
)) {
198 pss
->RegisterDataTypeController(
199 new AutofillProfileDataTypeController(this, profile_
));
202 // Bookmark sync is enabled by default. Register unless explicitly
204 if (!disabled_types
.Has(syncer::BOOKMARKS
)) {
205 pss
->RegisterDataTypeController(
206 new BookmarkDataTypeController(this, profile_
, pss
));
209 const bool history_disabled
=
210 profile_
->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled
);
211 // TypedUrl sync is enabled by default. Register unless explicitly disabled,
212 // or if saving history is disabled.
213 if (!disabled_types
.Has(syncer::TYPED_URLS
) && !history_disabled
) {
214 pss
->RegisterDataTypeController(
215 new TypedUrlDataTypeController(this, profile_
, pss
));
218 // Delete directive sync is enabled by default. Register unless full history
220 if (!disabled_types
.Has(syncer::HISTORY_DELETE_DIRECTIVES
) &&
222 pss
->RegisterDataTypeController(
223 new HistoryDeleteDirectivesDataTypeController(this, pss
));
226 // Session sync is enabled by default. Register unless explicitly disabled.
227 // This is also disabled if the browser history is disabled, because the
228 // tab sync data is added to the web history on the server.
229 if (!disabled_types
.Has(syncer::PROXY_TABS
) && !history_disabled
) {
230 pss
->RegisterDataTypeController(new ProxyDataTypeController(
231 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
232 syncer::PROXY_TABS
));
233 pss
->RegisterDataTypeController(
234 new SessionDataTypeController(this,
236 pss
->GetSyncedWindowDelegatesGetter(),
237 pss
->GetLocalDeviceInfoProvider()));
240 // Favicon sync is enabled by default. Register unless explicitly disabled.
241 if (!disabled_types
.Has(syncer::FAVICON_IMAGES
) &&
242 !disabled_types
.Has(syncer::FAVICON_TRACKING
) &&
244 // crbug/384552. We disable error uploading for this data types for now.
245 pss
->RegisterDataTypeController(
246 new UIDataTypeController(
247 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
249 syncer::FAVICON_IMAGES
,
251 pss
->RegisterDataTypeController(
252 new UIDataTypeController(
253 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
255 syncer::FAVICON_TRACKING
,
259 // Password sync is enabled by default. Register unless explicitly
261 if (!disabled_types
.Has(syncer::PASSWORDS
)) {
262 pss
->RegisterDataTypeController(
263 new PasswordDataTypeController(this, profile_
));
266 // Article sync is disabled by default. Register only if explicitly enabled.
267 if (IsEnableSyncArticlesSet()) {
268 pss
->RegisterDataTypeController(
269 new UIDataTypeController(
270 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
271 base::Bind(&ChromeReportUnrecoverableError
),
276 #if defined(ENABLE_MANAGED_USERS)
277 pss
->RegisterDataTypeController(
278 new SupervisedUserSyncDataTypeController(
279 syncer::SUPERVISED_USER_SETTINGS
,
285 void ProfileSyncComponentsFactoryImpl::RegisterDesktopDataTypes(
286 syncer::ModelTypeSet disabled_types
,
287 syncer::ModelTypeSet enabled_types
,
288 ProfileSyncService
* pss
) {
289 // App sync is enabled by default. Register unless explicitly
291 if (!disabled_types
.Has(syncer::APPS
)) {
292 pss
->RegisterDataTypeController(
293 new ExtensionDataTypeController(syncer::APPS
, this, profile_
));
296 // Extension sync is enabled by default. Register unless explicitly
298 if (!disabled_types
.Has(syncer::EXTENSIONS
)) {
299 pss
->RegisterDataTypeController(
300 new ExtensionDataTypeController(syncer::EXTENSIONS
, this, profile_
));
303 // Preference sync is enabled by default. Register unless explicitly
305 if (!disabled_types
.Has(syncer::PREFERENCES
)) {
306 pss
->RegisterDataTypeController(
307 new UIDataTypeController(
308 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
309 base::Bind(&ChromeReportUnrecoverableError
),
314 if (!disabled_types
.Has(syncer::PRIORITY_PREFERENCES
)) {
315 pss
->RegisterDataTypeController(
316 new UIDataTypeController(
317 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
318 base::Bind(&ChromeReportUnrecoverableError
),
319 syncer::PRIORITY_PREFERENCES
,
323 #if defined(ENABLE_THEMES)
324 // Theme sync is enabled by default. Register unless explicitly disabled.
325 if (!disabled_types
.Has(syncer::THEMES
)) {
326 pss
->RegisterDataTypeController(
327 new ThemeDataTypeController(this, profile_
));
331 // Search Engine sync is enabled by default. Register unless explicitly
333 if (!disabled_types
.Has(syncer::SEARCH_ENGINES
)) {
334 pss
->RegisterDataTypeController(
335 new SearchEngineDataTypeController(this, profile_
));
338 // Extension setting sync is enabled by default. Register unless explicitly
340 if (!disabled_types
.Has(syncer::EXTENSION_SETTINGS
)) {
341 pss
->RegisterDataTypeController(new ExtensionSettingDataTypeController(
342 syncer::EXTENSION_SETTINGS
, this, profile_
));
345 // App setting sync is enabled by default. Register unless explicitly
347 if (!disabled_types
.Has(syncer::APP_SETTINGS
)) {
348 pss
->RegisterDataTypeController(new ExtensionSettingDataTypeController(
349 syncer::APP_SETTINGS
, this, profile_
));
352 #if defined(ENABLE_APP_LIST)
353 if (app_list::switches::IsAppListSyncEnabled()) {
354 pss
->RegisterDataTypeController(
355 new UIDataTypeController(
356 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
357 base::Bind(&ChromeReportUnrecoverableError
),
363 // Synced Notifications are disabled by default.
364 #if defined(ENABLE_EXTENSIONS) && defined(ENABLE_NOTIFICATIONS)
365 if (enabled_types
.Has(syncer::SYNCED_NOTIFICATIONS
)) {
366 pss
->RegisterDataTypeController(
367 new ExtensionBackedDataTypeController(
368 syncer::SYNCED_NOTIFICATIONS
,
369 "", // TODO(dewittj): pass the extension hash here.
373 pss
->RegisterDataTypeController(
374 new ExtensionBackedDataTypeController(
375 syncer::SYNCED_NOTIFICATION_APP_INFO
,
376 "", // TODO(dewittj): pass the extension hash here.
382 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS)
383 // Dictionary sync is enabled by default.
384 if (!disabled_types
.Has(syncer::DICTIONARY
)) {
385 pss
->RegisterDataTypeController(
386 new UIDataTypeController(
387 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
),
388 base::Bind(&ChromeReportUnrecoverableError
),
394 #if defined(ENABLE_MANAGED_USERS)
395 pss
->RegisterDataTypeController(
396 new SupervisedUserSyncDataTypeController(
397 syncer::SUPERVISED_USERS
,
400 pss
->RegisterDataTypeController(
401 new SupervisedUserSyncDataTypeController(
402 syncer::SUPERVISED_USER_SHARED_SETTINGS
,
408 DataTypeManager
* ProfileSyncComponentsFactoryImpl::CreateDataTypeManager(
409 const syncer::WeakHandle
<syncer::DataTypeDebugInfoListener
>&
411 const DataTypeController::TypeMap
* controllers
,
412 const sync_driver::DataTypeEncryptionHandler
* encryption_handler
,
413 SyncBackendHost
* backend
,
414 DataTypeManagerObserver
* observer
) {
415 return new DataTypeManagerImpl(base::Bind(ChromeReportUnrecoverableError
),
423 browser_sync::SyncBackendHost
*
424 ProfileSyncComponentsFactoryImpl::CreateSyncBackendHost(
425 const std::string
& name
,
427 invalidation::InvalidationService
* invalidator
,
428 const base::WeakPtr
<sync_driver::SyncPrefs
>& sync_prefs
,
429 const base::FilePath
& sync_folder
) {
430 return new browser_sync::SyncBackendHostImpl(name
, profile
, invalidator
,
431 sync_prefs
, sync_folder
);
434 scoped_ptr
<browser_sync::LocalDeviceInfoProvider
>
435 ProfileSyncComponentsFactoryImpl::CreateLocalDeviceInfoProvider() {
436 return scoped_ptr
<browser_sync::LocalDeviceInfoProvider
>(
437 new browser_sync::LocalDeviceInfoProviderImpl());
440 base::WeakPtr
<syncer::SyncableService
> ProfileSyncComponentsFactoryImpl::
441 GetSyncableServiceForType(syncer::ModelType type
) {
442 if (!profile_
) { // For tests.
443 return base::WeakPtr
<syncer::SyncableService
>();
446 case syncer::PREFERENCES
:
447 return PrefServiceSyncable::FromProfile(
448 profile_
)->GetSyncableService(syncer::PREFERENCES
)->AsWeakPtr();
449 case syncer::PRIORITY_PREFERENCES
:
450 return PrefServiceSyncable::FromProfile(profile_
)->GetSyncableService(
451 syncer::PRIORITY_PREFERENCES
)->AsWeakPtr();
452 case syncer::AUTOFILL
:
453 case syncer::AUTOFILL_PROFILE
: {
454 if (!web_data_service_
.get())
455 return base::WeakPtr
<syncer::SyncableService
>();
456 if (type
== syncer::AUTOFILL
) {
457 return AutocompleteSyncableService::FromWebDataService(
458 web_data_service_
.get())->AsWeakPtr();
460 return autofill::AutofillProfileSyncableService::FromWebDataService(
461 web_data_service_
.get())->AsWeakPtr();
464 case syncer::SEARCH_ENGINES
:
465 return TemplateURLServiceFactory::GetForProfile(profile_
)->AsWeakPtr();
466 #if defined(ENABLE_EXTENSIONS)
468 case syncer::EXTENSIONS
:
469 return ExtensionSyncService::Get(profile_
)->AsWeakPtr();
470 case syncer::APP_SETTINGS
:
471 case syncer::EXTENSION_SETTINGS
:
472 return extensions::settings_sync_util::GetSyncableService(profile_
, type
)
475 #if defined(ENABLE_APP_LIST)
476 case syncer::APP_LIST
:
477 return app_list::AppListSyncableServiceFactory::GetForProfile(profile_
)->
480 #if defined(ENABLE_THEMES)
482 return ThemeServiceFactory::GetForProfile(profile_
)->
483 GetThemeSyncableService()->AsWeakPtr();
485 case syncer::HISTORY_DELETE_DIRECTIVES
: {
486 HistoryService
* history
=
487 HistoryServiceFactory::GetForProfile(
488 profile_
, Profile::EXPLICIT_ACCESS
);
489 return history
? history
->AsWeakPtr() : base::WeakPtr
<HistoryService
>();
491 #if defined(ENABLE_EXTENSIONS)
492 case syncer::SYNCED_NOTIFICATIONS
:
493 case syncer::SYNCED_NOTIFICATION_APP_INFO
: {
494 return notifier::ChromeNotifierServiceFactory::GetForProfile(
495 profile_
, Profile::IMPLICIT_ACCESS
)
496 ->GetSyncedNotificationsShim()
500 #if defined(ENABLE_SPELLCHECK)
501 case syncer::DICTIONARY
:
502 return SpellcheckServiceFactory::GetForContext(profile_
)->
503 GetCustomDictionary()->AsWeakPtr();
505 case syncer::FAVICON_IMAGES
:
506 case syncer::FAVICON_TRACKING
: {
507 browser_sync::FaviconCache
* favicons
=
508 ProfileSyncServiceFactory::GetForProfile(profile_
)->
510 return favicons
? favicons
->AsWeakPtr()
511 : base::WeakPtr
<syncer::SyncableService
>();
513 #if defined(ENABLE_MANAGED_USERS)
514 case syncer::SUPERVISED_USER_SETTINGS
:
515 return SupervisedUserSettingsServiceFactory::GetForProfile(profile_
)->
517 case syncer::SUPERVISED_USERS
:
518 return SupervisedUserSyncServiceFactory::GetForProfile(profile_
)->
520 case syncer::SUPERVISED_USER_SHARED_SETTINGS
:
521 return SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
522 profile_
)->AsWeakPtr();
524 case syncer::ARTICLES
: {
525 dom_distiller::DomDistillerService
* service
=
526 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext(
529 return service
->GetSyncableService()->AsWeakPtr();
530 return base::WeakPtr
<syncer::SyncableService
>();
532 case syncer::SESSIONS
: {
533 return ProfileSyncServiceFactory::GetForProfile(profile_
)->
534 GetSessionsSyncableService()->AsWeakPtr();
536 case syncer::PASSWORDS
: {
537 #if defined(PASSWORD_MANAGER_ENABLE_SYNC)
538 scoped_refptr
<password_manager::PasswordStore
> password_store
=
539 PasswordStoreFactory::GetForProfile(profile_
,
540 Profile::EXPLICIT_ACCESS
);
541 return password_store
.get() ? password_store
->GetPasswordSyncableService()
542 : base::WeakPtr
<syncer::SyncableService
>();
544 return base::WeakPtr
<syncer::SyncableService
>();
548 // The following datatypes still need to be transitioned to the
549 // syncer::SyncableService API:
553 return base::WeakPtr
<syncer::SyncableService
>();
557 class TokenServiceProvider
558 : public OAuth2TokenServiceRequest::TokenServiceProvider
{
560 TokenServiceProvider(
561 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
562 OAuth2TokenService
* token_service
);
564 // OAuth2TokenServiceRequest::TokenServiceProvider implementation.
565 virtual scoped_refptr
<base::SingleThreadTaskRunner
>
566 GetTokenServiceTaskRunner() OVERRIDE
;
567 virtual OAuth2TokenService
* GetTokenService() OVERRIDE
;
570 virtual ~TokenServiceProvider();
572 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
573 OAuth2TokenService
* token_service_
;
576 TokenServiceProvider::TokenServiceProvider(
577 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
578 OAuth2TokenService
* token_service
)
579 : task_runner_(task_runner
), token_service_(token_service
) {
582 TokenServiceProvider::~TokenServiceProvider() {
585 scoped_refptr
<base::SingleThreadTaskRunner
>
586 TokenServiceProvider::GetTokenServiceTaskRunner() {
590 OAuth2TokenService
* TokenServiceProvider::GetTokenService() {
591 return token_service_
;
594 scoped_ptr
<syncer::AttachmentService
>
595 ProfileSyncComponentsFactoryImpl::CreateAttachmentService(
596 const syncer::UserShare
& user_share
,
597 syncer::AttachmentService::Delegate
* delegate
) {
599 scoped_ptr
<syncer::AttachmentStore
> attachment_store(
600 new syncer::FakeAttachmentStore(
601 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
603 scoped_ptr
<syncer::AttachmentUploader
> attachment_uploader
;
604 scoped_ptr
<syncer::AttachmentDownloader
> attachment_downloader
;
605 // Only construct an AttachmentUploader and AttachmentDownload if we have sync
606 // credentials. We may not have sync credentials because there may not be a
607 // signed in sync user (e.g. sync is running in "backup" mode).
608 if (!user_share
.sync_credentials
.email
.empty() &&
609 !user_share
.sync_credentials
.scope_set
.empty()) {
610 scoped_refptr
<OAuth2TokenServiceRequest::TokenServiceProvider
>
611 token_service_provider(new TokenServiceProvider(
612 content::BrowserThread::GetMessageLoopProxyForThread(
613 content::BrowserThread::UI
),
615 // TODO(maniscalco): Use shared (one per profile) thread-safe instances of
616 // AttachmentUploader and AttachmentDownloader instead of creating a new one
617 // per AttachmentService (bug 369536).
618 attachment_uploader
.reset(new syncer::AttachmentUploaderImpl(
620 url_request_context_getter_
,
621 user_share
.sync_credentials
.email
,
622 user_share
.sync_credentials
.scope_set
,
623 token_service_provider
));
625 token_service_provider
= new TokenServiceProvider(
626 content::BrowserThread::GetMessageLoopProxyForThread(
627 content::BrowserThread::UI
),
629 attachment_downloader
= syncer::AttachmentDownloader::Create(
631 url_request_context_getter_
,
632 user_share
.sync_credentials
.email
,
633 user_share
.sync_credentials
.scope_set
,
634 token_service_provider
);
637 scoped_ptr
<syncer::AttachmentService
> attachment_service(
638 new syncer::AttachmentServiceImpl(attachment_store
.Pass(),
639 attachment_uploader
.Pass(),
640 attachment_downloader
.Pass(),
643 return attachment_service
.Pass();
646 ProfileSyncComponentsFactory::SyncComponents
647 ProfileSyncComponentsFactoryImpl::CreateBookmarkSyncComponents(
648 ProfileSyncService
* profile_sync_service
,
649 sync_driver::DataTypeErrorHandler
* error_handler
) {
650 BookmarkModel
* bookmark_model
=
651 BookmarkModelFactory::GetForProfile(profile_sync_service
->profile());
652 syncer::UserShare
* user_share
= profile_sync_service
->GetUserShare();
653 // TODO(akalin): We may want to propagate this switch up eventually.
654 #if defined(OS_ANDROID)
655 const bool kExpectMobileBookmarksFolder
= true;
657 const bool kExpectMobileBookmarksFolder
= false;
659 BookmarkModelAssociator
* model_associator
=
660 new BookmarkModelAssociator(bookmark_model
,
661 profile_sync_service
->profile(),
664 kExpectMobileBookmarksFolder
);
665 BookmarkChangeProcessor
* change_processor
=
666 new BookmarkChangeProcessor(profile_sync_service
->profile(),
669 return SyncComponents(model_associator
, change_processor
);
672 ProfileSyncComponentsFactory::SyncComponents
673 ProfileSyncComponentsFactoryImpl::CreateTypedUrlSyncComponents(
674 ProfileSyncService
* profile_sync_service
,
675 history::HistoryBackend
* history_backend
,
676 sync_driver::DataTypeErrorHandler
* error_handler
) {
677 TypedUrlModelAssociator
* model_associator
=
678 new TypedUrlModelAssociator(profile_sync_service
,
681 TypedUrlChangeProcessor
* change_processor
=
682 new TypedUrlChangeProcessor(profile_
,
686 return SyncComponents(model_associator
, change_processor
);