| OLD | NEW |
| 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/logging.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/login/user_manager.h" |
| 13 #include "chrome/browser/chromeos/settings/device_settings_provider.h" | 14 #include "chrome/browser/chromeos/settings/device_settings_provider.h" |
| 14 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 15 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 15 #include "chrome/browser/chromeos/settings/kiosk_app_local_settings.h" | 16 #include "chrome/browser/chromeos/settings/kiosk_app_local_settings.h" |
| 16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 17 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 17 #include "chrome/browser/chromeos/settings/system_settings_provider.h" | 18 #include "chrome/browser/chromeos/settings/system_settings_provider.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 21 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 22 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
| 23 #include "google_apis/gaia/gaia_auth_util.h" | 24 #include "google_apis/gaia/gaia_auth_util.h" |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 | 27 |
| 27 static base::LazyInstance<CrosSettings> g_cros_settings = | 28 static CrosSettings* g_cros_settings = NULL; |
| 28 LAZY_INSTANCE_INITIALIZER; | |
| 29 | 29 |
| 30 // static |
| 31 void CrosSettings::Initialize() { |
| 32 CHECK(!g_cros_settings); |
| 33 g_cros_settings = new CrosSettings(); |
| 34 } |
| 35 |
| 36 // static |
| 37 bool CrosSettings::IsInitialized() { |
| 38 return g_cros_settings; |
| 39 } |
| 40 |
| 41 // static |
| 42 void CrosSettings::Shutdown() { |
| 43 CHECK(g_cros_settings); |
| 44 delete g_cros_settings; |
| 45 g_cros_settings = NULL; |
| 46 } |
| 47 |
| 48 // static |
| 30 CrosSettings* CrosSettings::Get() { | 49 CrosSettings* CrosSettings::Get() { |
| 31 // TODO(xiyaun): Use real stuff when underlying libcros is ready. | 50 CHECK(g_cros_settings); |
| 32 return g_cros_settings.Pointer(); | 51 return g_cros_settings; |
| 33 } | 52 } |
| 34 | 53 |
| 35 bool CrosSettings::IsCrosSettings(const std::string& path) { | 54 bool CrosSettings::IsCrosSettings(const std::string& path) { |
| 36 return StartsWithASCII(path, kCrosSettingsPrefix, true); | 55 return StartsWithASCII(path, kCrosSettingsPrefix, true); |
| 37 } | 56 } |
| 38 | 57 |
| 39 void CrosSettings::Set(const std::string& path, const base::Value& in_value) { | 58 void CrosSettings::Set(const std::string& path, const base::Value& in_value) { |
| 40 DCHECK(CalledOnValidThread()); | 59 DCHECK(CalledOnValidThread()); |
| 41 CrosSettingsProvider* provider; | 60 CrosSettingsProvider* provider; |
| 42 provider = GetProvider(path); | 61 provider = GetProvider(path); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 322 |
| 304 NotificationObserverList::Iterator it(*(observer_iterator->second)); | 323 NotificationObserverList::Iterator it(*(observer_iterator->second)); |
| 305 content::NotificationObserver* observer; | 324 content::NotificationObserver* observer; |
| 306 while ((observer = it.GetNext()) != NULL) { | 325 while ((observer = it.GetNext()) != NULL) { |
| 307 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, | 326 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, |
| 308 content::Source<CrosSettings>(this), | 327 content::Source<CrosSettings>(this), |
| 309 content::Details<const std::string>(&path)); | 328 content::Details<const std::string>(&path)); |
| 310 } | 329 } |
| 311 } | 330 } |
| 312 | 331 |
| 332 ScopedTestCrosSettings::ScopedTestCrosSettings() |
| 333 : initialized_device_settings_service_(false) { |
| 334 if (!DeviceSettingsService::IsInitialized()) { |
| 335 DeviceSettingsService::Initialize(); |
| 336 initialized_device_settings_service_ = true; |
| 337 } |
| 338 CrosSettings::Initialize(); |
| 339 } |
| 340 |
| 341 ScopedTestCrosSettings::~ScopedTestCrosSettings() { |
| 342 // UserManager holds a CrosSettings*, so ensure that it is destroyed. |
| 343 UserManager::Set(NULL); |
| 344 CrosSettings::Shutdown(); |
| 345 if (initialized_device_settings_service_) |
| 346 DeviceSettingsService::Shutdown(); |
| 347 } |
| 348 |
| 313 } // namespace chromeos | 349 } // namespace chromeos |
| OLD | NEW |