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

Unified Diff: chrome/common/json_pref_store.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/common/json_pref_store.cc
diff --git a/chrome/common/json_pref_store.cc b/chrome/common/json_pref_store.cc
index 006ed3343e52ac90131e627898546b2f787fd7ab..8042c95db4cdba5d0b3689779371166a24a1290e 100644
--- a/chrome/common/json_pref_store.cc
+++ b/chrome/common/json_pref_store.cc
@@ -212,6 +212,10 @@ void JsonPrefStore::RemoveValue(const std::string& key) {
ReportValueChanged(key);
}
+void JsonPrefStore::MarkNeedsEmptyValue(const std::string& key) {
+ keys_needs_empty_value_.insert(key);
+}
+
bool JsonPrefStore::ReadOnly() const {
return read_only_;
}
@@ -310,5 +314,29 @@ bool JsonPrefStore::SerializeData(std::string* output) {
JSONStringValueSerializer serializer(output);
serializer.set_pretty_print(true);
scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren());
+
+ // Iterates |keys_needs_empty_value_| and if the key exists in |prefs_|,
+ // ensure its empty ListValue or DictonaryValue is preserved.
+ for (std::set<std::string>::const_iterator
+ it = keys_needs_empty_value_.begin();
+ it != keys_needs_empty_value_.end();
+ ++it) {
+ const std::string& key = *it;
+
+ base::Value* value = NULL;
+ if (!prefs_->Get(key, &value))
+ continue;
+
+ if (value->IsType(base::Value::TYPE_LIST)) {
+ base::ListValue* list = static_cast<base::ListValue*>(value);
+ if (list->empty())
+ copy->Set(key, new base::ListValue);
+ } else if (value->IsType(base::Value::TYPE_DICTIONARY)) {
+ base::DictionaryValue* dict = static_cast<base::DictionaryValue*>(value);
+ if (dict->empty())
+ copy->Set(key, new base::DictionaryValue);
+ }
+ }
+
return serializer.Serialize(*(copy.get()));
}

Powered by Google App Engine
This is Rietveld 408576698