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 // This provides a way to access the application's current preferences. | 5 // This provides a way to access the application's current preferences. |
6 | 6 |
7 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 7 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 public: | 35 public: |
36 // A helper class to store all the information associated with a preference. | 36 // A helper class to store all the information associated with a preference. |
37 class Preference { | 37 class Preference { |
38 public: | 38 public: |
39 | 39 |
40 // The type of the preference is determined by the type with which it is | 40 // The type of the preference is determined by the type with which it is |
41 // registered. This type needs to be a boolean, integer, real, string, | 41 // registered. This type needs to be a boolean, integer, real, string, |
42 // dictionary (a branch), or list. You shouldn't need to construct this on | 42 // dictionary (a branch), or list. You shouldn't need to construct this on |
43 // your own; use the PrefService::Register*Pref methods instead. | 43 // your own; use the PrefService::Register*Pref methods instead. |
44 Preference(const PrefService* service, | 44 Preference(const PrefService* service, |
45 const char* name); | 45 const char* name, |
46 Value::ValueType type); | |
46 ~Preference() {} | 47 ~Preference() {} |
47 | 48 |
48 // Returns the name of the Preference (i.e., the key, e.g., | 49 // Returns the name of the Preference (i.e., the key, e.g., |
49 // browser.window_placement). | 50 // browser.window_placement). |
50 const std::string name() const { return name_; } | 51 const std::string name() const { return name_; } |
51 | 52 |
52 // Returns the registered type of the preference. | 53 // Returns the registered type of the preference. |
53 Value::ValueType GetType() const; | 54 Value::ValueType GetType() const; |
54 | 55 |
55 // Returns the value of the Preference, falling back to the registered | 56 // Returns the value of the Preference, falling back to the registered |
(...skipping 29 matching lines...) Expand all Loading... | |
85 // Returns true if the user can change the Preference value, which is the | 86 // Returns true if the user can change the Preference value, which is the |
86 // case if no higher-priority source than the user store controls the | 87 // case if no higher-priority source than the user store controls the |
87 // Preference. | 88 // Preference. |
88 bool IsUserModifiable() const; | 89 bool IsUserModifiable() const; |
89 | 90 |
90 private: | 91 private: |
91 friend class PrefService; | 92 friend class PrefService; |
92 | 93 |
93 std::string name_; | 94 std::string name_; |
94 | 95 |
96 Value::ValueType type_; | |
97 | |
95 // Reference to the PrefService in which this pref was created. | 98 // Reference to the PrefService in which this pref was created. |
96 const PrefService* pref_service_; | 99 const PrefService* pref_service_; |
97 | 100 |
98 DISALLOW_COPY_AND_ASSIGN(Preference); | 101 DISALLOW_COPY_AND_ASSIGN(Preference); |
99 }; | 102 }; |
100 | 103 |
101 // Factory method that creates a new instance of a PrefService with the | 104 // Factory method that creates a new instance of a PrefService with the |
102 // applicable PrefStores. The |pref_filename| points to the user preference | 105 // applicable PrefStores. The |pref_filename| points to the user preference |
103 // file. The |profile| is the one to which these preferences apply; it may be | 106 // file. The |profile| is the one to which these preferences apply; it may be |
104 // NULL if we're dealing with the local state. This is the usual way to create | 107 // NULL if we're dealing with the local state. This is the usual way to create |
105 // a new PrefService. |extension_pref_store| is used as the source for | 108 // a new PrefService. |extension_pref_store| is used as the source for |
106 // extension-controlled preferences and may be NULL. The PrefService takes | 109 // extension-controlled preferences and may be NULL. The PrefService takes |
107 // ownership of |extension_pref_store|. | 110 // ownership of |extension_pref_store|. |
108 static PrefService* CreatePrefService(const FilePath& pref_filename, | 111 static PrefService* CreatePrefService( |
109 PrefStore* extension_pref_store, | 112 const FilePath& pref_filename, |
110 Profile* profile); | 113 scoped_refptr<PrefStore> extension_pref_store, |
114 Profile* profile); | |
115 | |
116 // Creates an incognito copy of the pref service that shares most pref stores | |
117 // but uses a fresh non-persistent overlay for the user pref store and an | |
118 // individual extension pref store (to cache the effective extension prefs for | |
119 // incognito windows). | |
120 PrefService* CreateIncognitoPrefService( | |
121 scoped_refptr<PrefStore> incognito_extension_prefs); | |
Mattias Nissler (ping if slow)
2010/12/20 14:50:02
We should have a unit test for this, ensuring that
battre
2010/12/21 18:51:59
Done.
| |
111 | 122 |
112 virtual ~PrefService(); | 123 virtual ~PrefService(); |
113 | 124 |
114 // Reloads the data from file. This should only be called when the importer | 125 // Reloads the data from file. This should only be called when the importer |
115 // is running during first run, and the main process may not change pref | 126 // is running during first run, and the main process may not change pref |
116 // values while the importer process is running. Returns true on success. | 127 // values while the importer process is running. Returns true on success. |
117 bool ReloadPersistentPrefs(); | 128 bool ReloadPersistentPrefs(); |
118 | 129 |
119 // Returns true if the preference for the given preference name is available | 130 // Returns true if the preference for the given preference name is available |
120 // and is managed. | 131 // and is managed. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 bool ReadOnly() const; | 229 bool ReadOnly() const; |
219 | 230 |
220 // TODO(mnissler): This should not be public. Change client code to call a | 231 // TODO(mnissler): This should not be public. Change client code to call a |
221 // preference setter or use ScopedPrefUpdate. | 232 // preference setter or use ScopedPrefUpdate. |
222 PrefNotifier* pref_notifier() const; | 233 PrefNotifier* pref_notifier() const; |
223 | 234 |
224 protected: | 235 protected: |
225 // Construct a new pref service, specifying the pref sources as explicit | 236 // Construct a new pref service, specifying the pref sources as explicit |
226 // PrefStore pointers. This constructor is what CreatePrefService() ends up | 237 // PrefStore pointers. This constructor is what CreatePrefService() ends up |
227 // calling. It's also used for unit tests. | 238 // calling. It's also used for unit tests. |
228 PrefService(PrefStore* managed_platform_prefs, | 239 PrefService(scoped_refptr<PrefStore> managed_platform_prefs, |
Mattias Nissler (ping if slow)
2010/12/20 14:50:02
The majority of the codebase passes reference coun
| |
229 PrefStore* device_management_prefs, | 240 scoped_refptr<PrefStore> device_management_prefs, |
230 PrefStore* extension_prefs, | 241 scoped_refptr<PrefStore> extension_prefs, |
231 PrefStore* command_line_prefs, | 242 scoped_refptr<PrefStore> command_line_prefs, |
232 PersistentPrefStore* user_prefs, | 243 scoped_refptr<PersistentPrefStore> user_prefs, |
233 PrefStore* recommended_prefs, | 244 scoped_refptr<PrefStore> recommended_prefs, |
234 Profile* profile); | 245 Profile* profile); |
235 | 246 |
247 // Constructor to be used only for CreateIncognitoPrefService. | |
Mattias Nissler (ping if slow)
2010/12/20 14:50:02
After pondering this for a while, I'm now leaning
battre
2010/12/21 18:51:59
Done.
| |
248 PrefService(PrefValueStore* old_pref_value_store, | |
249 scoped_refptr<PersistentPrefStore> old_user_pref_store, | |
250 scoped_refptr<PrefStore> incognito_extension_prefs, | |
251 scoped_refptr<DefaultPrefStore> default_store); | |
252 | |
236 // The PrefNotifier handles registering and notifying preference observers. | 253 // The PrefNotifier handles registering and notifying preference observers. |
237 // It is created and owned by this PrefService. Subclasses may access it for | 254 // It is created and owned by this PrefService. Subclasses may access it for |
238 // unit testing. | 255 // unit testing. |
239 scoped_ptr<PrefNotifierImpl> pref_notifier_; | 256 scoped_ptr<PrefNotifierImpl> pref_notifier_; |
240 | 257 |
241 private: | 258 private: |
242 friend class PrefServiceMockBuilder; | 259 friend class PrefServiceMockBuilder; |
243 | 260 |
244 // Registration of pref change observers must be done using the | 261 // Registration of pref change observers must be done using the |
245 // PrefChangeRegistrar, which is declared as a friend here to grant it | 262 // PrefChangeRegistrar, which is declared as a friend here to grant it |
(...skipping 21 matching lines...) Expand all Loading... | |
267 | 284 |
268 // Load preferences from storage, attempting to diagnose and handle errors. | 285 // Load preferences from storage, attempting to diagnose and handle errors. |
269 // This should only be called from the constructor. | 286 // This should only be called from the constructor. |
270 void InitFromStorage(); | 287 void InitFromStorage(); |
271 | 288 |
272 // The PrefValueStore provides prioritized preference values. It is created | 289 // The PrefValueStore provides prioritized preference values. It is created |
273 // and owned by this PrefService. Subclasses may access it for unit testing. | 290 // and owned by this PrefService. Subclasses may access it for unit testing. |
274 scoped_refptr<PrefValueStore> pref_value_store_; | 291 scoped_refptr<PrefValueStore> pref_value_store_; |
275 | 292 |
276 // The persistent pref store used for actual user data. | 293 // The persistent pref store used for actual user data. |
277 PersistentPrefStore* user_pref_store_; | 294 scoped_refptr<PersistentPrefStore> user_pref_store_; |
278 | 295 |
279 // Points to the default pref store we passed to the PrefValueStore. | 296 // Points to the default pref store we passed to the PrefValueStore. |
280 DefaultPrefStore* default_store_; | 297 scoped_refptr<DefaultPrefStore> default_store_; |
281 | 298 |
282 // A set of all the registered Preference objects. | 299 // Local cache of registered Preference objects. The default_store_ |
283 PreferenceSet prefs_; | 300 // is authoritative with respect to what the types and default values |
301 // of registered preferences are. | |
302 mutable PreferenceSet prefs_; | |
284 | 303 |
285 DISALLOW_COPY_AND_ASSIGN(PrefService); | 304 DISALLOW_COPY_AND_ASSIGN(PrefService); |
286 }; | 305 }; |
287 | 306 |
288 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 307 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
OLD | NEW |