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

Side by Side Diff: components/pref_registry/pref_registry_syncable.cc

Issue 1096833003: Convert PrefSyncStatus into PrefRegistrationFlags (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
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/pref_registry/pref_registry_syncable.h" 5 #include "components/pref_registry/pref_registry_syncable.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/prefs/default_pref_store.h" 8 #include "base/prefs/default_pref_store.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 11
12 namespace user_prefs { 12 namespace user_prefs {
13 13
14 namespace {
15
16 // Tests that |flags| contains a single sync flag since all sync flags are
17 // mutually exclusive.
18 bool HasSyncFlag(uint32 flags) {
19 size_t flag_count = 0;
20
21 const uint32 kSyncFlags[] = {
22 PrefRegistrySyncable::UNSYNCABLE_PREF,
23 PrefRegistrySyncable::SYNCABLE_PREF,
24 PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
25 };
26
27 for (uint32 i = 0; 0 < arraysize(kSyncFlags); ++i) {
28 if (flags && kSyncFlags[i])
29 flag_count++;
30 }
31
32 return flag_count == 1;
33 }
34
35 } // namespace
36
Mattias Nissler (ping if slow) 2015/04/20 09:33:34 nit: remove extra blank line
raymes 2015/04/21 07:58:54 Done.
37
14 PrefRegistrySyncable::PrefRegistrySyncable() { 38 PrefRegistrySyncable::PrefRegistrySyncable() {
15 } 39 }
16 40
17 PrefRegistrySyncable::~PrefRegistrySyncable() { 41 PrefRegistrySyncable::~PrefRegistrySyncable() {
18 } 42 }
19 43
20 const PrefRegistrySyncable::PrefToStatus&
21 PrefRegistrySyncable::syncable_preferences() const {
22 return syncable_preferences_;
23 }
24
25 void PrefRegistrySyncable::SetSyncableRegistrationCallback( 44 void PrefRegistrySyncable::SetSyncableRegistrationCallback(
26 const SyncableRegistrationCallback& cb) { 45 const SyncableRegistrationCallback& cb) {
27 callback_ = cb; 46 callback_ = cb;
28 } 47 }
29 48
30 void PrefRegistrySyncable::RegisterBooleanPref(const char* path, 49 void PrefRegistrySyncable::RegisterBooleanPref(const char* path,
31 bool default_value, 50 bool default_value,
32 PrefSyncStatus sync_status) { 51 uint32 flags) {
33 RegisterSyncablePreference( 52 RegisterSyncablePreference(
34 path, new base::FundamentalValue(default_value), sync_status); 53 path, new base::FundamentalValue(default_value), flags);
35 } 54 }
36 55
37 void PrefRegistrySyncable::RegisterIntegerPref(const char* path, 56 void PrefRegistrySyncable::RegisterIntegerPref(const char* path,
38 int default_value, 57 int default_value,
39 PrefSyncStatus sync_status) { 58 uint32 flags) {
40 RegisterSyncablePreference( 59 RegisterSyncablePreference(
41 path, new base::FundamentalValue(default_value), sync_status); 60 path, new base::FundamentalValue(default_value), flags);
42 } 61 }
43 62
44 void PrefRegistrySyncable::RegisterDoublePref(const char* path, 63 void PrefRegistrySyncable::RegisterDoublePref(const char* path,
45 double default_value, 64 double default_value,
46 PrefSyncStatus sync_status) { 65 uint32 flags) {
47 RegisterSyncablePreference( 66 RegisterSyncablePreference(
48 path, new base::FundamentalValue(default_value), sync_status); 67 path, new base::FundamentalValue(default_value), flags);
49 } 68 }
50 69
51 void PrefRegistrySyncable::RegisterStringPref(const char* path, 70 void PrefRegistrySyncable::RegisterStringPref(const char* path,
52 const std::string& default_value, 71 const std::string& default_value,
53 PrefSyncStatus sync_status) { 72 uint32 flags) {
54 RegisterSyncablePreference( 73 RegisterSyncablePreference(
55 path, new base::StringValue(default_value), sync_status); 74 path, new base::StringValue(default_value), flags);
56 } 75 }
57 76
58 void PrefRegistrySyncable::RegisterFilePathPref( 77 void PrefRegistrySyncable::RegisterFilePathPref(
59 const char* path, 78 const char* path,
60 const base::FilePath& default_value, 79 const base::FilePath& default_value,
61 PrefSyncStatus sync_status) { 80 uint32 flags) {
62 RegisterSyncablePreference( 81 RegisterSyncablePreference(
63 path, new base::StringValue(default_value.value()), sync_status); 82 path, new base::StringValue(default_value.value()), flags);
64 } 83 }
65 84
66 void PrefRegistrySyncable::RegisterListPref(const char* path, 85 void PrefRegistrySyncable::RegisterListPref(const char* path, uint32 flags) {
67 PrefSyncStatus sync_status) { 86 RegisterSyncablePreference(path, new base::ListValue(), flags);
68 RegisterSyncablePreference(path, new base::ListValue(), sync_status);
69 } 87 }
70 88
71 void PrefRegistrySyncable::RegisterListPref(const char* path, 89 void PrefRegistrySyncable::RegisterListPref(const char* path,
72 base::ListValue* default_value, 90 base::ListValue* default_value,
73 PrefSyncStatus sync_status) { 91 uint32 flags) {
74 RegisterSyncablePreference(path, default_value, sync_status); 92 RegisterSyncablePreference(path, default_value, flags);
75 } 93 }
76 94
77 void PrefRegistrySyncable::RegisterDictionaryPref(const char* path, 95 void PrefRegistrySyncable::RegisterDictionaryPref(const char* path,
78 PrefSyncStatus sync_status) { 96 uint32 flags) {
79 RegisterSyncablePreference(path, new base::DictionaryValue(), sync_status); 97 RegisterSyncablePreference(path, new base::DictionaryValue(), flags);
80 } 98 }
81 99
82 void PrefRegistrySyncable::RegisterDictionaryPref( 100 void PrefRegistrySyncable::RegisterDictionaryPref(
83 const char* path, 101 const char* path,
84 base::DictionaryValue* default_value, 102 base::DictionaryValue* default_value,
85 PrefSyncStatus sync_status) { 103 uint32 flags) {
86 RegisterSyncablePreference(path, default_value, sync_status); 104 RegisterSyncablePreference(path, default_value, flags);
87 } 105 }
88 106
89 void PrefRegistrySyncable::RegisterInt64Pref( 107 void PrefRegistrySyncable::RegisterInt64Pref(
90 const char* path, 108 const char* path,
91 int64 default_value, 109 int64 default_value,
92 PrefSyncStatus sync_status) { 110 uint32 flags) {
93 RegisterSyncablePreference( 111 RegisterSyncablePreference(
94 path, 112 path,
95 new base::StringValue(base::Int64ToString(default_value)), 113 new base::StringValue(base::Int64ToString(default_value)),
96 sync_status); 114 flags);
97 } 115 }
98 116
99 void PrefRegistrySyncable::RegisterUint64Pref( 117 void PrefRegistrySyncable::RegisterUint64Pref(
100 const char* path, 118 const char* path,
101 uint64 default_value, 119 uint64 default_value,
102 PrefSyncStatus sync_status) { 120 uint32 flags) {
103 RegisterSyncablePreference( 121 RegisterSyncablePreference(
104 path, 122 path,
105 new base::StringValue(base::Uint64ToString(default_value)), 123 new base::StringValue(base::Uint64ToString(default_value)),
106 sync_status); 124 flags);
107 } 125 }
108 126
109 void PrefRegistrySyncable::RegisterSyncablePreference( 127 void PrefRegistrySyncable::RegisterSyncablePreference(
110 const char* path, 128 const char* path,
111 base::Value* default_value, 129 base::Value* default_value,
112 PrefSyncStatus sync_status) { 130 uint32 flags) {
113 PrefRegistry::RegisterPreference(path, default_value); 131 DCHECK(HasSyncFlag(flags));
132 PrefRegistry::RegisterPreference(path, default_value, flags);
114 133
115 if (sync_status == PrefRegistrySyncable::SYNCABLE_PREF || 134 if (flags & PrefRegistrySyncable::SYNCABLE_PREF ||
116 sync_status == PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) { 135 flags & PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) {
117 syncable_preferences_[path] = sync_status;
118
119 if (!callback_.is_null()) 136 if (!callback_.is_null())
120 callback_.Run(path, sync_status); 137 callback_.Run(path, flags);
121 } 138 }
122 } 139 }
123 140
124 scoped_refptr<PrefRegistrySyncable> PrefRegistrySyncable::ForkForIncognito() { 141 scoped_refptr<PrefRegistrySyncable> PrefRegistrySyncable::ForkForIncognito() {
125 // TODO(joi): We can directly reuse the same PrefRegistry once 142 // TODO(joi): We can directly reuse the same PrefRegistry once
126 // PrefService no longer registers for callbacks on registration and 143 // PrefService no longer registers for callbacks on registration and
127 // unregistration. 144 // unregistration.
128 scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable()); 145 scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable());
129 registry->defaults_ = defaults_; 146 registry->defaults_ = defaults_;
130 return registry; 147 return registry;
131 } 148 }
132 149
133 } // namespace user_prefs 150 } // namespace user_prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698