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

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

Issue 14927015: Translate device-local account IDs to user IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix forward declaration. Created 7 years, 7 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/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 10 matching lines...) Expand all
21 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
22 #include "google_apis/gaia/gaia_auth_util.h" 22 #include "google_apis/gaia/gaia_auth_util.h"
23 23
24 namespace chromeos { 24 namespace chromeos {
25 25
26 static CrosSettings* g_cros_settings = NULL; 26 static CrosSettings* g_cros_settings = NULL;
27 27
28 // static 28 // static
29 void CrosSettings::Initialize() { 29 void CrosSettings::Initialize() {
30 CHECK(!g_cros_settings); 30 CHECK(!g_cros_settings);
31 g_cros_settings = new CrosSettings(); 31 g_cros_settings = new CrosSettings(DeviceSettingsService::Get());
32 } 32 }
33 33
34 // static 34 // static
35 bool CrosSettings::IsInitialized() { 35 bool CrosSettings::IsInitialized() {
36 return g_cros_settings; 36 return g_cros_settings;
37 } 37 }
38 38
39 // static 39 // static
40 void CrosSettings::Shutdown() { 40 void CrosSettings::Shutdown() {
41 DCHECK(g_cros_settings); 41 DCHECK(g_cros_settings);
42 delete g_cros_settings; 42 delete g_cros_settings;
43 g_cros_settings = NULL; 43 g_cros_settings = NULL;
44 } 44 }
45 45
46 // static 46 // static
47 CrosSettings* CrosSettings::Get() { 47 CrosSettings* CrosSettings::Get() {
48 CHECK(g_cros_settings); 48 CHECK(g_cros_settings);
49 return g_cros_settings; 49 return g_cros_settings;
50 } 50 }
51 51
52 CrosSettings::CrosSettings(DeviceSettingsService* device_settings_service) {
53 CrosSettingsProvider::NotifyObserversCallback notify_cb(
54 base::Bind(&CrosSettings::FireObservers,
55 // This is safe since |this| is never deleted.
56 base::Unretained(this)));
57 if (CommandLine::ForCurrentProcess()->HasSwitch(
58 switches::kStubCrosSettings)) {
59 AddSettingsProvider(new StubCrosSettingsProvider(notify_cb));
60 } else {
61 AddSettingsProvider(
62 new DeviceSettingsProvider(notify_cb, device_settings_service));
63 }
64 // System settings are not mocked currently.
65 AddSettingsProvider(new SystemSettingsProvider(notify_cb));
66 }
67
68 CrosSettings::~CrosSettings() {
69 STLDeleteElements(&providers_);
70 STLDeleteValues(&settings_observers_);
71 }
72
52 bool CrosSettings::IsCrosSettings(const std::string& path) { 73 bool CrosSettings::IsCrosSettings(const std::string& path) {
53 return StartsWithASCII(path, kCrosSettingsPrefix, true); 74 return StartsWithASCII(path, kCrosSettingsPrefix, true);
54 } 75 }
55 76
56 void CrosSettings::Set(const std::string& path, const base::Value& in_value) { 77 void CrosSettings::Set(const std::string& path, const base::Value& in_value) {
57 DCHECK(CalledOnValidThread()); 78 DCHECK(CalledOnValidThread());
58 CrosSettingsProvider* provider; 79 CrosSettingsProvider* provider;
59 provider = GetProvider(path); 80 provider = GetProvider(path);
60 if (provider) 81 if (provider)
61 provider->Set(path, in_value); 82 provider->Set(path, in_value);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 312
292 CrosSettingsProvider* CrosSettings::GetProvider( 313 CrosSettingsProvider* CrosSettings::GetProvider(
293 const std::string& path) const { 314 const std::string& path) const {
294 for (size_t i = 0; i < providers_.size(); ++i) { 315 for (size_t i = 0; i < providers_.size(); ++i) {
295 if (providers_[i]->HandlesSetting(path)) 316 if (providers_[i]->HandlesSetting(path))
296 return providers_[i]; 317 return providers_[i];
297 } 318 }
298 return NULL; 319 return NULL;
299 } 320 }
300 321
301 CrosSettings::CrosSettings() {
302 CrosSettingsProvider::NotifyObserversCallback notify_cb(
303 base::Bind(&CrosSettings::FireObservers,
304 // This is safe since |this| is never deleted.
305 base::Unretained(this)));
306 if (CommandLine::ForCurrentProcess()->HasSwitch(
307 switches::kStubCrosSettings)) {
308 AddSettingsProvider(new StubCrosSettingsProvider(notify_cb));
309 } else {
310 AddSettingsProvider(
311 new DeviceSettingsProvider(notify_cb, DeviceSettingsService::Get()));
312 }
313 // System settings are not mocked currently.
314 AddSettingsProvider(new SystemSettingsProvider(notify_cb));
315 }
316
317 CrosSettings::~CrosSettings() {
318 STLDeleteElements(&providers_);
319 STLDeleteValues(&settings_observers_);
320 }
321
322 void CrosSettings::FireObservers(const std::string& path) { 322 void CrosSettings::FireObservers(const std::string& path) {
323 DCHECK(CalledOnValidThread()); 323 DCHECK(CalledOnValidThread());
324 SettingsObserverMap::iterator observer_iterator = 324 SettingsObserverMap::iterator observer_iterator =
325 settings_observers_.find(path); 325 settings_observers_.find(path);
326 if (observer_iterator == settings_observers_.end()) 326 if (observer_iterator == settings_observers_.end())
327 return; 327 return;
328 328
329 NotificationObserverList::Iterator it(*(observer_iterator->second)); 329 NotificationObserverList::Iterator it(*(observer_iterator->second));
330 content::NotificationObserver* observer; 330 content::NotificationObserver* observer;
331 while ((observer = it.GetNext()) != NULL) { 331 while ((observer = it.GetNext()) != NULL) {
332 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, 332 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
333 content::Source<CrosSettings>(this), 333 content::Source<CrosSettings>(this),
334 content::Details<const std::string>(&path)); 334 content::Details<const std::string>(&path));
335 } 335 }
336 } 336 }
337 337
338 ScopedTestCrosSettings::ScopedTestCrosSettings() { 338 ScopedTestCrosSettings::ScopedTestCrosSettings() {
339 CrosSettings::Initialize(); 339 CrosSettings::Initialize();
340 } 340 }
341 341
342 ScopedTestCrosSettings::~ScopedTestCrosSettings() { 342 ScopedTestCrosSettings::~ScopedTestCrosSettings() {
343 CrosSettings::Shutdown(); 343 CrosSettings::Shutdown();
344 } 344 }
345 345
346 } // namespace chromeos 346 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/settings/cros_settings.h ('k') | chrome/browser/chromeos/settings/cros_settings_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698