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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/prefs/pref_member.h" | 9 #include "base/prefs/pref_member.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 base::Bind(&SyncPrefs::OnSyncManagedPrefChanged, | 38 base::Bind(&SyncPrefs::OnSyncManagedPrefChanged, |
39 base::Unretained(this))); | 39 base::Unretained(this))); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 SyncPrefs::~SyncPrefs() { | 43 SyncPrefs::~SyncPrefs() { |
44 DCHECK(CalledOnValidThread()); | 44 DCHECK(CalledOnValidThread()); |
45 } | 45 } |
46 | 46 |
47 // static | 47 // static |
48 void SyncPrefs::RegisterUserPrefs(PrefRegistrySyncable* registry) { | 48 void SyncPrefs::RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry) { |
49 // TODO(joi): Remove |prefs| parameter. | 49 // TODO(joi): Remove |prefs| parameter. |
50 registry->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, | 50 registry->RegisterBooleanPref( |
51 false, | 51 prefs::kSyncHasSetupCompleted, |
52 PrefRegistrySyncable::UNSYNCABLE_PREF); | 52 false, |
53 registry->RegisterBooleanPref(prefs::kSyncSuppressStart, | 53 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
54 false, | 54 registry->RegisterBooleanPref( |
55 PrefRegistrySyncable::UNSYNCABLE_PREF); | 55 prefs::kSyncSuppressStart, |
56 registry->RegisterInt64Pref(prefs::kSyncLastSyncedTime, | 56 false, |
57 0, | 57 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
58 PrefRegistrySyncable::UNSYNCABLE_PREF); | 58 registry->RegisterInt64Pref( |
| 59 prefs::kSyncLastSyncedTime, |
| 60 0, |
| 61 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
59 | 62 |
60 // All datatypes are on by default, but this gets set explicitly | 63 // All datatypes are on by default, but this gets set explicitly |
61 // when you configure sync (when turning it on), in | 64 // when you configure sync (when turning it on), in |
62 // ProfileSyncService::OnUserChoseDatatypes. | 65 // ProfileSyncService::OnUserChoseDatatypes. |
63 registry->RegisterBooleanPref(prefs::kSyncKeepEverythingSynced, | 66 registry->RegisterBooleanPref( |
64 true, | 67 prefs::kSyncKeepEverythingSynced, |
65 PrefRegistrySyncable::UNSYNCABLE_PREF); | 68 true, |
| 69 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
66 | 70 |
67 syncer::ModelTypeSet user_types = syncer::UserTypes(); | 71 syncer::ModelTypeSet user_types = syncer::UserTypes(); |
68 | 72 |
69 // Include proxy types as well, as they can be individually selected, | 73 // Include proxy types as well, as they can be individually selected, |
70 // although they don't have sync representations. | 74 // although they don't have sync representations. |
71 user_types.PutAll(syncer::ProxyTypes()); | 75 user_types.PutAll(syncer::ProxyTypes()); |
72 | 76 |
73 // Treat bookmarks specially. | 77 // Treat bookmarks specially. |
74 RegisterDataTypePreferredPref(registry, syncer::BOOKMARKS, true); | 78 RegisterDataTypePreferredPref(registry, syncer::BOOKMARKS, true); |
75 user_types.Remove(syncer::BOOKMARKS); | 79 user_types.Remove(syncer::BOOKMARKS); |
76 | 80 |
77 // All types are set to off by default, which forces a configuration to | 81 // All types are set to off by default, which forces a configuration to |
78 // explicitly enable them. GetPreferredTypes() will ensure that any new | 82 // explicitly enable them. GetPreferredTypes() will ensure that any new |
79 // implicit types are enabled when their pref group is, or via | 83 // implicit types are enabled when their pref group is, or via |
80 // KeepEverythingSynced. | 84 // KeepEverythingSynced. |
81 for (syncer::ModelTypeSet::Iterator it = user_types.First(); | 85 for (syncer::ModelTypeSet::Iterator it = user_types.First(); |
82 it.Good(); it.Inc()) { | 86 it.Good(); it.Inc()) { |
83 RegisterDataTypePreferredPref(registry, it.Get(), false); | 87 RegisterDataTypePreferredPref(registry, it.Get(), false); |
84 } | 88 } |
85 | 89 |
86 registry->RegisterBooleanPref(prefs::kSyncManaged, | 90 registry->RegisterBooleanPref( |
87 false, | 91 prefs::kSyncManaged, |
88 PrefRegistrySyncable::UNSYNCABLE_PREF); | 92 false, |
89 registry->RegisterStringPref(prefs::kSyncEncryptionBootstrapToken, | 93 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
90 std::string(), | 94 registry->RegisterStringPref( |
91 PrefRegistrySyncable::UNSYNCABLE_PREF); | 95 prefs::kSyncEncryptionBootstrapToken, |
92 registry->RegisterStringPref(prefs::kSyncKeystoreEncryptionBootstrapToken, | 96 std::string(), |
93 std::string(), | 97 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
94 PrefRegistrySyncable::UNSYNCABLE_PREF); | 98 registry->RegisterStringPref( |
| 99 prefs::kSyncKeystoreEncryptionBootstrapToken, |
| 100 std::string(), |
| 101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
95 #if defined(OS_CHROMEOS) | 102 #if defined(OS_CHROMEOS) |
96 registry->RegisterStringPref(prefs::kSyncSpareBootstrapToken, | 103 registry->RegisterStringPref( |
97 "", | 104 prefs::kSyncSpareBootstrapToken, |
98 PrefRegistrySyncable::UNSYNCABLE_PREF); | 105 "", |
| 106 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
99 #endif | 107 #endif |
100 | 108 |
101 registry->RegisterStringPref(prefs::kSyncSessionsGUID, | 109 registry->RegisterStringPref( |
102 std::string(), | 110 prefs::kSyncSessionsGUID, |
103 PrefRegistrySyncable::UNSYNCABLE_PREF); | 111 std::string(), |
| 112 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
104 | 113 |
105 // We will start prompting people about new data types after the launch of | 114 // We will start prompting people about new data types after the launch of |
106 // SESSIONS - all previously launched data types are treated as if they are | 115 // SESSIONS - all previously launched data types are treated as if they are |
107 // already acknowledged. | 116 // already acknowledged. |
108 syncer::ModelTypeSet model_set; | 117 syncer::ModelTypeSet model_set; |
109 model_set.Put(syncer::BOOKMARKS); | 118 model_set.Put(syncer::BOOKMARKS); |
110 model_set.Put(syncer::PREFERENCES); | 119 model_set.Put(syncer::PREFERENCES); |
111 model_set.Put(syncer::PASSWORDS); | 120 model_set.Put(syncer::PASSWORDS); |
112 model_set.Put(syncer::AUTOFILL_PROFILE); | 121 model_set.Put(syncer::AUTOFILL_PROFILE); |
113 model_set.Put(syncer::AUTOFILL); | 122 model_set.Put(syncer::AUTOFILL); |
114 model_set.Put(syncer::THEMES); | 123 model_set.Put(syncer::THEMES); |
115 model_set.Put(syncer::EXTENSIONS); | 124 model_set.Put(syncer::EXTENSIONS); |
116 model_set.Put(syncer::NIGORI); | 125 model_set.Put(syncer::NIGORI); |
117 model_set.Put(syncer::SEARCH_ENGINES); | 126 model_set.Put(syncer::SEARCH_ENGINES); |
118 model_set.Put(syncer::APPS); | 127 model_set.Put(syncer::APPS); |
119 model_set.Put(syncer::TYPED_URLS); | 128 model_set.Put(syncer::TYPED_URLS); |
120 model_set.Put(syncer::SESSIONS); | 129 model_set.Put(syncer::SESSIONS); |
121 registry->RegisterListPref(prefs::kSyncAcknowledgedSyncTypes, | 130 registry->RegisterListPref(prefs::kSyncAcknowledgedSyncTypes, |
122 syncer::ModelTypeSetToValue(model_set), | 131 syncer::ModelTypeSetToValue(model_set), |
123 PrefRegistrySyncable::UNSYNCABLE_PREF); | 132 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
124 } | 133 } |
125 | 134 |
126 // static | 135 // static |
127 bool SyncPrefs::IsSyncAccessibleOnIOThread(ProfileIOData* io_data) { | 136 bool SyncPrefs::IsSyncAccessibleOnIOThread(ProfileIOData* io_data) { |
128 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 137 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
129 return ProfileSyncService::IsSyncEnabled() && | 138 return ProfileSyncService::IsSyncEnabled() && |
130 !io_data->sync_disabled()->GetValue(); | 139 !io_data->sync_disabled()->GetValue(); |
131 } | 140 } |
132 | 141 |
133 void SyncPrefs::AddSyncPrefObserver(SyncPrefObserver* sync_pref_observer) { | 142 void SyncPrefs::AddSyncPrefObserver(SyncPrefObserver* sync_pref_observer) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 429 |
421 pref_groups_[syncer::PROXY_TABS].Put(syncer::SESSIONS); | 430 pref_groups_[syncer::PROXY_TABS].Put(syncer::SESSIONS); |
422 pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_IMAGES); | 431 pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_IMAGES); |
423 pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_TRACKING); | 432 pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_TRACKING); |
424 | 433 |
425 // TODO(zea): put favicons in the bookmarks group as well once it handles | 434 // TODO(zea): put favicons in the bookmarks group as well once it handles |
426 // those favicons. | 435 // those favicons. |
427 } | 436 } |
428 | 437 |
429 // static | 438 // static |
430 void SyncPrefs::RegisterDataTypePreferredPref(PrefRegistrySyncable* registry, | 439 void SyncPrefs::RegisterDataTypePreferredPref( |
431 syncer::ModelType type, | 440 user_prefs::PrefRegistrySyncable* registry, |
432 bool is_preferred) { | 441 syncer::ModelType type, |
| 442 bool is_preferred) { |
433 const char* pref_name = GetPrefNameForDataType(type); | 443 const char* pref_name = GetPrefNameForDataType(type); |
434 if (!pref_name) { | 444 if (!pref_name) { |
435 NOTREACHED(); | 445 NOTREACHED(); |
436 return; | 446 return; |
437 } | 447 } |
438 registry->RegisterBooleanPref(pref_name, is_preferred, | 448 registry->RegisterBooleanPref( |
439 PrefRegistrySyncable::UNSYNCABLE_PREF); | 449 pref_name, |
| 450 is_preferred, |
| 451 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
440 } | 452 } |
441 | 453 |
442 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { | 454 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { |
443 DCHECK(CalledOnValidThread()); | 455 DCHECK(CalledOnValidThread()); |
444 if (!pref_service_) { | 456 if (!pref_service_) { |
445 return false; | 457 return false; |
446 } | 458 } |
447 const char* pref_name = GetPrefNameForDataType(type); | 459 const char* pref_name = GetPrefNameForDataType(type); |
448 if (!pref_name) { | 460 if (!pref_name) { |
449 NOTREACHED(); | 461 NOTREACHED(); |
(...skipping 30 matching lines...) Expand all Loading... |
480 for (PrefGroupsMap::const_iterator i = pref_groups_.begin(); | 492 for (PrefGroupsMap::const_iterator i = pref_groups_.begin(); |
481 i != pref_groups_.end(); ++i) { | 493 i != pref_groups_.end(); ++i) { |
482 if (types.Has(i->first)) | 494 if (types.Has(i->first)) |
483 types_with_groups.PutAll(i->second); | 495 types_with_groups.PutAll(i->second); |
484 } | 496 } |
485 types_with_groups.RetainAll(registered_types); | 497 types_with_groups.RetainAll(registered_types); |
486 return types_with_groups; | 498 return types_with_groups; |
487 } | 499 } |
488 | 500 |
489 } // namespace browser_sync | 501 } // namespace browser_sync |
OLD | NEW |