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

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

Issue 14200028: Make CrosSettings and DeviceSettingsService non Lazy instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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"
10 #include "base/stl_util.h" 9 #include "base/stl_util.h"
11 #include "base/string_util.h" 10 #include "base/string_util.h"
12 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/chromeos/login/user_manager.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/device_settings_service.h"
15 #include "chrome/browser/chromeos/settings/kiosk_app_local_settings.h" 15 #include "chrome/browser/chromeos/settings/kiosk_app_local_settings.h"
16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
17 #include "chrome/browser/chromeos/settings/system_settings_provider.h" 17 #include "chrome/browser/chromeos/settings/system_settings_provider.h"
18 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.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 #include "google_apis/gaia/gaia_auth_util.h" 23 #include "google_apis/gaia/gaia_auth_util.h"
24 24
25 namespace chromeos { 25 namespace chromeos {
26 26
27 static base::LazyInstance<CrosSettings> g_cros_settings = 27 static CrosSettings* g_cros_settings = NULL;
28 LAZY_INSTANCE_INITIALIZER;
29 28
29 // static
30 void CrosSettings::Initialize() {
31 CHECK(!g_cros_settings);
bartfab (slow) 2013/04/17 11:14:10 Nit: #include "base/logging.h"
stevenjb 2013/04/17 16:27:12 Done.
32 g_cros_settings = new CrosSettings();
33 }
34
35 // static
36 bool CrosSettings::IsInitialized() {
37 return g_cros_settings != NULL;
bartfab (slow) 2013/04/17 11:14:10 Nit: No need to check against NULL. A simple |retu
stevenjb 2013/04/17 16:27:12 Done.
38 }
39
40 // static
41 void CrosSettings::Shutdown() {
42 CHECK(g_cros_settings);
43 delete g_cros_settings;
44 g_cros_settings = NULL;
45 }
46
47 // static
30 CrosSettings* CrosSettings::Get() { 48 CrosSettings* CrosSettings::Get() {
31 // TODO(xiyaun): Use real stuff when underlying libcros is ready. 49 CHECK(g_cros_settings);
32 return g_cros_settings.Pointer(); 50 return g_cros_settings;
33 } 51 }
34 52
35 bool CrosSettings::IsCrosSettings(const std::string& path) { 53 bool CrosSettings::IsCrosSettings(const std::string& path) {
36 return StartsWithASCII(path, kCrosSettingsPrefix, true); 54 return StartsWithASCII(path, kCrosSettingsPrefix, true);
37 } 55 }
38 56
39 void CrosSettings::Set(const std::string& path, const base::Value& in_value) { 57 void CrosSettings::Set(const std::string& path, const base::Value& in_value) {
40 DCHECK(CalledOnValidThread()); 58 DCHECK(CalledOnValidThread());
41 CrosSettingsProvider* provider; 59 CrosSettingsProvider* provider;
42 provider = GetProvider(path); 60 provider = GetProvider(path);
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 321
304 NotificationObserverList::Iterator it(*(observer_iterator->second)); 322 NotificationObserverList::Iterator it(*(observer_iterator->second));
305 content::NotificationObserver* observer; 323 content::NotificationObserver* observer;
306 while ((observer = it.GetNext()) != NULL) { 324 while ((observer = it.GetNext()) != NULL) {
307 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, 325 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
308 content::Source<CrosSettings>(this), 326 content::Source<CrosSettings>(this),
309 content::Details<const std::string>(&path)); 327 content::Details<const std::string>(&path));
310 } 328 }
311 } 329 }
312 330
331 ScopedTestCrosSettings::ScopedTestCrosSettings()
332 : initialized_device_settings_service_(false) {
333 if (!DeviceSettingsService::IsInitialized()) {
334 DeviceSettingsService::Initialize();
335 initialized_device_settings_service_ = true;
336 }
337 CrosSettings::Initialize();
338 }
339
340 ScopedTestCrosSettings::~ScopedTestCrosSettings() {
341 // UserManager holds a CrosSettings*, so ensure that it is destroyed.
342 UserManager::Set(NULL);
343 CrosSettings::Shutdown();
344 if (initialized_device_settings_service_)
345 DeviceSettingsService::Shutdown();
346 }
347
313 } // namespace chromeos 348 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698