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

Unified Diff: chrome/browser/prefs/pref_service.cc

Issue 10055003: Keep emtpy List/Dictionary pref value with non-empty default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for comments in #1 Created 8 years, 8 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/overlay_user_pref_store.cc ('k') | chrome/browser/prefs/pref_service_mock_builder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prefs/pref_service.cc
diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc
index cf9f22ed0ca0a25eb861411b84f73eea557b496b..de7f406748f82fbffd323af8b631ca6d1d6b8253 100644
--- a/chrome/browser/prefs/pref_service.cc
+++ b/chrome/browser/prefs/pref_service.cc
@@ -727,6 +727,23 @@ void PrefService::RegisterPreference(const char* path,
DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) <<
"invalid preference type: " << orig_type;
+ // For ListValue and DictionaryValue with non empty default, empty value
+ // for |path| needs to be persisted in |user_pref_store_|. So that
+ // non empty default is not used when user sets an empty ListValue or
+ // DictionaryValue.
+ bool needs_empty_value = false;
+ if (orig_type == base::Value::TYPE_LIST) {
+ const base::ListValue* list = NULL;
+ if (default_value->GetAsList(&list) && !list->empty())
+ needs_empty_value = true;
+ } else if (orig_type == base::Value::TYPE_DICTIONARY) {
+ const base::DictionaryValue* dict = NULL;
+ if (default_value->GetAsDictionary(&dict) && !dict->empty())
+ needs_empty_value = true;
+ }
+ if (needs_empty_value)
+ user_pref_store_->MarkNeedsEmptyValue(path);
+
// Hand off ownership.
default_store_->SetDefaultValue(path, scoped_value.release());
« no previous file with comments | « chrome/browser/prefs/overlay_user_pref_store.cc ('k') | chrome/browser/prefs/pref_service_mock_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698