Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/sync/sync_prefs.h" | 5 #include "chrome/browser/sync/sync_prefs.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/prefs/public/pref_member.h" | 8 #include "base/prefs/public/pref_member.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/prefs/pref_registry_syncable.h" | |
| 12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile_io_data.h" | 14 #include "chrome/browser/profiles/profile_io_data.h" |
| 14 #include "chrome/browser/sync/profile_sync_service.h" | 15 #include "chrome/browser/sync/profile_sync_service.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
| 19 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
| 20 | 21 |
| 21 namespace browser_sync { | 22 namespace browser_sync { |
| 22 | 23 |
| 23 SyncPrefObserver::~SyncPrefObserver() {} | 24 SyncPrefObserver::~SyncPrefObserver() {} |
| 24 | 25 |
| 25 SyncPrefs::SyncPrefs(PrefServiceSyncable* pref_service) | 26 SyncPrefs::SyncPrefs(PrefService* pref_service) |
| 26 : pref_service_(pref_service) { | 27 : pref_service_(pref_service) { |
| 27 RegisterPrefGroups(); | 28 RegisterPrefGroups(); |
| 28 // TODO(tim): Create a Mock instead of maintaining the if(!pref_service_) case | 29 // TODO(tim): Create a Mock instead of maintaining the if(!pref_service_) case |
| 29 // throughout this file. This is a problem now due to lack of injection at | 30 // throughout this file. This is a problem now due to lack of injection at |
| 30 // ProfileSyncService. Bug 130176. | 31 // ProfileSyncService. Bug 130176. |
| 31 if (pref_service_) { | 32 if (pref_service_) { |
| 32 // Watch the preference that indicates sync is managed so we can take | 33 // Watch the preference that indicates sync is managed so we can take |
| 33 // appropriate action. | 34 // appropriate action. |
| 34 pref_sync_managed_.Init(prefs::kSyncManaged, pref_service_, | 35 pref_sync_managed_.Init(prefs::kSyncManaged, pref_service_, |
| 35 base::Bind(&SyncPrefs::OnSyncManagedPrefChanged, | 36 base::Bind(&SyncPrefs::OnSyncManagedPrefChanged, |
| 36 base::Unretained(this))); | 37 base::Unretained(this))); |
| 37 } | 38 } |
| 38 } | 39 } |
| 39 | 40 |
| 40 SyncPrefs::~SyncPrefs() { | 41 SyncPrefs::~SyncPrefs() { |
| 41 DCHECK(CalledOnValidThread()); | 42 DCHECK(CalledOnValidThread()); |
| 42 } | 43 } |
| 43 | 44 |
| 44 // static | 45 // static |
| 45 void SyncPrefs::RegisterUserPrefs(PrefServiceSyncable* prefs) { | 46 void SyncPrefs::RegisterUserPrefs(PrefService* prefs, |
| 46 prefs->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, | 47 PrefRegistrySyncable* registry) { |
| 47 false, | 48 registry->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, |
| 48 PrefServiceSyncable::UNSYNCABLE_PREF); | 49 false, |
| 49 prefs->RegisterBooleanPref(prefs::kSyncSuppressStart, | 50 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 50 false, | 51 registry->RegisterBooleanPref(prefs::kSyncSuppressStart, |
| 51 PrefServiceSyncable::UNSYNCABLE_PREF); | 52 false, |
| 52 prefs->RegisterInt64Pref(prefs::kSyncLastSyncedTime, | 53 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 53 0, | 54 registry->RegisterInt64Pref(prefs::kSyncLastSyncedTime, |
| 54 PrefServiceSyncable::UNSYNCABLE_PREF); | 55 0, |
| 56 PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 55 | 57 |
| 56 // If you've never synced before, or if you're using Chrome OS or Android, | 58 // If you've never synced before, or if you're using Chrome OS or Android, |
| 57 // all datatypes are on by default. | 59 // all datatypes are on by default. |
| 58 // TODO(nick): Perhaps a better model would be to always default to false, | 60 // TODO(nick): Perhaps a better model would be to always default to false, |
| 59 // and explicitly call SetDataTypes() when the user shows the wizard. | 61 // and explicitly call SetDataTypes() when the user shows the wizard. |
| 60 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 62 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 61 bool enable_by_default = true; | 63 bool enable_by_default = true; |
| 62 #else | 64 #else |
| 63 bool enable_by_default = !prefs->HasPrefPath(prefs::kSyncHasSetupCompleted); | 65 bool enable_by_default = !prefs->HasPrefPath(prefs::kSyncHasSetupCompleted); |
|
Mattias Nissler (ping if slow)
2013/02/06 17:53:33
TODO: Remove |prefs| parameter.
Jói
2013/02/07 14:52:32
Done.
| |
| 64 #endif | 66 #endif |
| 65 | 67 |
| 66 prefs->RegisterBooleanPref(prefs::kSyncKeepEverythingSynced, | 68 registry->RegisterBooleanPref(prefs::kSyncKeepEverythingSynced, |
| 67 enable_by_default, | 69 enable_by_default, |
| 68 PrefServiceSyncable::UNSYNCABLE_PREF); | 70 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 69 | 71 |
| 70 syncer::ModelTypeSet user_types = syncer::UserTypes(); | 72 syncer::ModelTypeSet user_types = syncer::UserTypes(); |
| 71 | 73 |
| 72 // Treat bookmarks specially. | 74 // Treat bookmarks specially. |
| 73 RegisterDataTypePreferredPref(prefs, syncer::BOOKMARKS, true); | 75 RegisterDataTypePreferredPref(registry, syncer::BOOKMARKS, true); |
| 74 user_types.Remove(syncer::BOOKMARKS); | 76 user_types.Remove(syncer::BOOKMARKS); |
| 75 | 77 |
| 76 for (syncer::ModelTypeSet::Iterator it = user_types.First(); | 78 for (syncer::ModelTypeSet::Iterator it = user_types.First(); |
| 77 it.Good(); it.Inc()) { | 79 it.Good(); it.Inc()) { |
| 78 RegisterDataTypePreferredPref(prefs, it.Get(), enable_by_default); | 80 RegisterDataTypePreferredPref(registry, it.Get(), enable_by_default); |
| 79 } | 81 } |
| 80 | 82 |
| 81 prefs->RegisterBooleanPref(prefs::kSyncManaged, | 83 registry->RegisterBooleanPref(prefs::kSyncManaged, |
| 82 false, | 84 false, |
| 83 PrefServiceSyncable::UNSYNCABLE_PREF); | 85 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 84 prefs->RegisterStringPref(prefs::kSyncEncryptionBootstrapToken, | 86 registry->RegisterStringPref(prefs::kSyncEncryptionBootstrapToken, |
| 85 "", | 87 "", |
| 86 PrefServiceSyncable::UNSYNCABLE_PREF); | 88 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 87 prefs->RegisterStringPref(prefs::kSyncKeystoreEncryptionBootstrapToken, | 89 registry->RegisterStringPref(prefs::kSyncKeystoreEncryptionBootstrapToken, |
| 88 "", | 90 "", |
| 89 PrefServiceSyncable::UNSYNCABLE_PREF); | 91 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 90 #if defined(OS_CHROMEOS) | 92 #if defined(OS_CHROMEOS) |
| 91 prefs->RegisterStringPref(prefs::kSyncSpareBootstrapToken, | 93 registry->RegisterStringPref(prefs::kSyncSpareBootstrapToken, |
| 92 "", | 94 "", |
| 93 PrefServiceSyncable::UNSYNCABLE_PREF); | 95 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 94 #endif | 96 #endif |
| 95 | 97 |
| 96 // We will start prompting people about new data types after the launch of | 98 // We will start prompting people about new data types after the launch of |
| 97 // SESSIONS - all previously launched data types are treated as if they are | 99 // SESSIONS - all previously launched data types are treated as if they are |
| 98 // already acknowledged. | 100 // already acknowledged. |
| 99 syncer::ModelTypeSet model_set; | 101 syncer::ModelTypeSet model_set; |
| 100 model_set.Put(syncer::BOOKMARKS); | 102 model_set.Put(syncer::BOOKMARKS); |
| 101 model_set.Put(syncer::PREFERENCES); | 103 model_set.Put(syncer::PREFERENCES); |
| 102 model_set.Put(syncer::PASSWORDS); | 104 model_set.Put(syncer::PASSWORDS); |
| 103 model_set.Put(syncer::AUTOFILL_PROFILE); | 105 model_set.Put(syncer::AUTOFILL_PROFILE); |
| 104 model_set.Put(syncer::AUTOFILL); | 106 model_set.Put(syncer::AUTOFILL); |
| 105 model_set.Put(syncer::THEMES); | 107 model_set.Put(syncer::THEMES); |
| 106 model_set.Put(syncer::EXTENSIONS); | 108 model_set.Put(syncer::EXTENSIONS); |
| 107 model_set.Put(syncer::NIGORI); | 109 model_set.Put(syncer::NIGORI); |
| 108 model_set.Put(syncer::SEARCH_ENGINES); | 110 model_set.Put(syncer::SEARCH_ENGINES); |
| 109 model_set.Put(syncer::APPS); | 111 model_set.Put(syncer::APPS); |
| 110 model_set.Put(syncer::TYPED_URLS); | 112 model_set.Put(syncer::TYPED_URLS); |
| 111 model_set.Put(syncer::SESSIONS); | 113 model_set.Put(syncer::SESSIONS); |
| 112 prefs->RegisterListPref(prefs::kSyncAcknowledgedSyncTypes, | 114 registry->RegisterListPref(prefs::kSyncAcknowledgedSyncTypes, |
| 113 syncer::ModelTypeSetToValue(model_set), | 115 syncer::ModelTypeSetToValue(model_set), |
| 114 PrefServiceSyncable::UNSYNCABLE_PREF); | 116 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 115 } | 117 } |
| 116 | 118 |
| 117 // static | 119 // static |
| 118 bool SyncPrefs::IsSyncAccessibleOnIOThread(ProfileIOData* io_data) { | 120 bool SyncPrefs::IsSyncAccessibleOnIOThread(ProfileIOData* io_data) { |
| 119 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 121 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 120 return ProfileSyncService::IsSyncEnabled() && | 122 return ProfileSyncService::IsSyncEnabled() && |
| 121 !io_data->sync_disabled()->GetValue(); | 123 !io_data->sync_disabled()->GetValue(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 void SyncPrefs::AddSyncPrefObserver(SyncPrefObserver* sync_pref_observer) { | 126 void SyncPrefs::AddSyncPrefObserver(SyncPrefObserver* sync_pref_observer) { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 pref_groups_[syncer::EXTENSIONS].Put(syncer::EXTENSION_SETTINGS); | 384 pref_groups_[syncer::EXTENSIONS].Put(syncer::EXTENSION_SETTINGS); |
| 383 | 385 |
| 384 pref_groups_[syncer::PREFERENCES].Put(syncer::DICTIONARY); | 386 pref_groups_[syncer::PREFERENCES].Put(syncer::DICTIONARY); |
| 385 pref_groups_[syncer::PREFERENCES].Put(syncer::SEARCH_ENGINES); | 387 pref_groups_[syncer::PREFERENCES].Put(syncer::SEARCH_ENGINES); |
| 386 | 388 |
| 387 // TODO(akalin): Revisit this once UI lands. | 389 // TODO(akalin): Revisit this once UI lands. |
| 388 pref_groups_[syncer::SESSIONS].Put(syncer::HISTORY_DELETE_DIRECTIVES); | 390 pref_groups_[syncer::SESSIONS].Put(syncer::HISTORY_DELETE_DIRECTIVES); |
| 389 } | 391 } |
| 390 | 392 |
| 391 // static | 393 // static |
| 392 void SyncPrefs::RegisterDataTypePreferredPref(PrefServiceSyncable* prefs, | 394 void SyncPrefs::RegisterDataTypePreferredPref(PrefRegistrySyncable* registry, |
| 393 syncer::ModelType type, | 395 syncer::ModelType type, |
| 394 bool is_preferred) { | 396 bool is_preferred) { |
| 395 const char* pref_name = GetPrefNameForDataType(type); | 397 const char* pref_name = GetPrefNameForDataType(type); |
| 396 if (!pref_name) { | 398 if (!pref_name) { |
| 397 NOTREACHED(); | 399 NOTREACHED(); |
| 398 return; | 400 return; |
| 399 } | 401 } |
| 400 prefs->RegisterBooleanPref(pref_name, is_preferred, | 402 registry->RegisterBooleanPref(pref_name, is_preferred, |
| 401 PrefServiceSyncable::UNSYNCABLE_PREF); | 403 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 402 } | 404 } |
| 403 | 405 |
| 404 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { | 406 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { |
| 405 DCHECK(CalledOnValidThread()); | 407 DCHECK(CalledOnValidThread()); |
| 406 if (!pref_service_) { | 408 if (!pref_service_) { |
| 407 return false; | 409 return false; |
| 408 } | 410 } |
| 409 const char* pref_name = GetPrefNameForDataType(type); | 411 const char* pref_name = GetPrefNameForDataType(type); |
| 410 if (!pref_name) { | 412 if (!pref_name) { |
| 411 NOTREACHED(); | 413 NOTREACHED(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 437 if (types.Has(i->first)) | 439 if (types.Has(i->first)) |
| 438 types_with_groups.PutAll(i->second); | 440 types_with_groups.PutAll(i->second); |
| 439 else | 441 else |
| 440 types_with_groups.RemoveAll(i->second); | 442 types_with_groups.RemoveAll(i->second); |
| 441 } | 443 } |
| 442 types_with_groups.RetainAll(registered_types); | 444 types_with_groups.RetainAll(registered_types); |
| 443 return types_with_groups; | 445 return types_with_groups; |
| 444 } | 446 } |
| 445 | 447 |
| 446 } // namespace browser_sync | 448 } // namespace browser_sync |
| OLD | NEW |