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

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

Issue 14200028: Make CrosSettings and DeviceSettingsService non Lazy instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix LoginUtilsTest 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 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_ 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/hash_tables.h" 12 #include "base/hash_tables.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/threading/non_thread_safe.h" 14 #include "base/threading/non_thread_safe.h"
15 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 15 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
16 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" 16 #include "chrome/browser/chromeos/settings/cros_settings_provider.h"
17 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
18 18
19 namespace base { 19 namespace base {
20 template <typename T> struct DefaultLazyInstanceTraits;
21 class ListValue; 20 class ListValue;
22 class Value; 21 class Value;
23 } 22 }
24 23
25 namespace chromeos { 24 namespace chromeos {
26 25
27 // This class manages per-device/global settings. 26 // This class manages per-device/global settings.
28 class CrosSettings : public base::NonThreadSafe { 27 class CrosSettings : public base::NonThreadSafe {
29 public: 28 public:
30 // Class factory. 29 // Class factory.
Mattias Nissler (ping if slow) 2013/04/16 16:09:51 This comment is now out of place.
stevenjb 2013/04/16 16:49:43 Done.
30 static void Initialize();
31 static bool IsInitialized();
32 static void Shutdown();
31 static CrosSettings* Get(); 33 static CrosSettings* Get();
32 34
33 // Helper function to test if the given |path| is a valid cros setting. 35 // Helper function to test if the given |path| is a valid cros setting.
34 static bool IsCrosSettings(const std::string& path); 36 static bool IsCrosSettings(const std::string& path);
35 37
36 // Sets |in_value| to given |path| in cros settings. 38 // Sets |in_value| to given |path| in cros settings.
37 void Set(const std::string& path, const base::Value& in_value); 39 void Set(const std::string& path, const base::Value& in_value);
38 40
39 // Returns setting value for the given |path|. 41 // Returns setting value for the given |path|.
40 const base::Value* GetPref(const std::string& path) const; 42 const base::Value* GetPref(const std::string& path) const;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // method with NOTIFICATION_SYSTEM_SETTING_CHANGED. 87 // method with NOTIFICATION_SYSTEM_SETTING_CHANGED.
86 void AddSettingsObserver(const char* path, 88 void AddSettingsObserver(const char* path,
87 content::NotificationObserver* obs); 89 content::NotificationObserver* obs);
88 void RemoveSettingsObserver(const char* path, 90 void RemoveSettingsObserver(const char* path,
89 content::NotificationObserver* obs); 91 content::NotificationObserver* obs);
90 92
91 // Returns the provider that handles settings with the |path| or prefix. 93 // Returns the provider that handles settings with the |path| or prefix.
92 CrosSettingsProvider* GetProvider(const std::string& path) const; 94 CrosSettingsProvider* GetProvider(const std::string& path) const;
93 95
94 private: 96 private:
95 friend struct base::DefaultLazyInstanceTraits<CrosSettings>;
96 friend class CrosSettingsTest; 97 friend class CrosSettingsTest;
97 98
98 // Public for testing.
99 CrosSettings(); 99 CrosSettings();
100 ~CrosSettings(); 100 virtual ~CrosSettings();
Mattias Nissler (ping if slow) 2013/04/16 16:09:51 why? nothing is virtual here.
stevenjb 2013/04/16 16:49:43 PrepareTrustedValues
101 101
102 // Fires system setting change notification. 102 // Fires system setting change notification.
103 void FireObservers(const std::string& path); 103 void FireObservers(const std::string& path);
104 104
105 // List of ChromeOS system settings providers. 105 // List of ChromeOS system settings providers.
106 std::vector<CrosSettingsProvider*> providers_; 106 std::vector<CrosSettingsProvider*> providers_;
107 107
108 // A map from settings names to a list of observers. Observers get fired in 108 // A map from settings names to a list of observers. Observers get fired in
109 // the order they are added. 109 // the order they are added.
110 typedef ObserverList<content::NotificationObserver, true> 110 typedef ObserverList<content::NotificationObserver, true>
111 NotificationObserverList; 111 NotificationObserverList;
112 typedef base::hash_map<std::string, NotificationObserverList*> 112 typedef base::hash_map<std::string, NotificationObserverList*>
113 SettingsObserverMap; 113 SettingsObserverMap;
114 SettingsObserverMap settings_observers_; 114 SettingsObserverMap settings_observers_;
115 115
116 DISALLOW_COPY_AND_ASSIGN(CrosSettings); 116 DISALLOW_COPY_AND_ASSIGN(CrosSettings);
117 }; 117 };
118 118
119 // Helper class for unit tests. Initializes DeviceSettingsService and
120 // CrosSettings for tests that need them.
121 class ScopedTestCrosSettings {
122 public:
123 ScopedTestCrosSettings();
124 ~ScopedTestCrosSettings();
125
126 private:
127 DISALLOW_COPY_AND_ASSIGN(ScopedTestCrosSettings);
128 };
129
119 } // namespace chromeos 130 } // namespace chromeos
120 131
121 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_ 132 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698