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); | |
Mattias Nissler (ping if slow)
2010/12/22 12:09:03
Can't we just ask the PrefService of the type?
battre
2010/12/22 18:34:53
Will leave this in the Preference as discussed off
| |
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(const FilePath& pref_filename, |
109 PrefStore* extension_pref_store, | 112 PrefStore* extension_pref_store, |
110 Profile* profile); | 113 Profile* profile); |
111 | 114 |
115 // Creates an incognito copy of the pref service that shares most pref stores | |
116 // but uses a fresh non-persistent overlay for the user pref store and an | |
117 // individual extension pref store (to cache the effective extension prefs for | |
118 // incognito windows). | |
119 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); | |
120 | |
112 virtual ~PrefService(); | 121 virtual ~PrefService(); |
113 | 122 |
114 // Reloads the data from file. This should only be called when the importer | 123 // 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 | 124 // 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. | 125 // values while the importer process is running. Returns true on success. |
117 bool ReloadPersistentPrefs(); | 126 bool ReloadPersistentPrefs(); |
118 | 127 |
119 // Returns true if the preference for the given preference name is available | 128 // Returns true if the preference for the given preference name is available |
120 // and is managed. | 129 // and is managed. |
121 bool IsManagedPreference(const char* pref_name) const; | 130 bool IsManagedPreference(const char* pref_name) const; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 protected: | 233 protected: |
225 // Construct a new pref service, specifying the pref sources as explicit | 234 // Construct a new pref service, specifying the pref sources as explicit |
226 // PrefStore pointers. This constructor is what CreatePrefService() ends up | 235 // PrefStore pointers. This constructor is what CreatePrefService() ends up |
227 // calling. It's also used for unit tests. | 236 // calling. It's also used for unit tests. |
228 PrefService(PrefStore* managed_platform_prefs, | 237 PrefService(PrefStore* managed_platform_prefs, |
229 PrefStore* device_management_prefs, | 238 PrefStore* device_management_prefs, |
230 PrefStore* extension_prefs, | 239 PrefStore* extension_prefs, |
231 PrefStore* command_line_prefs, | 240 PrefStore* command_line_prefs, |
232 PersistentPrefStore* user_prefs, | 241 PersistentPrefStore* user_prefs, |
233 PrefStore* recommended_prefs, | 242 PrefStore* recommended_prefs, |
234 Profile* profile); | 243 DefaultPrefStore* default_store, |
244 Profile* profile, | |
245 bool init_from_storage); | |
235 | 246 |
236 // The PrefNotifier handles registering and notifying preference observers. | 247 // The PrefNotifier handles registering and notifying preference observers. |
237 // It is created and owned by this PrefService. Subclasses may access it for | 248 // It is created and owned by this PrefService. Subclasses may access it for |
238 // unit testing. | 249 // unit testing. |
239 scoped_ptr<PrefNotifierImpl> pref_notifier_; | 250 scoped_ptr<PrefNotifierImpl> pref_notifier_; |
240 | 251 |
241 private: | 252 private: |
242 friend class PrefServiceMockBuilder; | 253 friend class PrefServiceMockBuilder; |
243 | 254 |
244 // Registration of pref change observers must be done using the | 255 // Registration of pref change observers must be done using the |
(...skipping 21 matching lines...) Expand all Loading... | |
266 void SetUserPrefValue(const char* path, Value* new_value); | 277 void SetUserPrefValue(const char* path, Value* new_value); |
267 | 278 |
268 // Load preferences from storage, attempting to diagnose and handle errors. | 279 // Load preferences from storage, attempting to diagnose and handle errors. |
269 // This should only be called from the constructor. | 280 // This should only be called from the constructor. |
270 void InitFromStorage(); | 281 void InitFromStorage(); |
271 | 282 |
272 // The PrefValueStore provides prioritized preference values. It is created | 283 // The PrefValueStore provides prioritized preference values. It is created |
273 // and owned by this PrefService. Subclasses may access it for unit testing. | 284 // and owned by this PrefService. Subclasses may access it for unit testing. |
274 scoped_refptr<PrefValueStore> pref_value_store_; | 285 scoped_refptr<PrefValueStore> pref_value_store_; |
275 | 286 |
276 // The persistent pref store used for actual user data. | 287 // Pref Stores and profile that we passed to the PrefValueStore. |
277 PersistentPrefStore* user_pref_store_; | 288 scoped_refptr<PrefStore> managed_platform_prefs_; |
289 scoped_refptr<PrefStore> device_management_prefs_; | |
290 scoped_refptr<PrefStore> extension_prefs_; | |
291 scoped_refptr<PrefStore> command_line_prefs_; | |
292 scoped_refptr<PrefStore> recommended_prefs_; | |
293 scoped_refptr<PersistentPrefStore> user_pref_store_; | |
294 scoped_refptr<DefaultPrefStore> default_store_; | |
295 Profile* profile_; | |
278 | 296 |
279 // Points to the default pref store we passed to the PrefValueStore. | 297 // Local cache of registered Preference objects. The default_store_ |
280 DefaultPrefStore* default_store_; | 298 // is authoritative with respect to what the types and default values |
281 | 299 // of registered preferences are. |
282 // A set of all the registered Preference objects. | 300 mutable PreferenceSet prefs_; |
283 PreferenceSet prefs_; | |
284 | 301 |
285 DISALLOW_COPY_AND_ASSIGN(PrefService); | 302 DISALLOW_COPY_AND_ASSIGN(PrefService); |
286 }; | 303 }; |
287 | 304 |
288 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 305 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
OLD | NEW |