OLD | NEW |
---|---|
1 // Copyright (c) 2011 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 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 static PrefService* CreatePrefService(const FilePath& pref_filename, | 139 static PrefService* CreatePrefService(const FilePath& pref_filename, |
140 PrefStore* extension_pref_store, | 140 PrefStore* extension_pref_store, |
141 bool async); | 141 bool async); |
142 | 142 |
143 // Creates an incognito copy of the pref service that shares most pref stores | 143 // Creates an incognito copy of the pref service that shares most pref stores |
144 // but uses a fresh non-persistent overlay for the user pref store and an | 144 // but uses a fresh non-persistent overlay for the user pref store and an |
145 // individual extension pref store (to cache the effective extension prefs for | 145 // individual extension pref store (to cache the effective extension prefs for |
146 // incognito windows). | 146 // incognito windows). |
147 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); | 147 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); |
148 | 148 |
149 // Creates a per-tab copy of the pref service that shares most pref stores | |
150 // and allows WebKit-related preferences to be overridden on per-tab basis. | |
151 PrefService* CreatePrefServiceWithPerTabPrefStore(); | |
152 | |
149 virtual ~PrefService(); | 153 virtual ~PrefService(); |
150 | 154 |
151 // Reloads the data from file. This should only be called when the importer | 155 // Reloads the data from file. This should only be called when the importer |
152 // is running during first run, and the main process may not change pref | 156 // is running during first run, and the main process may not change pref |
153 // values while the importer process is running. Returns true on success. | 157 // values while the importer process is running. Returns true on success. |
154 bool ReloadPersistentPrefs(); | 158 bool ReloadPersistentPrefs(); |
155 | 159 |
156 // Returns true if the preference for the given preference name is available | 160 // Returns true if the preference for the given preference name is available |
157 // and is managed. | 161 // and is managed. |
158 bool IsManagedPreference(const char* pref_name) const; | 162 bool IsManagedPreference(const char* pref_name) const; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 // preference is not registered. | 294 // preference is not registered. |
291 const Preference* FindPreference(const char* pref_name) const; | 295 const Preference* FindPreference(const char* pref_name) const; |
292 | 296 |
293 bool ReadOnly() const; | 297 bool ReadOnly() const; |
294 | 298 |
295 // SyncableService getter. | 299 // SyncableService getter. |
296 // TODO(zea): Have PrefService implement SyncableService directly. | 300 // TODO(zea): Have PrefService implement SyncableService directly. |
297 SyncableService* GetSyncableService(); | 301 SyncableService* GetSyncableService(); |
298 | 302 |
299 protected: | 303 protected: |
300 // Construct a new pref service, specifying the pref sources as explicit | 304 // Construct a new pref service. This constructor is what |
301 // PrefStore pointers. This constructor is what CreatePrefService() ends up | 305 // CreatePrefService() ends up calling and what is used for unit tests. |
302 // calling. It's also used for unit tests. | |
303 PrefService(PrefStore* managed_platform_prefs, | 306 PrefService(PrefStore* managed_platform_prefs, |
304 PrefStore* managed_cloud_prefs, | 307 PrefStore* managed_cloud_prefs, |
305 PrefStore* extension_prefs, | 308 PrefStore* extension_prefs, |
306 PrefStore* command_line_prefs, | 309 PrefStore* command_line_prefs, |
307 PersistentPrefStore* user_prefs, | 310 PersistentPrefStore* user_prefs, |
308 PrefStore* recommended_platform_prefs, | 311 PrefStore* recommended_platform_prefs, |
309 PrefStore* recommended_cloud_prefs, | 312 PrefStore* recommended_cloud_prefs, |
310 DefaultPrefStore* default_store, | |
311 bool async); | 313 bool async); |
312 | 314 |
313 // The PrefNotifier handles registering and notifying preference observers. | 315 // An overloaded version that clones and specializes value store. |
314 // It is created and owned by this PrefService. Subclasses may access it for | 316 // Used for CreateIncognito and Create...PerTabPrefStore. |
315 // unit testing. | 317 PrefService(PrefValueStore* source_store, |
316 scoped_ptr<PrefNotifierImpl> pref_notifier_; | 318 PrefStore* managed_platform_prefs, |
319 PrefStore* managed_cloud_prefs, | |
320 PrefStore* extension_prefs, | |
321 PrefStore* command_line_prefs, | |
322 PersistentPrefStore* user_prefs, | |
323 PrefStore* recommended_platform_prefs, | |
324 PrefStore* recommended_cloud_prefs, | |
325 DefaultPrefStore* default_store); | |
Mattias Nissler (ping if slow)
2011/11/17 20:08:13
Oh, I had totally missed that there's now a second
mnaganov (inactive)
2011/11/18 11:20:45
The difference between them is that the first one
mnaganov (inactive)
2011/11/18 11:24:48
In theory, we can exploit multiple inheritance her
Mattias Nissler (ping if slow)
2011/11/18 12:01:37
Ah, I remember :) TestingPrefServiceBase was origi
mnaganov (inactive)
2011/11/18 14:35:05
I have discovered a nice trick that in constructor
| |
317 | 326 |
318 private: | 327 private: |
319 class PreferencePathComparator { | 328 class PreferencePathComparator { |
320 public: | 329 public: |
321 bool operator() (Preference* lhs, Preference* rhs) const { | 330 bool operator() (Preference* lhs, Preference* rhs) const { |
322 return lhs->name() < rhs->name(); | 331 return lhs->name() < rhs->name(); |
323 } | 332 } |
324 }; | 333 }; |
325 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet; | 334 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet; |
326 | 335 |
327 friend class PrefServiceMockBuilder; | 336 friend class PrefServiceMockBuilder; |
328 | 337 |
329 // Registration of pref change observers must be done using the | 338 // Registration of pref change observers must be done using the |
330 // PrefChangeRegistrar, which is declared as a friend here to grant it | 339 // PrefChangeRegistrar, which is declared as a friend here to grant it |
331 // access to the otherwise protected members Add/RemovePrefObserver. | 340 // access to the otherwise protected members Add/RemovePrefObserver. |
332 // PrefMember registers for preferences changes notification directly to | 341 // PrefMember registers for preferences changes notification directly to |
333 // avoid the storage overhead of the registrar, so its base class must be | 342 // avoid the storage overhead of the registrar, so its base class must be |
334 // declared as a friend, too. | 343 // declared as a friend, too. |
335 friend class PrefChangeRegistrar; | 344 friend class PrefChangeRegistrar; |
336 friend class subtle::PrefMemberBase; | 345 friend class subtle::PrefMemberBase; |
337 | 346 |
338 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). | 347 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). |
339 friend class subtle::ScopedUserPrefUpdateBase; | 348 friend class subtle::ScopedUserPrefUpdateBase; |
340 | 349 |
341 // Construct an incognito version of the pref service. Use | |
342 // CreateIncognitoPrefService() instead of calling this constructor directly. | |
343 PrefService(const PrefService& original, | |
344 PrefStore* incognito_extension_prefs); | |
345 | |
346 // Sends notification of a changed preference. This needs to be called by | 350 // Sends notification of a changed preference. This needs to be called by |
347 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. | 351 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. |
348 void ReportUserPrefChanged(const std::string& key); | 352 void ReportUserPrefChanged(const std::string& key); |
349 | 353 |
350 // If the pref at the given path changes, we call the observer's Observe | 354 // If the pref at the given path changes, we call the observer's Observe |
351 // method with PREF_CHANGED. Note that observers should not call these methods | 355 // method with PREF_CHANGED. Note that observers should not call these methods |
352 // directly but rather use a PrefChangeRegistrar to make sure the observer | 356 // directly but rather use a PrefChangeRegistrar to make sure the observer |
353 // gets cleaned up properly. | 357 // gets cleaned up properly. |
354 virtual void AddPrefObserver(const char* path, | 358 virtual void AddPrefObserver(const char* path, |
355 content::NotificationObserver* obs); | 359 content::NotificationObserver* obs); |
(...skipping 19 matching lines...) Expand all Loading... | |
375 // Used to set the value of dictionary or list values in the user pref store. | 379 // Used to set the value of dictionary or list values in the user pref store. |
376 // This will create a dictionary or list if one does not exist in the user | 380 // This will create a dictionary or list if one does not exist in the user |
377 // pref store. This method returns NULL only if you're requesting an | 381 // pref store. This method returns NULL only if you're requesting an |
378 // unregistered pref or a non-dict/non-list pref. | 382 // unregistered pref or a non-dict/non-list pref. |
379 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and | 383 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and |
380 // |path| must point to a registered preference of type |type|. | 384 // |path| must point to a registered preference of type |type|. |
381 // Ownership of the returned value remains at the user pref store. | 385 // Ownership of the returned value remains at the user pref store. |
382 base::Value* GetMutableUserPref(const char* path, | 386 base::Value* GetMutableUserPref(const char* path, |
383 base::Value::Type type); | 387 base::Value::Type type); |
384 | 388 |
385 // The PrefValueStore provides prioritized preference values. It is created | 389 // The PrefNotifier handles registering and notifying preference observers. |
386 // and owned by this PrefService. Subclasses may access it for unit testing. | 390 // It is created and owned by this PrefService. |
387 scoped_ptr<PrefValueStore> pref_value_store_; | 391 scoped_ptr<PrefNotifierImpl> pref_notifier_; |
388 | 392 |
389 // Pref Stores and profile that we passed to the PrefValueStore. | 393 // Pref Stores and profile that we passed to the PrefValueStore. |
390 scoped_refptr<PersistentPrefStore> user_pref_store_; | 394 scoped_refptr<PersistentPrefStore> user_pref_store_; |
391 scoped_refptr<DefaultPrefStore> default_store_; | 395 scoped_refptr<DefaultPrefStore> default_store_; |
392 | 396 |
393 // Local cache of registered Preference objects. The default_store_ | 397 // Local cache of registered Preference objects. The default_store_ |
394 // is authoritative with respect to what the types and default values | 398 // is authoritative with respect to what the types and default values |
395 // of registered preferences are. | 399 // of registered preferences are. |
396 mutable PreferenceSet prefs_; | 400 mutable PreferenceSet prefs_; |
397 | 401 |
398 // The model associator that maintains the links with the sync db. | 402 // The model associator that maintains the links with the sync db. |
399 scoped_ptr<PrefModelAssociator> pref_sync_associator_; | 403 scoped_ptr<PrefModelAssociator> pref_sync_associator_; |
400 | 404 |
405 // The PrefValueStore provides prioritized preference values. It is created | |
406 // and owned by this PrefService. Subclasses may access it for unit testing. | |
407 scoped_ptr<PrefValueStore> pref_value_store_; | |
408 | |
401 DISALLOW_COPY_AND_ASSIGN(PrefService); | 409 DISALLOW_COPY_AND_ASSIGN(PrefService); |
402 }; | 410 }; |
403 | 411 |
404 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 412 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
OLD | NEW |