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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prefs/pref_value_store.cc
diff --git a/chrome/browser/prefs/pref_value_store.cc b/chrome/browser/prefs/pref_value_store.cc
index 8d59f4e52505854dff94849f63a080b5796752f3..dd9466728938c08a3bb81fafbd3f848e2475a658 100644
--- a/chrome/browser/prefs/pref_value_store.cc
+++ b/chrome/browser/prefs/pref_value_store.cc
@@ -101,36 +101,37 @@ bool PrefValueStore::GetValue(const std::string& name,
base::Value::Type type,
const Value** out_value) const {
*out_value = NULL;
- // Check the |PrefStore|s in order of their priority from highest to lowest
- // to find the value of the preference described by the given preference name.
+ // Check the |PrefStore|s in order of their priority from highest to lowest,
+ // looking for the first preference value with the given |name| and |type|.
for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
- if (GetValueFromStore(name.c_str(), static_cast<PrefStoreType>(i),
- out_value)) {
- if (!(*out_value)->IsType(type)) {
- LOG(WARNING) << "Expected type for " << name << " is " << type
- << " but got " << (*out_value)->GetType()
- << " in store " << i;
- continue;
- }
+ if (GetValueFromStoreWithType(name.c_str(),
Mattias Nissler (ping if slow) 2012/07/27 13:21:45 nit: In function calls, you may put multiple argum
bartfab (slow) 2012/07/27 13:24:42 Done.
+ type,
+ static_cast<PrefStoreType>(i),
+ out_value))
return true;
- }
}
return false;
}
+bool PrefValueStore::GetRecommendedValue(const std::string& name,
+ base::Value::Type type,
+ const Value** out_value) const {
+ return GetValueFromStoreWithType(name.c_str(),
Mattias Nissler (ping if slow) 2012/07/27 13:21:45 same here.
bartfab (slow) 2012/07/27 13:24:42 Done.
+ type,
+ RECOMMENDED_STORE,
+ out_value);
+}
+
void PrefValueStore::NotifyPrefChanged(
const char* path,
PrefValueStore::PrefStoreType new_store) {
DCHECK(new_store != INVALID_STORE);
-
- // If the pref is controlled by a higher-priority store, its effective value
- // cannot have changed.
- PrefStoreType controller = ControllingPrefStoreForPref(path);
- if (controller == INVALID_STORE || controller >= new_store) {
- pref_notifier_->OnPreferenceChanged(path);
- if (pref_sync_associator_)
- pref_sync_associator_->ProcessPrefChange(path);
- }
+ // A notification is sent when the pref value in any store changes. If this
+ // store is currently being overridden by a higher-priority store, the
+ // effective value of the pref will not have changed.
+ pref_notifier_->OnPreferenceChanged(path);
+ if (pref_sync_associator_)
+ pref_sync_associator_->ProcessPrefChange(path);
}
bool PrefValueStore::PrefValueInManagedStore(const char* name) const {
@@ -239,6 +240,23 @@ bool PrefValueStore::GetValueFromStore(const char* name,
return false;
}
+bool PrefValueStore::GetValueFromStoreWithType(const char* name,
+ base::Value::Type type,
+ PrefStoreType store,
+ const Value** out_value) const {
+ if (GetValueFromStore(name, store, out_value)) {
+ if ((*out_value)->IsType(type))
+ return true;
+
+ LOG(WARNING) << "Expected type for " << name << " is " << type
+ << " but got " << (*out_value)->GetType()
+ << " in store " << store;
+ }
+
+ *out_value = NULL;
+ return false;
+}
+
void PrefValueStore::OnPrefValueChanged(PrefValueStore::PrefStoreType type,
const std::string& key) {
NotifyPrefChanged(key.c_str(), type);

Powered by Google App Engine
This is Rietveld 408576698