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

Side by Side Diff: chrome/browser/sync/sync_prefs.cc

Issue 12079097: Introduce PrefRegistrySyncable, simplifying PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head again; base::File changes conflicted. Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/sync_prefs.h ('k') | chrome/browser/sync/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 "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/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 "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 // TODO(joi): Remove |prefs| parameter.
48 PrefServiceSyncable::UNSYNCABLE_PREF); 49 registry->RegisterBooleanPref(prefs::kSyncHasSetupCompleted,
49 prefs->RegisterBooleanPref(prefs::kSyncSuppressStart, 50 false,
50 false, 51 PrefRegistrySyncable::UNSYNCABLE_PREF);
51 PrefServiceSyncable::UNSYNCABLE_PREF); 52 registry->RegisterBooleanPref(prefs::kSyncSuppressStart,
52 prefs->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 53 false,
53 0, 54 PrefRegistrySyncable::UNSYNCABLE_PREF);
54 PrefServiceSyncable::UNSYNCABLE_PREF); 55 registry->RegisterInt64Pref(prefs::kSyncLastSyncedTime,
56 0,
57 PrefRegistrySyncable::UNSYNCABLE_PREF);
55 58
56 // If you've never synced before, or if you're using Chrome OS or Android, 59 // If you've never synced before, or if you're using Chrome OS or Android,
57 // all datatypes are on by default. 60 // all datatypes are on by default.
58 // TODO(nick): Perhaps a better model would be to always default to false, 61 // TODO(nick): Perhaps a better model would be to always default to false,
59 // and explicitly call SetDataTypes() when the user shows the wizard. 62 // and explicitly call SetDataTypes() when the user shows the wizard.
60 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) 63 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
61 bool enable_by_default = true; 64 bool enable_by_default = true;
62 #else 65 #else
63 bool enable_by_default = !prefs->HasPrefPath(prefs::kSyncHasSetupCompleted); 66 bool enable_by_default = !prefs->HasPrefPath(prefs::kSyncHasSetupCompleted);
64 #endif 67 #endif
65 68
66 prefs->RegisterBooleanPref(prefs::kSyncKeepEverythingSynced, 69 registry->RegisterBooleanPref(prefs::kSyncKeepEverythingSynced,
67 enable_by_default, 70 enable_by_default,
68 PrefServiceSyncable::UNSYNCABLE_PREF); 71 PrefRegistrySyncable::UNSYNCABLE_PREF);
69 72
70 syncer::ModelTypeSet user_types = syncer::UserTypes(); 73 syncer::ModelTypeSet user_types = syncer::UserTypes();
71 74
72 // Include proxy types as well, as they can be individually selected, 75 // Include proxy types as well, as they can be individually selected,
73 // although they don't have sync representations. 76 // although they don't have sync representations.
74 user_types.PutAll(syncer::ProxyTypes()); 77 user_types.PutAll(syncer::ProxyTypes());
75 78
76 // Treat bookmarks specially. 79 // Treat bookmarks specially.
77 RegisterDataTypePreferredPref(prefs, syncer::BOOKMARKS, true); 80 RegisterDataTypePreferredPref(registry, syncer::BOOKMARKS, true);
78 user_types.Remove(syncer::BOOKMARKS); 81 user_types.Remove(syncer::BOOKMARKS);
79 82
80 for (syncer::ModelTypeSet::Iterator it = user_types.First(); 83 for (syncer::ModelTypeSet::Iterator it = user_types.First();
81 it.Good(); it.Inc()) { 84 it.Good(); it.Inc()) {
82 RegisterDataTypePreferredPref(prefs, it.Get(), enable_by_default); 85 RegisterDataTypePreferredPref(registry, it.Get(), enable_by_default);
83 } 86 }
84 87
85 prefs->RegisterBooleanPref(prefs::kSyncManaged, 88 registry->RegisterBooleanPref(prefs::kSyncManaged,
86 false, 89 false,
87 PrefServiceSyncable::UNSYNCABLE_PREF); 90 PrefRegistrySyncable::UNSYNCABLE_PREF);
88 prefs->RegisterStringPref(prefs::kSyncEncryptionBootstrapToken, 91 registry->RegisterStringPref(prefs::kSyncEncryptionBootstrapToken,
89 "", 92 "",
90 PrefServiceSyncable::UNSYNCABLE_PREF); 93 PrefRegistrySyncable::UNSYNCABLE_PREF);
91 prefs->RegisterStringPref(prefs::kSyncKeystoreEncryptionBootstrapToken, 94 registry->RegisterStringPref(prefs::kSyncKeystoreEncryptionBootstrapToken,
92 "", 95 "",
93 PrefServiceSyncable::UNSYNCABLE_PREF); 96 PrefRegistrySyncable::UNSYNCABLE_PREF);
94 #if defined(OS_CHROMEOS) 97 #if defined(OS_CHROMEOS)
95 prefs->RegisterStringPref(prefs::kSyncSpareBootstrapToken, 98 registry->RegisterStringPref(prefs::kSyncSpareBootstrapToken,
96 "", 99 "",
97 PrefServiceSyncable::UNSYNCABLE_PREF); 100 PrefRegistrySyncable::UNSYNCABLE_PREF);
98 #endif 101 #endif
99 102
100 // We will start prompting people about new data types after the launch of 103 // We will start prompting people about new data types after the launch of
101 // SESSIONS - all previously launched data types are treated as if they are 104 // SESSIONS - all previously launched data types are treated as if they are
102 // already acknowledged. 105 // already acknowledged.
103 syncer::ModelTypeSet model_set; 106 syncer::ModelTypeSet model_set;
104 model_set.Put(syncer::BOOKMARKS); 107 model_set.Put(syncer::BOOKMARKS);
105 model_set.Put(syncer::PREFERENCES); 108 model_set.Put(syncer::PREFERENCES);
106 model_set.Put(syncer::PASSWORDS); 109 model_set.Put(syncer::PASSWORDS);
107 model_set.Put(syncer::AUTOFILL_PROFILE); 110 model_set.Put(syncer::AUTOFILL_PROFILE);
108 model_set.Put(syncer::AUTOFILL); 111 model_set.Put(syncer::AUTOFILL);
109 model_set.Put(syncer::THEMES); 112 model_set.Put(syncer::THEMES);
110 model_set.Put(syncer::EXTENSIONS); 113 model_set.Put(syncer::EXTENSIONS);
111 model_set.Put(syncer::NIGORI); 114 model_set.Put(syncer::NIGORI);
112 model_set.Put(syncer::SEARCH_ENGINES); 115 model_set.Put(syncer::SEARCH_ENGINES);
113 model_set.Put(syncer::APPS); 116 model_set.Put(syncer::APPS);
114 model_set.Put(syncer::TYPED_URLS); 117 model_set.Put(syncer::TYPED_URLS);
115 model_set.Put(syncer::SESSIONS); 118 model_set.Put(syncer::SESSIONS);
116 prefs->RegisterListPref(prefs::kSyncAcknowledgedSyncTypes, 119 registry->RegisterListPref(prefs::kSyncAcknowledgedSyncTypes,
117 syncer::ModelTypeSetToValue(model_set), 120 syncer::ModelTypeSetToValue(model_set),
118 PrefServiceSyncable::UNSYNCABLE_PREF); 121 PrefRegistrySyncable::UNSYNCABLE_PREF);
119 } 122 }
120 123
121 // static 124 // static
122 bool SyncPrefs::IsSyncAccessibleOnIOThread(ProfileIOData* io_data) { 125 bool SyncPrefs::IsSyncAccessibleOnIOThread(ProfileIOData* io_data) {
123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 126 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
124 return ProfileSyncService::IsSyncEnabled() && 127 return ProfileSyncService::IsSyncEnabled() &&
125 !io_data->sync_disabled()->GetValue(); 128 !io_data->sync_disabled()->GetValue();
126 } 129 }
127 130
128 void SyncPrefs::AddSyncPrefObserver(SyncPrefObserver* sync_pref_observer) { 131 void SyncPrefs::AddSyncPrefObserver(SyncPrefObserver* sync_pref_observer) {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 pref_groups_[syncer::EXTENSIONS].Put(syncer::EXTENSION_SETTINGS); 389 pref_groups_[syncer::EXTENSIONS].Put(syncer::EXTENSION_SETTINGS);
387 390
388 pref_groups_[syncer::PREFERENCES].Put(syncer::DICTIONARY); 391 pref_groups_[syncer::PREFERENCES].Put(syncer::DICTIONARY);
389 pref_groups_[syncer::PREFERENCES].Put(syncer::SEARCH_ENGINES); 392 pref_groups_[syncer::PREFERENCES].Put(syncer::SEARCH_ENGINES);
390 393
391 // TODO(akalin): Revisit this once UI lands. 394 // TODO(akalin): Revisit this once UI lands.
392 pref_groups_[syncer::SESSIONS].Put(syncer::HISTORY_DELETE_DIRECTIVES); 395 pref_groups_[syncer::SESSIONS].Put(syncer::HISTORY_DELETE_DIRECTIVES);
393 } 396 }
394 397
395 // static 398 // static
396 void SyncPrefs::RegisterDataTypePreferredPref(PrefServiceSyncable* prefs, 399 void SyncPrefs::RegisterDataTypePreferredPref(PrefRegistrySyncable* registry,
397 syncer::ModelType type, 400 syncer::ModelType type,
398 bool is_preferred) { 401 bool is_preferred) {
399 const char* pref_name = GetPrefNameForDataType(type); 402 const char* pref_name = GetPrefNameForDataType(type);
400 if (!pref_name) { 403 if (!pref_name) {
401 NOTREACHED(); 404 NOTREACHED();
402 return; 405 return;
403 } 406 }
404 prefs->RegisterBooleanPref(pref_name, is_preferred, 407 registry->RegisterBooleanPref(pref_name, is_preferred,
405 PrefServiceSyncable::UNSYNCABLE_PREF); 408 PrefRegistrySyncable::UNSYNCABLE_PREF);
406 } 409 }
407 410
408 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { 411 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const {
409 DCHECK(CalledOnValidThread()); 412 DCHECK(CalledOnValidThread());
410 if (!pref_service_) { 413 if (!pref_service_) {
411 return false; 414 return false;
412 } 415 }
413 const char* pref_name = GetPrefNameForDataType(type); 416 const char* pref_name = GetPrefNameForDataType(type);
414 if (!pref_name) { 417 if (!pref_name) {
415 NOTREACHED(); 418 NOTREACHED();
(...skipping 25 matching lines...) Expand all
441 if (types.Has(i->first)) 444 if (types.Has(i->first))
442 types_with_groups.PutAll(i->second); 445 types_with_groups.PutAll(i->second);
443 else 446 else
444 types_with_groups.RemoveAll(i->second); 447 types_with_groups.RemoveAll(i->second);
445 } 448 }
446 types_with_groups.RetainAll(registered_types); 449 types_with_groups.RetainAll(registered_types);
447 return types_with_groups; 450 return types_with_groups;
448 } 451 }
449 452
450 } // namespace browser_sync 453 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_prefs.h ('k') | chrome/browser/sync/sync_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698