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

Side by Side Diff: chrome/common/json_pref_store.cc

Issue 8198007: Remove PrefService::ScheduleSavePersistentPrefs and SavePersistentPrefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 8 years, 12 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 return PREF_READ_ERROR_FILE_NOT_SPECIFIED; 275 return PREF_READ_ERROR_FILE_NOT_SPECIFIED;
276 } 276 }
277 277
278 PrefReadError error; 278 PrefReadError error;
279 bool no_dir; 279 bool no_dir;
280 Value* value = FileThreadDeserializer::DoReading(path_, &error, &no_dir); 280 Value* value = FileThreadDeserializer::DoReading(path_, &error, &no_dir);
281 OnFileRead(value, error, no_dir); 281 OnFileRead(value, error, no_dir);
282 return error; 282 return error;
283 } 283 }
284 284
285 bool JsonPrefStore::WritePrefs() {
286 std::string data;
287 if (!SerializeData(&data))
288 return false;
289
290 // Don't actually write prefs if we're read-only or don't have any pending
291 // writes.
292 // TODO(bauerb): Make callers of this method call CommitPendingWrite directly.
293 if (writer_.HasPendingWrite() && !read_only_)
294 writer_.WriteNow(data);
295
296 return true;
297 }
298
299 void JsonPrefStore::ScheduleWritePrefs() {
300 // Writing prefs should be scheduled automatically, so this is a no-op
301 // for now.
302 // TODO(bauerb): Remove calls to this method.
303 }
304
305 void JsonPrefStore::CommitPendingWrite() { 285 void JsonPrefStore::CommitPendingWrite() {
306 if (writer_.HasPendingWrite() && !read_only_) 286 if (writer_.HasPendingWrite() && !read_only_)
307 writer_.DoScheduledWrite(); 287 writer_.DoScheduledWrite();
308 } 288 }
309 289
310 void JsonPrefStore::ReportValueChanged(const std::string& key) { 290 void JsonPrefStore::ReportValueChanged(const std::string& key) {
311 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key)); 291 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
312 if (!read_only_) 292 if (!read_only_)
313 writer_.ScheduleWrite(this); 293 writer_.ScheduleWrite(this);
314 } 294 }
315 295
316 bool JsonPrefStore::SerializeData(std::string* output) { 296 bool JsonPrefStore::SerializeData(std::string* output) {
317 // TODO(tc): Do we want to prune webkit preferences that match the default 297 // TODO(tc): Do we want to prune webkit preferences that match the default
318 // value? 298 // value?
319 JSONStringValueSerializer serializer(output); 299 JSONStringValueSerializer serializer(output);
320 serializer.set_pretty_print(true); 300 serializer.set_pretty_print(true);
321 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); 301 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren());
322 return serializer.Serialize(*(copy.get())); 302 return serializer.Serialize(*(copy.get()));
323 } 303 }
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