A subtle bug was exposed when the following was added to Preferences::RegisterUserPrefs:
prefs->RegisterIntegerPref(prefs::kLabsTalkEnabled, 0);
Because prefs::kLabsTalkEnabled = "extensions.settings.ggnioahjipcehijkhpdjekioddnjoben.state",
"extensions.settings" in the DEFAULT pref store is forced to a DictionaryValue
instead of an empty value so that data can be stored in it. This invalidaded a
test in PrefService::GetMutableDictionary, causing GetMutableDictionary to
return a pointer to a DictionaryValue in the default pref store instead of
creating a dictionary in the user pref store.
BUG=http://code.google.com/p/chromium-os/issues/detail?id=7066
TEST=See bug; should no longer repro. Also, test preferences in general.
Review URL: http://codereview.chromium.org/3533008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61209 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc
index 0668ed4..d807f5a4 100644
--- a/chrome/browser/prefs/pref_service.cc
+++ b/chrome/browser/prefs/pref_service.cc
@@ -502,7 +502,9 @@
DictionaryValue* dict = NULL;
Value* tmp_value = NULL;
- if (!pref_value_store_->GetValue(path, &tmp_value) ||
+ // Look for an existing preference in the user store. If it doesn't
+ // exist or isn't the correct type, create a new user preference.
+ if (!pref_value_store_->GetUserValue(path, &tmp_value) ||
!tmp_value->IsType(Value::TYPE_DICTIONARY)) {
dict = new DictionaryValue;
pref_value_store_->SetUserPrefValue(path, dict);
@@ -527,7 +529,9 @@
ListValue* list = NULL;
Value* tmp_value = NULL;
- if (!pref_value_store_->GetValue(path, &tmp_value) ||
+ // Look for an existing preference in the user store. If it doesn't
+ // exist or isn't the correct type, create a new user preference.
+ if (!pref_value_store_->GetUserValue(path, &tmp_value) ||
!tmp_value->IsType(Value::TYPE_LIST)) {
list = new ListValue;
pref_value_store_->SetUserPrefValue(path, list);