Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: chrome/browser/prefs/pref_service.h

Issue 5441002: Clean up pref change notification handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix extension prefs breakage Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/prefs/pref_observer_mock.h ('k') | chrome/browser/prefs/pref_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
25 class PrefNotifierImpl;
24 class PrefValueStore; 26 class PrefValueStore;
25 class Profile; 27 class Profile;
26 28
27 namespace subtle { 29 namespace subtle {
28 class PrefMemberBase; 30 class PrefMemberBase;
29 }; 31 };
30 32
31 class PrefService : public NonThreadSafe { 33 class PrefService : public NonThreadSafe {
32 public: 34 public:
33 // A helper class to store all the information associated with a preference. 35 // A helper class to store all the information associated with a preference.
34 class Preference { 36 class Preference {
35 public: 37 public:
36 38
37 // The type of the preference is determined by the type with which it is 39 // The type of the preference is determined by the type with which it is
38 // registered. This type needs to be a boolean, integer, real, string, 40 // registered. This type needs to be a boolean, integer, real, string,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 friend class PrefService; 90 friend class PrefService;
89 91
90 std::string name_; 92 std::string name_;
91 93
92 // Reference to the PrefService in which this pref was created. 94 // Reference to the PrefService in which this pref was created.
93 const PrefService* pref_service_; 95 const PrefService* pref_service_;
94 96
95 DISALLOW_COPY_AND_ASSIGN(Preference); 97 DISALLOW_COPY_AND_ASSIGN(Preference);
96 }; 98 };
97 99
98 // Factory method that creates a new instance of a PrefService with 100 // Factory method that creates a new instance of a PrefService with the
99 // a PrefValueStore containing all platform-applicable PrefStores. 101 // applicable PrefStores. The |pref_filename| points to the user preference
100 // The |pref_filename| points to the user preference file. The |profile| is 102 // 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 103 // 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. 104 // a new PrefService.
103 static PrefService* CreatePrefService(const FilePath& pref_filename, 105 static PrefService* CreatePrefService(const FilePath& pref_filename,
104 Profile* profile); 106 Profile* profile);
105 107
106 // Convenience factory method for use in unit tests. Creates a new 108 // Convenience factory method for use in unit tests. Creates a new
107 // PrefService that uses a PrefValueStore with user preferences at the given 109 // PrefService that uses a PrefValueStore with user preferences at the given
108 // |pref_filename|, a default PrefStore, and no other PrefStores (i.e., no 110 // |pref_filename|, a default PrefStore, and no other PrefStores (i.e., no
109 // other types of preferences). 111 // other types of preferences).
110 static PrefService* CreateUserPrefService(const FilePath& pref_filename); 112 static PrefService* CreateUserPrefService(const FilePath& pref_filename);
111 113
112 // This constructor is primarily used by tests. The |pref_value_store|
113 // provides preference values.
114 explicit PrefService(PrefValueStore* pref_value_store);
115
116 virtual ~PrefService(); 114 virtual ~PrefService();
117 115
118 // Reloads the data from file. This should only be called when the importer 116 // 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 117 // 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. 118 // values while the importer process is running. Returns true on success.
121 bool ReloadPersistentPrefs(); 119 bool ReloadPersistentPrefs();
122 120
123 // Returns true if the preference for the given preference name is available 121 // Returns true if the preference for the given preference name is available
124 // and is managed. 122 // and is managed.
125 bool IsManagedPreference(const char* pref_name) const; 123 bool IsManagedPreference(const char* pref_name) const;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 }; 212 };
215 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet; 213 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet;
216 const PreferenceSet& preference_set() const { return prefs_; } 214 const PreferenceSet& preference_set() const { return prefs_; }
217 215
218 // A helper method to quickly look up a preference. Returns NULL if the 216 // A helper method to quickly look up a preference. Returns NULL if the
219 // preference is not registered. 217 // preference is not registered.
220 const Preference* FindPreference(const char* pref_name) const; 218 const Preference* FindPreference(const char* pref_name) const;
221 219
222 bool ReadOnly() const; 220 bool ReadOnly() const;
223 221
224 PrefNotifier* pref_notifier() const { return pref_notifier_.get(); } 222 // TODO(mnissler): This should not be public. Change client code to call a
223 // preference setter or use ScopedPrefUpdate.
224 PrefNotifier* pref_notifier() const;
225 225
226 PrefValueStore* pref_value_store() const { return pref_value_store_.get(); } 226 // Get the extension PrefStore.
227 227 PrefStore* GetExtensionPrefStore();
228 PrefStore* GetExtensionPrefStore() const;
229 228
230 protected: 229 protected:
230 // Construct a new pref service, specifying the pref sources as explicit
231 // PrefStore pointers. This constructor is what CreatePrefService() ends up
232 // calling. It's also used for unit tests.
233 PrefService(PrefStore* managed_platform_prefs,
234 PrefStore* device_management_prefs,
235 PrefStore* extension_prefs,
236 PrefStore* command_line_prefs,
237 PrefStore* user_prefs,
238 PrefStore* recommended_prefs,
239 Profile* profile);
240
231 // The PrefNotifier handles registering and notifying preference observers. 241 // The PrefNotifier handles registering and notifying preference observers.
232 // It is created and owned by this PrefService. Subclasses may access it for 242 // It is created and owned by this PrefService. Subclasses may access it for
233 // unit testing. 243 // unit testing.
234 scoped_ptr<PrefNotifier> pref_notifier_; 244 scoped_ptr<PrefNotifierImpl> pref_notifier_;
235 245
236 private: 246 private:
247 friend class TestingPrefService;
248
237 // Registration of pref change observers must be done using the 249 // Registration of pref change observers must be done using the
238 // PrefChangeRegistrar, which is declared as a friend here to grant it 250 // PrefChangeRegistrar, which is declared as a friend here to grant it
239 // access to the otherwise protected members Add/RemovePrefObserver. 251 // access to the otherwise protected members Add/RemovePrefObserver.
240 // PrefMember registers for preferences changes notification directly to 252 // PrefMember registers for preferences changes notification directly to
241 // avoid the storage overhead of the registrar, so its base class must be 253 // avoid the storage overhead of the registrar, so its base class must be
242 // declared as a friend, too. 254 // declared as a friend, too.
243 friend class PrefChangeRegistrar; 255 friend class PrefChangeRegistrar;
244 friend class subtle::PrefMemberBase; 256 friend class subtle::PrefMemberBase;
245 257
246 // If the pref at the given path changes, we call the observer's Observe 258 // If the pref at the given path changes, we call the observer's Observe
(...skipping 19 matching lines...) Expand all
266 PrefStore::PrefReadError LoadPersistentPrefs(); 278 PrefStore::PrefReadError LoadPersistentPrefs();
267 279
268 // Load preferences from storage, attempting to diagnose and handle errors. 280 // Load preferences from storage, attempting to diagnose and handle errors.
269 // This should only be called from the constructor. 281 // This should only be called from the constructor.
270 void InitFromStorage(); 282 void InitFromStorage();
271 283
272 // The PrefValueStore provides prioritized preference values. It is created 284 // The PrefValueStore provides prioritized preference values. It is created
273 // and owned by this PrefService. Subclasses may access it for unit testing. 285 // and owned by this PrefService. Subclasses may access it for unit testing.
274 scoped_refptr<PrefValueStore> pref_value_store_; 286 scoped_refptr<PrefValueStore> pref_value_store_;
275 287
288 // The extension pref store registered with the PrefValueStore.
289 PrefStore* extension_store_;
290
291 // Points to the default pref store we passed to the PrefValueStore.
292 PrefStore* default_store_;
293
276 // A set of all the registered Preference objects. 294 // A set of all the registered Preference objects.
277 PreferenceSet prefs_; 295 PreferenceSet prefs_;
278 296
279 DISALLOW_COPY_AND_ASSIGN(PrefService); 297 DISALLOW_COPY_AND_ASSIGN(PrefService);
280 }; 298 };
281 299
282 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ 300 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_observer_mock.h ('k') | chrome/browser/prefs/pref_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698