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

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: Nits 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
« no previous file with comments | « chrome/browser/prefs/pref_value_store.h ('k') | chrome/browser/prefs/pref_value_store_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..3829748cdb49b5c0e52fb6e0defaee955095dfb2 100644
--- a/chrome/browser/prefs/pref_value_store.cc
+++ b/chrome/browser/prefs/pref_value_store.cc
@@ -100,37 +100,33 @@ PrefValueStore* PrefValueStore::CloneAndSpecialize(
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(), 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(), 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 +235,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);
« no previous file with comments | « chrome/browser/prefs/pref_value_store.h ('k') | chrome/browser/prefs/pref_value_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698