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

Unified Diff: chrome/common/pref_service.cc

Issue 16270: Change the signature of JSONReader::Read() and related methods to be more (Closed)
Patch Set: fixens Created 12 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/pref_service.cc
diff --git a/chrome/common/pref_service.cc b/chrome/common/pref_service.cc
index 8f3322a00986e0bf5e2952a7f376a6c4de7c71c9..870e79e0b111fb9eaf12b6f7c501e99e3e34bc3b 100644
--- a/chrome/common/pref_service.cc
+++ b/chrome/common/pref_service.cc
@@ -136,38 +136,34 @@ bool PrefService::LoadPersistentPrefs(const std::wstring& file_path) {
DCHECK(CalledOnValidThread());
JSONFileValueSerializer serializer(file_path);
- Value* root = NULL;
- if (serializer.Deserialize(&root, NULL)) {
- // Preferences should always have a dictionary root.
- if (!root->IsType(Value::TYPE_DICTIONARY)) {
- delete root;
- return false;
- }
+ scoped_ptr<Value> root(serializer.Deserialize(NULL));
+ if (!root.get())
+ return false;
- persistent_.reset(static_cast<DictionaryValue*>(root));
- return true;
- }
+ // Preferences should always have a dictionary root.
+ if (!root->IsType(Value::TYPE_DICTIONARY))
+ return false;
- return false;
+ persistent_.reset(static_cast<DictionaryValue*>(root.release()));
+ return true;
}
void PrefService::ReloadPersistentPrefs() {
DCHECK(CalledOnValidThread());
JSONFileValueSerializer serializer(pref_filename_);
- Value* root;
- if (serializer.Deserialize(&root, NULL)) {
- // Preferences should always have a dictionary root.
- if (!root->IsType(Value::TYPE_DICTIONARY)) {
- delete root;
- return;
- }
+ scoped_ptr<Value> root(serializer.Deserialize(NULL));
+ if (!root.get())
+ return;
- persistent_.reset(static_cast<DictionaryValue*>(root));
- for (PreferenceSet::iterator it = prefs_.begin();
- it != prefs_.end(); ++it) {
- (*it)->root_pref_ = persistent_.get();
- }
+ // Preferences should always have a dictionary root.
+ if (!root->IsType(Value::TYPE_DICTIONARY))
+ return;
+
+ persistent_.reset(static_cast<DictionaryValue*>(root.release()));
+ for (PreferenceSet::iterator it = prefs_.begin();
+ it != prefs_.end(); ++it) {
+ (*it)->root_pref_ = persistent_.get();
}
}

Powered by Google App Engine
This is Rietveld 408576698