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

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

Issue 8899002: [cros] Add --stub-cros-settings option for testing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CrosSettingsProvider instances use a callback for notifying observers. 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/bind.h"
8 #include "base/command_line.h"
7 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
8 #include "base/stl_util.h" 10 #include "base/stl_util.h"
9 #include "base/string_util.h" 11 #include "base/string_util.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 #include "chrome/browser/chromeos/device_settings_provider.h" 13 #include "chrome/browser/chromeos/device_settings_provider.h"
14 #include "chrome/browser/chromeos/stub_cros_settings_provider.h"
12 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h" 15 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h"
13 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/chrome_switches.h"
14 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
16 #include "content/public/browser/notification_types.h" 20 #include "content/public/browser/notification_types.h"
17 21
18 namespace chromeos { 22 namespace chromeos {
19 23
20 static base::LazyInstance<CrosSettings> g_cros_settings = 24 static base::LazyInstance<CrosSettings> g_cros_settings =
21 LAZY_INSTANCE_INITIALIZER; 25 LAZY_INSTANCE_INITIALIZER;
22 26
23 CrosSettings* CrosSettings::Get() { 27 CrosSettings* CrosSettings::Get() {
24 // TODO(xiyaun): Use real stuff when underlying libcros is ready. 28 // TODO(xiyaun): Use real stuff when underlying libcros is ready.
25 return g_cros_settings.Pointer(); 29 return g_cros_settings.Pointer();
26 } 30 }
27 31
28 bool CrosSettings::IsCrosSettings(const std::string& path) { 32 bool CrosSettings::IsCrosSettings(const std::string& path) {
29 return StartsWithASCII(path, kCrosSettingsPrefix, true); 33 return StartsWithASCII(path, kCrosSettingsPrefix, true);
30 } 34 }
31 35
32 void CrosSettings::FireObservers(const char* path) { 36 void CrosSettings::FireObservers(const std::string& path) {
33 DCHECK(CalledOnValidThread()); 37 DCHECK(CalledOnValidThread());
34 std::string path_str(path);
35 SettingsObserverMap::iterator observer_iterator = 38 SettingsObserverMap::iterator observer_iterator =
36 settings_observers_.find(path_str); 39 settings_observers_.find(path);
37 if (observer_iterator == settings_observers_.end()) 40 if (observer_iterator == settings_observers_.end())
38 return; 41 return;
39 42
40 NotificationObserverList::Iterator it(*(observer_iterator->second)); 43 NotificationObserverList::Iterator it(*(observer_iterator->second));
41 content::NotificationObserver* observer; 44 content::NotificationObserver* observer;
42 while ((observer = it.GetNext()) != NULL) { 45 while ((observer = it.GetNext()) != NULL) {
43 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, 46 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
44 content::Source<CrosSettings>(this), 47 content::Source<CrosSettings>(this),
45 content::Details<std::string>(&path_str)); 48 content::Details<const std::string>(&path));
46 } 49 }
47 } 50 }
48 51
49 void CrosSettings::Set(const std::string& path, const base::Value& in_value) { 52 void CrosSettings::Set(const std::string& path, const base::Value& in_value) {
50 DCHECK(CalledOnValidThread()); 53 DCHECK(CalledOnValidThread());
51 CrosSettingsProvider* provider; 54 CrosSettingsProvider* provider;
52 provider = GetProvider(path); 55 provider = GetProvider(path);
53 if (provider) 56 if (provider)
54 provider->Set(path, in_value); 57 provider->Set(path, in_value);
55 } 58 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 bool CrosSettings::GetList(const std::string& path, 259 bool CrosSettings::GetList(const std::string& path,
257 const base::ListValue** out_value) const { 260 const base::ListValue** out_value) const {
258 DCHECK(CalledOnValidThread()); 261 DCHECK(CalledOnValidThread());
259 const base::Value* value = GetPref(path); 262 const base::Value* value = GetPref(path);
260 if (value) 263 if (value)
261 return value->GetAsList(out_value); 264 return value->GetAsList(out_value);
262 return false; 265 return false;
263 } 266 }
264 267
265 CrosSettings::CrosSettings() { 268 CrosSettings::CrosSettings() {
266 AddSettingsProvider(new SystemSettingsProvider()); 269 CrosSettingsProvider::NotifyObserversCallback notify_cb(
267 AddSettingsProvider(new DeviceSettingsProvider()); 270 base::Bind(&CrosSettings::FireObservers,
271 // This is safe since |this| is never deleted.
272 base::Unretained(this)));
273 if (CommandLine::ForCurrentProcess()->HasSwitch(
274 switches::kStubCrosSettings)) {
275 AddSettingsProvider(new StubCrosSettingsProvider(notify_cb));
276 }
277 AddSettingsProvider(new SystemSettingsProvider(notify_cb));
pastarmovj 2011/12/13 13:41:07 You might even want to put the real providers in a
Ivan Korotkov 2011/12/13 14:46:16 Done for Device provider (System provider is not m
278 AddSettingsProvider(new DeviceSettingsProvider(notify_cb));
268 } 279 }
269 280
270 CrosSettings::~CrosSettings() { 281 CrosSettings::~CrosSettings() {
271 STLDeleteElements(&providers_); 282 STLDeleteElements(&providers_);
272 STLDeleteValues(&settings_observers_); 283 STLDeleteValues(&settings_observers_);
273 } 284 }
274 285
275 } // namespace chromeos 286 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698