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

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

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, fix up unit tests. 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
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"
19 18
20 class DefaultPrefStore; 19 class DefaultPrefStore;
21 class FilePath; 20 class FilePath;
22 class NotificationObserver; 21 class NotificationObserver;
22 class PersistentPrefStore;
23 class PrefChangeObserver; 23 class PrefChangeObserver;
24 class PrefNotifier; 24 class PrefNotifier;
25 class PrefNotifierImpl; 25 class PrefNotifierImpl;
26 class PrefStore;
26 class PrefValueStore; 27 class PrefValueStore;
27 class Profile; 28 class Profile;
28 29
29 namespace subtle { 30 namespace subtle {
30 class PrefMemberBase; 31 class PrefMemberBase;
31 }; 32 };
32 33
33 class PrefService : public NonThreadSafe { 34 class PrefService : public NonThreadSafe {
34 public: 35 public:
35 // 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.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Reference to the PrefService in which this pref was created. 95 // Reference to the PrefService in which this pref was created.
95 const PrefService* pref_service_; 96 const PrefService* pref_service_;
96 97
97 DISALLOW_COPY_AND_ASSIGN(Preference); 98 DISALLOW_COPY_AND_ASSIGN(Preference);
98 }; 99 };
99 100
100 // Factory method that creates a new instance of a PrefService with the 101 // Factory method that creates a new instance of a PrefService with the
101 // applicable PrefStores. The |pref_filename| points to the user preference 102 // applicable PrefStores. The |pref_filename| points to the user preference
102 // file. The |profile| is the one to which these preferences apply; it may be 103 // file. The |profile| is the one to which these preferences apply; it may be
103 // NULL if we're dealing with the local state. This is the usual way to create 104 // NULL if we're dealing with the local state. This is the usual way to create
104 // a new PrefService. 105 // a new PrefService. |extension_pref_store| is used as the source for
106 // extension-controlled preferences and may be NULL. The PrefService takes
107 // ownership of |extension_pref_store|.
105 static PrefService* CreatePrefService(const FilePath& pref_filename, 108 static PrefService* CreatePrefService(const FilePath& pref_filename,
109 PrefStore* extension_pref_store,
106 Profile* profile); 110 Profile* profile);
107 111
108 // Convenience factory method for use in unit tests. Creates a new 112 // Convenience factory method for use in unit tests. Creates a new
109 // PrefService that uses a PrefValueStore with user preferences at the given 113 // PrefService that uses a PrefValueStore with user preferences at the given
110 // |pref_filename|, a default PrefStore, and no other PrefStores (i.e., no 114 // |pref_filename|, a default PrefStore, and no other PrefStores (i.e., no
111 // other types of preferences). 115 // other types of preferences).
112 static PrefService* CreateUserPrefService(const FilePath& pref_filename); 116 static PrefService* CreateUserPrefService(const FilePath& pref_filename);
113 117
114 virtual ~PrefService(); 118 virtual ~PrefService();
115 119
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // A helper method to quickly look up a preference. Returns NULL if the 220 // A helper method to quickly look up a preference. Returns NULL if the
217 // preference is not registered. 221 // preference is not registered.
218 const Preference* FindPreference(const char* pref_name) const; 222 const Preference* FindPreference(const char* pref_name) const;
219 223
220 bool ReadOnly() const; 224 bool ReadOnly() const;
221 225
222 // TODO(mnissler): This should not be public. Change client code to call a 226 // TODO(mnissler): This should not be public. Change client code to call a
223 // preference setter or use ScopedPrefUpdate. 227 // preference setter or use ScopedPrefUpdate.
224 PrefNotifier* pref_notifier() const; 228 PrefNotifier* pref_notifier() const;
225 229
226 // Get the extension PrefStore.
227 PrefStore* GetExtensionPrefStore();
228
229 protected: 230 protected:
230 // Construct a new pref service, specifying the pref sources as explicit 231 // Construct a new pref service, specifying the pref sources as explicit
231 // PrefStore pointers. This constructor is what CreatePrefService() ends up 232 // PrefStore pointers. This constructor is what CreatePrefService() ends up
232 // calling. It's also used for unit tests. 233 // calling. It's also used for unit tests.
233 PrefService(PrefStore* managed_platform_prefs, 234 PrefService(PrefStore* managed_platform_prefs,
234 PrefStore* device_management_prefs, 235 PrefStore* device_management_prefs,
235 PrefStore* extension_prefs, 236 PrefStore* extension_prefs,
236 PrefStore* command_line_prefs, 237 PrefStore* command_line_prefs,
237 PrefStore* user_prefs, 238 PersistentPrefStore* user_prefs,
238 PrefStore* recommended_prefs, 239 PrefStore* recommended_prefs,
239 Profile* profile); 240 Profile* profile);
240 241
241 // The PrefNotifier handles registering and notifying preference observers. 242 // The PrefNotifier handles registering and notifying preference observers.
242 // It is created and owned by this PrefService. Subclasses may access it for 243 // It is created and owned by this PrefService. Subclasses may access it for
243 // unit testing. 244 // unit testing.
244 scoped_ptr<PrefNotifierImpl> pref_notifier_; 245 scoped_ptr<PrefNotifierImpl> pref_notifier_;
245 246
246 private: 247 private:
247 friend class TestingPrefService; 248 friend class TestingPrefService;
(...skipping 11 matching lines...) Expand all
259 // method with PREF_CHANGED. Note that observers should not call these methods 260 // method with PREF_CHANGED. Note that observers should not call these methods
260 // directly but rather use a PrefChangeRegistrar to make sure the observer 261 // directly but rather use a PrefChangeRegistrar to make sure the observer
261 // gets cleaned up properly. 262 // gets cleaned up properly.
262 virtual void AddPrefObserver(const char* path, NotificationObserver* obs); 263 virtual void AddPrefObserver(const char* path, NotificationObserver* obs);
263 virtual void RemovePrefObserver(const char* path, NotificationObserver* obs); 264 virtual void RemovePrefObserver(const char* path, NotificationObserver* obs);
264 265
265 // Add a preference to the PreferenceMap. If the pref already exists, return 266 // Add a preference to the PreferenceMap. If the pref already exists, return
266 // false. This method takes ownership of |default_value|. 267 // false. This method takes ownership of |default_value|.
267 void RegisterPreference(const char* path, Value* default_value); 268 void RegisterPreference(const char* path, Value* default_value);
268 269
269 // Returns a copy of the current pref value. The caller is responsible for
270 // deleting the returned object.
271 Value* GetPrefCopy(const char* pref_name);
272
273 // Sets the value for this pref path in the user pref store and informs the 270 // Sets the value for this pref path in the user pref store and informs the
274 // PrefNotifier of the change. 271 // PrefNotifier of the change.
275 void SetUserPrefValue(const char* path, Value* new_value); 272 void SetUserPrefValue(const char* path, Value* new_value);
276 273
277 // Load from disk. Returns a non-zero error code on failure.
278 PrefStore::PrefReadError LoadPersistentPrefs();
279
280 // Load preferences from storage, attempting to diagnose and handle errors. 274 // Load preferences from storage, attempting to diagnose and handle errors.
281 // This should only be called from the constructor. 275 // This should only be called from the constructor.
282 void InitFromStorage(); 276 void InitFromStorage();
283 277
284 // The PrefValueStore provides prioritized preference values. It is created 278 // The PrefValueStore provides prioritized preference values. It is created
285 // 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.
286 scoped_refptr<PrefValueStore> pref_value_store_; 280 scoped_refptr<PrefValueStore> pref_value_store_;
287 281
288 // The extension pref store registered with the PrefValueStore. 282 // The persistent pref store used for actual user data.
289 PrefStore* extension_store_; 283 PersistentPrefStore* user_pref_store_;
290 284
291 // Points to the default pref store we passed to the PrefValueStore. 285 // Points to the default pref store we passed to the PrefValueStore.
292 PrefStore* default_store_; 286 DefaultPrefStore* default_store_;
293 287
294 // A set of all the registered Preference objects. 288 // A set of all the registered Preference objects.
295 PreferenceSet prefs_; 289 PreferenceSet prefs_;
296 290
297 DISALLOW_COPY_AND_ASSIGN(PrefService); 291 DISALLOW_COPY_AND_ASSIGN(PrefService);
298 }; 292 };
299 293
300 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ 294 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698