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

Side by Side Diff: chrome/browser/managed_mode/managed_user_settings_service.h

Issue 23466004: Add ManagedUserSettingsService and a SupervisedUserPrefStore using it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: xx Created 7 years, 3 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 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 CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SETTINGS_SERVICE_H_
6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SETTINGS_SERVICE_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/prefs/pref_store.h"
15 #include "base/values.h"
16 #include "chrome/browser/managed_mode/managed_users.h"
17 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
18
19 class PersistentPrefStore;
20 class Profile;
21
22 namespace base {
23 class FilePath;
24 class SequencedTaskRunner;
25 }
26
27 // TODO(bauerb): This class is not yet fully functional.
28 // This class syncs managed user settings from a server, which are mapped to
29 // preferences. The downloaded settings are persisted in a PrefStore.
Pam (message me for reviews) 2013/09/04 10:21:47 It would be helpful to mention here too that this
Bernhard Bauer 2013/09/04 11:56:19 Done.
30 // Settings are key-value pairs, where the key uniquely identifies the setting.
31 // The value is a string containing a JSON serialization of an arbitrary value,
32 // which is the value of the setting.
33 //
34 // There are two kinds of settings handled by this class: Atomic and split
35 // settings.
36 // Atomic settings consist of a single key (which will be mapped to a pref key)
37 // and a single (arbitrary) value.
38 // Split settings encode a dictionary value and are stored as multiple Sync
39 // items, one for each dictionary entry. The key for each of these Sync items
40 // is the key of the split setting, followed by a separator (':') and the key
41 // for the dictionary entry. The value of the Sync item is the value of the
42 // dictionary entry.
43 //
44 // As an example, a split setting with key "Moose" and value
45 // {
46 // "foo": "bar",
47 // "baz": "blurp"
48 // }
49 // would be encoded as two sync items, one with key "Moose:foo" and value "bar",
50 // and one with key "Moose:baz" and value "blurp".
51 class ManagedUserSettingsService : public BrowserContextKeyedService,
52 public PrefStore::Observer {
53 public:
54 // A callback whose first parameter is a dictionary containing all managed
55 // user settings. If the dictionary is NULL, it means that the service is
56 // inactive, i.e. the user is not managed.
57 typedef base::Callback<void(const base::DictionaryValue*)> SettingsCallback;
58
59 ManagedUserSettingsService();
60 virtual ~ManagedUserSettingsService();
61
62 // Initializes the service by loading its settings from the |pref_store|.
63 // Use this method in tests to inject a different PrefStore than the
64 // default one.
65 void Init(scoped_refptr<PersistentPrefStore> pref_store);
66
67 // Adds a callback to be called when managed user settings are initially
68 // available, or when they change.
69 void Subscribe(const SettingsCallback& callback);
70
71 // Activates the service. This happens when the user is managed.
72 void Activate();
73
74 // Whether managed user settings are available.
75 bool IsReady();
76
77 // Clears all managed user settings and items.
78 void Clear();
79
80 // Sets the setting with the given |key| to a copy of the given |value|.
81 void SetLocalSettingForTesting(const std::string& key,
82 scoped_ptr<base::Value> value);
83
84 // BrowserContextKeyedService implementation:
85 virtual void Shutdown() OVERRIDE;
86
87 // PrefStore::Observer implementation:
88 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE;
89 virtual void OnInitializationCompleted(bool success) OVERRIDE;
90
91 private:
92 base::DictionaryValue* GetOrCreateDictionary(const std::string& key) const;
93 base::DictionaryValue* GetAtomicSettings() const;
94 base::DictionaryValue* GetSplitSettings() const;
95 base::DictionaryValue* GetQueuedItems() const;
96
97 // Returns a dictionary with all managed user settings if the service is
98 // active, or NULL otherwise.
99 scoped_ptr<base::DictionaryValue> GetSettings();
100
101 // Sends the settings to all subscribers. This method should be called by the
102 // subclass whenever the settings change.
103 void InformSubscribers();
104
105 // Used for persisting the settings. Unlike other PrefStores, this one is not
106 // directly hooked up to the PrefService.
107 scoped_refptr<PersistentPrefStore> store_;
108
109 bool active_;
110
111 // A set of local settings that are fixed and not configured remotely.
112 scoped_ptr<base::DictionaryValue> local_settings_;
113
114 std::vector<SettingsCallback> subscribers_;
115
116 DISALLOW_COPY_AND_ASSIGN(ManagedUserSettingsService);
117 };
118
119 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SETTINGS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698