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/prefs/pref_value_store.h" | 5 #include "chrome/browser/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 "chrome/browser/prefs/pref_model_associator.h" | 9 #include "chrome/browser/prefs/pref_model_associator.h" |
10 | 10 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 207 } |
208 return INVALID_STORE; | 208 return INVALID_STORE; |
209 } | 209 } |
210 | 210 |
211 bool PrefValueStore::GetValueFromStore(const char* name, | 211 bool PrefValueStore::GetValueFromStore(const char* name, |
212 PrefValueStore::PrefStoreType store_type, | 212 PrefValueStore::PrefStoreType store_type, |
213 const Value** out_value) const { | 213 const Value** out_value) const { |
214 // Only return true if we find a value and it is the correct type, so stale | 214 // Only return true if we find a value and it is the correct type, so stale |
215 // values with the incorrect type will be ignored. | 215 // values with the incorrect type will be ignored. |
216 const PrefStore* store = GetPrefStore(static_cast<PrefStoreType>(store_type)); | 216 const PrefStore* store = GetPrefStore(static_cast<PrefStoreType>(store_type)); |
217 if (store) { | 217 if (store && store->GetValue(name, out_value)) |
218 switch (store->GetValue(name, out_value)) { | 218 return true; |
219 case PrefStore::READ_USE_DEFAULT: | |
220 store = GetPrefStore(DEFAULT_STORE); | |
221 if (!store || store->GetValue(name, out_value) != PrefStore::READ_OK) { | |
222 *out_value = NULL; | |
223 return false; | |
224 } | |
225 // Fall through... | |
226 case PrefStore::READ_OK: | |
227 return true; | |
228 case PrefStore::READ_NO_VALUE: | |
229 break; | |
230 } | |
231 } | |
232 | 219 |
233 // No valid value found for the given preference name: set the return false. | 220 // No valid value found for the given preference name: set the return value |
| 221 // to false. |
234 *out_value = NULL; | 222 *out_value = NULL; |
235 return false; | 223 return false; |
236 } | 224 } |
237 | 225 |
238 bool PrefValueStore::GetValueFromStoreWithType(const char* name, | 226 bool PrefValueStore::GetValueFromStoreWithType(const char* name, |
239 base::Value::Type type, | 227 base::Value::Type type, |
240 PrefStoreType store, | 228 PrefStoreType store, |
241 const Value** out_value) const { | 229 const Value** out_value) const { |
242 if (GetValueFromStore(name, store, out_value)) { | 230 if (GetValueFromStore(name, store, out_value)) { |
243 if ((*out_value)->IsType(type)) | 231 if ((*out_value)->IsType(type)) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 if (initialization_failed_) | 266 if (initialization_failed_) |
279 return; | 267 return; |
280 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { | 268 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { |
281 scoped_refptr<PrefStore> store = | 269 scoped_refptr<PrefStore> store = |
282 GetPrefStore(static_cast<PrefStoreType>(i)); | 270 GetPrefStore(static_cast<PrefStoreType>(i)); |
283 if (store && !store->IsInitializationComplete()) | 271 if (store && !store->IsInitializationComplete()) |
284 return; | 272 return; |
285 } | 273 } |
286 pref_notifier_->OnInitializationCompleted(true); | 274 pref_notifier_->OnInitializationCompleted(true); |
287 } | 275 } |
OLD | NEW |