Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(553)

Side by Side Diff: chrome/browser/chromeos/cros_settings.h

Issue 10824112: Move Chrome OS device settings stuff to chrome/browser/chromeos/settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback_forward.h"
12 #include "base/hash_tables.h"
13 #include "base/observer_list.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "chrome/browser/chromeos/cros_settings_names.h"
16 #include "chrome/browser/chromeos/cros_settings_provider.h"
17 #include "content/public/browser/notification_observer.h"
18
19 namespace base {
20 template <typename T> struct DefaultLazyInstanceTraits;
21 class ListValue;
22 class Value;
23 }
24
25 namespace chromeos {
26
27 // This class manages per-device/global settings.
28 class CrosSettings : public base::NonThreadSafe {
29 public:
30 // Class factory.
31 static CrosSettings* Get();
32
33 // Helper function to test if the given |path| is a valid cros setting.
34 static bool IsCrosSettings(const std::string& path);
35
36 // Sets |in_value| to given |path| in cros settings.
37 void Set(const std::string& path, const base::Value& in_value);
38
39 // Returns setting value for the given |path|.
40 const base::Value* GetPref(const std::string& path) const;
41
42 // Requests all providers to fetch their values from a trusted store, if they
43 // haven't done so yet. Returns true if the cros settings returned by |this|
44 // are trusted during the current loop cycle; otherwise returns false, and
45 // |callback| will be invoked later when trusted values become available.
46 // PrepareTrustedValues() should be tried again in that case.
47 virtual CrosSettingsProvider::TrustedStatus PrepareTrustedValues(
48 const base::Closure& callback) const;
49
50 // Convenience forms of Set(). These methods will replace any existing
51 // value at that |path|, even if it has a different type.
52 void SetBoolean(const std::string& path, bool in_value);
53 void SetInteger(const std::string& path, int in_value);
54 void SetDouble(const std::string& path, double in_value);
55 void SetString(const std::string& path, const std::string& in_value);
56
57 // Convenience functions for manipulating lists. Note that the following
58 // functions employs a read, modify and write pattern. If underlying settings
59 // provider updates its value asynchronously such as DeviceSettingsProvider,
60 // value cache they read from might not be fresh and multiple calls to those
61 // function would lose data. See http://crbug.com/127215
62 void AppendToList(const std::string& path, const base::Value* value);
63 void RemoveFromList(const std::string& path, const base::Value* value);
64
65 // These are convenience forms of Get(). The value will be retrieved
66 // and the return value will be true if the |path| is valid and the value at
67 // the end of the path can be returned in the form specified.
68 bool GetBoolean(const std::string& path, bool* out_value) const;
69 bool GetInteger(const std::string& path, int* out_value) const;
70 bool GetDouble(const std::string& path, double* out_value) const;
71 bool GetString(const std::string& path, std::string* out_value) const;
72 bool GetList(const std::string& path,
73 const base::ListValue** out_value) const;
74
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 respects whitelists so foo@bar.baz will match *@bar.baz too.
78 bool FindEmailInList(const std::string& path, const std::string& email) const;
79
80 // Adding/removing of providers.
81 bool AddSettingsProvider(CrosSettingsProvider* provider);
82 bool RemoveSettingsProvider(CrosSettingsProvider* provider);
83
84 // If the pref at the given |path| changes, we call the observer's Observe
85 // method with NOTIFICATION_SYSTEM_SETTING_CHANGED.
86 void AddSettingsObserver(const char* path,
87 content::NotificationObserver* obs);
88 void RemoveSettingsObserver(const char* path,
89 content::NotificationObserver* obs);
90
91 // Returns the provider that handles settings with the |path| or prefix.
92 CrosSettingsProvider* GetProvider(const std::string& path) const;
93
94 // Forces all providers to reload their caches from the respective backing
95 // stores if they have any.
96 void ReloadProviders();
97
98 private:
99 friend struct base::DefaultLazyInstanceTraits<CrosSettings>;
100
101 // List of ChromeOS system settings providers.
102 std::vector<CrosSettingsProvider*> providers_;
103
104 // A map from settings names to a list of observers. Observers get fired in
105 // the order they are added.
106 typedef ObserverList<content::NotificationObserver, true>
107 NotificationObserverList;
108 typedef base::hash_map<std::string, NotificationObserverList*>
109 SettingsObserverMap;
110 SettingsObserverMap settings_observers_;
111
112 CrosSettings();
113 ~CrosSettings();
114
115 // Fires system setting change notification.
116 void FireObservers(const std::string& path);
117
118 DISALLOW_COPY_AND_ASSIGN(CrosSettings);
119 };
120
121 } // namespace chromeos
122
123 #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library_impl_cros.cc ('k') | chrome/browser/chromeos/cros_settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698