Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_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/cros_settings_names.h" | 15 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 16 #include "chrome/browser/chromeos/cros_settings_provider.h" | 16 #include "chrome/browser/chromeos/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; | 20 template <typename T> struct DefaultLazyInstanceTraits; |
| 21 class ListValue; | 21 class ListValue; |
| 22 class Value; | 22 class Value; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace chromeos { | 25 namespace chromeos { |
| 26 | 26 |
| 27 // This class manages per-device/global settings. | 27 // This class manages per-device/global settings. |
| 28 class CrosSettings : public base::NonThreadSafe { | 28 class CrosSettings : public base::NonThreadSafe { |
| 29 public: | 29 public: |
| 30 // Public for testing. | |
|
pastarmovj
2012/07/30 13:55:02
This looks dangerous to me. It gets too easy to in
Mattias Nissler (ping if slow)
2012/08/02 12:01:52
Done.
| |
| 31 CrosSettings(); | |
| 32 ~CrosSettings(); | |
| 33 | |
| 30 // Class factory. | 34 // Class factory. |
| 31 static CrosSettings* Get(); | 35 static CrosSettings* Get(); |
| 32 | 36 |
| 33 // Helper function to test if the given |path| is a valid cros setting. | 37 // Helper function to test if the given |path| is a valid cros setting. |
| 34 static bool IsCrosSettings(const std::string& path); | 38 static bool IsCrosSettings(const std::string& path); |
| 35 | 39 |
| 36 // Sets |in_value| to given |path| in cros settings. | 40 // Sets |in_value| to given |path| in cros settings. |
| 37 void Set(const std::string& path, const base::Value& in_value); | 41 void Set(const std::string& path, const base::Value& in_value); |
| 38 | 42 |
| 39 // Returns setting value for the given |path|. | 43 // Returns setting value for the given |path|. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 // If the pref at the given |path| changes, we call the observer's Observe | 88 // If the pref at the given |path| changes, we call the observer's Observe |
| 85 // method with NOTIFICATION_SYSTEM_SETTING_CHANGED. | 89 // method with NOTIFICATION_SYSTEM_SETTING_CHANGED. |
| 86 void AddSettingsObserver(const char* path, | 90 void AddSettingsObserver(const char* path, |
| 87 content::NotificationObserver* obs); | 91 content::NotificationObserver* obs); |
| 88 void RemoveSettingsObserver(const char* path, | 92 void RemoveSettingsObserver(const char* path, |
| 89 content::NotificationObserver* obs); | 93 content::NotificationObserver* obs); |
| 90 | 94 |
| 91 // Returns the provider that handles settings with the |path| or prefix. | 95 // Returns the provider that handles settings with the |path| or prefix. |
| 92 CrosSettingsProvider* GetProvider(const std::string& path) const; | 96 CrosSettingsProvider* GetProvider(const std::string& path) const; |
| 93 | 97 |
| 94 // Forces all providers to reload their caches from the respective backing | |
| 95 // stores if they have any. | |
| 96 void ReloadProviders(); | |
| 97 | |
| 98 private: | 98 private: |
| 99 friend struct base::DefaultLazyInstanceTraits<CrosSettings>; | |
| 100 | |
| 101 // List of ChromeOS system settings providers. | 99 // List of ChromeOS system settings providers. |
| 102 std::vector<CrosSettingsProvider*> providers_; | 100 std::vector<CrosSettingsProvider*> providers_; |
| 103 | 101 |
| 104 // A map from settings names to a list of observers. Observers get fired in | 102 // A map from settings names to a list of observers. Observers get fired in |
| 105 // the order they are added. | 103 // the order they are added. |
| 106 typedef ObserverList<content::NotificationObserver, true> | 104 typedef ObserverList<content::NotificationObserver, true> |
| 107 NotificationObserverList; | 105 NotificationObserverList; |
| 108 typedef base::hash_map<std::string, NotificationObserverList*> | 106 typedef base::hash_map<std::string, NotificationObserverList*> |
| 109 SettingsObserverMap; | 107 SettingsObserverMap; |
| 110 SettingsObserverMap settings_observers_; | 108 SettingsObserverMap settings_observers_; |
| 111 | 109 |
| 112 CrosSettings(); | |
| 113 ~CrosSettings(); | |
| 114 | |
| 115 // Fires system setting change notification. | 110 // Fires system setting change notification. |
| 116 void FireObservers(const std::string& path); | 111 void FireObservers(const std::string& path); |
| 117 | 112 |
| 118 DISALLOW_COPY_AND_ASSIGN(CrosSettings); | 113 DISALLOW_COPY_AND_ASSIGN(CrosSettings); |
| 119 }; | 114 }; |
| 120 | 115 |
| 121 } // namespace chromeos | 116 } // namespace chromeos |
| 122 | 117 |
| 123 #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ | 118 #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ |
| OLD | NEW |