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 // factory methods end up calling and what is used for unit tests. |
302 // calling. It's also used for unit tests. | 306 PrefService(PrefNotifierImpl* pref_notifier, |
303 PrefService(PrefStore* managed_platform_prefs, | 307 PrefValueStore* pref_value_store, |
304 PrefStore* managed_cloud_prefs, | |
305 PrefStore* extension_prefs, | |
306 PrefStore* command_line_prefs, | |
307 PersistentPrefStore* user_prefs, | 308 PersistentPrefStore* user_prefs, |
308 PrefStore* recommended_platform_prefs, | |
309 PrefStore* recommended_cloud_prefs, | |
310 DefaultPrefStore* default_store, | 309 DefaultPrefStore* default_store, |
| 310 PrefModelAssociator* pref_sync_associator, |
311 bool async); | 311 bool async); |
312 | 312 |
313 // The PrefNotifier handles registering and notifying preference observers. | 313 // The PrefNotifier handles registering and notifying preference observers. |
314 // It is created and owned by this PrefService. Subclasses may access it for | 314 // It is created and owned by this PrefService. Subclasses may access it for |
315 // unit testing. | 315 // unit testing. |
316 scoped_ptr<PrefNotifierImpl> pref_notifier_; | 316 scoped_ptr<PrefNotifierImpl> pref_notifier_; |
317 | 317 |
318 private: | 318 private: |
319 class PreferencePathComparator { | 319 class PreferencePathComparator { |
320 public: | 320 public: |
(...skipping 10 matching lines...) Expand all Loading... |
331 // access to the otherwise protected members Add/RemovePrefObserver. | 331 // access to the otherwise protected members Add/RemovePrefObserver. |
332 // PrefMember registers for preferences changes notification directly to | 332 // PrefMember registers for preferences changes notification directly to |
333 // avoid the storage overhead of the registrar, so its base class must be | 333 // avoid the storage overhead of the registrar, so its base class must be |
334 // declared as a friend, too. | 334 // declared as a friend, too. |
335 friend class PrefChangeRegistrar; | 335 friend class PrefChangeRegistrar; |
336 friend class subtle::PrefMemberBase; | 336 friend class subtle::PrefMemberBase; |
337 | 337 |
338 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). | 338 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). |
339 friend class subtle::ScopedUserPrefUpdateBase; | 339 friend class subtle::ScopedUserPrefUpdateBase; |
340 | 340 |
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 | 341 // Sends notification of a changed preference. This needs to be called by |
347 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. | 342 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. |
348 void ReportUserPrefChanged(const std::string& key); | 343 void ReportUserPrefChanged(const std::string& key); |
349 | 344 |
350 // If the pref at the given path changes, we call the observer's Observe | 345 // 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 | 346 // method with PREF_CHANGED. Note that observers should not call these methods |
352 // directly but rather use a PrefChangeRegistrar to make sure the observer | 347 // directly but rather use a PrefChangeRegistrar to make sure the observer |
353 // gets cleaned up properly. | 348 // gets cleaned up properly. |
354 virtual void AddPrefObserver(const char* path, | 349 virtual void AddPrefObserver(const char* path, |
355 content::NotificationObserver* obs); | 350 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. | 370 // 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 | 371 // 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 | 372 // pref store. This method returns NULL only if you're requesting an |
378 // unregistered pref or a non-dict/non-list pref. | 373 // unregistered pref or a non-dict/non-list pref. |
379 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and | 374 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and |
380 // |path| must point to a registered preference of type |type|. | 375 // |path| must point to a registered preference of type |type|. |
381 // Ownership of the returned value remains at the user pref store. | 376 // Ownership of the returned value remains at the user pref store. |
382 base::Value* GetMutableUserPref(const char* path, | 377 base::Value* GetMutableUserPref(const char* path, |
383 base::Value::Type type); | 378 base::Value::Type type); |
384 | 379 |
385 // The PrefValueStore provides prioritized preference values. It is created | 380 // The PrefValueStore provides prioritized preference values. It is owned by |
386 // and owned by this PrefService. Subclasses may access it for unit testing. | 381 // this PrefService. Subclasses may access it for unit testing. |
387 scoped_ptr<PrefValueStore> pref_value_store_; | 382 scoped_ptr<PrefValueStore> pref_value_store_; |
388 | 383 |
389 // Pref Stores and profile that we passed to the PrefValueStore. | 384 // Pref Stores and profile that we passed to the PrefValueStore. |
390 scoped_refptr<PersistentPrefStore> user_pref_store_; | 385 scoped_refptr<PersistentPrefStore> user_pref_store_; |
391 scoped_refptr<DefaultPrefStore> default_store_; | 386 scoped_refptr<DefaultPrefStore> default_store_; |
392 | 387 |
393 // Local cache of registered Preference objects. The default_store_ | 388 // Local cache of registered Preference objects. The default_store_ |
394 // is authoritative with respect to what the types and default values | 389 // is authoritative with respect to what the types and default values |
395 // of registered preferences are. | 390 // of registered preferences are. |
396 mutable PreferenceSet prefs_; | 391 mutable PreferenceSet prefs_; |
397 | 392 |
398 // The model associator that maintains the links with the sync db. | 393 // The model associator that maintains the links with the sync db. |
399 scoped_ptr<PrefModelAssociator> pref_sync_associator_; | 394 scoped_ptr<PrefModelAssociator> pref_sync_associator_; |
400 | 395 |
401 DISALLOW_COPY_AND_ASSIGN(PrefService); | 396 DISALLOW_COPY_AND_ASSIGN(PrefService); |
402 }; | 397 }; |
403 | 398 |
404 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 399 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
OLD | NEW |