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

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

Issue 11365112: Change PrefStore::ReadResult to a boolean. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 8 years, 1 month 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) 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 : path_(filename), 142 : path_(filename),
143 file_message_loop_proxy_(file_message_loop_proxy), 143 file_message_loop_proxy_(file_message_loop_proxy),
144 prefs_(new DictionaryValue()), 144 prefs_(new DictionaryValue()),
145 read_only_(false), 145 read_only_(false),
146 writer_(filename, file_message_loop_proxy), 146 writer_(filename, file_message_loop_proxy),
147 error_delegate_(NULL), 147 error_delegate_(NULL),
148 initialized_(false), 148 initialized_(false),
149 read_error_(PREF_READ_ERROR_OTHER) { 149 read_error_(PREF_READ_ERROR_OTHER) {
150 } 150 }
151 151
152 PrefStore::ReadResult JsonPrefStore::GetValue(const std::string& key, 152 bool JsonPrefStore::GetValue(const std::string& key,
153 const Value** result) const { 153 const Value** result) const {
154 Value* tmp = NULL; 154 Value* tmp = NULL;
155 if (prefs_->Get(key, &tmp)) { 155 if (!prefs_->Get(key, &tmp))
156 if (result) 156 return false;
157 *result = tmp; 157
158 return READ_OK; 158 if (result)
159 } 159 *result = tmp;
160 return READ_NO_VALUE; 160 return true;
161 } 161 }
162 162
163 void JsonPrefStore::AddObserver(PrefStore::Observer* observer) { 163 void JsonPrefStore::AddObserver(PrefStore::Observer* observer) {
164 observers_.AddObserver(observer); 164 observers_.AddObserver(observer);
165 } 165 }
166 166
167 void JsonPrefStore::RemoveObserver(PrefStore::Observer* observer) { 167 void JsonPrefStore::RemoveObserver(PrefStore::Observer* observer) {
168 observers_.RemoveObserver(observer); 168 observers_.RemoveObserver(observer);
169 } 169 }
170 170
171 size_t JsonPrefStore::NumberOfObservers() const { 171 size_t JsonPrefStore::NumberOfObservers() const {
172 return observers_.size(); 172 return observers_.size();
173 } 173 }
174 174
175 bool JsonPrefStore::IsInitializationComplete() const { 175 bool JsonPrefStore::IsInitializationComplete() const {
176 return initialized_; 176 return initialized_;
177 } 177 }
178 178
179 PrefStore::ReadResult JsonPrefStore::GetMutableValue(const std::string& key, 179 bool JsonPrefStore::GetMutableValue(const std::string& key,
180 Value** result) { 180 Value** result) {
181 return prefs_->Get(key, result) ? READ_OK : READ_NO_VALUE; 181 return prefs_->Get(key, result);
182 } 182 }
183 183
184 void JsonPrefStore::SetValue(const std::string& key, Value* value) { 184 void JsonPrefStore::SetValue(const std::string& key, Value* value) {
185 DCHECK(value); 185 DCHECK(value);
186 scoped_ptr<Value> new_value(value); 186 scoped_ptr<Value> new_value(value);
187 Value* old_value = NULL; 187 Value* old_value = NULL;
188 prefs_->Get(key, &old_value); 188 prefs_->Get(key, &old_value);
189 if (!old_value || !value->Equals(old_value)) { 189 if (!old_value || !value->Equals(old_value)) {
190 prefs_->Set(key, new_value.release()); 190 prefs_->Set(key, new_value.release());
191 ReportValueChanged(key); 191 ReportValueChanged(key);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 copy->Set(key, new base::ListValue); 335 copy->Set(key, new base::ListValue);
336 } else if (value->IsType(base::Value::TYPE_DICTIONARY)) { 336 } else if (value->IsType(base::Value::TYPE_DICTIONARY)) {
337 const base::DictionaryValue* dict = NULL; 337 const base::DictionaryValue* dict = NULL;
338 if (value->GetAsDictionary(&dict) && dict->empty()) 338 if (value->GetAsDictionary(&dict) && dict->empty())
339 copy->Set(key, new base::DictionaryValue); 339 copy->Set(key, new base::DictionaryValue);
340 } 340 }
341 } 341 }
342 342
343 return serializer.Serialize(*(copy.get())); 343 return serializer.Serialize(*(copy.get()));
344 } 344 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698