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

Side by Side Diff: chrome/browser/chromeos/cros_settings.cc

Issue 8727037: Signed settings refactoring: Proper caching and more tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to ToT and removed some debug output left. Created 9 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 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/browser/chromeos/cros_settings.h" 5 #include "chrome/browser/chromeos/cros_settings.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 11 #include "chrome/browser/chromeos/device_settings_provider.h"
12 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h" 12 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h"
13 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
14 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
16 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
17 17
18 namespace chromeos { 18 namespace chromeos {
19 19
20 static base::LazyInstance<CrosSettings> g_cros_settings = 20 static base::LazyInstance<CrosSettings> g_cros_settings =
21 LAZY_INSTANCE_INITIALIZER; 21 LAZY_INSTANCE_INITIALIZER;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 void CrosSettings::SetString(const std::string& path, 76 void CrosSettings::SetString(const std::string& path,
77 const std::string& in_value) { 77 const std::string& in_value) {
78 DCHECK(CalledOnValidThread()); 78 DCHECK(CalledOnValidThread());
79 base::StringValue value(in_value); 79 base::StringValue value(in_value);
80 Set(path, value); 80 Set(path, value);
81 } 81 }
82 82
83 void CrosSettings::AppendToList(const std::string& path, 83 void CrosSettings::AppendToList(const std::string& path,
84 const base::Value* value) { 84 const base::Value* value) {
85 DCHECK(CalledOnValidThread()); 85 DCHECK(CalledOnValidThread());
86 const base::Value* old_value = GetPref(path); 86 base::Value* old_value = GetPref(path);
87 scoped_ptr<base::Value> new_value( 87 scoped_ptr<base::Value> new_value(
88 old_value ? old_value->DeepCopy() : new base::ListValue()); 88 old_value ? old_value : new base::ListValue());
89 static_cast<base::ListValue*>(new_value.get())->Append(value->DeepCopy()); 89 static_cast<base::ListValue*>(new_value.get())->Append(value->DeepCopy());
90 Set(path, *new_value); 90 Set(path, *new_value);
91 } 91 }
92 92
93 void CrosSettings::RemoveFromList(const std::string& path, 93 void CrosSettings::RemoveFromList(const std::string& path,
94 const base::Value* value) { 94 const base::Value* value) {
95 DCHECK(CalledOnValidThread()); 95 DCHECK(CalledOnValidThread());
96 const base::Value* old_value = GetPref(path); 96 base::Value* old_value = GetPref(path);
97 scoped_ptr<base::Value> new_value( 97 scoped_ptr<base::Value> new_value(
98 old_value ? old_value->DeepCopy() : new base::ListValue()); 98 old_value ? old_value : new base::ListValue());
99 static_cast<base::ListValue*>(new_value.get())->Remove(*value, NULL); 99 static_cast<base::ListValue*>(new_value.get())->Remove(*value, NULL);
100 Set(path, *new_value); 100 Set(path, *new_value);
101 } 101 }
102 102
103 bool CrosSettings::FindEmailInList(const std::string& path, 103 bool CrosSettings::FindEmailInList(const std::string& path,
104 const std::string& email) const { 104 const std::string& email) const {
105 DCHECK(CalledOnValidThread()); 105 DCHECK(CalledOnValidThread());
106 base::StringValue email_value(email); 106 base::StringValue email_value(email);
107 const base::ListValue* value = 107 scoped_ptr<base::ListValue> value(
108 static_cast<const base::ListValue*>(GetPref(path)); 108 static_cast<base::ListValue*>(GetPref(path)));
109 if (value) { 109 if (value.get()) {
110 if (value->Find(email_value) != value->end()) 110 if (value->Find(email_value) != value->end())
111 return true; 111 return true;
112 std::string::size_type at_pos = email.find('@'); 112 std::string::size_type at_pos = email.find('@');
113 if (at_pos != std::string::npos) { 113 if (at_pos != std::string::npos) {
114 base::StringValue wildcarded_value( 114 base::StringValue wildcarded_value(
115 std::string("*").append(email.substr(at_pos))); 115 std::string("*").append(email.substr(at_pos)));
116 return value->Find(wildcarded_value) != value->end(); 116 return value->Find(wildcarded_value) != value->end();
117 } 117 }
118 } 118 }
119 return false; 119 return false;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 CrosSettingsProvider* CrosSettings::GetProvider( 189 CrosSettingsProvider* CrosSettings::GetProvider(
190 const std::string& path) const { 190 const std::string& path) const {
191 for (size_t i = 0; i < providers_.size(); ++i) { 191 for (size_t i = 0; i < providers_.size(); ++i) {
192 if (providers_[i]->HandlesSetting(path)) 192 if (providers_[i]->HandlesSetting(path))
193 return providers_[i]; 193 return providers_[i];
194 } 194 }
195 return NULL; 195 return NULL;
196 } 196 }
197 197
198 const base::Value* CrosSettings::GetPref(const std::string& path) const { 198 void CrosSettings::ReloadProviders() const {
199 for (size_t i = 0; i < providers_.size(); ++i) {
200 providers_[i]->Reload();
201 }
202 }
203
204 base::Value* CrosSettings::GetPref(const std::string& path) const {
199 DCHECK(CalledOnValidThread()); 205 DCHECK(CalledOnValidThread());
200 CrosSettingsProvider* provider = GetProvider(path); 206 CrosSettingsProvider* provider = GetProvider(path);
201 if (provider) 207 if (provider)
202 return provider->Get(path); 208 return provider->Get(path);
203 NOTREACHED() << path << " preference was not found in the signed settings."; 209 NOTREACHED() << path << " preference was not found in the signed settings.";
204 return NULL; 210 return NULL;
205 } 211 }
206 212
207 bool CrosSettings::GetTrusted(const std::string& path, 213 bool CrosSettings::GetTrusted(const std::string& path,
208 const base::Closure& callback) const { 214 const base::Closure& callback) const {
209 DCHECK(CalledOnValidThread()); 215 DCHECK(CalledOnValidThread());
210 CrosSettingsProvider* provider = GetProvider(path); 216 CrosSettingsProvider* provider = GetProvider(path);
211 if (provider) 217 if (provider)
212 return provider->GetTrusted(path, callback); 218 return provider->GetTrusted(path, callback);
213 NOTREACHED() << "CrosSettings::GetTrusted called for unknown pref : " << path; 219 NOTREACHED() << "CrosSettings::GetTrusted called for unknown pref : " << path;
214 return false; 220 return false;
215 } 221 }
216 222
217 bool CrosSettings::GetBoolean(const std::string& path, 223 bool CrosSettings::GetBoolean(const std::string& path,
218 bool* bool_value) const { 224 bool* bool_value) const {
219 DCHECK(CalledOnValidThread()); 225 DCHECK(CalledOnValidThread());
220 const base::Value* value = GetPref(path); 226 scoped_ptr<base::Value> value(GetPref(path));
221 if (value) 227 if (value.get())
222 return value->GetAsBoolean(bool_value); 228 return value->GetAsBoolean(bool_value);
223 return false; 229 return false;
224 } 230 }
225 231
226 bool CrosSettings::GetInteger(const std::string& path, 232 bool CrosSettings::GetInteger(const std::string& path,
227 int* out_value) const { 233 int* out_value) const {
228 DCHECK(CalledOnValidThread()); 234 DCHECK(CalledOnValidThread());
229 const base::Value* value = GetPref(path); 235 scoped_ptr<base::Value> value(GetPref(path));
230 if (value) 236 if (value.get())
231 return value->GetAsInteger(out_value); 237 return value->GetAsInteger(out_value);
232 return false; 238 return false;
233 } 239 }
234 240
235 bool CrosSettings::GetDouble(const std::string& path, 241 bool CrosSettings::GetDouble(const std::string& path,
236 double* out_value) const { 242 double* out_value) const {
237 DCHECK(CalledOnValidThread()); 243 DCHECK(CalledOnValidThread());
238 const base::Value* value = GetPref(path); 244 scoped_ptr<base::Value> value(GetPref(path));
239 if (value) 245 if (value.get())
240 return value->GetAsDouble(out_value); 246 return value->GetAsDouble(out_value);
241 return false; 247 return false;
242 } 248 }
243 249
244 bool CrosSettings::GetString(const std::string& path, 250 bool CrosSettings::GetString(const std::string& path,
245 std::string* out_value) const { 251 std::string* out_value) const {
246 DCHECK(CalledOnValidThread()); 252 DCHECK(CalledOnValidThread());
247 const base::Value* value = GetPref(path); 253 scoped_ptr<base::Value> value(GetPref(path));
248 if (value) 254 if (value.get())
249 return value->GetAsString(out_value); 255 return value->GetAsString(out_value);
250 return false; 256 return false;
251 } 257 }
252 258
253 bool CrosSettings::GetList(const std::string& path, 259 bool CrosSettings::GetList(const std::string& path,
254 const base::ListValue** out_value) const { 260 const base::ListValue** out_value) const {
255 DCHECK(CalledOnValidThread()); 261 DCHECK(CalledOnValidThread());
256 const base::Value* value = GetPref(path); 262 scoped_ptr<base::Value> value(GetPref(path));
257 if (value) 263 if (value.get())
258 return value->GetAsList(out_value); 264 return value->GetAsList(out_value);
259 return false; 265 return false;
260 } 266 }
261 267
262 CrosSettings::CrosSettings() { 268 CrosSettings::CrosSettings() {
263 AddSettingsProvider(new SystemSettingsProvider()); 269 AddSettingsProvider(new SystemSettingsProvider());
264 AddSettingsProvider(new UserCrosSettingsProvider()); 270 AddSettingsProvider(new DeviceSettingsProvider());
265 } 271 }
266 272
267 CrosSettings::~CrosSettings() { 273 CrosSettings::~CrosSettings() {
268 STLDeleteElements(&providers_); 274 STLDeleteElements(&providers_);
269 STLDeleteValues(&settings_observers_); 275 STLDeleteValues(&settings_observers_);
270 } 276 }
271 277
272 } // namespace chromeos 278 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698