Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 // A class manages per-device/global settings. | 28 // A class manages per-device/global settings. |
| 29 class CrosSettings : public base::NonThreadSafe { | 29 class CrosSettings : public base::NonThreadSafe { |
| 30 public: | 30 public: |
| 31 // Class factory. | 31 // Class factory. |
| 32 static CrosSettings* Get(); | 32 static CrosSettings* Get(); |
| 33 | 33 |
| 34 // Helper function to test if given path is a value cros settings name. | 34 // Helper function to test if given path is a value cros settings name. |
| 35 static bool IsCrosSettings(const std::string& path); | 35 static bool IsCrosSettings(const std::string& path); |
| 36 | 36 |
| 37 // Sets |in_value| to given |path| in cros settings. | 37 // Sets |in_value| to given |path| in cros settings. |
| 38 // Note that this takes ownership of |in_value|. | 38 void Set(const std::string& path, const base::Value& in_value); |
| 39 void Set(const std::string& path, base::Value* in_value); | |
| 40 | 39 |
| 41 // Fires system setting change notification. | 40 // Fires system setting change notification. |
| 42 // TODO(pastarmovj): Consider to remove this function from the public | 41 // TODO(pastarmovj): Consider to remove this function from the public |
| 43 // interface. | 42 // interface. |
| 44 void FireObservers(const char* path); | 43 void FireObservers(const char* path); |
| 45 | 44 |
| 46 // Gets settings value of given |path| to |out_value|. | 45 // Gets settings value of given |path| to |out_value|. |
| 47 const base::Value* GetPref(const std::string& path) const; | 46 const base::Value* GetPref(const std::string& path) const; |
| 48 | 47 |
| 49 // Starts a fetch from the trusted store for the value of |path| if not loaded | 48 // Starts a fetch from the trusted store for the value of |path| if not loaded |
| 50 // yet. It will call the |callback| function upon completion if a new fetch | 49 // yet. It will call the |callback| function upon completion if a new fetch |
| 51 // was needed in which case the return value is false. Else it will return | 50 // was needed in which case the return value is false. Else it will return |
| 52 // true and won't call the |callback|. | 51 // true and won't call the |callback|. |
| 53 bool GetTrusted(const std::string& path, | 52 bool GetTrusted(const std::string& path, |
| 54 const base::Closure& callback) const; | 53 const base::Closure& callback) const; |
| 55 | 54 |
| 56 // Convenience forms of Set(). These methods will replace any existing | 55 // Convenience forms of Set(). These methods will replace any existing |
| 57 // value at that path, even if it has a different type. | 56 // value at that path, even if it has a different type. |
| 58 void SetBoolean(const std::string& path, bool in_value); | 57 void SetBoolean(const std::string& path, bool in_value); |
| 59 void SetInteger(const std::string& path, int in_value); | 58 void SetInteger(const std::string& path, int in_value); |
| 60 void SetDouble(const std::string& path, double in_value); | 59 void SetDouble(const std::string& path, double in_value); |
| 61 void SetString(const std::string& path, const std::string& in_value); | 60 void SetString(const std::string& path, const std::string& in_value); |
| 62 | 61 |
| 62 // Convenience functions for manipulating lists. | |
| 63 void AppendToList(const std::string& path, const base::Value* value); | |
| 64 void RemoveFromList(const std::string& path, const base::Value* value); | |
| 65 | |
| 63 // These are convenience forms of Get(). The value will be retrieved | 66 // These are convenience forms of Get(). The value will be retrieved |
| 64 // and the return value will be true if the path is valid and the value at | 67 // and the return value will be true if the path is valid and the value at |
| 65 // the end of the path can be returned in the form specified. | 68 // the end of the path can be returned in the form specified. |
| 66 bool GetBoolean(const std::string& path, bool* out_value) const; | 69 bool GetBoolean(const std::string& path, bool* out_value) const; |
| 67 bool GetInteger(const std::string& path, int* out_value) const; | 70 bool GetInteger(const std::string& path, int* out_value) const; |
| 68 bool GetDouble(const std::string& path, double* out_value) const; | 71 bool GetDouble(const std::string& path, double* out_value) const; |
| 69 bool GetString(const std::string& path, std::string* out_value) const; | 72 bool GetString(const std::string& path, std::string* out_value) const; |
| 70 bool GetList(const std::string& path, | 73 bool GetList(const std::string& path, |
| 71 const base::ListValue** out_value) const; | 74 const base::ListValue** out_value) const; |
|
Mattias Nissler (ping if slow)
2011/10/28 14:44:07
newline before comment
pastarmovj
2011/11/18 13:18:42
Done.
| |
| 75 // Helper function for the whitelist op. Implemented here because we will need | |
| 76 // this in a few places. The functions searches for |email| in the pref |path| | |
| 77 // It will respect whitelists too so foo@bar.baz will match *@bar.baz too. | |
|
Mattias Nissler (ping if slow)
2011/10/28 14:44:07
s/will respect/respects/
too...too?
pastarmovj
2011/11/18 13:18:42
Too...too...the train is coming :)
| |
| 78 bool FindEmailInList(const std::string& path, const std::string& email) const; | |
| 72 | 79 |
| 73 // adding/removing of providers | 80 // adding/removing of providers |
| 74 bool AddSettingsProvider(CrosSettingsProvider* provider); | 81 bool AddSettingsProvider(CrosSettingsProvider* provider); |
| 75 bool RemoveSettingsProvider(CrosSettingsProvider* provider); | 82 bool RemoveSettingsProvider(CrosSettingsProvider* provider); |
| 76 | 83 |
| 77 // If the pref at the given path changes, we call the observer's Observe | 84 // If the pref at the given path changes, we call the observer's Observe |
| 78 // method with PREF_CHANGED. | 85 // method with PREF_CHANGED. |
| 79 void AddSettingsObserver(const char* path, | 86 void AddSettingsObserver(const char* path, |
| 80 content::NotificationObserver* obs); | 87 content::NotificationObserver* obs); |
| 81 void RemoveSettingsObserver(const char* path, | 88 void RemoveSettingsObserver(const char* path, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 98 CrosSettings(); | 105 CrosSettings(); |
| 99 ~CrosSettings(); | 106 ~CrosSettings(); |
| 100 friend struct base::DefaultLazyInstanceTraits<CrosSettings>; | 107 friend struct base::DefaultLazyInstanceTraits<CrosSettings>; |
| 101 | 108 |
| 102 DISALLOW_COPY_AND_ASSIGN(CrosSettings); | 109 DISALLOW_COPY_AND_ASSIGN(CrosSettings); |
| 103 }; | 110 }; |
| 104 | 111 |
| 105 } // namespace chromeos | 112 } // namespace chromeos |
| 106 | 113 |
| 107 #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ | 114 #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ |
| OLD | NEW |