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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/json_pref_store.h ('k') | chrome/common/json_pref_store_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/json_pref_store.h" 5 #include "chrome/common/json_pref_store.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (!read_only_) 205 if (!read_only_)
206 writer_.ScheduleWrite(this); 206 writer_.ScheduleWrite(this);
207 } 207 }
208 } 208 }
209 209
210 void JsonPrefStore::RemoveValue(const std::string& key) { 210 void JsonPrefStore::RemoveValue(const std::string& key) {
211 if (prefs_->Remove(key, NULL)) 211 if (prefs_->Remove(key, NULL))
212 ReportValueChanged(key); 212 ReportValueChanged(key);
213 } 213 }
214 214
215 void JsonPrefStore::MarkNeedsEmptyValue(const std::string& key) {
216 keys_need_empty_value_.insert(key);
217 }
218
215 bool JsonPrefStore::ReadOnly() const { 219 bool JsonPrefStore::ReadOnly() const {
216 return read_only_; 220 return read_only_;
217 } 221 }
218 222
219 PersistentPrefStore::PrefReadError JsonPrefStore::GetReadError() const { 223 PersistentPrefStore::PrefReadError JsonPrefStore::GetReadError() const {
220 return read_error_; 224 return read_error_;
221 } 225 }
222 226
223 void JsonPrefStore::OnFileRead(Value* value_owned, 227 void JsonPrefStore::OnFileRead(Value* value_owned,
224 PersistentPrefStore::PrefReadError error, 228 PersistentPrefStore::PrefReadError error,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 if (!read_only_) 307 if (!read_only_)
304 writer_.ScheduleWrite(this); 308 writer_.ScheduleWrite(this);
305 } 309 }
306 310
307 bool JsonPrefStore::SerializeData(std::string* output) { 311 bool JsonPrefStore::SerializeData(std::string* output) {
308 // TODO(tc): Do we want to prune webkit preferences that match the default 312 // TODO(tc): Do we want to prune webkit preferences that match the default
309 // value? 313 // value?
310 JSONStringValueSerializer serializer(output); 314 JSONStringValueSerializer serializer(output);
311 serializer.set_pretty_print(true); 315 serializer.set_pretty_print(true);
312 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); 316 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren());
317
318 // Iterates |keys_need_empty_value_| and if the key exists in |prefs_|,
319 // ensure its empty ListValue or DictonaryValue is preserved.
320 for (std::set<std::string>::const_iterator
321 it = keys_need_empty_value_.begin();
322 it != keys_need_empty_value_.end();
323 ++it) {
324 const std::string& key = *it;
325
326 base::Value* value = NULL;
327 if (!prefs_->Get(key, &value))
328 continue;
329
330 if (value->IsType(base::Value::TYPE_LIST)) {
331 const base::ListValue* list = NULL;
332 if (value->GetAsList(&list) && list->empty())
333 copy->Set(key, new base::ListValue);
334 } else if (value->IsType(base::Value::TYPE_DICTIONARY)) {
335 const base::DictionaryValue* dict = NULL;
336 if (value->GetAsDictionary(&dict) && dict->empty())
337 copy->Set(key, new base::DictionaryValue);
338 }
339 }
340
313 return serializer.Serialize(*(copy.get())); 341 return serializer.Serialize(*(copy.get()));
314 } 342 }
OLDNEW
« no previous file with comments | « chrome/common/json_pref_store.h ('k') | chrome/common/json_pref_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698