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

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

Issue 5915004: Introduce incognito preference settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits and crasher on Mac Created 9 years, 11 months 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) 2011 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>
(...skipping 23 matching lines...) Expand all
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
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 232
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,
243 DefaultPrefStore* default_store);
244
245 // Construct an incognito version of the pref service. Use
246 // CreateIncognitoPrefService() instead of calling this constructor directly.
247 PrefService(const PrefService& original,
248 PrefStore* incognito_extension_prefs);
Mattias Nissler (ping if slow) 2011/01/21 08:53:08 can this be private?
battre 2011/01/24 17:47:18 Done.
234 249
235 // The PrefNotifier handles registering and notifying preference observers. 250 // The PrefNotifier handles registering and notifying preference observers.
236 // It is created and owned by this PrefService. Subclasses may access it for 251 // It is created and owned by this PrefService. Subclasses may access it for
237 // unit testing. 252 // unit testing.
238 scoped_ptr<PrefNotifierImpl> pref_notifier_; 253 scoped_ptr<PrefNotifierImpl> pref_notifier_;
239 254
240 private: 255 private:
241 friend class PrefServiceMockBuilder; 256 friend class PrefServiceMockBuilder;
242 257
243 // Registration of pref change observers must be done using the 258 // Registration of pref change observers must be done using the
(...skipping 21 matching lines...) Expand all
265 void SetUserPrefValue(const char* path, Value* new_value); 280 void SetUserPrefValue(const char* path, Value* new_value);
266 281
267 // Load preferences from storage, attempting to diagnose and handle errors. 282 // Load preferences from storage, attempting to diagnose and handle errors.
268 // This should only be called from the constructor. 283 // This should only be called from the constructor.
269 void InitFromStorage(); 284 void InitFromStorage();
270 285
271 // The PrefValueStore provides prioritized preference values. It is created 286 // The PrefValueStore provides prioritized preference values. It is created
272 // and owned by this PrefService. Subclasses may access it for unit testing. 287 // and owned by this PrefService. Subclasses may access it for unit testing.
273 scoped_refptr<PrefValueStore> pref_value_store_; 288 scoped_refptr<PrefValueStore> pref_value_store_;
274 289
275 // The persistent pref store used for actual user data. 290 // Pref Stores and profile that we passed to the PrefValueStore.
276 PersistentPrefStore* user_pref_store_; 291 scoped_refptr<PersistentPrefStore> user_pref_store_;
292 scoped_refptr<DefaultPrefStore> default_store_;
277 293
278 // Points to the default pref store we passed to the PrefValueStore. 294 // Local cache of registered Preference objects. The default_store_
279 DefaultPrefStore* default_store_; 295 // is authoritative with respect to what the types and default values
280 296 // of registered preferences are.
281 // A set of all the registered Preference objects. 297 mutable PreferenceSet prefs_;
282 PreferenceSet prefs_;
283 298
284 DISALLOW_COPY_AND_ASSIGN(PrefService); 299 DISALLOW_COPY_AND_ASSIGN(PrefService);
285 }; 300 };
286 301
287 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ 302 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698