| 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_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 class DictionaryValue; | 20 class DictionaryValue; |
| 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 class DeviceSettingsService; |
| 28 |
| 27 // This class manages per-device/global settings. | 29 // This class manages per-device/global settings. |
| 28 class CrosSettings : public base::NonThreadSafe { | 30 class CrosSettings : public base::NonThreadSafe { |
| 29 public: | 31 public: |
| 30 // Manage singleton instance. | 32 // Manage singleton instance. |
| 31 static void Initialize(); | 33 static void Initialize(); |
| 32 static bool IsInitialized(); | 34 static bool IsInitialized(); |
| 33 static void Shutdown(); | 35 static void Shutdown(); |
| 34 static CrosSettings* Get(); | 36 static CrosSettings* Get(); |
| 35 | 37 |
| 38 // Creates a device settings service instance. This is meant for unit tests, |
| 39 // production code uses the singleton returned by Get() above. |
| 40 CrosSettings(DeviceSettingsService* device_settings_service); |
| 41 virtual ~CrosSettings(); |
| 42 |
| 36 // Helper function to test if the given |path| is a valid cros setting. | 43 // Helper function to test if the given |path| is a valid cros setting. |
| 37 static bool IsCrosSettings(const std::string& path); | 44 static bool IsCrosSettings(const std::string& path); |
| 38 | 45 |
| 39 // Sets |in_value| to given |path| in cros settings. | 46 // Sets |in_value| to given |path| in cros settings. |
| 40 void Set(const std::string& path, const base::Value& in_value); | 47 void Set(const std::string& path, const base::Value& in_value); |
| 41 | 48 |
| 42 // Returns setting value for the given |path|. | 49 // Returns setting value for the given |path|. |
| 43 const base::Value* GetPref(const std::string& path) const; | 50 const base::Value* GetPref(const std::string& path) const; |
| 44 | 51 |
| 45 // Requests all providers to fetch their values from a trusted store, if they | 52 // Requests all providers to fetch their values from a trusted store, if they |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 content::NotificationObserver* obs); | 99 content::NotificationObserver* obs); |
| 93 void RemoveSettingsObserver(const char* path, | 100 void RemoveSettingsObserver(const char* path, |
| 94 content::NotificationObserver* obs); | 101 content::NotificationObserver* obs); |
| 95 | 102 |
| 96 // Returns the provider that handles settings with the |path| or prefix. | 103 // Returns the provider that handles settings with the |path| or prefix. |
| 97 CrosSettingsProvider* GetProvider(const std::string& path) const; | 104 CrosSettingsProvider* GetProvider(const std::string& path) const; |
| 98 | 105 |
| 99 private: | 106 private: |
| 100 friend class CrosSettingsTest; | 107 friend class CrosSettingsTest; |
| 101 | 108 |
| 102 CrosSettings(); | |
| 103 virtual ~CrosSettings(); | |
| 104 | |
| 105 // Fires system setting change notification. | 109 // Fires system setting change notification. |
| 106 void FireObservers(const std::string& path); | 110 void FireObservers(const std::string& path); |
| 107 | 111 |
| 108 // List of ChromeOS system settings providers. | 112 // List of ChromeOS system settings providers. |
| 109 std::vector<CrosSettingsProvider*> providers_; | 113 std::vector<CrosSettingsProvider*> providers_; |
| 110 | 114 |
| 111 // A map from settings names to a list of observers. Observers get fired in | 115 // A map from settings names to a list of observers. Observers get fired in |
| 112 // the order they are added. | 116 // the order they are added. |
| 113 typedef ObserverList<content::NotificationObserver, true> | 117 typedef ObserverList<content::NotificationObserver, true> |
| 114 NotificationObserverList; | 118 NotificationObserverList; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 126 ScopedTestCrosSettings(); | 130 ScopedTestCrosSettings(); |
| 127 ~ScopedTestCrosSettings(); | 131 ~ScopedTestCrosSettings(); |
| 128 | 132 |
| 129 private: | 133 private: |
| 130 DISALLOW_COPY_AND_ASSIGN(ScopedTestCrosSettings); | 134 DISALLOW_COPY_AND_ASSIGN(ScopedTestCrosSettings); |
| 131 }; | 135 }; |
| 132 | 136 |
| 133 } // namespace chromeos | 137 } // namespace chromeos |
| 134 | 138 |
| 135 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_ | 139 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_ |
| OLD | NEW |