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

Side by Side Diff: chrome/browser/prefs/pref_value_store.cc

Issue 10821047: Provide access to recommended pref values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed. Created 8 years, 4 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 "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 "chrome/browser/prefs/pref_model_associator.h" 8 #include "chrome/browser/prefs/pref_model_associator.h"
9 #include "chrome/browser/prefs/pref_notifier.h" 9 #include "chrome/browser/prefs/pref_notifier.h"
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 default_prefs = GetPrefStore(DEFAULT_STORE); 93 default_prefs = GetPrefStore(DEFAULT_STORE);
94 94
95 return new PrefValueStore( 95 return new PrefValueStore(
96 managed_prefs, extension_prefs, command_line_prefs, user_prefs, 96 managed_prefs, extension_prefs, command_line_prefs, user_prefs,
97 recommended_prefs, default_prefs, pref_sync_associator, pref_notifier); 97 recommended_prefs, default_prefs, pref_sync_associator, pref_notifier);
98 } 98 }
99 99
100 bool PrefValueStore::GetValue(const std::string& name, 100 bool PrefValueStore::GetValue(const std::string& name,
101 base::Value::Type type, 101 base::Value::Type type,
102 const Value** out_value) const { 102 const Value** out_value) const {
103 *out_value = NULL; 103 return GetValueInRange(name,
104 // Check the |PrefStore|s in order of their priority from highest to lowest 104 type,
105 // to find the value of the preference described by the given preference name. 105 out_value,
106 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { 106 MANAGED_STORE,
107 if (GetValueFromStore(name.c_str(), static_cast<PrefStoreType>(i), 107 PREF_STORE_TYPE_MAX);
108 out_value)) { 108 }
109 if (!(*out_value)->IsType(type)) { 109
110 LOG(WARNING) << "Expected type for " << name << " is " << type 110 bool PrefValueStore::GetRecommendedValue(const std::string& name,
111 << " but got " << (*out_value)->GetType() 111 base::Value::Type type,
112 << " in store " << i; 112 const Value** out_value) const {
113 continue; 113 return GetValueInRange(name,
114 } 114 type,
115 return true; 115 out_value,
116 } 116 RECOMMENDED_STORE,
117 } 117 RECOMMENDED_STORE);
118 return false;
119 } 118 }
120 119
121 void PrefValueStore::NotifyPrefChanged( 120 void PrefValueStore::NotifyPrefChanged(
122 const char* path, 121 const char* path,
123 PrefValueStore::PrefStoreType new_store) { 122 PrefValueStore::PrefStoreType new_store) {
124 DCHECK(new_store != INVALID_STORE); 123 DCHECK(new_store != INVALID_STORE);
125 124 // A notification is sent when the pref value in any store changes. If this
126 // If the pref is controlled by a higher-priority store, its effective value 125 // store is currently being overridden by a higher-priority store, the
127 // cannot have changed. 126 // effective value of the pref will not have changed.
128 PrefStoreType controller = ControllingPrefStoreForPref(path); 127 pref_notifier_->OnPreferenceChanged(path);
129 if (controller == INVALID_STORE || controller >= new_store) { 128 if (pref_sync_associator_)
130 pref_notifier_->OnPreferenceChanged(path); 129 pref_sync_associator_->ProcessPrefChange(path);
131 if (pref_sync_associator_)
132 pref_sync_associator_->ProcessPrefChange(path);
133 }
134 } 130 }
135 131
136 bool PrefValueStore::PrefValueInManagedStore(const char* name) const { 132 bool PrefValueStore::PrefValueInManagedStore(const char* name) const {
137 return PrefValueInStore(name, MANAGED_STORE); 133 return PrefValueInStore(name, MANAGED_STORE);
138 } 134 }
139 135
140 bool PrefValueStore::PrefValueInExtensionStore(const char* name) const { 136 bool PrefValueStore::PrefValueInExtensionStore(const char* name) const {
141 return PrefValueInStore(name, EXTENSION_STORE); 137 return PrefValueInStore(name, EXTENSION_STORE);
142 } 138 }
143 139
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 case PrefStore::READ_NO_VALUE: 228 case PrefStore::READ_NO_VALUE:
233 break; 229 break;
234 } 230 }
235 } 231 }
236 232
237 // No valid value found for the given preference name: set the return false. 233 // No valid value found for the given preference name: set the return false.
238 *out_value = NULL; 234 *out_value = NULL;
239 return false; 235 return false;
240 } 236 }
241 237
238 bool PrefValueStore::GetValueInRange(
239 const std::string& name,
240 base::Value::Type type,
241 const Value** out_value,
242 PrefValueStore::PrefStoreType first_checked_store,
243 PrefValueStore::PrefStoreType last_checked_store) const {
244 *out_value = NULL;
245 // Check the |PrefStore|s in order of their priority from highest to lowest,
246 // looking for the first preference value with the given |name| and |type|.
247 for (size_t i = first_checked_store;
248 i <= static_cast<size_t>(last_checked_store); ++i) {
Mattias Nissler (ping if slow) 2012/07/27 12:21:58 I'd rather put the loop into GetValue(), and make
bartfab (slow) 2012/07/27 13:12:08 Done.
249 if (GetValueFromStore(name.c_str(), static_cast<PrefStoreType>(i),
250 out_value)) {
251 if (!(*out_value)->IsType(type)) {
252 LOG(WARNING) << "Expected type for " << name << " is " << type
253 << " but got " << (*out_value)->GetType()
254 << " in store " << i;
255 continue;
256 }
257 return true;
258 }
259 }
260 return false;
261 }
262
242 void PrefValueStore::OnPrefValueChanged(PrefValueStore::PrefStoreType type, 263 void PrefValueStore::OnPrefValueChanged(PrefValueStore::PrefStoreType type,
243 const std::string& key) { 264 const std::string& key) {
244 NotifyPrefChanged(key.c_str(), type); 265 NotifyPrefChanged(key.c_str(), type);
245 } 266 }
246 267
247 void PrefValueStore::OnInitializationCompleted( 268 void PrefValueStore::OnInitializationCompleted(
248 PrefValueStore::PrefStoreType type, bool succeeded) { 269 PrefValueStore::PrefStoreType type, bool succeeded) {
249 if (initialization_failed_) 270 if (initialization_failed_)
250 return; 271 return;
251 if (!succeeded) { 272 if (!succeeded) {
(...skipping 13 matching lines...) Expand all
265 if (initialization_failed_) 286 if (initialization_failed_)
266 return; 287 return;
267 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { 288 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
268 scoped_refptr<PrefStore> store = 289 scoped_refptr<PrefStore> store =
269 GetPrefStore(static_cast<PrefStoreType>(i)); 290 GetPrefStore(static_cast<PrefStoreType>(i));
270 if (store && !store->IsInitializationComplete()) 291 if (store && !store->IsInitializationComplete())
271 return; 292 return;
272 } 293 }
273 pref_notifier_->OnInitializationCompleted(true); 294 pref_notifier_->OnInitializationCompleted(true);
274 } 295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698