Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Chromium settings and storage represent user-selected preferences and | 7 // Chromium settings and storage represent user-selected preferences and |
| 8 // information and MUST not be extracted, overwritten or modified except | 8 // information and MUST not be extracted, overwritten or modified except |
| 9 // through Chromium defined APIs. | 9 // through Chromium defined APIs. |
| 10 | 10 |
| 11 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 11 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| 12 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 12 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| 13 | 13 |
| 14 #include <set> | 14 #include <set> |
| 15 #include <string> | 15 #include <string> |
| 16 | 16 |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/hash_tables.h" | 19 #include "base/hash_tables.h" |
| 20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
| 21 #include "base/prefs/public/pref_service_base.h" | 21 #include "base/prefs/public/pref_service_base.h" |
| 22 #include "base/threading/non_thread_safe.h" | 22 #include "base/threading/non_thread_safe.h" |
| 23 | 23 |
| 24 class CommandLine; | 24 class CommandLine; |
| 25 class DefaultPrefStore; | 25 class DefaultPrefStore; |
| 26 class PersistentPrefStore; | 26 class PersistentPrefStore; |
| 27 class PrefModelAssociator; | 27 class PrefModelAssociator; |
| 28 class PrefNotifier; | 28 class PrefNotifier; |
| 29 class PrefNotifierImpl; | 29 class PrefNotifierImpl; |
| 30 class PrefObserver; | |
| 31 class PrefInitObserver; | |
| 30 class PrefServiceObserver; | 32 class PrefServiceObserver; |
| 31 class PrefStore; | 33 class PrefStore; |
| 32 class PrefValueStore; | 34 class PrefValueStore; |
| 33 | 35 |
| 34 namespace syncer { | 36 namespace syncer { |
| 35 class SyncableService; | 37 class SyncableService; |
| 36 } | 38 } |
| 37 | 39 |
| 38 namespace policy { | 40 namespace policy { |
| 39 class PolicyService; | 41 class PolicyService; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 PrefInitializationStatus GetInitializationStatus() const; | 266 PrefInitializationStatus GetInitializationStatus() const; |
| 265 | 267 |
| 266 // syncer::SyncableService getter. | 268 // syncer::SyncableService getter. |
| 267 // TODO(zea): Have PrefService implement syncer::SyncableService directly. | 269 // TODO(zea): Have PrefService implement syncer::SyncableService directly. |
| 268 syncer::SyncableService* GetSyncableService(); | 270 syncer::SyncableService* GetSyncableService(); |
| 269 | 271 |
| 270 // Tell our PrefValueStore to update itself using |command_line|. | 272 // Tell our PrefValueStore to update itself using |command_line|. |
| 271 // Do not call this after having derived an incognito or per tab pref service. | 273 // Do not call this after having derived an incognito or per tab pref service. |
| 272 void UpdateCommandLinePrefStore(CommandLine* command_line); | 274 void UpdateCommandLinePrefStore(CommandLine* command_line); |
| 273 | 275 |
| 276 void AddPrefInitObserver(PrefInitObserver* obs); | |
|
Mattias Nissler (ping if slow)
2012/10/30 13:37:07
needs documentation
| |
| 277 void RemovePrefInitObserver(PrefInitObserver* obs); | |
| 278 | |
| 274 protected: | 279 protected: |
| 275 // Construct a new pref service. This constructor is what | 280 // Construct a new pref service. This constructor is what |
| 276 // factory methods end up calling and what is used for unit tests. | 281 // factory methods end up calling and what is used for unit tests. |
| 277 PrefService(PrefNotifierImpl* pref_notifier, | 282 PrefService(PrefNotifierImpl* pref_notifier, |
| 278 PrefValueStore* pref_value_store, | 283 PrefValueStore* pref_value_store, |
| 279 PersistentPrefStore* user_prefs, | 284 PersistentPrefStore* user_prefs, |
| 280 DefaultPrefStore* default_store, | 285 DefaultPrefStore* default_store, |
| 281 PrefModelAssociator* pref_sync_associator, | 286 PrefModelAssociator* pref_sync_associator, |
| 282 bool async); | 287 bool async); |
| 283 | 288 |
| 284 // The PrefNotifier handles registering and notifying preference observers. | 289 // The PrefNotifier handles registering and notifying preference observers. |
| 285 // It is created and owned by this PrefService. Subclasses may access it for | 290 // It is created and owned by this PrefService. Subclasses may access it for |
| 286 // unit testing. | 291 // unit testing. |
| 287 scoped_ptr<PrefNotifierImpl> pref_notifier_; | 292 scoped_ptr<PrefNotifierImpl> pref_notifier_; |
| 288 | 293 |
| 289 private: | 294 private: |
| 290 // Hash map expected to be fastest here since it minimises expensive | 295 // Hash map expected to be fastest here since it minimises expensive |
| 291 // string comparisons. Order is unimportant, and deletions are rare. | 296 // string comparisons. Order is unimportant, and deletions are rare. |
| 292 // Confirmed on Android where this speeded Chrome startup by roughly 50ms | 297 // Confirmed on Android where this speeded Chrome startup by roughly 50ms |
| 293 // vs. std::map, and by roughly 180ms vs. std::set of Preference pointers. | 298 // vs. std::map, and by roughly 180ms vs. std::set of Preference pointers. |
| 294 typedef base::hash_map<std::string, Preference> PreferenceMap; | 299 typedef base::hash_map<std::string, Preference> PreferenceMap; |
| 295 | 300 |
| 296 friend class PrefServiceMockBuilder; | 301 friend class PrefServiceMockBuilder; |
| 297 | 302 |
| 298 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). | 303 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). |
| 299 friend class subtle::ScopedUserPrefUpdateBase; | 304 friend class subtle::ScopedUserPrefUpdateBase; |
| 300 | 305 |
| 301 // PrefServiceBase implementation (protected in base, private here). | 306 // PrefServiceBase implementation (protected in base, private here). |
| 302 virtual void AddPrefObserver(const char* path, | 307 virtual void AddPrefObserver(const char* path, |
| 303 content::NotificationObserver* obs) OVERRIDE; | 308 PrefObserver* obs) OVERRIDE; |
| 304 virtual void RemovePrefObserver(const char* path, | 309 virtual void RemovePrefObserver(const char* path, |
| 305 content::NotificationObserver* obs) OVERRIDE; | 310 PrefObserver* obs) OVERRIDE; |
| 306 | 311 |
| 307 // Sends notification of a changed preference. This needs to be called by | 312 // Sends notification of a changed preference. This needs to be called by |
| 308 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. | 313 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. |
| 309 void ReportUserPrefChanged(const std::string& key); | 314 void ReportUserPrefChanged(const std::string& key); |
| 310 | 315 |
| 311 // Registers a new preference at |path|. The |default_value| must not be | 316 // Registers a new preference at |path|. The |default_value| must not be |
| 312 // NULL as it determines the preference value's type. | 317 // NULL as it determines the preference value's type. |
| 313 // RegisterPreference must not be called twice for the same path. | 318 // RegisterPreference must not be called twice for the same path. |
| 314 // This method takes ownership of |default_value|. | 319 // This method takes ownership of |default_value|. |
| 315 void RegisterPreference(const char* path, | 320 void RegisterPreference(const char* path, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 // CreatePrefServiceWithPerTabPrefStore() have been called to create a | 359 // CreatePrefServiceWithPerTabPrefStore() have been called to create a |
| 355 // "forked" PrefService. | 360 // "forked" PrefService. |
| 356 bool pref_service_forked_; | 361 bool pref_service_forked_; |
| 357 | 362 |
| 358 ObserverList<PrefServiceObserver> observer_list_; | 363 ObserverList<PrefServiceObserver> observer_list_; |
| 359 | 364 |
| 360 DISALLOW_COPY_AND_ASSIGN(PrefService); | 365 DISALLOW_COPY_AND_ASSIGN(PrefService); |
| 361 }; | 366 }; |
| 362 | 367 |
| 363 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 368 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| OLD | NEW |