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
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/chrome_sync_client.h"
7 #include "chrome/browser/autofill/personal_data_manager_factory.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.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/prefs/pref_service_syncable.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search_engines/template_url_service_factory.h"
15 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
16 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/sync/profile_sync_service_factory.h"
18 #include "chrome/browser/themes/theme_service.h"
19 #include "chrome/browser/themes/theme_service_factory.h"
20 #include "chrome/browser/themes/theme_syncable_service.h"
21 #include "chrome/browser/web_data_service_factory.h"
22 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service.h"
23 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h"
24 #include "components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h"
25 #include "components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h"
26 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
27 #include "components/dom_distiller/core/dom_distiller_service.h"
28 #include "components/history/core/browser/history_service.h"
29 #include "components/password_manager/core/browser/password_store.h"
30 #include "content/public/browser/browser_thread.h"
32 #if defined(ENABLE_APP_LIST)
33 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
34 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
35 #include "ui/app_list/app_list_switches.h"
38 #if defined(ENABLE_EXTENSIONS)
39 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
40 #include "chrome/browser/extensions/extension_sync_service.h"
41 #include "chrome/browser/sync/glue/extension_data_type_controller.h"
42 #include "chrome/browser/sync/glue/extension_setting_data_type_controller.h"
45 #if defined(ENABLE_SUPERVISED_USERS)
46 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service.h"
47 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service_factory.h"
48 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h"
49 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_factory.h"
50 #include "chrome/browser/supervised_user/supervised_user_service.h"
51 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
52 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
53 #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
54 #include "chrome/browser/supervised_user/supervised_user_sync_data_type_controller.h"
55 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h"
58 #if defined(ENABLE_SPELLCHECK)
59 #include "chrome/browser/spellchecker/spellcheck_factory.h"
60 #include "chrome/browser/spellchecker/spellcheck_service.h"
63 #if defined(OS_CHROMEOS)
64 #include "components/wifi_sync/wifi_credential_syncable_service.h"
65 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h"
68 namespace browser_sync
{
70 ChromeSyncClient::ChromeSyncClient(
72 sync_driver::SyncApiComponentFactory
* component_factory
)
74 component_factory_(component_factory
) {
76 ChromeSyncClient::~ChromeSyncClient() {
79 void ChromeSyncClient::Initialize(sync_driver::SyncService
* sync_service
) {
80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
81 sync_service_
= sync_service
;
82 web_data_service_
= GetWebDataService();
83 password_store_
= GetPasswordStore();
86 sync_driver::SyncService
* ChromeSyncClient::GetSyncService() {
87 // TODO(zea): bring back this DCHECK after Typed URLs are converted to
89 // DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
93 PrefService
* ChromeSyncClient::GetPrefService() {
94 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
95 return profile_
->GetPrefs();
98 bookmarks::BookmarkModel
* ChromeSyncClient::GetBookmarkModel() {
99 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
100 return BookmarkModelFactory::GetForProfile(profile_
);
103 history::HistoryService
* ChromeSyncClient::GetHistoryService() {
104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
105 return HistoryServiceFactory::GetForProfile(
106 profile_
, ServiceAccessType::EXPLICIT_ACCESS
);
109 autofill::PersonalDataManager
* ChromeSyncClient::GetPersonalDataManager() {
110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
111 return autofill::PersonalDataManagerFactory::GetForProfile(profile_
);
114 scoped_refptr
<password_manager::PasswordStore
>
115 ChromeSyncClient::GetPasswordStore() {
116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
117 return PasswordStoreFactory::GetForProfile(
118 profile_
, ServiceAccessType::EXPLICIT_ACCESS
);
121 scoped_refptr
<autofill::AutofillWebDataService
>
122 ChromeSyncClient::GetWebDataService() {
123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
124 return WebDataServiceFactory::GetAutofillWebDataForProfile(
125 profile_
, ServiceAccessType::EXPLICIT_ACCESS
);
128 base::WeakPtr
<syncer::SyncableService
>
129 ChromeSyncClient::GetSyncableServiceForType(syncer::ModelType type
) {
130 if (!profile_
) { // For tests.
131 return base::WeakPtr
<syncer::SyncableService
>();
134 case syncer::DEVICE_INFO
:
135 return ProfileSyncServiceFactory::GetForProfile(profile_
)
136 ->GetDeviceInfoSyncableService()
138 case syncer::PREFERENCES
:
139 return PrefServiceSyncable::FromProfile(
140 profile_
)->GetSyncableService(syncer::PREFERENCES
)->AsWeakPtr();
141 case syncer::PRIORITY_PREFERENCES
:
142 return PrefServiceSyncable::FromProfile(profile_
)->GetSyncableService(
143 syncer::PRIORITY_PREFERENCES
)->AsWeakPtr();
144 case syncer::AUTOFILL
:
145 case syncer::AUTOFILL_PROFILE
:
146 case syncer::AUTOFILL_WALLET_DATA
:
147 case syncer::AUTOFILL_WALLET_METADATA
: {
148 if (!web_data_service_
)
149 return base::WeakPtr
<syncer::SyncableService
>();
150 if (type
== syncer::AUTOFILL
) {
151 return autofill::AutocompleteSyncableService::FromWebDataService(
152 web_data_service_
.get())->AsWeakPtr();
153 } else if (type
== syncer::AUTOFILL_PROFILE
) {
154 return autofill::AutofillProfileSyncableService::FromWebDataService(
155 web_data_service_
.get())->AsWeakPtr();
156 } else if (type
== syncer::AUTOFILL_WALLET_METADATA
) {
157 return autofill::AutofillWalletMetadataSyncableService::
158 FromWebDataService(web_data_service_
.get())->AsWeakPtr();
160 return autofill::AutofillWalletSyncableService::FromWebDataService(
161 web_data_service_
.get())->AsWeakPtr();
163 case syncer::SEARCH_ENGINES
:
164 return TemplateURLServiceFactory::GetForProfile(profile_
)->AsWeakPtr();
165 #if defined(ENABLE_EXTENSIONS)
167 case syncer::EXTENSIONS
:
168 return ExtensionSyncService::Get(profile_
)->AsWeakPtr();
169 case syncer::APP_SETTINGS
:
170 case syncer::EXTENSION_SETTINGS
:
171 return extensions::settings_sync_util::GetSyncableService(profile_
, type
)
174 #if defined(ENABLE_APP_LIST)
175 case syncer::APP_LIST
:
176 return app_list::AppListSyncableServiceFactory::GetForProfile(profile_
)->
179 #if defined(ENABLE_THEMES)
181 return ThemeServiceFactory::GetForProfile(profile_
)->
182 GetThemeSyncableService()->AsWeakPtr();
184 case syncer::HISTORY_DELETE_DIRECTIVES
: {
185 history::HistoryService
* history
= GetHistoryService();
186 return history
? history
->AsWeakPtr()
187 : base::WeakPtr
<history::HistoryService
>();
189 #if defined(ENABLE_SPELLCHECK)
190 case syncer::DICTIONARY
:
191 return SpellcheckServiceFactory::GetForContext(profile_
)->
192 GetCustomDictionary()->AsWeakPtr();
194 case syncer::FAVICON_IMAGES
:
195 case syncer::FAVICON_TRACKING
: {
196 browser_sync::FaviconCache
* favicons
=
197 ProfileSyncServiceFactory::GetForProfile(profile_
)->
199 return favicons
? favicons
->AsWeakPtr()
200 : base::WeakPtr
<syncer::SyncableService
>();
202 #if defined(ENABLE_SUPERVISED_USERS)
203 case syncer::SUPERVISED_USER_SETTINGS
:
204 return SupervisedUserSettingsServiceFactory::GetForProfile(profile_
)->
206 #if !defined(OS_ANDROID) && !defined(OS_IOS)
207 case syncer::SUPERVISED_USERS
:
208 return SupervisedUserSyncServiceFactory::GetForProfile(profile_
)->
210 case syncer::SUPERVISED_USER_SHARED_SETTINGS
:
211 return SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
212 profile_
)->AsWeakPtr();
214 case syncer::SUPERVISED_USER_WHITELISTS
:
215 return SupervisedUserServiceFactory::GetForProfile(profile_
)
216 ->GetWhitelistService()
219 case syncer::ARTICLES
: {
220 dom_distiller::DomDistillerService
* service
=
221 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext(
224 return service
->GetSyncableService()->AsWeakPtr();
225 return base::WeakPtr
<syncer::SyncableService
>();
227 case syncer::SESSIONS
: {
228 return ProfileSyncServiceFactory::GetForProfile(profile_
)->
229 GetSessionsSyncableService()->AsWeakPtr();
231 case syncer::PASSWORDS
: {
232 return password_store_
.get()
233 ? password_store_
->GetPasswordSyncableService()
234 : base::WeakPtr
<syncer::SyncableService
>();
236 #if defined(OS_CHROMEOS)
237 case syncer::WIFI_CREDENTIALS
:
238 return wifi_sync::WifiCredentialSyncableServiceFactory::
239 GetForBrowserContext(profile_
)->AsWeakPtr();
242 // The following datatypes still need to be transitioned to the
243 // syncer::SyncableService API:
247 return base::WeakPtr
<syncer::SyncableService
>();
251 sync_driver::SyncApiComponentFactory
*
252 ChromeSyncClient::GetSyncApiComponentFactory() {
253 return component_factory_
;
256 } // namespace browser_sync