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 |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/non_thread_safe.h" | 14 #include "base/non_thread_safe.h" |
15 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
16 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/common/pref_store.h" | 18 #include "chrome/common/pref_store.h" |
19 | 19 |
20 class DefaultPrefStore; | |
20 class FilePath; | 21 class FilePath; |
21 class NotificationObserver; | 22 class NotificationObserver; |
22 class PrefChangeObserver; | 23 class PrefChangeObserver; |
23 class PrefNotifier; | 24 class PrefNotifier; |
24 class PrefValueStore; | 25 class PrefValueStore; |
25 class Profile; | 26 class Profile; |
26 | 27 |
27 namespace subtle { | 28 namespace subtle { |
28 class PrefMemberBase; | 29 class PrefMemberBase; |
29 }; | 30 }; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 friend class PrefService; | 89 friend class PrefService; |
89 | 90 |
90 std::string name_; | 91 std::string name_; |
91 | 92 |
92 // Reference to the PrefService in which this pref was created. | 93 // Reference to the PrefService in which this pref was created. |
93 const PrefService* pref_service_; | 94 const PrefService* pref_service_; |
94 | 95 |
95 DISALLOW_COPY_AND_ASSIGN(Preference); | 96 DISALLOW_COPY_AND_ASSIGN(Preference); |
96 }; | 97 }; |
97 | 98 |
98 // Factory method that creates a new instance of a PrefService with | 99 // Factory method that creates a new instance of a PrefService with the |
99 // a PrefValueStore containing all platform-applicable PrefStores. | 100 // applicable PrefStores. The |pref_filename| points to the user preference |
100 // The |pref_filename| points to the user preference file. The |profile| is | 101 // file. The |profile| is the one to which these preferences apply; it may be |
101 // the one to which these preferences apply; it may be NULL if we're dealing | 102 // NULL if we're dealing with the local state. This is the usual way to create |
102 // with the local state. This is the usual way to create a new PrefService. | 103 // a new PrefService. |
103 static PrefService* CreatePrefService(const FilePath& pref_filename, | 104 static PrefService* CreatePrefService(const FilePath& pref_filename, |
104 Profile* profile); | 105 Profile* profile); |
105 | 106 |
106 // Convenience factory method for use in unit tests. Creates a new | 107 // Convenience factory method for use in unit tests. Creates a new |
107 // PrefService that uses a PrefValueStore with user preferences at the given | 108 // PrefService that uses a PrefValueStore with user preferences at the given |
108 // |pref_filename|, a default PrefStore, and no other PrefStores (i.e., no | 109 // |pref_filename|, a default PrefStore, and no other PrefStores (i.e., no |
109 // other types of preferences). | 110 // other types of preferences). |
110 static PrefService* CreateUserPrefService(const FilePath& pref_filename); | 111 static PrefService* CreateUserPrefService(const FilePath& pref_filename); |
111 | 112 |
112 // This constructor is primarily used by tests. The |pref_value_store| | 113 // Construct a new pref service, specifying the pref sources as explicit |
113 // provides preference values. | 114 // PrefStore pointers. This constructor is what CreatePrefService() ends up |
114 explicit PrefService(PrefValueStore* pref_value_store); | 115 // calling. It's also used for unit tests. |
116 PrefService(PrefStore* managed_platform_prefs, | |
117 PrefStore* device_management_prefs, | |
118 PrefStore* extension_prefs, | |
119 PrefStore* command_line_prefs, | |
120 PrefStore* user_prefs, | |
121 PrefStore* recommended_prefs, | |
122 Profile* profile); | |
danno
2010/12/02 10:31:52
How about making this protected and the testingpre
Mattias Nissler (ping if slow)
2010/12/02 16:38:24
Done.
| |
115 | 123 |
116 virtual ~PrefService(); | 124 virtual ~PrefService(); |
117 | 125 |
118 // Reloads the data from file. This should only be called when the importer | 126 // Reloads the data from file. This should only be called when the importer |
119 // is running during first run, and the main process may not change pref | 127 // is running during first run, and the main process may not change pref |
120 // values while the importer process is running. Returns true on success. | 128 // values while the importer process is running. Returns true on success. |
121 bool ReloadPersistentPrefs(); | 129 bool ReloadPersistentPrefs(); |
122 | 130 |
123 // Returns true if the preference for the given preference name is available | 131 // Returns true if the preference for the given preference name is available |
124 // and is managed. | 132 // and is managed. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 }; | 222 }; |
215 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet; | 223 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet; |
216 const PreferenceSet& preference_set() const { return prefs_; } | 224 const PreferenceSet& preference_set() const { return prefs_; } |
217 | 225 |
218 // A helper method to quickly look up a preference. Returns NULL if the | 226 // A helper method to quickly look up a preference. Returns NULL if the |
219 // preference is not registered. | 227 // preference is not registered. |
220 const Preference* FindPreference(const char* pref_name) const; | 228 const Preference* FindPreference(const char* pref_name) const; |
221 | 229 |
222 bool ReadOnly() const; | 230 bool ReadOnly() const; |
223 | 231 |
224 PrefNotifier* pref_notifier() const { return pref_notifier_.get(); } | 232 // TODO(mnissler): This should not be public. Change client code to call a |
225 | 233 // preference setter or use ScopedPrefUpdate. |
226 PrefValueStore* pref_value_store() const { return pref_value_store_.get(); } | 234 PrefNotifier* pref_notifier() const; |
227 | 235 |
228 protected: | 236 protected: |
229 // The PrefNotifier handles registering and notifying preference observers. | 237 // The PrefNotifier handles registering and notifying preference observers. |
230 // It is created and owned by this PrefService. Subclasses may access it for | 238 // It is created and owned by this PrefService. Subclasses may access it for |
231 // unit testing. | 239 // unit testing. |
232 scoped_ptr<PrefNotifier> pref_notifier_; | 240 scoped_ptr<PrefNotifier> pref_notifier_; |
233 | 241 |
234 private: | 242 private: |
235 // Registration of pref change observers must be done using the | 243 // Registration of pref change observers must be done using the |
236 // PrefChangeRegistrar, which is declared as a friend here to grant it | 244 // PrefChangeRegistrar, which is declared as a friend here to grant it |
(...skipping 27 matching lines...) Expand all Loading... | |
264 PrefStore::PrefReadError LoadPersistentPrefs(); | 272 PrefStore::PrefReadError LoadPersistentPrefs(); |
265 | 273 |
266 // Load preferences from storage, attempting to diagnose and handle errors. | 274 // Load preferences from storage, attempting to diagnose and handle errors. |
267 // This should only be called from the constructor. | 275 // This should only be called from the constructor. |
268 void InitFromStorage(); | 276 void InitFromStorage(); |
269 | 277 |
270 // The PrefValueStore provides prioritized preference values. It is created | 278 // The PrefValueStore provides prioritized preference values. It is created |
271 // and owned by this PrefService. Subclasses may access it for unit testing. | 279 // and owned by this PrefService. Subclasses may access it for unit testing. |
272 scoped_refptr<PrefValueStore> pref_value_store_; | 280 scoped_refptr<PrefValueStore> pref_value_store_; |
273 | 281 |
282 // Points to the default pref store we passed to the PrefValueStore. | |
283 DefaultPrefStore* default_store_; | |
284 | |
274 // A set of all the registered Preference objects. | 285 // A set of all the registered Preference objects. |
275 PreferenceSet prefs_; | 286 PreferenceSet prefs_; |
276 | 287 |
277 DISALLOW_COPY_AND_ASSIGN(PrefService); | 288 DISALLOW_COPY_AND_ASSIGN(PrefService); |
278 }; | 289 }; |
279 | 290 |
280 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 291 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
OLD | NEW |