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

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: Addressed comments. 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->DeepCopy() : 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 const base::ListValue* value(
108 static_cast<const base::ListValue*>(GetPref(path)); 108 static_cast<const base::ListValue*>(GetPref(path)));
109 if (value) { 109 if (value) {
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 }
(...skipping 69 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 void CrosSettings::ReloadProviders() const {
199 for (size_t i = 0; i < providers_.size(); ++i) {
Denis Lagno 2011/12/01 00:38:12 nit: no curly braces for one-liner loops
pastarmovj 2011/12/01 10:07:17 Done.
200 providers_[i]->Reload();
201 }
202 }
203
198 const base::Value* CrosSettings::GetPref(const std::string& path) const { 204 const 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,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const base::Value* value = GetPref(path);
257 if (value) 263 if (value)
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