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

Side by Side Diff: base/prefs/pref_value_store.cc

Issue 16797003: Make base use the proper Value namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: iwarnings fixed Created 7 years, 6 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
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 "base/prefs/pref_value_store.h" 5 #include "base/prefs/pref_value_store.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/prefs/pref_notifier.h" 8 #include "base/prefs/pref_notifier.h"
9 #include "base/prefs/pref_observer.h" 9 #include "base/prefs/pref_observer.h"
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 managed_prefs, extension_prefs, command_line_prefs, user_prefs, 93 managed_prefs, extension_prefs, command_line_prefs, user_prefs,
94 recommended_prefs, default_prefs, pref_notifier); 94 recommended_prefs, default_prefs, pref_notifier);
95 } 95 }
96 96
97 void PrefValueStore::set_callback(const PrefChangedCallback& callback) { 97 void PrefValueStore::set_callback(const PrefChangedCallback& callback) {
98 pref_changed_callback_ = callback; 98 pref_changed_callback_ = callback;
99 } 99 }
100 100
101 bool PrefValueStore::GetValue(const std::string& name, 101 bool PrefValueStore::GetValue(const std::string& name,
102 base::Value::Type type, 102 base::Value::Type type,
103 const Value** out_value) const { 103 const base::Value** out_value) const {
104 // Check the |PrefStore|s in order of their priority from highest to lowest, 104 // Check the |PrefStore|s in order of their priority from highest to lowest,
105 // looking for the first preference value with the given |name| and |type|. 105 // looking for the first preference value with the given |name| and |type|.
106 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { 106 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
107 if (GetValueFromStoreWithType(name.c_str(), type, 107 if (GetValueFromStoreWithType(name.c_str(), type,
108 static_cast<PrefStoreType>(i), out_value)) 108 static_cast<PrefStoreType>(i), out_value))
109 return true; 109 return true;
110 } 110 }
111 return false; 111 return false;
112 } 112 }
113 113
114 bool PrefValueStore::GetRecommendedValue(const std::string& name, 114 bool PrefValueStore::GetRecommendedValue(const std::string& name,
115 base::Value::Type type, 115 base::Value::Type type,
116 const Value** out_value) const { 116 const base::Value** out_value) const {
117 return GetValueFromStoreWithType(name.c_str(), type, RECOMMENDED_STORE, 117 return GetValueFromStoreWithType(name.c_str(), type, RECOMMENDED_STORE,
118 out_value); 118 out_value);
119 } 119 }
120 120
121 void PrefValueStore::NotifyPrefChanged( 121 void PrefValueStore::NotifyPrefChanged(
122 const char* path, 122 const char* path,
123 PrefValueStore::PrefStoreType new_store) { 123 PrefValueStore::PrefStoreType new_store) {
124 DCHECK(new_store != INVALID_STORE); 124 DCHECK(new_store != INVALID_STORE);
125 // A notification is sent when the pref value in any store changes. If this 125 // A notification is sent when the pref value in any store changes. If this
126 // store is currently being overridden by a higher-priority store, the 126 // store is currently being overridden by a higher-priority store, the
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 void PrefValueStore::UpdateCommandLinePrefStore(PrefStore* command_line_prefs) { 173 void PrefValueStore::UpdateCommandLinePrefStore(PrefStore* command_line_prefs) {
174 InitPrefStore(COMMAND_LINE_STORE, command_line_prefs); 174 InitPrefStore(COMMAND_LINE_STORE, command_line_prefs);
175 } 175 }
176 176
177 bool PrefValueStore::PrefValueInStore( 177 bool PrefValueStore::PrefValueInStore(
178 const char* name, 178 const char* name,
179 PrefValueStore::PrefStoreType store) const { 179 PrefValueStore::PrefStoreType store) const {
180 // Declare a temp Value* and call GetValueFromStore, 180 // Declare a temp Value* and call GetValueFromStore,
181 // ignoring the output value. 181 // ignoring the output value.
182 const Value* tmp_value = NULL; 182 const base::Value* tmp_value = NULL;
183 return GetValueFromStore(name, store, &tmp_value); 183 return GetValueFromStore(name, store, &tmp_value);
184 } 184 }
185 185
186 bool PrefValueStore::PrefValueInStoreRange( 186 bool PrefValueStore::PrefValueInStoreRange(
187 const char* name, 187 const char* name,
188 PrefValueStore::PrefStoreType first_checked_store, 188 PrefValueStore::PrefStoreType first_checked_store,
189 PrefValueStore::PrefStoreType last_checked_store) const { 189 PrefValueStore::PrefStoreType last_checked_store) const {
190 if (first_checked_store > last_checked_store) { 190 if (first_checked_store > last_checked_store) {
191 NOTREACHED(); 191 NOTREACHED();
192 return false; 192 return false;
(...skipping 11 matching lines...) Expand all
204 const char* name) const { 204 const char* name) const {
205 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { 205 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
206 if (PrefValueInStore(name, static_cast<PrefStoreType>(i))) 206 if (PrefValueInStore(name, static_cast<PrefStoreType>(i)))
207 return static_cast<PrefStoreType>(i); 207 return static_cast<PrefStoreType>(i);
208 } 208 }
209 return INVALID_STORE; 209 return INVALID_STORE;
210 } 210 }
211 211
212 bool PrefValueStore::GetValueFromStore(const char* name, 212 bool PrefValueStore::GetValueFromStore(const char* name,
213 PrefValueStore::PrefStoreType store_type, 213 PrefValueStore::PrefStoreType store_type,
214 const Value** out_value) const { 214 const base::Value** out_value) const {
215 // Only return true if we find a value and it is the correct type, so stale 215 // Only return true if we find a value and it is the correct type, so stale
216 // values with the incorrect type will be ignored. 216 // values with the incorrect type will be ignored.
217 const PrefStore* store = GetPrefStore(static_cast<PrefStoreType>(store_type)); 217 const PrefStore* store = GetPrefStore(static_cast<PrefStoreType>(store_type));
218 if (store && store->GetValue(name, out_value)) 218 if (store && store->GetValue(name, out_value))
219 return true; 219 return true;
220 220
221 // No valid value found for the given preference name: set the return value 221 // No valid value found for the given preference name: set the return value
222 // to false. 222 // to false.
223 *out_value = NULL; 223 *out_value = NULL;
224 return false; 224 return false;
225 } 225 }
226 226
227 bool PrefValueStore::GetValueFromStoreWithType(const char* name, 227 bool PrefValueStore::GetValueFromStoreWithType(
228 base::Value::Type type, 228 const char* name,
229 PrefStoreType store, 229 base::Value::Type type,
230 const Value** out_value) const { 230 PrefStoreType store,
231 const base::Value** out_value) const {
231 if (GetValueFromStore(name, store, out_value)) { 232 if (GetValueFromStore(name, store, out_value)) {
232 if ((*out_value)->IsType(type)) 233 if ((*out_value)->IsType(type))
233 return true; 234 return true;
234 235
235 LOG(WARNING) << "Expected type for " << name << " is " << type 236 LOG(WARNING) << "Expected type for " << name << " is " << type
236 << " but got " << (*out_value)->GetType() 237 << " but got " << (*out_value)->GetType()
237 << " in store " << store; 238 << " in store " << store;
238 } 239 }
239 240
240 *out_value = NULL; 241 *out_value = NULL;
(...skipping 26 matching lines...) Expand all
267 if (initialization_failed_) 268 if (initialization_failed_)
268 return; 269 return;
269 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { 270 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
270 scoped_refptr<PrefStore> store = 271 scoped_refptr<PrefStore> store =
271 GetPrefStore(static_cast<PrefStoreType>(i)); 272 GetPrefStore(static_cast<PrefStoreType>(i));
272 if (store.get() && !store->IsInitializationComplete()) 273 if (store.get() && !store->IsInitializationComplete())
273 return; 274 return;
274 } 275 }
275 pref_notifier_->OnInitializationCompleted(true); 276 pref_notifier_->OnInitializationCompleted(true);
276 } 277 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698