Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: components/sync/driver/sync_prefs.cc

Issue 2388163002: [Sync] Move //components/sync to the syncer namespace, take 2. (Closed)
Patch Set: Rebase. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/sync/driver/sync_prefs.h ('k') | components/sync/driver/sync_prefs_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sync/driver/sync_prefs.h" 5 #include "components/sync/driver/sync_prefs.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "components/pref_registry/pref_registry_syncable.h" 11 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "components/prefs/pref_service.h" 12 #include "components/prefs/pref_service.h"
13 #include "components/sync/driver/pref_names.h" 13 #include "components/sync/driver/pref_names.h"
14 14
15 namespace sync_driver { 15 namespace syncer {
16 16
17 SyncPrefObserver::~SyncPrefObserver() {} 17 SyncPrefObserver::~SyncPrefObserver() {}
18 18
19 SyncPrefs::SyncPrefs(PrefService* pref_service) : pref_service_(pref_service) { 19 SyncPrefs::SyncPrefs(PrefService* pref_service) : pref_service_(pref_service) {
20 DCHECK(pref_service); 20 DCHECK(pref_service);
21 RegisterPrefGroups(); 21 RegisterPrefGroups();
22 // Watch the preference that indicates sync is managed so we can take 22 // Watch the preference that indicates sync is managed so we can take
23 // appropriate action. 23 // appropriate action.
24 pref_sync_managed_.Init( 24 pref_sync_managed_.Init(
25 prefs::kSyncManaged, pref_service_, 25 prefs::kSyncManaged, pref_service_,
(...skipping 13 matching lines...) Expand all
39 registry->RegisterBooleanPref(prefs::kSyncSuppressStart, false); 39 registry->RegisterBooleanPref(prefs::kSyncSuppressStart, false);
40 registry->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); 40 registry->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0);
41 registry->RegisterInt64Pref(prefs::kSyncLastPollTime, 0); 41 registry->RegisterInt64Pref(prefs::kSyncLastPollTime, 0);
42 registry->RegisterInt64Pref(prefs::kSyncFirstSyncTime, 0); 42 registry->RegisterInt64Pref(prefs::kSyncFirstSyncTime, 0);
43 43
44 // All datatypes are on by default, but this gets set explicitly 44 // All datatypes are on by default, but this gets set explicitly
45 // when you configure sync (when turning it on), in 45 // when you configure sync (when turning it on), in
46 // ProfileSyncService::OnUserChoseDatatypes. 46 // ProfileSyncService::OnUserChoseDatatypes.
47 registry->RegisterBooleanPref(prefs::kSyncKeepEverythingSynced, true); 47 registry->RegisterBooleanPref(prefs::kSyncKeepEverythingSynced, true);
48 48
49 syncer::ModelTypeSet user_types = syncer::UserTypes(); 49 ModelTypeSet user_types = UserTypes();
50 50
51 // Include proxy types as well, as they can be individually selected, 51 // Include proxy types as well, as they can be individually selected,
52 // although they don't have sync representations. 52 // although they don't have sync representations.
53 user_types.PutAll(syncer::ProxyTypes()); 53 user_types.PutAll(ProxyTypes());
54 54
55 // Treat bookmarks and device info specially. 55 // Treat bookmarks and device info specially.
56 RegisterDataTypePreferredPref(registry, syncer::BOOKMARKS, true); 56 RegisterDataTypePreferredPref(registry, BOOKMARKS, true);
57 RegisterDataTypePreferredPref(registry, syncer::DEVICE_INFO, true); 57 RegisterDataTypePreferredPref(registry, DEVICE_INFO, true);
58 user_types.Remove(syncer::BOOKMARKS); 58 user_types.Remove(BOOKMARKS);
59 user_types.Remove(syncer::DEVICE_INFO); 59 user_types.Remove(DEVICE_INFO);
60 60
61 // All types are set to off by default, which forces a configuration to 61 // All types are set to off by default, which forces a configuration to
62 // explicitly enable them. GetPreferredTypes() will ensure that any new 62 // explicitly enable them. GetPreferredTypes() will ensure that any new
63 // implicit types are enabled when their pref group is, or via 63 // implicit types are enabled when their pref group is, or via
64 // KeepEverythingSynced. 64 // KeepEverythingSynced.
65 for (syncer::ModelTypeSet::Iterator it = user_types.First(); it.Good(); 65 for (ModelTypeSet::Iterator it = user_types.First(); it.Good(); it.Inc()) {
66 it.Inc()) {
67 RegisterDataTypePreferredPref(registry, it.Get(), false); 66 RegisterDataTypePreferredPref(registry, it.Get(), false);
68 } 67 }
69 68
70 registry->RegisterBooleanPref(prefs::kSyncManaged, false); 69 registry->RegisterBooleanPref(prefs::kSyncManaged, false);
71 registry->RegisterStringPref(prefs::kSyncEncryptionBootstrapToken, 70 registry->RegisterStringPref(prefs::kSyncEncryptionBootstrapToken,
72 std::string()); 71 std::string());
73 registry->RegisterStringPref(prefs::kSyncKeystoreEncryptionBootstrapToken, 72 registry->RegisterStringPref(prefs::kSyncKeystoreEncryptionBootstrapToken,
74 std::string()); 73 std::string());
75 #if defined(OS_CHROMEOS) 74 #if defined(OS_CHROMEOS)
76 registry->RegisterStringPref(prefs::kSyncSpareBootstrapToken, ""); 75 registry->RegisterStringPref(prefs::kSyncSpareBootstrapToken, "");
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 DCHECK(CalledOnValidThread()); 177 DCHECK(CalledOnValidThread());
179 return pref_service_->GetBoolean(prefs::kSyncKeepEverythingSynced); 178 return pref_service_->GetBoolean(prefs::kSyncKeepEverythingSynced);
180 } 179 }
181 180
182 void SyncPrefs::SetKeepEverythingSynced(bool keep_everything_synced) { 181 void SyncPrefs::SetKeepEverythingSynced(bool keep_everything_synced) {
183 DCHECK(CalledOnValidThread()); 182 DCHECK(CalledOnValidThread());
184 pref_service_->SetBoolean(prefs::kSyncKeepEverythingSynced, 183 pref_service_->SetBoolean(prefs::kSyncKeepEverythingSynced,
185 keep_everything_synced); 184 keep_everything_synced);
186 } 185 }
187 186
188 syncer::ModelTypeSet SyncPrefs::GetPreferredDataTypes( 187 ModelTypeSet SyncPrefs::GetPreferredDataTypes(
189 syncer::ModelTypeSet registered_types) const { 188 ModelTypeSet registered_types) const {
190 DCHECK(CalledOnValidThread()); 189 DCHECK(CalledOnValidThread());
191 190
192 if (pref_service_->GetBoolean(prefs::kSyncKeepEverythingSynced)) { 191 if (pref_service_->GetBoolean(prefs::kSyncKeepEverythingSynced)) {
193 return registered_types; 192 return registered_types;
194 } 193 }
195 194
196 syncer::ModelTypeSet preferred_types; 195 ModelTypeSet preferred_types;
197 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); it.Good(); 196 for (ModelTypeSet::Iterator it = registered_types.First(); it.Good();
198 it.Inc()) { 197 it.Inc()) {
199 if (GetDataTypePreferred(it.Get())) { 198 if (GetDataTypePreferred(it.Get())) {
200 preferred_types.Put(it.Get()); 199 preferred_types.Put(it.Get());
201 } 200 }
202 } 201 }
203 return ResolvePrefGroups(registered_types, preferred_types); 202 return ResolvePrefGroups(registered_types, preferred_types);
204 } 203 }
205 204
206 void SyncPrefs::SetPreferredDataTypes(syncer::ModelTypeSet registered_types, 205 void SyncPrefs::SetPreferredDataTypes(ModelTypeSet registered_types,
207 syncer::ModelTypeSet preferred_types) { 206 ModelTypeSet preferred_types) {
208 DCHECK(CalledOnValidThread()); 207 DCHECK(CalledOnValidThread());
209 preferred_types = ResolvePrefGroups(registered_types, preferred_types); 208 preferred_types = ResolvePrefGroups(registered_types, preferred_types);
210 DCHECK(registered_types.HasAll(preferred_types)); 209 DCHECK(registered_types.HasAll(preferred_types));
211 for (syncer::ModelTypeSet::Iterator i = registered_types.First(); i.Good(); 210 for (ModelTypeSet::Iterator i = registered_types.First(); i.Good(); i.Inc()) {
212 i.Inc()) {
213 SetDataTypePreferred(i.Get(), preferred_types.Has(i.Get())); 211 SetDataTypePreferred(i.Get(), preferred_types.Has(i.Get()));
214 } 212 }
215 } 213 }
216 214
217 bool SyncPrefs::IsManaged() const { 215 bool SyncPrefs::IsManaged() const {
218 DCHECK(CalledOnValidThread()); 216 DCHECK(CalledOnValidThread());
219 return pref_service_->GetBoolean(prefs::kSyncManaged); 217 return pref_service_->GetBoolean(prefs::kSyncManaged);
220 } 218 }
221 219
222 std::string SyncPrefs::GetEncryptionBootstrapToken() const { 220 std::string SyncPrefs::GetEncryptionBootstrapToken() const {
(...skipping 20 matching lines...) Expand all
243 DCHECK(CalledOnValidThread()); 241 DCHECK(CalledOnValidThread());
244 return pref_service_->GetString(prefs::kSyncSessionsGUID); 242 return pref_service_->GetString(prefs::kSyncSessionsGUID);
245 } 243 }
246 244
247 void SyncPrefs::SetSyncSessionsGUID(const std::string& guid) { 245 void SyncPrefs::SetSyncSessionsGUID(const std::string& guid) {
248 DCHECK(CalledOnValidThread()); 246 DCHECK(CalledOnValidThread());
249 pref_service_->SetString(prefs::kSyncSessionsGUID, guid); 247 pref_service_->SetString(prefs::kSyncSessionsGUID, guid);
250 } 248 }
251 249
252 // static 250 // static
253 const char* SyncPrefs::GetPrefNameForDataType(syncer::ModelType data_type) { 251 const char* SyncPrefs::GetPrefNameForDataType(ModelType data_type) {
254 switch (data_type) { 252 switch (data_type) {
255 case syncer::BOOKMARKS: 253 case BOOKMARKS:
256 return prefs::kSyncBookmarks; 254 return prefs::kSyncBookmarks;
257 case syncer::PASSWORDS: 255 case PASSWORDS:
258 return prefs::kSyncPasswords; 256 return prefs::kSyncPasswords;
259 case syncer::PREFERENCES: 257 case PREFERENCES:
260 return prefs::kSyncPreferences; 258 return prefs::kSyncPreferences;
261 case syncer::AUTOFILL: 259 case AUTOFILL:
262 return prefs::kSyncAutofill; 260 return prefs::kSyncAutofill;
263 case syncer::AUTOFILL_PROFILE: 261 case AUTOFILL_PROFILE:
264 return prefs::kSyncAutofillProfile; 262 return prefs::kSyncAutofillProfile;
265 case syncer::AUTOFILL_WALLET_DATA: 263 case AUTOFILL_WALLET_DATA:
266 return prefs::kSyncAutofillWallet; 264 return prefs::kSyncAutofillWallet;
267 case syncer::AUTOFILL_WALLET_METADATA: 265 case AUTOFILL_WALLET_METADATA:
268 return prefs::kSyncAutofillWalletMetadata; 266 return prefs::kSyncAutofillWalletMetadata;
269 case syncer::THEMES: 267 case THEMES:
270 return prefs::kSyncThemes; 268 return prefs::kSyncThemes;
271 case syncer::TYPED_URLS: 269 case TYPED_URLS:
272 return prefs::kSyncTypedUrls; 270 return prefs::kSyncTypedUrls;
273 case syncer::EXTENSION_SETTINGS: 271 case EXTENSION_SETTINGS:
274 return prefs::kSyncExtensionSettings; 272 return prefs::kSyncExtensionSettings;
275 case syncer::EXTENSIONS: 273 case EXTENSIONS:
276 return prefs::kSyncExtensions; 274 return prefs::kSyncExtensions;
277 case syncer::APP_LIST: 275 case APP_LIST:
278 return prefs::kSyncAppList; 276 return prefs::kSyncAppList;
279 case syncer::APP_SETTINGS: 277 case APP_SETTINGS:
280 return prefs::kSyncAppSettings; 278 return prefs::kSyncAppSettings;
281 case syncer::APPS: 279 case APPS:
282 return prefs::kSyncApps; 280 return prefs::kSyncApps;
283 case syncer::SEARCH_ENGINES: 281 case SEARCH_ENGINES:
284 return prefs::kSyncSearchEngines; 282 return prefs::kSyncSearchEngines;
285 case syncer::SESSIONS: 283 case SESSIONS:
286 return prefs::kSyncSessions; 284 return prefs::kSyncSessions;
287 case syncer::APP_NOTIFICATIONS: 285 case APP_NOTIFICATIONS:
288 return prefs::kSyncAppNotifications; 286 return prefs::kSyncAppNotifications;
289 case syncer::HISTORY_DELETE_DIRECTIVES: 287 case HISTORY_DELETE_DIRECTIVES:
290 return prefs::kSyncHistoryDeleteDirectives; 288 return prefs::kSyncHistoryDeleteDirectives;
291 case syncer::SYNCED_NOTIFICATIONS: 289 case SYNCED_NOTIFICATIONS:
292 return prefs::kSyncSyncedNotifications; 290 return prefs::kSyncSyncedNotifications;
293 case syncer::SYNCED_NOTIFICATION_APP_INFO: 291 case SYNCED_NOTIFICATION_APP_INFO:
294 return prefs::kSyncSyncedNotificationAppInfo; 292 return prefs::kSyncSyncedNotificationAppInfo;
295 case syncer::DICTIONARY: 293 case DICTIONARY:
296 return prefs::kSyncDictionary; 294 return prefs::kSyncDictionary;
297 case syncer::FAVICON_IMAGES: 295 case FAVICON_IMAGES:
298 return prefs::kSyncFaviconImages; 296 return prefs::kSyncFaviconImages;
299 case syncer::FAVICON_TRACKING: 297 case FAVICON_TRACKING:
300 return prefs::kSyncFaviconTracking; 298 return prefs::kSyncFaviconTracking;
301 case syncer::SUPERVISED_USER_SETTINGS: 299 case SUPERVISED_USER_SETTINGS:
302 return prefs::kSyncSupervisedUserSettings; 300 return prefs::kSyncSupervisedUserSettings;
303 case syncer::PROXY_TABS: 301 case PROXY_TABS:
304 return prefs::kSyncTabs; 302 return prefs::kSyncTabs;
305 case syncer::PRIORITY_PREFERENCES: 303 case PRIORITY_PREFERENCES:
306 return prefs::kSyncPriorityPreferences; 304 return prefs::kSyncPriorityPreferences;
307 case syncer::SUPERVISED_USERS: 305 case SUPERVISED_USERS:
308 return prefs::kSyncSupervisedUsers; 306 return prefs::kSyncSupervisedUsers;
309 case syncer::ARTICLES: 307 case ARTICLES:
310 return prefs::kSyncArticles; 308 return prefs::kSyncArticles;
311 case syncer::SUPERVISED_USER_SHARED_SETTINGS: 309 case SUPERVISED_USER_SHARED_SETTINGS:
312 return prefs::kSyncSupervisedUserSharedSettings; 310 return prefs::kSyncSupervisedUserSharedSettings;
313 case syncer::SUPERVISED_USER_WHITELISTS: 311 case SUPERVISED_USER_WHITELISTS:
314 return prefs::kSyncSupervisedUserWhitelists; 312 return prefs::kSyncSupervisedUserWhitelists;
315 case syncer::DEVICE_INFO: 313 case DEVICE_INFO:
316 return prefs::kSyncDeviceInfo; 314 return prefs::kSyncDeviceInfo;
317 case syncer::WIFI_CREDENTIALS: 315 case WIFI_CREDENTIALS:
318 return prefs::kSyncWifiCredentials; 316 return prefs::kSyncWifiCredentials;
319 case syncer::ARC_PACKAGE: 317 case ARC_PACKAGE:
320 return prefs::kSyncArcPackage; 318 return prefs::kSyncArcPackage;
321 case syncer::PRINTERS: 319 case PRINTERS:
322 return prefs::kSyncPrinters; 320 return prefs::kSyncPrinters;
323 case syncer::READING_LIST: 321 case READING_LIST:
324 return prefs::kSyncReadingList; 322 return prefs::kSyncReadingList;
325 default: 323 default:
326 break; 324 break;
327 } 325 }
328 NOTREACHED() << "Type is " << data_type; 326 NOTREACHED() << "Type is " << data_type;
329 return NULL; 327 return NULL;
330 } 328 }
331 329
332 #if defined(OS_CHROMEOS) 330 #if defined(OS_CHROMEOS)
333 std::string SyncPrefs::GetSpareBootstrapToken() const { 331 std::string SyncPrefs::GetSpareBootstrapToken() const {
(...skipping 12 matching lines...) Expand all
346 FOR_EACH_OBSERVER(SyncPrefObserver, sync_pref_observers_, 344 FOR_EACH_OBSERVER(SyncPrefObserver, sync_pref_observers_,
347 OnSyncManagedPrefChange(*pref_sync_managed_)); 345 OnSyncManagedPrefChange(*pref_sync_managed_));
348 } 346 }
349 347
350 void SyncPrefs::SetManagedForTest(bool is_managed) { 348 void SyncPrefs::SetManagedForTest(bool is_managed) {
351 DCHECK(CalledOnValidThread()); 349 DCHECK(CalledOnValidThread());
352 pref_service_->SetBoolean(prefs::kSyncManaged, is_managed); 350 pref_service_->SetBoolean(prefs::kSyncManaged, is_managed);
353 } 351 }
354 352
355 void SyncPrefs::RegisterPrefGroups() { 353 void SyncPrefs::RegisterPrefGroups() {
356 pref_groups_[syncer::APPS].Put(syncer::APP_NOTIFICATIONS); 354 pref_groups_[APPS].Put(APP_NOTIFICATIONS);
357 pref_groups_[syncer::APPS].Put(syncer::APP_SETTINGS); 355 pref_groups_[APPS].Put(APP_SETTINGS);
358 pref_groups_[syncer::APPS].Put(syncer::APP_LIST); 356 pref_groups_[APPS].Put(APP_LIST);
359 pref_groups_[syncer::APPS].Put(syncer::ARC_PACKAGE); 357 pref_groups_[APPS].Put(ARC_PACKAGE);
360 pref_groups_[syncer::APPS].Put(syncer::READING_LIST); 358 pref_groups_[APPS].Put(READING_LIST);
361 359
362 pref_groups_[syncer::AUTOFILL].Put(syncer::AUTOFILL_PROFILE); 360 pref_groups_[AUTOFILL].Put(AUTOFILL_PROFILE);
363 pref_groups_[syncer::AUTOFILL].Put(syncer::AUTOFILL_WALLET_DATA); 361 pref_groups_[AUTOFILL].Put(AUTOFILL_WALLET_DATA);
364 pref_groups_[syncer::AUTOFILL].Put(syncer::AUTOFILL_WALLET_METADATA); 362 pref_groups_[AUTOFILL].Put(AUTOFILL_WALLET_METADATA);
365 363
366 pref_groups_[syncer::EXTENSIONS].Put(syncer::EXTENSION_SETTINGS); 364 pref_groups_[EXTENSIONS].Put(EXTENSION_SETTINGS);
367 365
368 pref_groups_[syncer::PREFERENCES].Put(syncer::DICTIONARY); 366 pref_groups_[PREFERENCES].Put(DICTIONARY);
369 pref_groups_[syncer::PREFERENCES].Put(syncer::PRIORITY_PREFERENCES); 367 pref_groups_[PREFERENCES].Put(PRIORITY_PREFERENCES);
370 pref_groups_[syncer::PREFERENCES].Put(syncer::SEARCH_ENGINES); 368 pref_groups_[PREFERENCES].Put(SEARCH_ENGINES);
371 369
372 pref_groups_[syncer::TYPED_URLS].Put(syncer::HISTORY_DELETE_DIRECTIVES); 370 pref_groups_[TYPED_URLS].Put(HISTORY_DELETE_DIRECTIVES);
373 pref_groups_[syncer::TYPED_URLS].Put(syncer::SESSIONS); 371 pref_groups_[TYPED_URLS].Put(SESSIONS);
374 pref_groups_[syncer::TYPED_URLS].Put(syncer::FAVICON_IMAGES); 372 pref_groups_[TYPED_URLS].Put(FAVICON_IMAGES);
375 pref_groups_[syncer::TYPED_URLS].Put(syncer::FAVICON_TRACKING); 373 pref_groups_[TYPED_URLS].Put(FAVICON_TRACKING);
376 374
377 pref_groups_[syncer::PROXY_TABS].Put(syncer::SESSIONS); 375 pref_groups_[PROXY_TABS].Put(SESSIONS);
378 pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_IMAGES); 376 pref_groups_[PROXY_TABS].Put(FAVICON_IMAGES);
379 pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_TRACKING); 377 pref_groups_[PROXY_TABS].Put(FAVICON_TRACKING);
380 378
381 // TODO(zea): put favicons in the bookmarks group as well once it handles 379 // TODO(zea): put favicons in the bookmarks group as well once it handles
382 // those favicons. 380 // those favicons.
383 } 381 }
384 382
385 // static 383 // static
386 void SyncPrefs::RegisterDataTypePreferredPref( 384 void SyncPrefs::RegisterDataTypePreferredPref(
387 user_prefs::PrefRegistrySyncable* registry, 385 user_prefs::PrefRegistrySyncable* registry,
388 syncer::ModelType type, 386 ModelType type,
389 bool is_preferred) { 387 bool is_preferred) {
390 const char* pref_name = GetPrefNameForDataType(type); 388 const char* pref_name = GetPrefNameForDataType(type);
391 if (!pref_name) { 389 if (!pref_name) {
392 NOTREACHED(); 390 NOTREACHED();
393 return; 391 return;
394 } 392 }
395 registry->RegisterBooleanPref(pref_name, is_preferred); 393 registry->RegisterBooleanPref(pref_name, is_preferred);
396 } 394 }
397 395
398 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { 396 bool SyncPrefs::GetDataTypePreferred(ModelType type) const {
399 DCHECK(CalledOnValidThread()); 397 DCHECK(CalledOnValidThread());
400 const char* pref_name = GetPrefNameForDataType(type); 398 const char* pref_name = GetPrefNameForDataType(type);
401 if (!pref_name) { 399 if (!pref_name) {
402 NOTREACHED(); 400 NOTREACHED();
403 return false; 401 return false;
404 } 402 }
405 403
406 // Device info is always enabled. 404 // Device info is always enabled.
407 if (pref_name == prefs::kSyncDeviceInfo) 405 if (pref_name == prefs::kSyncDeviceInfo)
408 return true; 406 return true;
409 407
410 if (type == syncer::PROXY_TABS && 408 if (type == PROXY_TABS &&
411 pref_service_->GetUserPrefValue(pref_name) == NULL && 409 pref_service_->GetUserPrefValue(pref_name) == NULL &&
412 pref_service_->IsUserModifiablePreference(pref_name)) { 410 pref_service_->IsUserModifiablePreference(pref_name)) {
413 // If there is no tab sync preference yet (i.e. newly enabled type), 411 // If there is no tab sync preference yet (i.e. newly enabled type),
414 // default to the session sync preference value. 412 // default to the session sync preference value.
415 pref_name = GetPrefNameForDataType(syncer::SESSIONS); 413 pref_name = GetPrefNameForDataType(SESSIONS);
416 } 414 }
417 415
418 return pref_service_->GetBoolean(pref_name); 416 return pref_service_->GetBoolean(pref_name);
419 } 417 }
420 418
421 void SyncPrefs::SetDataTypePreferred(syncer::ModelType type, 419 void SyncPrefs::SetDataTypePreferred(ModelType type, bool is_preferred) {
422 bool is_preferred) {
423 DCHECK(CalledOnValidThread()); 420 DCHECK(CalledOnValidThread());
424 const char* pref_name = GetPrefNameForDataType(type); 421 const char* pref_name = GetPrefNameForDataType(type);
425 if (!pref_name) { 422 if (!pref_name) {
426 NOTREACHED(); 423 NOTREACHED();
427 return; 424 return;
428 } 425 }
429 426
430 // Device info is always preferred. 427 // Device info is always preferred.
431 if (type == syncer::DEVICE_INFO) 428 if (type == DEVICE_INFO)
432 return; 429 return;
433 430
434 pref_service_->SetBoolean(pref_name, is_preferred); 431 pref_service_->SetBoolean(pref_name, is_preferred);
435 } 432 }
436 433
437 syncer::ModelTypeSet SyncPrefs::ResolvePrefGroups( 434 ModelTypeSet SyncPrefs::ResolvePrefGroups(ModelTypeSet registered_types,
438 syncer::ModelTypeSet registered_types, 435 ModelTypeSet types) const {
439 syncer::ModelTypeSet types) const { 436 ModelTypeSet types_with_groups = types;
440 syncer::ModelTypeSet types_with_groups = types;
441 for (PrefGroupsMap::const_iterator i = pref_groups_.begin(); 437 for (PrefGroupsMap::const_iterator i = pref_groups_.begin();
442 i != pref_groups_.end(); ++i) { 438 i != pref_groups_.end(); ++i) {
443 if (types.Has(i->first)) 439 if (types.Has(i->first))
444 types_with_groups.PutAll(i->second); 440 types_with_groups.PutAll(i->second);
445 } 441 }
446 types_with_groups.RetainAll(registered_types); 442 types_with_groups.RetainAll(registered_types);
447 return types_with_groups; 443 return types_with_groups;
448 } 444 }
449 445
450 base::Time SyncPrefs::GetFirstSyncTime() const { 446 base::Time SyncPrefs::GetFirstSyncTime() const {
(...skipping 27 matching lines...) Expand all
478 474
479 bool SyncPrefs::DidSyncShutdownCleanly() const { 475 bool SyncPrefs::DidSyncShutdownCleanly() const {
480 return pref_service_->GetBoolean(prefs::kSyncShutdownCleanly); 476 return pref_service_->GetBoolean(prefs::kSyncShutdownCleanly);
481 } 477 }
482 478
483 void SyncPrefs::SetCleanShutdown(bool value) { 479 void SyncPrefs::SetCleanShutdown(bool value) {
484 pref_service_->SetBoolean(prefs::kSyncShutdownCleanly, value); 480 pref_service_->SetBoolean(prefs::kSyncShutdownCleanly, value);
485 } 481 }
486 482
487 void SyncPrefs::GetInvalidationVersions( 483 void SyncPrefs::GetInvalidationVersions(
488 std::map<syncer::ModelType, int64_t>* invalidation_versions) const { 484 std::map<ModelType, int64_t>* invalidation_versions) const {
489 const base::DictionaryValue* invalidation_dictionary = 485 const base::DictionaryValue* invalidation_dictionary =
490 pref_service_->GetDictionary(prefs::kSyncInvalidationVersions); 486 pref_service_->GetDictionary(prefs::kSyncInvalidationVersions);
491 syncer::ModelTypeSet protocol_types = syncer::ProtocolTypes(); 487 ModelTypeSet protocol_types = ProtocolTypes();
492 for (auto iter = protocol_types.First(); iter.Good(); iter.Inc()) { 488 for (auto iter = protocol_types.First(); iter.Good(); iter.Inc()) {
493 std::string key = syncer::ModelTypeToString(iter.Get()); 489 std::string key = ModelTypeToString(iter.Get());
494 std::string version_str; 490 std::string version_str;
495 if (!invalidation_dictionary->GetString(key, &version_str)) 491 if (!invalidation_dictionary->GetString(key, &version_str))
496 continue; 492 continue;
497 int64_t version = 0; 493 int64_t version = 0;
498 if (!base::StringToInt64(version_str, &version)) 494 if (!base::StringToInt64(version_str, &version))
499 continue; 495 continue;
500 (*invalidation_versions)[iter.Get()] = version; 496 (*invalidation_versions)[iter.Get()] = version;
501 } 497 }
502 } 498 }
503 499
504 void SyncPrefs::UpdateInvalidationVersions( 500 void SyncPrefs::UpdateInvalidationVersions(
505 const std::map<syncer::ModelType, int64_t>& invalidation_versions) { 501 const std::map<ModelType, int64_t>& invalidation_versions) {
506 std::unique_ptr<base::DictionaryValue> invalidation_dictionary( 502 std::unique_ptr<base::DictionaryValue> invalidation_dictionary(
507 new base::DictionaryValue()); 503 new base::DictionaryValue());
508 for (const auto& map_iter : invalidation_versions) { 504 for (const auto& map_iter : invalidation_versions) {
509 std::string version_str = base::Int64ToString(map_iter.second); 505 std::string version_str = base::Int64ToString(map_iter.second);
510 invalidation_dictionary->SetString( 506 invalidation_dictionary->SetString(ModelTypeToString(map_iter.first),
511 syncer::ModelTypeToString(map_iter.first), version_str); 507 version_str);
512 } 508 }
513 pref_service_->Set(prefs::kSyncInvalidationVersions, 509 pref_service_->Set(prefs::kSyncInvalidationVersions,
514 *invalidation_dictionary); 510 *invalidation_dictionary);
515 } 511 }
516 512
517 std::string SyncPrefs::GetLastRunVersion() const { 513 std::string SyncPrefs::GetLastRunVersion() const {
518 return pref_service_->GetString(prefs::kSyncLastRunVersion); 514 return pref_service_->GetString(prefs::kSyncLastRunVersion);
519 } 515 }
520 516
521 void SyncPrefs::SetLastRunVersion(const std::string& current_version) { 517 void SyncPrefs::SetLastRunVersion(const std::string& current_version) {
522 pref_service_->SetString(prefs::kSyncLastRunVersion, current_version); 518 pref_service_->SetString(prefs::kSyncLastRunVersion, current_version);
523 } 519 }
524 520
525 void SyncPrefs::SetPassphraseEncryptionTransitionInProgress(bool value) { 521 void SyncPrefs::SetPassphraseEncryptionTransitionInProgress(bool value) {
526 pref_service_->SetBoolean( 522 pref_service_->SetBoolean(
527 prefs::kSyncPassphraseEncryptionTransitionInProgress, value); 523 prefs::kSyncPassphraseEncryptionTransitionInProgress, value);
528 } 524 }
529 525
530 bool SyncPrefs::GetPassphraseEncryptionTransitionInProgress() const { 526 bool SyncPrefs::GetPassphraseEncryptionTransitionInProgress() const {
531 return pref_service_->GetBoolean( 527 return pref_service_->GetBoolean(
532 prefs::kSyncPassphraseEncryptionTransitionInProgress); 528 prefs::kSyncPassphraseEncryptionTransitionInProgress);
533 } 529 }
534 530
535 void SyncPrefs::SetSavedNigoriStateForPassphraseEncryptionTransition( 531 void SyncPrefs::SetSavedNigoriStateForPassphraseEncryptionTransition(
536 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) { 532 const SyncEncryptionHandler::NigoriState& nigori_state) {
537 std::string encoded; 533 std::string encoded;
538 base::Base64Encode(nigori_state.nigori_specifics.SerializeAsString(), 534 base::Base64Encode(nigori_state.nigori_specifics.SerializeAsString(),
539 &encoded); 535 &encoded);
540 pref_service_->SetString(prefs::kSyncNigoriStateForPassphraseTransition, 536 pref_service_->SetString(prefs::kSyncNigoriStateForPassphraseTransition,
541 encoded); 537 encoded);
542 } 538 }
543 539
544 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> 540 std::unique_ptr<SyncEncryptionHandler::NigoriState>
545 SyncPrefs::GetSavedNigoriStateForPassphraseEncryptionTransition() const { 541 SyncPrefs::GetSavedNigoriStateForPassphraseEncryptionTransition() const {
546 const std::string encoded = 542 const std::string encoded =
547 pref_service_->GetString(prefs::kSyncNigoriStateForPassphraseTransition); 543 pref_service_->GetString(prefs::kSyncNigoriStateForPassphraseTransition);
548 std::string decoded; 544 std::string decoded;
549 if (!base::Base64Decode(encoded, &decoded)) 545 if (!base::Base64Decode(encoded, &decoded))
550 return std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>(); 546 return std::unique_ptr<SyncEncryptionHandler::NigoriState>();
551 547
552 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> result( 548 std::unique_ptr<SyncEncryptionHandler::NigoriState> result(
553 new syncer::SyncEncryptionHandler::NigoriState()); 549 new SyncEncryptionHandler::NigoriState());
554 if (!result->nigori_specifics.ParseFromString(decoded)) 550 if (!result->nigori_specifics.ParseFromString(decoded))
555 return std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>(); 551 return std::unique_ptr<SyncEncryptionHandler::NigoriState>();
556 return result; 552 return result;
557 } 553 }
558 554
559 } // namespace sync_driver 555 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/sync_prefs.h ('k') | components/sync/driver/sync_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698