OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_PREFS_PREF_VALUE_STORE_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ |
6 #define CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/ref_counted.h" | 16 #include "base/ref_counted.h" |
17 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/browser_thread.h" | 19 #include "chrome/browser/browser_thread.h" |
20 #include "chrome/browser/prefs/pref_notifier.h" | 20 #include "chrome/common/notification_observer.h" |
| 21 #include "chrome/common/notification_registrar.h" |
21 #include "chrome/common/pref_store.h" | 22 #include "chrome/common/pref_store.h" |
22 | 23 |
23 class FilePath; | 24 class FilePath; |
| 25 class PrefNotifier; |
24 class PrefStore; | 26 class PrefStore; |
25 class Profile; | 27 class Profile; |
26 | 28 |
27 // The PrefValueStore manages various sources of values for Preferences | 29 // The PrefValueStore manages various sources of values for Preferences |
28 // (e.g., configuration policies, extensions, and user settings). It returns | 30 // (e.g., configuration policies, extensions, and user settings). It returns |
29 // the value of a Preference from the source with the highest priority, and | 31 // the value of a Preference from the source with the highest priority, and |
30 // allows setting user-defined values for preferences that are not managed. | 32 // allows setting user-defined values for preferences that are not managed. |
31 // See PrefNotifier for a list of the available preference sources (PrefStores) | |
32 // and their descriptions. | |
33 // | 33 // |
34 // Unless otherwise explicitly noted, all of the methods of this class must | 34 // Unless otherwise explicitly noted, all of the methods of this class must |
35 // be called on the UI thread. | 35 // be called on the UI thread. |
36 class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { | 36 class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore>, |
| 37 public NotificationObserver { |
37 public: | 38 public: |
38 // Returns a new PrefValueStore with all applicable PrefStores. The | 39 // In decreasing order of precedence: |
39 // |pref_filename| points to the user preference file. The |profile| is the | 40 // |managed_platform_prefs| contains all managed platform (non-cloud policy) |
40 // one to which these preferences apply; it may be NULL if we're dealing | 41 // preference values. |
41 // with the local state. If |pref_filename| is empty, the user PrefStore will | 42 // |device_management_prefs| contains all device management (cloud policy) |
42 // not be created. If |user_only| is true, no PrefStores will be created | 43 // preference values. |
43 // other than the user and default PrefStores. This should not normally be | 44 // |extension_prefs| contains preference values set by extensions. |
44 // called directly: the usual way to create a PrefValueStore is by creating a | 45 // |command_line_prefs| contains preference values set by command-line |
45 // PrefService. | 46 // switches. |
46 static PrefValueStore* CreatePrefValueStore(const FilePath& pref_filename, | 47 // |user_prefs| contains all user-set preference values. |
47 Profile* profile, | 48 // |recommended_prefs| contains all recommended (policy) preference values. |
48 bool user_only); | 49 // |default_prefs| contains application-default preference values. It must |
49 | 50 // be non-null if any preferences are to be registered. |
50 ~PrefValueStore(); | 51 // |
| 52 // |pref_notifier| facilitates broadcasting preference change notifications |
| 53 // to the world. |
| 54 // |
| 55 // The |profile| parameter is used to construct a replacement device |
| 56 // management pref store. This is done after policy refresh when we swap out |
| 57 // the policy pref stores for new ones, so the |profile| pointer needs to be |
| 58 // kept around for then. It is safe to pass a NULL pointer for local state |
| 59 // preferences. |
| 60 // |
| 61 // TODO(mnissler, danno): Refactor the pref store interface and refresh logic |
| 62 // so refreshes can be handled by the pref store itself without swapping |
| 63 // stores. This way we can get rid of the profile pointer here. |
| 64 PrefValueStore(PrefStore* managed_platform_prefs, |
| 65 PrefStore* device_management_prefs, |
| 66 PrefStore* extension_prefs, |
| 67 PrefStore* command_line_prefs, |
| 68 PrefStore* user_prefs, |
| 69 PrefStore* recommended_prefs, |
| 70 PrefStore* default_prefs, |
| 71 PrefNotifier* pref_notifier, |
| 72 Profile* profile); |
| 73 virtual ~PrefValueStore(); |
51 | 74 |
52 // Gets the value for the given preference name that has a valid value type; | 75 // Gets the value for the given preference name that has a valid value type; |
53 // that is, the same type the preference was registered with, or NULL for | 76 // that is, the same type the preference was registered with, or NULL for |
54 // default values of Dictionaries and Lists. Returns true if a valid value | 77 // default values of Dictionaries and Lists. Returns true if a valid value |
55 // was found in any of the available PrefStores. Most callers should use | 78 // was found in any of the available PrefStores. Most callers should use |
56 // Preference::GetValue() instead of calling this method directly. | 79 // Preference::GetValue() instead of calling this method directly. |
57 bool GetValue(const std::string& name, Value** out_value) const; | 80 bool GetValue(const std::string& name, Value** out_value) const; |
58 | 81 |
59 // Same as GetValue but only searches USER_STORE. | 82 // Same as GetValue but only searches the user store. |
60 bool GetUserValue(const std::string& name, Value** out_value) const; | 83 bool GetUserValue(const std::string& name, Value** out_value) const; |
61 | 84 |
62 // Adds a preference to the mapping of names to types. | 85 // Adds a preference to the mapping of names to types. |
63 void RegisterPreferenceType(const std::string& name, Value::ValueType type); | 86 void RegisterPreferenceType(const std::string& name, Value::ValueType type); |
64 | 87 |
65 // Gets the registered value type for the given preference name. Returns | 88 // Gets the registered value type for the given preference name. Returns |
66 // Value::TYPE_NULL if the preference has never been registered. | 89 // Value::TYPE_NULL if the preference has never been registered. |
67 Value::ValueType GetRegisteredType(const std::string& name) const; | 90 Value::ValueType GetRegisteredType(const std::string& name) const; |
68 | 91 |
69 // Read preference values into the three PrefStores so that they are available | 92 // Read preference values into the three PrefStores so that they are available |
70 // through the GetValue method. Return the first error that occurs (but | 93 // through the GetValue method. Return the first error that occurs (but |
71 // continue reading the remaining PrefStores). | 94 // continue reading the remaining PrefStores). |
72 PrefStore::PrefReadError ReadPrefs(); | 95 PrefStore::PrefReadError ReadPrefs(); |
73 | 96 |
74 // Persists prefs (to disk or elsewhere). Returns true if writing values was | 97 // Persists prefs (to disk or elsewhere). Returns true if writing values was |
75 // successful. In practice, only the user prefs are expected to be written | 98 // successful. In practice, only the user prefs are expected to be written |
76 // out. | 99 // out. |
| 100 // TODO(mnissler, danno): Handle writes through PrefService and remove. |
77 bool WritePrefs(); | 101 bool WritePrefs(); |
78 | 102 |
79 // Calls the method ScheduleWritePrefs on the PrefStores. In practice, only | 103 // Calls the method ScheduleWritePrefs on the PrefStores. In practice, only |
80 // the user prefs are expected to be written out. | 104 // the user prefs are expected to be written out. |
| 105 // TODO(mnissler, danno): Handle writes through PrefService and remove. |
81 void ScheduleWritePrefs(); | 106 void ScheduleWritePrefs(); |
82 | 107 |
83 // Returns true if the PrefValueStore contains the given preference (i.e., | 108 // Returns true if the PrefValueStore contains the given preference (i.e., |
84 // it's been registered), and a value with the correct type has been actively | 109 // it's been registered), and a value with the correct type has been actively |
85 // set in some pref store. The application default specified when the pref was | 110 // set in some pref store. The application default specified when the pref was |
86 // registered does not count as an "actively set" value, but another pref | 111 // registered does not count as an "actively set" value, but another pref |
87 // store setting a value that happens to be equal to the default does. | 112 // store setting a value that happens to be equal to the default does. |
88 bool HasPrefPath(const char* name) const; | 113 bool HasPrefPath(const char* name) const; |
89 | 114 |
90 // Called by the PrefNotifier when the value of the preference at |path| has | |
91 // changed, been added, or been removed in one of the PrefStores. The | |
92 // |new_store| is the PrefStoreType of the caller. Returns true if the | |
93 // effective value of the preference has changed, or if the store controlling | |
94 // the pref has changed. Virtual so it can be mocked for a unit test. | |
95 virtual bool PrefHasChanged(const char* path, | |
96 PrefNotifier::PrefStoreType new_store); | |
97 | |
98 // Returns true if the PrefValueStore is read-only. Because the managed | 115 // Returns true if the PrefValueStore is read-only. Because the managed |
99 // platform, device management and recommended PrefStores are always | 116 // platform, device management and recommended PrefStores are always |
100 // read-only, the PrefValueStore as a whole is read-only if the PrefStore | 117 // read-only, the PrefValueStore as a whole is read-only if the PrefStore |
101 // containing the user preferences is read-only. | 118 // containing the user preferences is read-only. |
102 bool ReadOnly(); | 119 bool ReadOnly() const; |
103 | 120 |
104 // Alters the user-defined value of a preference. Even if the preference is | 121 // Alters the user-defined value of a preference. Even if the preference is |
105 // managed this method allows the user-defined value of the preference to be | 122 // managed this method allows the user-defined value of the preference to be |
106 // set. But GetValue calls will not return this value as long as the | 123 // set. However, GetValue calls will not return this value as long as the |
107 // preference is managed. Instead GetValue will return the managed value | 124 // preference is overriden by a store of higher precedence. Note that the |
108 // of the preference. Note that the PrefValueStore takes the ownership of | 125 // PrefValueStore takes the ownership of the value referenced by |in_value|. |
109 // the value referenced by |in_value|. It is an error to call this when no | 126 // It is an error to call this when no user PrefStore has been set. Triggers |
110 // user PrefStore has been set. Returns true if the user-set value of the | 127 // notifications if the user-visible value changes. |
111 // preference was newly added or changed. | 128 // TODO(mnissler, danno): Handle writes in PrefService and notifications in |
112 bool SetUserPrefValue(const char* name, Value* in_value); | 129 // the pref store implementation, so we can remove this call. |
| 130 void SetUserPrefValue(const char* name, Value* in_value); |
113 | 131 |
114 // Removes a value from the user PrefStore. If a preference is managed | 132 // Like SetUserPrefValue, but silently puts the value without triggering |
115 // this function should have no visible effect. Returns true if there was a | 133 // notifications. |
116 // user-set value to be removed. | 134 // TODO(mnissler, danno): Handle writes in PrefService and notifications in |
117 bool RemoveUserPrefValue(const char* name); | 135 // the pref store implementation, so we can remove this call. |
| 136 void SetUserPrefValueSilently(const char* name, Value* in_value); |
118 | 137 |
119 // Sets a value in the DefaultPrefStore, which takes ownership of the Value. | 138 // Removes a value from the user PrefStore. If a preference is overriden by a |
120 void SetDefaultPrefValue(const char* name, Value* in_value); | 139 // store of higher precedence, this function will have no immediately visible |
| 140 // effect. Triggers notifications if the user-visible value changes. |
| 141 // TODO(mnissler, danno): Handle writes in PrefService and notifications in |
| 142 // the pref store implementation, so we can remove this call. |
| 143 void RemoveUserPrefValue(const char* name); |
121 | 144 |
122 // These methods return true if a preference with the given name is in the | 145 // These methods return true if a preference with the given name is in the |
123 // indicated pref store, even if that value is currently being overridden by | 146 // indicated pref store, even if that value is currently being overridden by |
124 // a higher-priority source. | 147 // a higher-priority source. |
125 bool PrefValueInManagedPlatformStore(const char* name) const; | 148 bool PrefValueInManagedPlatformStore(const char* name) const; |
126 bool PrefValueInDeviceManagementStore(const char* name) const; | 149 bool PrefValueInDeviceManagementStore(const char* name) const; |
127 bool PrefValueInExtensionStore(const char* name) const; | 150 bool PrefValueInExtensionStore(const char* name) const; |
128 bool PrefValueInUserStore(const char* name) const; | 151 bool PrefValueInUserStore(const char* name) const; |
129 | 152 |
130 // Returns true if a preference has an explicit value in any of the | |
131 // stores in the range specified by |first_checked_store| and | |
132 // |last_checked_store|, even if that value is currently being | |
133 // overridden by a higher-priority store. | |
134 bool PrefValueInStoreRange(const char* name, | |
135 PrefNotifier::PrefStoreType first_checked_store, | |
136 PrefNotifier::PrefStoreType last_checked_store); | |
137 | |
138 // These methods return true if a preference with the given name is actually | 153 // These methods return true if a preference with the given name is actually |
139 // being controlled by the indicated pref store and not being overridden by | 154 // being controlled by the indicated pref store and not being overridden by |
140 // a higher-priority source. | 155 // a higher-priority source. |
141 bool PrefValueFromExtensionStore(const char* name) const; | 156 bool PrefValueFromExtensionStore(const char* name) const; |
142 bool PrefValueFromUserStore(const char* name) const; | 157 bool PrefValueFromUserStore(const char* name) const; |
143 bool PrefValueFromDefaultStore(const char* name) const; | 158 bool PrefValueFromDefaultStore(const char* name) const; |
144 | 159 |
145 // Check whether a Preference value is modifiable by the user, i.e. whether | 160 // Check whether a Preference value is modifiable by the user, i.e. whether |
146 // there is no higher-priority source controlling it. | 161 // there is no higher-priority source controlling it. |
147 bool PrefValueUserModifiable(const char* name) const; | 162 bool PrefValueUserModifiable(const char* name) const; |
148 | 163 |
149 // Returns the pref store type identifying the source that controls the | |
150 // Preference identified by |name|. If none of the sources has a value, | |
151 // PrefNotifier::INVALID_STORE is returned. In practice, the default PrefStore | |
152 // should always have a value for any registered preferencem, so INVALID_STORE | |
153 // indicates an error. | |
154 PrefNotifier::PrefStoreType ControllingPrefStoreForPref( | |
155 const char* name) const; | |
156 | |
157 // Signature of callback triggered after policy refresh. Parameter is not | |
158 // passed as reference to prevent passing along a pointer to a set whose | |
159 // lifecycle is managed in another thread. | |
160 typedef Callback1<std::vector<std::string> >::Type AfterRefreshCallback; | |
161 | |
162 // Called as a result of a notification of policy change. Triggers a reload of | |
163 // managed platform, device management and recommended preferences from policy | |
164 // from a Task on the FILE thread. The Task will take ownership of the | |
165 // |callback|. |callback| is called with the set of preferences changed by the | |
166 // policy refresh. |callback| is called on the caller's thread as a Task | |
167 // after RefreshPolicyPrefs has returned. | |
168 void RefreshPolicyPrefs(AfterRefreshCallback* callback); | |
169 | |
170 // Returns true if there are proxy preferences in user-modifiable | 164 // Returns true if there are proxy preferences in user-modifiable |
171 // preference stores (e.g. CommandLinePrefStore, ExtensionPrefStore) | 165 // preference stores (e.g. CommandLinePrefStore, ExtensionPrefStore) |
172 // that conflict with proxy settings specified by proxy policy. | 166 // that conflict with proxy settings specified by proxy policy. |
173 bool HasPolicyConflictingUserProxySettings(); | 167 bool HasPolicyConflictingUserProxySettings() const; |
174 | |
175 // TODO(mnissler) delete after applying your patch. | |
176 // This is only called only by PrefService. | |
177 PrefStore* GetExtensionPrefStore() const; | |
178 | |
179 protected: | |
180 // In decreasing order of precedence: | |
181 // |managed_platform_prefs| contains all managed platform (non-cloud policy) | |
182 // preference values. | |
183 // |device_management_prefs| contains all device management (cloud policy) | |
184 // preference values. | |
185 // |extension_prefs| contains preference values set by extensions. | |
186 // |command_line_prefs| contains preference values set by command-line | |
187 // switches. | |
188 // |user_prefs| contains all user-set preference values. | |
189 // |recommended_prefs| contains all recommended (policy) preference values. | |
190 // |default_prefs| contains application-default preference values. It must | |
191 // be non-null if any preferences are to be registered. | |
192 // | |
193 // The |profile| parameter is used to construct a replacement device | |
194 // management pref store. This is done after policy refresh when we swap out | |
195 // the policy pref stores for new ones, so the |profile| pointer needs to be | |
196 // kept around for then. It is safe to pass a NULL pointer for local state | |
197 // preferences. | |
198 // | |
199 // TODO(mnissler, danno): Refactor the pref store interface and refresh logic | |
200 // so refreshes can be handled by the pref store itself without swapping | |
201 // stores. This way we can get rid of the profile pointer here. | |
202 // | |
203 // This constructor should only be used internally, or by subclasses in | |
204 // testing. The usual way to create a PrefValueStore is by creating a | |
205 // PrefService. | |
206 PrefValueStore(PrefStore* managed_platform_prefs, | |
207 PrefStore* device_management_prefs, | |
208 PrefStore* extension_prefs, | |
209 PrefStore* command_line_prefs, | |
210 PrefStore* user_prefs, | |
211 PrefStore* recommended_prefs, | |
212 PrefStore* default_prefs, | |
213 Profile* profile); | |
214 | 168 |
215 private: | 169 private: |
| 170 // PrefStores must be listed here in order from highest to lowest priority. |
| 171 // MANAGED_PLATFORM contains all managed preference values that are |
| 172 // provided by a platform-specific policy mechanism (e.g. Windows |
| 173 // Group Policy). |
| 174 // DEVICE_MANAGEMENT contains all managed preference values supplied |
| 175 // by the device management server (cloud policy). |
| 176 // EXTENSION contains preference values set by extensions. |
| 177 // COMMAND_LINE contains preference values set by command-line switches. |
| 178 // USER contains all user-set preference values. |
| 179 // RECOMMENDED contains all recommended (policy) preference values. |
| 180 // DEFAULT contains all application default preference values. |
| 181 enum PrefStoreType { |
| 182 // INVALID_STORE is not associated with an actual PrefStore but used as |
| 183 // an invalid marker, e.g. as a return value. |
| 184 INVALID_STORE = -1, |
| 185 MANAGED_PLATFORM_STORE = 0, |
| 186 DEVICE_MANAGEMENT_STORE, |
| 187 EXTENSION_STORE, |
| 188 COMMAND_LINE_STORE, |
| 189 USER_STORE, |
| 190 RECOMMENDED_STORE, |
| 191 DEFAULT_STORE, |
| 192 PREF_STORE_TYPE_MAX = DEFAULT_STORE |
| 193 }; |
| 194 |
| 195 // Keeps a PrefStore reference on behalf of the PrefValueStore and monitors |
| 196 // the PrefStore for changes, forwarding notifications to PrefValueStore. This |
| 197 // indirection is here for the sake of disambiguating notifications from the |
| 198 // individual PrefStores. |
| 199 class PrefStoreKeeper : public PrefStore::ObserverInterface { |
| 200 public: |
| 201 PrefStoreKeeper(); |
| 202 virtual ~PrefStoreKeeper(); |
| 203 |
| 204 // Takes ownership of |pref_store|. |
| 205 void Initialize(PrefValueStore* store, |
| 206 PrefStore* pref_store, |
| 207 PrefStoreType type); |
| 208 |
| 209 PrefStore* store() { return pref_store_.get(); } |
| 210 const PrefStore* store() const { return pref_store_.get(); } |
| 211 |
| 212 private: |
| 213 // PrefStore::ObserverInterface implementation. |
| 214 virtual void OnPrefValueChanged(const std::string& key); |
| 215 virtual void OnInitializationCompleted(); |
| 216 |
| 217 // PrefValueStore this keeper is part of. |
| 218 PrefValueStore* pref_value_store_; |
| 219 |
| 220 // The PrefStore managed by this keeper. |
| 221 scoped_ptr<PrefStore> pref_store_; |
| 222 |
| 223 // Type of the pref store. |
| 224 PrefStoreType type_; |
| 225 |
| 226 DISALLOW_COPY_AND_ASSIGN(PrefStoreKeeper); |
| 227 }; |
| 228 |
216 typedef std::map<std::string, Value::ValueType> PrefTypeMap; | 229 typedef std::map<std::string, Value::ValueType> PrefTypeMap; |
217 | 230 |
218 friend class PrefValueStoreTest; | 231 friend class PrefValueStoreTest; |
| 232 FRIEND_TEST_ALL_PREFIXES(PrefValueStoreTest, TestPolicyRefresh); |
219 FRIEND_TEST_ALL_PREFIXES(PrefValueStoreTest, | 233 FRIEND_TEST_ALL_PREFIXES(PrefValueStoreTest, |
220 TestRefreshPolicyPrefsCompletion); | 234 TestRefreshPolicyPrefsCompletion); |
| 235 FRIEND_TEST_ALL_PREFIXES(PrefValueStoreTest, |
| 236 TestConcurrentPolicyRefresh); |
| 237 |
| 238 // Returns true if the actual type is a valid type for the expected type when |
| 239 // found in the given store. |
| 240 static bool IsValidType(Value::ValueType expected, |
| 241 Value::ValueType actual, |
| 242 PrefStoreType store); |
221 | 243 |
222 // Returns true if the preference with the given name has a value in the | 244 // Returns true if the preference with the given name has a value in the |
223 // given PrefStoreType, of the same value type as the preference was | 245 // given PrefStoreType, of the same value type as the preference was |
224 // registered with. | 246 // registered with. |
225 bool PrefValueInStore(const char* name, | 247 bool PrefValueInStore(const char* name, PrefStoreType store) const; |
226 PrefNotifier::PrefStoreType store) const; | 248 |
| 249 // Returns true if a preference has an explicit value in any of the |
| 250 // stores in the range specified by |first_checked_store| and |
| 251 // |last_checked_store|, even if that value is currently being |
| 252 // overridden by a higher-priority store. |
| 253 bool PrefValueInStoreRange(const char* name, |
| 254 PrefStoreType first_checked_store, |
| 255 PrefStoreType last_checked_store) const; |
| 256 |
| 257 // Returns the pref store type identifying the source that controls the |
| 258 // Preference identified by |name|. If none of the sources has a value, |
| 259 // INVALID_STORE is returned. In practice, the default PrefStore |
| 260 // should always have a value for any registered preferencem, so INVALID_STORE |
| 261 // indicates an error. |
| 262 PrefStoreType ControllingPrefStoreForPref(const char* name) const; |
227 | 263 |
228 // Get a value from the specified store type. | 264 // Get a value from the specified store type. |
229 bool GetValueFromStore(const char* name, | 265 bool GetValueFromStore(const char* name, |
230 PrefNotifier::PrefStoreType store, | 266 PrefStoreType store, |
231 Value** out_value) const; | 267 Value** out_value) const; |
232 | 268 |
| 269 // Called upon changes in individual pref stores in order to determine whether |
| 270 // the user-visible pref value has changed. Triggers the change notification |
| 271 // if the effective value of the preference has changed, or if the store |
| 272 // controlling the pref has changed. |
| 273 void NotifyPrefChanged(const char* path, PrefStoreType new_store); |
| 274 |
| 275 // Called as a result of a notification of policy change. Triggers a reload of |
| 276 // managed platform, device management and recommended preferences from policy |
| 277 // from a Task on the FILE thread. |
| 278 void RefreshPolicyPrefs(); |
| 279 |
233 // Called during policy refresh after ReadPrefs completes on the thread | 280 // Called during policy refresh after ReadPrefs completes on the thread |
234 // that initiated the policy refresh. RefreshPolicyPrefsCompletion takes | 281 // that initiated the policy refresh. RefreshPolicyPrefsCompletion takes |
235 // ownership of the |callback| object. | 282 // ownership of the |callback| object. |
236 void RefreshPolicyPrefsCompletion( | 283 void RefreshPolicyPrefsCompletion( |
237 PrefStore* new_managed_platform_pref_store, | 284 PrefStore* new_managed_platform_pref_store, |
238 PrefStore* new_device_management_pref_store, | 285 PrefStore* new_device_management_pref_store, |
239 PrefStore* new_recommended_pref_store, | 286 PrefStore* new_recommended_pref_store); |
240 AfterRefreshCallback* callback); | |
241 | 287 |
242 // Called during policy refresh to do the ReadPrefs on the FILE thread. | 288 // Called during policy refresh to do the ReadPrefs on the FILE thread. |
243 // RefreshPolicyPrefsOnFileThread takes ownership of the |callback| object. | 289 // RefreshPolicyPrefsOnFileThread takes ownership of the |callback| object. |
244 void RefreshPolicyPrefsOnFileThread( | 290 void RefreshPolicyPrefsOnFileThread( |
245 BrowserThread::ID calling_thread_id, | 291 BrowserThread::ID calling_thread_id, |
246 PrefStore* new_managed_platform_pref_store, | 292 PrefStore* new_managed_platform_pref_store, |
247 PrefStore* new_device_management_pref_store, | 293 PrefStore* new_device_management_pref_store, |
248 PrefStore* new_recommended_pref_store, | 294 PrefStore* new_recommended_pref_store); |
249 AfterRefreshCallback* callback); | |
250 | 295 |
251 scoped_ptr<PrefStore> pref_stores_[PrefNotifier::PREF_STORE_TYPE_MAX + 1]; | 296 // NotificationObserver methods: |
| 297 virtual void Observe(NotificationType type, |
| 298 const NotificationSource& source, |
| 299 const NotificationDetails& details); |
| 300 |
| 301 // Called from the PrefStoreKeeper implementation when a pref value for |key| |
| 302 // changed in the pref store for |type|. |
| 303 void OnPrefValueChanged(PrefStoreType type, const std::string& key); |
| 304 |
| 305 // Handle the event that the store for |type| has completed initialization. |
| 306 void OnInitializationCompleted(PrefStoreType type); |
| 307 |
| 308 // Initializes a pref store keeper. Sets up a PrefStoreKeeper that will take |
| 309 // ownership of the passed |pref_store|. |
| 310 void InitPrefStore(PrefStoreType type, PrefStore* pref_store); |
| 311 |
| 312 // Checks whether initialization is completed and tells the notifier if that |
| 313 // is the case. |
| 314 void CheckInitializationCompleted(); |
| 315 |
| 316 // Get the PrefStore pointer for the given type. May return NULL if there is |
| 317 // no PrefStore for that type. |
| 318 PrefStore* GetPrefStore(PrefStoreType type) { |
| 319 return pref_stores_[type].store(); |
| 320 } |
| 321 const PrefStore* GetPrefStore(PrefStoreType type) const { |
| 322 return pref_stores_[type].store(); |
| 323 } |
| 324 |
| 325 // Keeps the PrefStore references in order of precedence. |
| 326 PrefStoreKeeper pref_stores_[PREF_STORE_TYPE_MAX + 1]; |
| 327 |
| 328 // Used for generating PREF_CHANGED and PREF_INITIALIZATION_COMPLETED |
| 329 // notifications. This is a weak reference, since the notifier is owned by the |
| 330 // corresponding PrefService. |
| 331 PrefNotifier* pref_notifier_; |
252 | 332 |
253 // A mapping of preference names to their registered types. | 333 // A mapping of preference names to their registered types. |
254 PrefTypeMap pref_types_; | 334 PrefTypeMap pref_types_; |
255 | 335 |
256 // The associated profile, in case this value store is associated with a | 336 // The associated profile, in case this value store is associated with a |
257 // profile pref service. Used for recreating the device management pref store | 337 // profile pref service. Used for recreating the device management pref store |
258 // upon policy refresh. | 338 // upon policy refresh. |
259 Profile* profile_; | 339 Profile* profile_; |
260 | 340 |
| 341 // TODO(mnissler): Remove this after cleaning up policy refresh handling. |
| 342 NotificationRegistrar registrar_; |
| 343 |
261 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 344 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
262 }; | 345 }; |
263 | 346 |
264 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ | 347 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ |
OLD | NEW |