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

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

Issue 10918027: Revert 154457 - Switch from SignedSettings to DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months 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 "chrome/browser/chromeos/settings/cros_settings.h" 5 #include "chrome/browser/chromeos/settings/cros_settings.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/chromeos/settings/device_settings_provider.h" 13 #include "chrome/browser/chromeos/settings/device_settings_provider.h"
14 #include "chrome/browser/chromeos/settings/device_settings_service.h" 14 #include "chrome/browser/chromeos/settings/signed_settings_helper.h"
15 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 15 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
16 #include "chrome/browser/chromeos/settings/system_settings_provider.h" 16 #include "chrome/browser/chromeos/settings/system_settings_provider.h"
17 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/net/gaia/gaia_auth_util.h" 19 #include "chrome/common/net/gaia/gaia_auth_util.h"
20 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
21 #include "content/public/browser/notification_source.h" 21 #include "content/public/browser/notification_source.h"
22 #include "content/public/browser/notification_types.h" 22 #include "content/public/browser/notification_types.h"
23 23
24 namespace chromeos { 24 namespace chromeos {
25 25
26 static base::LazyInstance<CrosSettings> g_cros_settings = 26 static base::LazyInstance<CrosSettings> g_cros_settings =
27 LAZY_INSTANCE_INITIALIZER; 27 LAZY_INSTANCE_INITIALIZER;
28 28
29 CrosSettings* CrosSettings::Get() { 29 CrosSettings* CrosSettings::Get() {
30 // TODO(xiyaun): Use real stuff when underlying libcros is ready. 30 // TODO(xiyaun): Use real stuff when underlying libcros is ready.
31 return g_cros_settings.Pointer(); 31 return g_cros_settings.Pointer();
32 } 32 }
33 33
34 bool CrosSettings::IsCrosSettings(const std::string& path) { 34 bool CrosSettings::IsCrosSettings(const std::string& path) {
35 return StartsWithASCII(path, kCrosSettingsPrefix, true); 35 return StartsWithASCII(path, kCrosSettingsPrefix, true);
36 } 36 }
37 37
38 void CrosSettings::FireObservers(const std::string& path) {
39 DCHECK(CalledOnValidThread());
40 SettingsObserverMap::iterator observer_iterator =
41 settings_observers_.find(path);
42 if (observer_iterator == settings_observers_.end())
43 return;
44
45 NotificationObserverList::Iterator it(*(observer_iterator->second));
46 content::NotificationObserver* observer;
47 while ((observer = it.GetNext()) != NULL) {
48 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
49 content::Source<CrosSettings>(this),
50 content::Details<const std::string>(&path));
51 }
52 }
53
38 void CrosSettings::Set(const std::string& path, const base::Value& in_value) { 54 void CrosSettings::Set(const std::string& path, const base::Value& in_value) {
39 DCHECK(CalledOnValidThread()); 55 DCHECK(CalledOnValidThread());
40 CrosSettingsProvider* provider; 56 CrosSettingsProvider* provider;
41 provider = GetProvider(path); 57 provider = GetProvider(path);
42 if (provider) 58 if (provider)
43 provider->Set(path, in_value); 59 provider->Set(path, in_value);
44 } 60 }
45 61
46 const base::Value* CrosSettings::GetPref(const std::string& path) const {
47 DCHECK(CalledOnValidThread());
48 CrosSettingsProvider* provider = GetProvider(path);
49 if (provider)
50 return provider->Get(path);
51 NOTREACHED() << path << " preference was not found in the signed settings.";
52 return NULL;
53 }
54
55 CrosSettingsProvider::TrustedStatus CrosSettings::PrepareTrustedValues(
56 const base::Closure& callback) const {
57 DCHECK(CalledOnValidThread());
58 for (size_t i = 0; i < providers_.size(); ++i) {
59 CrosSettingsProvider::TrustedStatus status =
60 providers_[i]->PrepareTrustedValues(callback);
61 if (status != CrosSettingsProvider::TRUSTED)
62 return status;
63 }
64 return CrosSettingsProvider::TRUSTED;
65 }
66
67 void CrosSettings::SetBoolean(const std::string& path, bool in_value) { 62 void CrosSettings::SetBoolean(const std::string& path, bool in_value) {
68 DCHECK(CalledOnValidThread()); 63 DCHECK(CalledOnValidThread());
69 base::FundamentalValue value(in_value); 64 base::FundamentalValue value(in_value);
70 Set(path, value); 65 Set(path, value);
71 } 66 }
72 67
73 void CrosSettings::SetInteger(const std::string& path, int in_value) { 68 void CrosSettings::SetInteger(const std::string& path, int in_value) {
74 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
75 base::FundamentalValue value(in_value); 70 base::FundamentalValue value(in_value);
76 Set(path, value); 71 Set(path, value);
(...skipping 25 matching lines...) Expand all
102 void CrosSettings::RemoveFromList(const std::string& path, 97 void CrosSettings::RemoveFromList(const std::string& path,
103 const base::Value* value) { 98 const base::Value* value) {
104 DCHECK(CalledOnValidThread()); 99 DCHECK(CalledOnValidThread());
105 const base::Value* old_value = GetPref(path); 100 const base::Value* old_value = GetPref(path);
106 scoped_ptr<base::Value> new_value( 101 scoped_ptr<base::Value> new_value(
107 old_value ? old_value->DeepCopy() : new base::ListValue()); 102 old_value ? old_value->DeepCopy() : new base::ListValue());
108 static_cast<base::ListValue*>(new_value.get())->Remove(*value, NULL); 103 static_cast<base::ListValue*>(new_value.get())->Remove(*value, NULL);
109 Set(path, *new_value); 104 Set(path, *new_value);
110 } 105 }
111 106
112 bool CrosSettings::GetBoolean(const std::string& path,
113 bool* bool_value) const {
114 DCHECK(CalledOnValidThread());
115 const base::Value* value = GetPref(path);
116 if (value)
117 return value->GetAsBoolean(bool_value);
118 return false;
119 }
120
121 bool CrosSettings::GetInteger(const std::string& path,
122 int* out_value) const {
123 DCHECK(CalledOnValidThread());
124 const base::Value* value = GetPref(path);
125 if (value)
126 return value->GetAsInteger(out_value);
127 return false;
128 }
129
130 bool CrosSettings::GetDouble(const std::string& path,
131 double* out_value) const {
132 DCHECK(CalledOnValidThread());
133 const base::Value* value = GetPref(path);
134 if (value)
135 return value->GetAsDouble(out_value);
136 return false;
137 }
138
139 bool CrosSettings::GetString(const std::string& path,
140 std::string* out_value) const {
141 DCHECK(CalledOnValidThread());
142 const base::Value* value = GetPref(path);
143 if (value)
144 return value->GetAsString(out_value);
145 return false;
146 }
147
148 bool CrosSettings::GetList(const std::string& path,
149 const base::ListValue** out_value) const {
150 DCHECK(CalledOnValidThread());
151 const base::Value* value = GetPref(path);
152 if (value)
153 return value->GetAsList(out_value);
154 return false;
155 }
156
157 bool CrosSettings::FindEmailInList(const std::string& path, 107 bool CrosSettings::FindEmailInList(const std::string& path,
158 const std::string& email) const { 108 const std::string& email) const {
159 DCHECK(CalledOnValidThread()); 109 DCHECK(CalledOnValidThread());
160 std::string canonicalized_email( 110 std::string canonicalized_email(
161 gaia::CanonicalizeEmail(gaia::SanitizeEmail(email))); 111 gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)));
162 std::string wildcard_email; 112 std::string wildcard_email;
163 std::string::size_type at_pos = canonicalized_email.find('@'); 113 std::string::size_type at_pos = canonicalized_email.find('@');
164 if (at_pos != std::string::npos) { 114 if (at_pos != std::string::npos) {
165 wildcard_email = 115 wildcard_email =
166 std::string("*").append(canonicalized_email.substr(at_pos)); 116 std::string("*").append(canonicalized_email.substr(at_pos));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 213
264 CrosSettingsProvider* CrosSettings::GetProvider( 214 CrosSettingsProvider* CrosSettings::GetProvider(
265 const std::string& path) const { 215 const std::string& path) const {
266 for (size_t i = 0; i < providers_.size(); ++i) { 216 for (size_t i = 0; i < providers_.size(); ++i) {
267 if (providers_[i]->HandlesSetting(path)) 217 if (providers_[i]->HandlesSetting(path))
268 return providers_[i]; 218 return providers_[i];
269 } 219 }
270 return NULL; 220 return NULL;
271 } 221 }
272 222
223 void CrosSettings::ReloadProviders() {
224 for (size_t i = 0; i < providers_.size(); ++i)
225 providers_[i]->Reload();
226 }
227
228 const base::Value* CrosSettings::GetPref(const std::string& path) const {
229 DCHECK(CalledOnValidThread());
230 CrosSettingsProvider* provider = GetProvider(path);
231 if (provider)
232 return provider->Get(path);
233 NOTREACHED() << path << " preference was not found in the signed settings.";
234 return NULL;
235 }
236
237 CrosSettingsProvider::TrustedStatus CrosSettings::PrepareTrustedValues(
238 const base::Closure& callback) const {
239 DCHECK(CalledOnValidThread());
240 for (size_t i = 0; i < providers_.size(); ++i) {
241 CrosSettingsProvider::TrustedStatus status =
242 providers_[i]->PrepareTrustedValues(callback);
243 if (status != CrosSettingsProvider::TRUSTED)
244 return status;
245 }
246 return CrosSettingsProvider::TRUSTED;
247 }
248
249 bool CrosSettings::GetBoolean(const std::string& path,
250 bool* bool_value) const {
251 DCHECK(CalledOnValidThread());
252 const base::Value* value = GetPref(path);
253 if (value)
254 return value->GetAsBoolean(bool_value);
255 return false;
256 }
257
258 bool CrosSettings::GetInteger(const std::string& path,
259 int* out_value) const {
260 DCHECK(CalledOnValidThread());
261 const base::Value* value = GetPref(path);
262 if (value)
263 return value->GetAsInteger(out_value);
264 return false;
265 }
266
267 bool CrosSettings::GetDouble(const std::string& path,
268 double* out_value) const {
269 DCHECK(CalledOnValidThread());
270 const base::Value* value = GetPref(path);
271 if (value)
272 return value->GetAsDouble(out_value);
273 return false;
274 }
275
276 bool CrosSettings::GetString(const std::string& path,
277 std::string* out_value) const {
278 DCHECK(CalledOnValidThread());
279 const base::Value* value = GetPref(path);
280 if (value)
281 return value->GetAsString(out_value);
282 return false;
283 }
284
285 bool CrosSettings::GetList(const std::string& path,
286 const base::ListValue** out_value) const {
287 DCHECK(CalledOnValidThread());
288 const base::Value* value = GetPref(path);
289 if (value)
290 return value->GetAsList(out_value);
291 return false;
292 }
293
273 CrosSettings::CrosSettings() { 294 CrosSettings::CrosSettings() {
274 CrosSettingsProvider::NotifyObserversCallback notify_cb( 295 CrosSettingsProvider::NotifyObserversCallback notify_cb(
275 base::Bind(&CrosSettings::FireObservers, 296 base::Bind(&CrosSettings::FireObservers,
276 // This is safe since |this| is never deleted. 297 // This is safe since |this| is never deleted.
277 base::Unretained(this))); 298 base::Unretained(this)));
278 if (CommandLine::ForCurrentProcess()->HasSwitch( 299 if (CommandLine::ForCurrentProcess()->HasSwitch(
279 switches::kStubCrosSettings)) { 300 switches::kStubCrosSettings)) {
280 AddSettingsProvider(new StubCrosSettingsProvider(notify_cb)); 301 AddSettingsProvider(new StubCrosSettingsProvider(notify_cb));
281 } else { 302 } else {
282 AddSettingsProvider( 303 AddSettingsProvider(
283 new DeviceSettingsProvider(notify_cb, DeviceSettingsService::Get())); 304 new DeviceSettingsProvider(notify_cb, SignedSettingsHelper::Get()));
284 } 305 }
285 // System settings are not mocked currently. 306 // System settings are not mocked currently.
286 AddSettingsProvider(new SystemSettingsProvider(notify_cb)); 307 AddSettingsProvider(new SystemSettingsProvider(notify_cb));
287 } 308 }
288 309
289 CrosSettings::~CrosSettings() { 310 CrosSettings::~CrosSettings() {
290 STLDeleteElements(&providers_); 311 STLDeleteElements(&providers_);
291 STLDeleteValues(&settings_observers_); 312 STLDeleteValues(&settings_observers_);
292 } 313 }
293 314
294 void CrosSettings::FireObservers(const std::string& path) {
295 DCHECK(CalledOnValidThread());
296 SettingsObserverMap::iterator observer_iterator =
297 settings_observers_.find(path);
298 if (observer_iterator == settings_observers_.end())
299 return;
300
301 NotificationObserverList::Iterator it(*(observer_iterator->second));
302 content::NotificationObserver* observer;
303 while ((observer = it.GetNext()) != NULL) {
304 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
305 content::Source<CrosSettings>(this),
306 content::Details<const std::string>(&path));
307 }
308 }
309
310 } // namespace chromeos 315 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/settings/cros_settings.h ('k') | chrome/browser/chromeos/settings/cros_settings_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698