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

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

Powered by Google App Engine
This is Rietveld 408576698