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

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
« 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 : path_(filename), 155 : path_(filename),
156 sequenced_task_runner_(sequenced_task_runner), 156 sequenced_task_runner_(sequenced_task_runner),
157 prefs_(new DictionaryValue()), 157 prefs_(new DictionaryValue()),
158 read_only_(false), 158 read_only_(false),
159 writer_(filename, sequenced_task_runner), 159 writer_(filename, sequenced_task_runner),
160 error_delegate_(NULL), 160 error_delegate_(NULL),
161 initialized_(false), 161 initialized_(false),
162 read_error_(PREF_READ_ERROR_OTHER) { 162 read_error_(PREF_READ_ERROR_OTHER) {
163 } 163 }
164 164
165 PrefStore::ReadResult JsonPrefStore::GetValue(const std::string& key, 165 bool JsonPrefStore::GetValue(const std::string& key,
166 const Value** result) const { 166 const Value** result) const {
167 Value* tmp = NULL; 167 Value* tmp = NULL;
168 if (prefs_->Get(key, &tmp)) { 168 if (!prefs_->Get(key, &tmp))
169 if (result) 169 return false;
170 *result = tmp; 170
171 return READ_OK; 171 if (result)
172 } 172 *result = tmp;
173 return READ_NO_VALUE; 173 return true;
174 } 174 }
175 175
176 void JsonPrefStore::AddObserver(PrefStore::Observer* observer) { 176 void JsonPrefStore::AddObserver(PrefStore::Observer* observer) {
177 observers_.AddObserver(observer); 177 observers_.AddObserver(observer);
178 } 178 }
179 179
180 void JsonPrefStore::RemoveObserver(PrefStore::Observer* observer) { 180 void JsonPrefStore::RemoveObserver(PrefStore::Observer* observer) {
181 observers_.RemoveObserver(observer); 181 observers_.RemoveObserver(observer);
182 } 182 }
183 183
184 size_t JsonPrefStore::NumberOfObservers() const { 184 size_t JsonPrefStore::NumberOfObservers() const {
185 return observers_.size(); 185 return observers_.size();
186 } 186 }
187 187
188 bool JsonPrefStore::IsInitializationComplete() const { 188 bool JsonPrefStore::IsInitializationComplete() const {
189 return initialized_; 189 return initialized_;
190 } 190 }
191 191
192 PrefStore::ReadResult JsonPrefStore::GetMutableValue(const std::string& key, 192 bool JsonPrefStore::GetMutableValue(const std::string& key,
193 Value** result) { 193 Value** result) {
194 return prefs_->Get(key, result) ? READ_OK : READ_NO_VALUE; 194 return prefs_->Get(key, result);
195 } 195 }
196 196
197 void JsonPrefStore::SetValue(const std::string& key, Value* value) { 197 void JsonPrefStore::SetValue(const std::string& key, Value* value) {
198 DCHECK(value); 198 DCHECK(value);
199 scoped_ptr<Value> new_value(value); 199 scoped_ptr<Value> new_value(value);
200 Value* old_value = NULL; 200 Value* old_value = NULL;
201 prefs_->Get(key, &old_value); 201 prefs_->Get(key, &old_value);
202 if (!old_value || !value->Equals(old_value)) { 202 if (!old_value || !value->Equals(old_value)) {
203 prefs_->Set(key, new_value.release()); 203 prefs_->Set(key, new_value.release());
204 ReportValueChanged(key); 204 ReportValueChanged(key);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 copy->Set(key, new base::ListValue); 348 copy->Set(key, new base::ListValue);
349 } else if (value->IsType(base::Value::TYPE_DICTIONARY)) { 349 } else if (value->IsType(base::Value::TYPE_DICTIONARY)) {
350 const base::DictionaryValue* dict = NULL; 350 const base::DictionaryValue* dict = NULL;
351 if (value->GetAsDictionary(&dict) && dict->empty()) 351 if (value->GetAsDictionary(&dict) && dict->empty())
352 copy->Set(key, new base::DictionaryValue); 352 copy->Set(key, new base::DictionaryValue);
353 } 353 }
354 } 354 }
355 355
356 return serializer.Serialize(*(copy.get())); 356 return serializer.Serialize(*(copy.get()));
357 } 357 }
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