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

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: 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
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..500ec96938efd2eb710be8dee21510a47c7dd2c6 100644
--- a/chrome/browser/prefs/pref_service.cc
+++ b/chrome/browser/prefs/pref_service.cc
@@ -727,6 +727,22 @@ 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) {
+ base::ListValue * list = static_cast<base::ListValue*>(default_value);
battre 2012/04/11 21:55:51 nit: base::ListValue*
battre 2012/04/11 21:55:51 instead of the static_cast, I would recommend to u
xiyuan 2012/04/11 22:36:46 Done.
xiyuan 2012/04/11 22:36:46 Done.
+ needs_empty_value = !list->empty();
+ } else if (orig_type == base::Value::TYPE_DICTIONARY) {
+ base::DictionaryValue* dict =
+ static_cast<base::DictionaryValue*>(default_value);
+ needs_empty_value = !dict->empty();
+ }
+ if (needs_empty_value)
+ user_pref_store_->MarkNeedsEmptyValue(path);
+
// Hand off ownership.
default_store_->SetDefaultValue(path, scoped_value.release());

Powered by Google App Engine
This is Rietveld 408576698