OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 | |
12 namespace base { | |
13 class Value; | |
14 } | |
15 | |
16 namespace chromeos { | |
17 | |
18 class CrosSettingsProvider { | |
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 // Possible results of a trusted check. | |
25 enum TrustedStatus { | |
26 // The trusted values were populated in the cache and can be accessed | |
27 // until the next iteration of the message loop. | |
28 TRUSTED, | |
29 // Either a store or a load operation is in progress. The provided | |
30 // callback will be invoked once the verification has finished. | |
31 TEMPORARILY_UNTRUSTED, | |
32 // The verification of the trusted store has failed permanently. The | |
33 // client should assume this state final and further checks for | |
34 // trustedness will fail at least until the browser restarts. | |
35 PERMANENTLY_UNTRUSTED, | |
36 }; | |
37 | |
38 // Creates a new provider instance. |notify_cb| will be used to notify | |
39 // about setting changes. | |
40 explicit CrosSettingsProvider(const NotifyObserversCallback& notify_cb); | |
41 virtual ~CrosSettingsProvider(); | |
42 | |
43 // Sets |in_value| to given |path| in cros settings. | |
44 void Set(const std::string& path, const base::Value& in_value); | |
45 | |
46 // Gets settings value of given |path| to |out_value|. | |
47 virtual const base::Value* Get(const std::string& path) const = 0; | |
48 | |
49 // Requests the provider to fetch its values from a trusted store, if it | |
50 // hasn't done so yet. Returns TRUSTED if the values returned by this provider | |
51 // are trusted during the current loop cycle. Otherwise returns | |
52 // TEMPORARILY_UNTRUSTED, and |callback| will be invoked later when trusted | |
53 // values become available, PrepareTrustedValues() should be tried again in | |
54 // that case. Returns PERMANENTLY_UNTRUSTED if a permanent error has occurred. | |
55 virtual TrustedStatus PrepareTrustedValues( | |
56 const base::Closure& callback) = 0; | |
57 | |
58 // Gets the namespace prefix provided by this provider. | |
59 virtual bool HandlesSetting(const std::string& path) const = 0; | |
60 | |
61 // Reloads the caches if the provider has any. | |
62 virtual void Reload() = 0; | |
63 | |
64 void SetNotifyObserversCallback(const NotifyObserversCallback& notify_cb); | |
65 | |
66 protected: | |
67 // Notifies the observers about a setting change. | |
68 void NotifyObservers(const std::string& path); | |
69 | |
70 private: | |
71 // Does the real job for Set(). | |
72 virtual void DoSet(const std::string& path, | |
73 const base::Value& in_value) = 0; | |
74 | |
75 // Callback used to notify about setting changes. | |
76 NotifyObserversCallback notify_cb_; | |
77 }; | |
78 | |
79 } // namespace chromeos | |
80 | |
81 #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_PROVIDER_H_ | |
OLD | NEW |