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

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

Issue 8568019: Introduce per-tab preferences service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed Created 9 years, 1 month 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) 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
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
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);
Mattias Nissler (ping if slow) 2011/11/17 18:44:39 newline before comment.
mnaganov (inactive) 2011/11/17 19:53:32 Done.
312 314 // An overloaded version that clones and specializes value store.
313 // The PrefNotifier handles registering and notifying preference observers. 315 // Used for CreateIncognito and Create...PerTabPrefStore.
314 // It is created and owned by this PrefService. Subclasses may access it for 316 PrefService(PrefValueStore* source_store,
315 // unit testing. 317 PrefStore* managed_platform_prefs,
316 scoped_ptr<PrefNotifierImpl> pref_notifier_; 318 PrefStore* managed_cloud_prefs,
319 PrefStore* extension_prefs,
320 PrefStore* command_line_prefs,
321 PersistentPrefStore* user_prefs,
322 PrefStore* recommended_platform_prefs,
323 PrefStore* recommended_cloud_prefs,
324 DefaultPrefStore* default_store);
317 325
318 private: 326 private:
319 class PreferencePathComparator { 327 class PreferencePathComparator {
320 public: 328 public:
321 bool operator() (Preference* lhs, Preference* rhs) const { 329 bool operator() (Preference* lhs, Preference* rhs) const {
322 return lhs->name() < rhs->name(); 330 return lhs->name() < rhs->name();
323 } 331 }
324 }; 332 };
325 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet; 333 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet;
326 334
327 friend class PrefServiceMockBuilder; 335 friend class PrefServiceMockBuilder;
328 336
329 // Registration of pref change observers must be done using the 337 // Registration of pref change observers must be done using the
330 // PrefChangeRegistrar, which is declared as a friend here to grant it 338 // PrefChangeRegistrar, which is declared as a friend here to grant it
331 // access to the otherwise protected members Add/RemovePrefObserver. 339 // access to the otherwise protected members Add/RemovePrefObserver.
332 // PrefMember registers for preferences changes notification directly to 340 // PrefMember registers for preferences changes notification directly to
333 // avoid the storage overhead of the registrar, so its base class must be 341 // avoid the storage overhead of the registrar, so its base class must be
334 // declared as a friend, too. 342 // declared as a friend, too.
335 friend class PrefChangeRegistrar; 343 friend class PrefChangeRegistrar;
336 friend class subtle::PrefMemberBase; 344 friend class subtle::PrefMemberBase;
337 345
338 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). 346 // Give access to ReportUserPrefChanged() and GetMutableUserPref().
339 friend class subtle::ScopedUserPrefUpdateBase; 347 friend class subtle::ScopedUserPrefUpdateBase;
340 348
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 349 // Sends notification of a changed preference. This needs to be called by
347 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. 350 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed.
348 void ReportUserPrefChanged(const std::string& key); 351 void ReportUserPrefChanged(const std::string& key);
349 352
350 // If the pref at the given path changes, we call the observer's Observe 353 // 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 354 // method with PREF_CHANGED. Note that observers should not call these methods
352 // directly but rather use a PrefChangeRegistrar to make sure the observer 355 // directly but rather use a PrefChangeRegistrar to make sure the observer
353 // gets cleaned up properly. 356 // gets cleaned up properly.
354 virtual void AddPrefObserver(const char* path, 357 virtual void AddPrefObserver(const char* path,
355 content::NotificationObserver* obs); 358 content::NotificationObserver* obs);
(...skipping 19 matching lines...) Expand all
375 // Used to set the value of dictionary or list values in the user pref store. 378 // 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 379 // 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 380 // pref store. This method returns NULL only if you're requesting an
378 // unregistered pref or a non-dict/non-list pref. 381 // unregistered pref or a non-dict/non-list pref.
379 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and 382 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and
380 // |path| must point to a registered preference of type |type|. 383 // |path| must point to a registered preference of type |type|.
381 // Ownership of the returned value remains at the user pref store. 384 // Ownership of the returned value remains at the user pref store.
382 base::Value* GetMutableUserPref(const char* path, 385 base::Value* GetMutableUserPref(const char* path,
383 base::Value::Type type); 386 base::Value::Type type);
384 387
385 // The PrefValueStore provides prioritized preference values. It is created 388 // The PrefNotifier handles registering and notifying preference observers.
386 // and owned by this PrefService. Subclasses may access it for unit testing. 389 // It is created and owned by this PrefService.
387 scoped_ptr<PrefValueStore> pref_value_store_; 390 scoped_ptr<PrefNotifierImpl> pref_notifier_;
388 391
389 // Pref Stores and profile that we passed to the PrefValueStore. 392 // Pref Stores and profile that we passed to the PrefValueStore.
390 scoped_refptr<PersistentPrefStore> user_pref_store_; 393 scoped_refptr<PersistentPrefStore> user_pref_store_;
391 scoped_refptr<DefaultPrefStore> default_store_; 394 scoped_refptr<DefaultPrefStore> default_store_;
392 395
393 // Local cache of registered Preference objects. The default_store_ 396 // Local cache of registered Preference objects. The default_store_
394 // is authoritative with respect to what the types and default values 397 // is authoritative with respect to what the types and default values
395 // of registered preferences are. 398 // of registered preferences are.
396 mutable PreferenceSet prefs_; 399 mutable PreferenceSet prefs_;
397 400
398 // The model associator that maintains the links with the sync db. 401 // The model associator that maintains the links with the sync db.
399 scoped_ptr<PrefModelAssociator> pref_sync_associator_; 402 scoped_ptr<PrefModelAssociator> pref_sync_associator_;
400 403
404 // The PrefValueStore provides prioritized preference values. It is created
405 // and owned by this PrefService. Subclasses may access it for unit testing.
406 scoped_ptr<PrefValueStore> pref_value_store_;
407
401 DISALLOW_COPY_AND_ASSIGN(PrefService); 408 DISALLOW_COPY_AND_ASSIGN(PrefService);
402 }; 409 };
403 410
404 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ 411 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698