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

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

Issue 10832035: Switch from SignedSettings to DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More test fixing... Created 8 years, 4 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/cros_settings.h" 5 #include "chrome/browser/chromeos/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/device_settings_provider.h" 13 #include "chrome/browser/chromeos/device_settings_provider.h"
14 #include "chrome/browser/chromeos/login/signed_settings_helper.h" 14 #include "chrome/browser/chromeos/login/device_settings_service.h"
15 #include "chrome/browser/chromeos/stub_cros_settings_provider.h" 15 #include "chrome/browser/chromeos/stub_cros_settings_provider.h"
16 #include "chrome/browser/chromeos/system_settings_provider.h" 16 #include "chrome/browser/chromeos/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() {
30 CrosSettingsProvider::NotifyObserversCallback notify_cb(
31 base::Bind(&CrosSettings::FireObservers,
32 // This is safe since |this| is never deleted.
33 base::Unretained(this)));
34 if (CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kStubCrosSettings)) {
36 AddSettingsProvider(new StubCrosSettingsProvider(notify_cb));
37 } else {
38 AddSettingsProvider(
39 new DeviceSettingsProvider(notify_cb, DeviceSettingsService::Get()));
40 }
41 // System settings are not mocked currently.
42 AddSettingsProvider(new SystemSettingsProvider(notify_cb));
43 }
44
45 CrosSettings::~CrosSettings() {
46 STLDeleteElements(&providers_);
47 STLDeleteValues(&settings_observers_);
48 }
49
29 CrosSettings* CrosSettings::Get() { 50 CrosSettings* CrosSettings::Get() {
30 // TODO(xiyaun): Use real stuff when underlying libcros is ready. 51 // TODO(xiyaun): Use real stuff when underlying libcros is ready.
31 return g_cros_settings.Pointer(); 52 return g_cros_settings.Pointer();
32 } 53 }
33 54
34 bool CrosSettings::IsCrosSettings(const std::string& path) { 55 bool CrosSettings::IsCrosSettings(const std::string& path) {
35 return StartsWithASCII(path, kCrosSettingsPrefix, true); 56 return StartsWithASCII(path, kCrosSettingsPrefix, true);
36 } 57 }
37 58
38 void CrosSettings::FireObservers(const std::string& path) { 59 void CrosSettings::FireObservers(const std::string& path) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 234
214 CrosSettingsProvider* CrosSettings::GetProvider( 235 CrosSettingsProvider* CrosSettings::GetProvider(
215 const std::string& path) const { 236 const std::string& path) const {
216 for (size_t i = 0; i < providers_.size(); ++i) { 237 for (size_t i = 0; i < providers_.size(); ++i) {
217 if (providers_[i]->HandlesSetting(path)) 238 if (providers_[i]->HandlesSetting(path))
218 return providers_[i]; 239 return providers_[i];
219 } 240 }
220 return NULL; 241 return NULL;
221 } 242 }
222 243
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 { 244 const base::Value* CrosSettings::GetPref(const std::string& path) const {
229 DCHECK(CalledOnValidThread()); 245 DCHECK(CalledOnValidThread());
230 CrosSettingsProvider* provider = GetProvider(path); 246 CrosSettingsProvider* provider = GetProvider(path);
231 if (provider) 247 if (provider)
232 return provider->Get(path); 248 return provider->Get(path);
233 NOTREACHED() << path << " preference was not found in the signed settings."; 249 NOTREACHED() << path << " preference was not found in the signed settings.";
234 return NULL; 250 return NULL;
235 } 251 }
236 252
237 CrosSettingsProvider::TrustedStatus CrosSettings::PrepareTrustedValues( 253 CrosSettingsProvider::TrustedStatus CrosSettings::PrepareTrustedValues(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 300
285 bool CrosSettings::GetList(const std::string& path, 301 bool CrosSettings::GetList(const std::string& path,
286 const base::ListValue** out_value) const { 302 const base::ListValue** out_value) const {
287 DCHECK(CalledOnValidThread()); 303 DCHECK(CalledOnValidThread());
288 const base::Value* value = GetPref(path); 304 const base::Value* value = GetPref(path);
289 if (value) 305 if (value)
290 return value->GetAsList(out_value); 306 return value->GetAsList(out_value);
291 return false; 307 return false;
292 } 308 }
293 309
294 CrosSettings::CrosSettings() {
295 CrosSettingsProvider::NotifyObserversCallback notify_cb(
296 base::Bind(&CrosSettings::FireObservers,
297 // This is safe since |this| is never deleted.
298 base::Unretained(this)));
299 if (CommandLine::ForCurrentProcess()->HasSwitch(
300 switches::kStubCrosSettings)) {
301 AddSettingsProvider(new StubCrosSettingsProvider(notify_cb));
302 } else {
303 AddSettingsProvider(
304 new DeviceSettingsProvider(notify_cb, SignedSettingsHelper::Get()));
305 }
306 // System settings are not mocked currently.
307 AddSettingsProvider(new SystemSettingsProvider(notify_cb));
308 }
309
310 CrosSettings::~CrosSettings() {
311 STLDeleteElements(&providers_);
312 STLDeleteValues(&settings_observers_);
313 }
314
315 } // namespace chromeos 310 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698