| 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_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 | 11 |
| 12 namespace base { | 12 namespace base { |
| 13 class Value; | 13 class Value; |
| 14 } | 14 } |
| 15 | 15 |
| 16 namespace chromeos { | 16 namespace chromeos { |
| 17 | 17 |
| 18 class CrosSettingsProvider { | 18 class CrosSettingsProvider { |
| 19 public: | 19 public: |
| 20 // The callback type that is called to notify the CrosSettings observers |
| 21 // about a setting change. |
| 22 typedef base::Callback<void(const std::string&)> NotifyObserversCallback; |
| 23 |
| 24 // Creates a new provider instance. |notify_cb| will be used to notify |
| 25 // about setting changes. |
| 26 explicit CrosSettingsProvider(const NotifyObserversCallback& notify_cb); |
| 20 virtual ~CrosSettingsProvider() {} | 27 virtual ~CrosSettingsProvider() {} |
| 21 | 28 |
| 22 // Sets |in_value| to given |path| in cros settings. | 29 // Sets |in_value| to given |path| in cros settings. |
| 23 void Set(const std::string& path, const base::Value& in_value); | 30 void Set(const std::string& path, const base::Value& in_value); |
| 24 | 31 |
| 25 // Gets settings value of given |path| to |out_value|. | 32 // Gets settings value of given |path| to |out_value|. |
| 26 virtual const base::Value* Get(const std::string& path) const = 0; | 33 virtual const base::Value* Get(const std::string& path) const = 0; |
| 27 | 34 |
| 28 // Starts a fetch from the trusted store for the value of |path| if not loaded | 35 // Starts a fetch from the trusted store for the value of |path| if not loaded |
| 29 // yet. It will call the |callback| function upon completion if a new fetch | 36 // yet. It will call the |callback| function upon completion if a new fetch |
| 30 // was needed in which case the return value is false. Else it will return | 37 // was needed in which case the return value is false. Else it will return |
| 31 // true and won't call the |callback|. | 38 // true and won't call the |callback|. |
| 32 virtual bool GetTrusted(const std::string& path, | 39 virtual bool GetTrusted(const std::string& path, |
| 33 const base::Closure& callback) = 0; | 40 const base::Closure& callback) = 0; |
| 34 | 41 |
| 35 // Gets the namespace prefix provided by this provider. | 42 // Gets the namespace prefix provided by this provider. |
| 36 virtual bool HandlesSetting(const std::string& path) const = 0; | 43 virtual bool HandlesSetting(const std::string& path) const = 0; |
| 37 | 44 |
| 38 // Reloads the caches if the provider has any. | 45 // Reloads the caches if the provider has any. |
| 39 virtual void Reload() = 0; | 46 virtual void Reload() = 0; |
| 40 | 47 |
| 48 protected: |
| 49 // Notifies the observers about a setting change. |
| 50 void NotifyObservers(const std::string& path); |
| 51 |
| 41 private: | 52 private: |
| 42 // Does the real job for Set(). | 53 // Does the real job for Set(). |
| 43 virtual void DoSet(const std::string& path, | 54 virtual void DoSet(const std::string& path, |
| 44 const base::Value& in_value) = 0; | 55 const base::Value& in_value) = 0; |
| 56 |
| 57 // Callback used to notify about setting changes. |
| 58 NotifyObserversCallback notify_cb_; |
| 45 }; | 59 }; |
| 46 | 60 |
| 47 } // namespace chromeos | 61 } // namespace chromeos |
| 48 | 62 |
| 49 #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_H_ | 63 #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_H_ |
| OLD | NEW |