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