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" | |
15 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
16 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
17 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
18 #include "base/values.h" | 17 #include "base/values.h" |
19 #include "chrome/browser/browser_thread.h" | 18 #include "chrome/browser/browser_thread.h" |
20 #include "chrome/common/notification_observer.h" | |
21 #include "chrome/common/notification_registrar.h" | |
22 #include "chrome/common/pref_store.h" | 19 #include "chrome/common/pref_store.h" |
23 | 20 |
24 class FilePath; | 21 class FilePath; |
25 class PrefNotifier; | 22 class PrefNotifier; |
26 class PrefStore; | 23 class PrefStore; |
27 class Profile; | 24 class Profile; |
28 | 25 |
29 // TODO(danno, mnissler): Remove after policy refresh cleanup. | |
30 namespace policy { | |
31 class ConfigurationPolicyPrefStore; | |
32 } | |
33 | |
34 // The PrefValueStore manages various sources of values for Preferences | 26 // The PrefValueStore manages various sources of values for Preferences |
35 // (e.g., configuration policies, extensions, and user settings). It returns | 27 // (e.g., configuration policies, extensions, and user settings). It returns |
36 // the value of a Preference from the source with the highest priority, and | 28 // the value of a Preference from the source with the highest priority, and |
37 // allows setting user-defined values for preferences that are not managed. | 29 // allows setting user-defined values for preferences that are not managed. |
38 // | 30 // |
39 // Unless otherwise explicitly noted, all of the methods of this class must | 31 // Unless otherwise explicitly noted, all of the methods of this class must |
40 // be called on the UI thread. | 32 // be called on the UI thread. |
41 class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore>, | 33 class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { |
42 public NotificationObserver { | |
43 public: | 34 public: |
44 // In decreasing order of precedence: | 35 // In decreasing order of precedence: |
45 // |managed_platform_prefs| contains all managed platform (non-cloud policy) | 36 // |managed_platform_prefs| contains all managed platform (non-cloud policy) |
46 // preference values. | 37 // preference values. |
47 // |device_management_prefs| contains all device management (cloud policy) | 38 // |device_management_prefs| contains all device management (cloud policy) |
48 // preference values. | 39 // preference values. |
49 // |extension_prefs| contains preference values set by extensions. | 40 // |extension_prefs| contains preference values set by extensions. |
50 // |command_line_prefs| contains preference values set by command-line | 41 // |command_line_prefs| contains preference values set by command-line |
51 // switches. | 42 // switches. |
52 // |user_prefs| contains all user-set preference values. | 43 // |user_prefs| contains all user-set preference values. |
53 // |recommended_prefs| contains all recommended (policy) preference values. | 44 // |recommended_prefs| contains all recommended (policy) preference values. |
54 // |default_prefs| contains application-default preference values. It must | 45 // |default_prefs| contains application-default preference values. It must |
55 // be non-null if any preferences are to be registered. | 46 // be non-null if any preferences are to be registered. |
56 // | 47 // |
57 // |pref_notifier| facilitates broadcasting preference change notifications | 48 // |pref_notifier| facilitates broadcasting preference change notifications |
58 // to the world. | 49 // to the world. |
59 // | 50 // |
60 // The |profile| parameter is used to construct a replacement device | 51 // The |profile| parameter is used to construct a replacement device |
61 // management pref store. This is done after policy refresh when we swap out | 52 // management pref store. This is done after policy refresh when we swap out |
62 // the policy pref stores for new ones, so the |profile| pointer needs to be | 53 // the policy pref stores for new ones, so the |profile| pointer needs to be |
63 // kept around for then. It is safe to pass a NULL pointer for local state | 54 // kept around for then. It is safe to pass a NULL pointer for local state |
64 // preferences. | 55 // preferences. |
65 // | |
66 // TODO(mnissler, danno): Refactor the pref store interface and refresh logic | |
67 // so refreshes can be handled by the pref store itself without swapping | |
68 // stores. This way we can get rid of the profile pointer here. | |
69 PrefValueStore(PrefStore* managed_platform_prefs, | 56 PrefValueStore(PrefStore* managed_platform_prefs, |
70 PrefStore* device_management_prefs, | 57 PrefStore* device_management_prefs, |
71 PrefStore* extension_prefs, | 58 PrefStore* extension_prefs, |
72 PrefStore* command_line_prefs, | 59 PrefStore* command_line_prefs, |
73 PrefStore* user_prefs, | 60 PrefStore* user_prefs, |
74 PrefStore* recommended_prefs, | 61 PrefStore* recommended_prefs, |
75 PrefStore* default_prefs, | 62 PrefStore* default_prefs, |
76 PrefNotifier* pref_notifier, | 63 PrefNotifier* pref_notifier); |
77 Profile* profile); | |
78 virtual ~PrefValueStore(); | 64 virtual ~PrefValueStore(); |
79 | 65 |
80 // Gets the value for the given preference name that has a valid value type; | 66 // Gets the value for the given preference name that has a valid value type; |
81 // that is, the same type the preference was registered with, or NULL for | 67 // that is, the same type the preference was registered with, or NULL for |
82 // default values of Dictionaries and Lists. Returns true if a valid value | 68 // default values of Dictionaries and Lists. Returns true if a valid value |
83 // was found in any of the available PrefStores. Most callers should use | 69 // was found in any of the available PrefStores. Most callers should use |
84 // Preference::GetValue() instead of calling this method directly. | 70 // Preference::GetValue() instead of calling this method directly. |
85 bool GetValue(const std::string& name, Value** out_value) const; | 71 bool GetValue(const std::string& name, Value** out_value) const; |
86 | 72 |
87 // Adds a preference to the mapping of names to types. | 73 // Adds a preference to the mapping of names to types. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 bool GetValueFromStore(const char* name, | 202 bool GetValueFromStore(const char* name, |
217 PrefStoreType store, | 203 PrefStoreType store, |
218 Value** out_value) const; | 204 Value** out_value) const; |
219 | 205 |
220 // Called upon changes in individual pref stores in order to determine whether | 206 // Called upon changes in individual pref stores in order to determine whether |
221 // the user-visible pref value has changed. Triggers the change notification | 207 // the user-visible pref value has changed. Triggers the change notification |
222 // if the effective value of the preference has changed, or if the store | 208 // if the effective value of the preference has changed, or if the store |
223 // controlling the pref has changed. | 209 // controlling the pref has changed. |
224 void NotifyPrefChanged(const char* path, PrefStoreType new_store); | 210 void NotifyPrefChanged(const char* path, PrefStoreType new_store); |
225 | 211 |
226 // Called as a result of a notification of policy change. Triggers a reload of | |
227 // managed platform, device management and recommended preferences from policy | |
228 // from a Task on the FILE thread. | |
229 void RefreshPolicyPrefs(); | |
230 | |
231 // Called during policy refresh after ReadPrefs completes on the thread | |
232 // that initiated the policy refresh. RefreshPolicyPrefsCompletion takes | |
233 // ownership of the |callback| object. | |
234 void RefreshPolicyPrefsCompletion( | |
235 policy::ConfigurationPolicyPrefStore* new_managed_platform_pref_store, | |
236 policy::ConfigurationPolicyPrefStore* new_device_management_pref_store, | |
237 policy::ConfigurationPolicyPrefStore* new_recommended_pref_store); | |
238 | |
239 // Called during policy refresh to do the ReadPrefs on the FILE thread. | |
240 // RefreshPolicyPrefsOnFileThread takes ownership of the |callback| object. | |
241 void RefreshPolicyPrefsOnFileThread( | |
242 BrowserThread::ID calling_thread_id, | |
243 policy::ConfigurationPolicyPrefStore* new_managed_platform_pref_store, | |
244 policy::ConfigurationPolicyPrefStore* new_device_management_pref_store, | |
245 policy::ConfigurationPolicyPrefStore* new_recommended_pref_store); | |
246 | |
247 // NotificationObserver methods: | |
248 virtual void Observe(NotificationType type, | |
249 const NotificationSource& source, | |
250 const NotificationDetails& details); | |
251 | |
252 // Called from the PrefStoreKeeper implementation when a pref value for |key| | 212 // Called from the PrefStoreKeeper implementation when a pref value for |key| |
253 // changed in the pref store for |type|. | 213 // changed in the pref store for |type|. |
254 void OnPrefValueChanged(PrefStoreType type, const std::string& key); | 214 void OnPrefValueChanged(PrefStoreType type, const std::string& key); |
255 | 215 |
256 // Handle the event that the store for |type| has completed initialization. | 216 // Handle the event that the store for |type| has completed initialization. |
257 void OnInitializationCompleted(PrefStoreType type); | 217 void OnInitializationCompleted(PrefStoreType type); |
258 | 218 |
259 // Initializes a pref store keeper. Sets up a PrefStoreKeeper that will take | 219 // Initializes a pref store keeper. Sets up a PrefStoreKeeper that will take |
260 // ownership of the passed |pref_store|. | 220 // ownership of the passed |pref_store|. |
261 void InitPrefStore(PrefStoreType type, PrefStore* pref_store); | 221 void InitPrefStore(PrefStoreType type, PrefStore* pref_store); |
(...skipping 15 matching lines...) Expand all Loading... |
277 PrefStoreKeeper pref_stores_[PREF_STORE_TYPE_MAX + 1]; | 237 PrefStoreKeeper pref_stores_[PREF_STORE_TYPE_MAX + 1]; |
278 | 238 |
279 // Used for generating PREF_CHANGED and PREF_INITIALIZATION_COMPLETED | 239 // Used for generating PREF_CHANGED and PREF_INITIALIZATION_COMPLETED |
280 // notifications. This is a weak reference, since the notifier is owned by the | 240 // notifications. This is a weak reference, since the notifier is owned by the |
281 // corresponding PrefService. | 241 // corresponding PrefService. |
282 PrefNotifier* pref_notifier_; | 242 PrefNotifier* pref_notifier_; |
283 | 243 |
284 // A mapping of preference names to their registered types. | 244 // A mapping of preference names to their registered types. |
285 PrefTypeMap pref_types_; | 245 PrefTypeMap pref_types_; |
286 | 246 |
287 // The associated profile, in case this value store is associated with a | |
288 // profile pref service. Used for recreating the device management pref store | |
289 // upon policy refresh. | |
290 Profile* profile_; | |
291 | |
292 // TODO(mnissler): Remove this after cleaning up policy refresh handling. | |
293 NotificationRegistrar registrar_; | |
294 | |
295 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 247 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
296 }; | 248 }; |
297 | 249 |
298 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ | 250 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ |
OLD | NEW |