OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" |
13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/prefs/pref_store.h" | 16 #include "base/prefs/pref_store.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 | 18 |
18 class PrefModelAssociator; | |
19 class PrefNotifier; | 19 class PrefNotifier; |
20 class PrefStore; | 20 class PrefStore; |
21 | 21 |
22 // The PrefValueStore manages various sources of values for Preferences | 22 // The PrefValueStore manages various sources of values for Preferences |
23 // (e.g., configuration policies, extensions, and user settings). It returns | 23 // (e.g., configuration policies, extensions, and user settings). It returns |
24 // the value of a Preference from the source with the highest priority, and | 24 // the value of a Preference from the source with the highest priority, and |
25 // allows setting user-defined values for preferences that are not managed. | 25 // allows setting user-defined values for preferences that are not managed. |
26 // | 26 // |
27 // Unless otherwise explicitly noted, all of the methods of this class must | 27 // Unless otherwise explicitly noted, all of the methods of this class must |
28 // be called on the UI thread. | 28 // be called on the UI thread. |
29 class PrefValueStore { | 29 class PrefValueStore { |
30 public: | 30 public: |
| 31 typedef base::Callback<void(const std::string&)> PrefChangedCallback; |
| 32 |
31 // In decreasing order of precedence: | 33 // In decreasing order of precedence: |
32 // |managed_prefs| contains all preferences from mandatory policies. | 34 // |managed_prefs| contains all preferences from mandatory policies. |
33 // |extension_prefs| contains preference values set by extensions. | 35 // |extension_prefs| contains preference values set by extensions. |
34 // |command_line_prefs| contains preference values set by command-line | 36 // |command_line_prefs| contains preference values set by command-line |
35 // switches. | 37 // switches. |
36 // |user_prefs| contains all user-set preference values. | 38 // |user_prefs| contains all user-set preference values. |
37 // |recommended_prefs| contains all preferences from recommended policies. | 39 // |recommended_prefs| contains all preferences from recommended policies. |
38 // |default_prefs| contains application-default preference values. It must | 40 // |default_prefs| contains application-default preference values. It must |
39 // be non-null if any preferences are to be registered. | 41 // be non-null if any preferences are to be registered. |
40 // | 42 // |
(...skipping 11 matching lines...) Expand all Loading... |
52 // Creates a clone of this PrefValueStore with PrefStores overwritten | 54 // Creates a clone of this PrefValueStore with PrefStores overwritten |
53 // by the parameters passed, if unequal NULL. | 55 // by the parameters passed, if unequal NULL. |
54 PrefValueStore* CloneAndSpecialize(PrefStore* managed_prefs, | 56 PrefValueStore* CloneAndSpecialize(PrefStore* managed_prefs, |
55 PrefStore* extension_prefs, | 57 PrefStore* extension_prefs, |
56 PrefStore* command_line_prefs, | 58 PrefStore* command_line_prefs, |
57 PrefStore* user_prefs, | 59 PrefStore* user_prefs, |
58 PrefStore* recommended_prefs, | 60 PrefStore* recommended_prefs, |
59 PrefStore* default_prefs, | 61 PrefStore* default_prefs, |
60 PrefNotifier* pref_notifier); | 62 PrefNotifier* pref_notifier); |
61 | 63 |
62 // TODO(joi): Remove this completely; the part PrefModelAssociator | 64 // A PrefValueStore can have exactly one callback that is directly |
63 // needs can be handled simply as a PrefObserver. | 65 // notified of preferences changing in the store. This does not |
64 void set_sync_associator(PrefModelAssociator* sync_associator); | 66 // filter through the PrefNotifier mechanism, which may not forward |
| 67 // certain changes (e.g. unregistered prefs). |
| 68 void set_callback(const PrefChangedCallback& callback); |
65 | 69 |
66 // Gets the value for the given preference name that has the specified value | 70 // Gets the value for the given preference name that has the specified value |
67 // type. Values stored in a PrefStore that have the matching |name| but | 71 // type. Values stored in a PrefStore that have the matching |name| but |
68 // a non-matching |type| are silently skipped. Returns true if a valid value | 72 // a non-matching |type| are silently skipped. Returns true if a valid value |
69 // was found in any of the available PrefStores. Most callers should use | 73 // was found in any of the available PrefStores. Most callers should use |
70 // Preference::GetValue() instead of calling this method directly. | 74 // Preference::GetValue() instead of calling this method directly. |
71 bool GetValue(const std::string& name, | 75 bool GetValue(const std::string& name, |
72 base::Value::Type type, | 76 base::Value::Type type, |
73 const Value** out_value) const; | 77 const Value** out_value) const; |
74 | 78 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 PrefStore* GetPrefStore(PrefStoreType type) { | 234 PrefStore* GetPrefStore(PrefStoreType type) { |
231 return pref_stores_[type].store(); | 235 return pref_stores_[type].store(); |
232 } | 236 } |
233 const PrefStore* GetPrefStore(PrefStoreType type) const { | 237 const PrefStore* GetPrefStore(PrefStoreType type) const { |
234 return pref_stores_[type].store(); | 238 return pref_stores_[type].store(); |
235 } | 239 } |
236 | 240 |
237 // Keeps the PrefStore references in order of precedence. | 241 // Keeps the PrefStore references in order of precedence. |
238 PrefStoreKeeper pref_stores_[PREF_STORE_TYPE_MAX + 1]; | 242 PrefStoreKeeper pref_stores_[PREF_STORE_TYPE_MAX + 1]; |
239 | 243 |
240 // The associator for syncing preferences. | 244 PrefChangedCallback pref_changed_callback_; |
241 PrefModelAssociator* pref_sync_associator_; | |
242 | 245 |
243 // Used for generating PREF_CHANGED and PREF_INITIALIZATION_COMPLETED | 246 // Used for generating notifications. This is a weak reference, |
244 // notifications. This is a weak reference, since the notifier is owned by the | 247 // since the notifier is owned by the corresponding PrefService. |
245 // corresponding PrefService. | |
246 PrefNotifier* pref_notifier_; | 248 PrefNotifier* pref_notifier_; |
247 | 249 |
248 // A mapping of preference names to their registered types. | 250 // A mapping of preference names to their registered types. |
249 PrefTypeMap pref_types_; | 251 PrefTypeMap pref_types_; |
250 | 252 |
251 // True if not all of the PrefStores were initialized successfully. | 253 // True if not all of the PrefStores were initialized successfully. |
252 bool initialization_failed_; | 254 bool initialization_failed_; |
253 | 255 |
254 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 256 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
255 }; | 257 }; |
256 | 258 |
257 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ | 259 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ |
OLD | NEW |