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

Side by Side Diff: base/prefs/json_pref_store.cc

Issue 81183005: Remove JsonPrefStore pruning of empty values on write. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove else Created 7 years 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 | « base/prefs/json_pref_store.h ('k') | base/prefs/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 "base/prefs/json_pref_store.h" 5 #include "base/prefs/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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 base::Value* old_value = NULL; 210 base::Value* old_value = NULL;
211 prefs_->Get(key, &old_value); 211 prefs_->Get(key, &old_value);
212 if (!old_value || !value->Equals(old_value)) { 212 if (!old_value || !value->Equals(old_value)) {
213 prefs_->Set(key, new_value.release()); 213 prefs_->Set(key, new_value.release());
214 if (!read_only_) 214 if (!read_only_)
215 writer_.ScheduleWrite(this); 215 writer_.ScheduleWrite(this);
216 } 216 }
217 } 217 }
218 218
219 void JsonPrefStore::RemoveValue(const std::string& key) { 219 void JsonPrefStore::RemoveValue(const std::string& key) {
220 if (prefs_->Remove(key, NULL)) 220 if (prefs_->RemovePath(key, NULL))
221 ReportValueChanged(key); 221 ReportValueChanged(key);
222 } 222 }
223 223
224 void JsonPrefStore::MarkNeedsEmptyValue(const std::string& key) {
225 keys_need_empty_value_.insert(key);
226 }
227
228 bool JsonPrefStore::ReadOnly() const { 224 bool JsonPrefStore::ReadOnly() const {
229 return read_only_; 225 return read_only_;
230 } 226 }
231 227
232 PersistentPrefStore::PrefReadError JsonPrefStore::GetReadError() const { 228 PersistentPrefStore::PrefReadError JsonPrefStore::GetReadError() const {
233 return read_error_; 229 return read_error_;
234 } 230 }
235 231
236 PersistentPrefStore::PrefReadError JsonPrefStore::ReadPrefs() { 232 PersistentPrefStore::PrefReadError JsonPrefStore::ReadPrefs() {
237 if (path_.empty()) { 233 if (path_.empty()) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 FOR_EACH_OBSERVER(PrefStore::Observer, 313 FOR_EACH_OBSERVER(PrefStore::Observer,
318 observers_, 314 observers_,
319 OnInitializationCompleted(true)); 315 OnInitializationCompleted(true));
320 } 316 }
321 317
322 JsonPrefStore::~JsonPrefStore() { 318 JsonPrefStore::~JsonPrefStore() {
323 CommitPendingWrite(); 319 CommitPendingWrite();
324 } 320 }
325 321
326 bool JsonPrefStore::SerializeData(std::string* output) { 322 bool JsonPrefStore::SerializeData(std::string* output) {
327 // TODO(tc): Do we want to prune webkit preferences that match the default
328 // value?
329 JSONStringValueSerializer serializer(output); 323 JSONStringValueSerializer serializer(output);
330 serializer.set_pretty_print(true); 324 serializer.set_pretty_print(true);
331 scoped_ptr<base::DictionaryValue> copy( 325 return serializer.Serialize(*prefs_);
332 prefs_->DeepCopyWithoutEmptyChildren());
333
334 // Iterates |keys_need_empty_value_| and if the key exists in |prefs_|,
335 // ensure its empty ListValue or DictonaryValue is preserved.
336 for (std::set<std::string>::const_iterator
337 it = keys_need_empty_value_.begin();
338 it != keys_need_empty_value_.end();
339 ++it) {
340 const std::string& key = *it;
341
342 base::Value* value = NULL;
343 if (!prefs_->Get(key, &value))
344 continue;
345
346 if (value->IsType(base::Value::TYPE_LIST)) {
347 const base::ListValue* list = NULL;
348 if (value->GetAsList(&list) && list->empty())
349 copy->Set(key, new base::ListValue);
350 } else if (value->IsType(base::Value::TYPE_DICTIONARY)) {
351 const base::DictionaryValue* dict = NULL;
352 if (value->GetAsDictionary(&dict) && dict->empty())
353 copy->Set(key, new base::DictionaryValue);
354 }
355 }
356
357 return serializer.Serialize(*(copy.get()));
358 } 326 }
OLDNEW
« no previous file with comments | « base/prefs/json_pref_store.h ('k') | base/prefs/json_pref_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698