[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ |
| 6 | #define CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 8 | |
| 9 | #include <string> |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 11 | |
[email protected] | 7096f56 | 2010-08-16 21:59:04 | [diff] [blame] | 12 | #include "base/hash_tables.h" |
[email protected] | 7096f56 | 2010-08-16 21:59:04 | [diff] [blame] | 13 | #include "base/observer_list.h" |
| 14 | #include "base/singleton.h" |
[email protected] | c917750 | 2011-01-01 04:48:49 | [diff] [blame^] | 15 | #include "base/threading/non_thread_safe.h" |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 16 | #include "chrome/browser/chromeos/cros_settings_names.h" |
[email protected] | 7096f56 | 2010-08-16 21:59:04 | [diff] [blame] | 17 | #include "chrome/common/notification_observer.h" |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 18 | |
[email protected] | dc8caba | 2010-12-13 16:52:35 | [diff] [blame] | 19 | namespace base { |
| 20 | template <typename T> struct DefaultLazyInstanceTraits; |
| 21 | } |
| 22 | |
[email protected] | c02c853d7 | 2010-08-07 06:23:24 | [diff] [blame] | 23 | class Value; |
| 24 | |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 25 | namespace chromeos { |
| 26 | |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 27 | class CrosSettingsProvider; |
| 28 | |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 29 | // A class manages per-device/global settings. |
[email protected] | c917750 | 2011-01-01 04:48:49 | [diff] [blame^] | 30 | class CrosSettings : public base::NonThreadSafe { |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 31 | public: |
| 32 | // Class factory. |
| 33 | static CrosSettings* Get(); |
| 34 | |
| 35 | // Helper function to test if given path is a value cros settings name. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 36 | static bool IsCrosSettings(const std::string& path); |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 37 | |
| 38 | // Sets |in_value| to given |path| in cros settings. |
| 39 | // Note that this takes ownership of |in_value|. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 40 | void Set(const std::string& path, Value* in_value); |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 41 | |
[email protected] | 7096f56 | 2010-08-16 21:59:04 | [diff] [blame] | 42 | // Fires system setting change notification. |
| 43 | void FireObservers(const char* path); |
| 44 | |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 45 | // Gets settings value of given |path| to |out_value|. |
[email protected] | 5bc6e985 | 2010-09-16 16:36:16 | [diff] [blame] | 46 | // Note that the caller owns |out_value| returned. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 47 | bool Get(const std::string& path, Value** out_value) const; |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 48 | |
| 49 | // Convenience forms of Set(). These methods will replace any existing |
| 50 | // value at that path, even if it has a different type. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 51 | void SetBoolean(const std::string& path, bool in_value); |
| 52 | void SetInteger(const std::string& path, int in_value); |
| 53 | void SetReal(const std::string& path, double in_value); |
| 54 | void SetString(const std::string& path, const std::string& in_value); |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 55 | |
| 56 | // These are convenience forms of Get(). The value will be retrieved |
| 57 | // and the return value will be true if the path is valid and the value at |
| 58 | // the end of the path can be returned in the form specified. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 59 | bool GetBoolean(const std::string& path, bool* out_value) const; |
| 60 | bool GetInteger(const std::string& path, int* out_value) const; |
| 61 | bool GetReal(const std::string& path, double* out_value) const; |
| 62 | bool GetString(const std::string& path, std::string* out_value) const; |
[email protected] | 46ebf064 | 2010-07-24 02:47:40 | [diff] [blame] | 63 | |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 64 | // adding/removing of providers |
[email protected] | 7096f56 | 2010-08-16 21:59:04 | [diff] [blame] | 65 | bool AddSettingsProvider(CrosSettingsProvider* provider); |
| 66 | bool RemoveSettingsProvider(CrosSettingsProvider* provider); |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 67 | |
[email protected] | 7096f56 | 2010-08-16 21:59:04 | [diff] [blame] | 68 | // If the pref at the given path changes, we call the observer's Observe |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 69 | // method with PREF_CHANGED. |
[email protected] | 7096f56 | 2010-08-16 21:59:04 | [diff] [blame] | 70 | void AddSettingsObserver(const char* path, NotificationObserver* obs); |
| 71 | void RemoveSettingsObserver(const char* path, NotificationObserver* obs); |
| 72 | |
| 73 | private: |
| 74 | // List of ChromeOS system settings providers. |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 75 | std::vector<CrosSettingsProvider*> providers_; |
| 76 | |
[email protected] | 7096f56 | 2010-08-16 21:59:04 | [diff] [blame] | 77 | // A map from settings names to a list of observers. Observers get fired in |
| 78 | // the order they are added. |
| 79 | typedef ObserverList<NotificationObserver> NotificationObserverList; |
| 80 | typedef base::hash_map<std::string, NotificationObserverList*> |
| 81 | SettingsObserverMap; |
| 82 | SettingsObserverMap settings_observers_; |
| 83 | |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 84 | CrosSettings(); |
| 85 | ~CrosSettings(); |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 86 | CrosSettingsProvider* GetProvider(const std::string& path) const; |
[email protected] | dc8caba | 2010-12-13 16:52:35 | [diff] [blame] | 87 | friend struct base::DefaultLazyInstanceTraits<CrosSettings>; |
[email protected] | 7096f56 | 2010-08-16 21:59:04 | [diff] [blame] | 88 | |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 89 | DISALLOW_COPY_AND_ASSIGN(CrosSettings); |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | } // namespace chromeos |
| 93 | |
| 94 | #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ |