| 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/callback.h" |
| 17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/hash_tables.h" | 20 #include "base/hash_tables.h" |
| 20 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
| 21 #include "base/prefs/public/pref_service_base.h" | 22 #include "base/prefs/public/pref_service_base.h" |
| 22 #include "base/threading/non_thread_safe.h" | 23 #include "base/threading/non_thread_safe.h" |
| 23 | 24 |
| 24 class CommandLine; | 25 class CommandLine; |
| 25 class DefaultPrefStore; | 26 class DefaultPrefStore; |
| 26 class PersistentPrefStore; | 27 class PersistentPrefStore; |
| 27 class PrefModelAssociator; | 28 class PrefModelAssociator; |
| 28 class PrefNotifier; | 29 class PrefNotifier; |
| 29 class PrefNotifierImpl; | 30 class PrefNotifierImpl; |
| 31 class PrefObserver; |
| 30 class PrefServiceObserver; | 32 class PrefServiceObserver; |
| 31 class PrefStore; | 33 class PrefStore; |
| 32 class PrefValueStore; | 34 class PrefValueStore; |
| 33 | 35 |
| 34 namespace base { | 36 namespace base { |
| 35 class SequencedTaskRunner; | 37 class SequencedTaskRunner; |
| 36 } | 38 } |
| 37 | 39 |
| 38 namespace syncer { | 40 namespace syncer { |
| 39 class SyncableService; | 41 class SyncableService; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 PrefInitializationStatus GetInitializationStatus() const; | 272 PrefInitializationStatus GetInitializationStatus() const; |
| 271 | 273 |
| 272 // syncer::SyncableService getter. | 274 // syncer::SyncableService getter. |
| 273 // TODO(zea): Have PrefService implement syncer::SyncableService directly. | 275 // TODO(zea): Have PrefService implement syncer::SyncableService directly. |
| 274 syncer::SyncableService* GetSyncableService(); | 276 syncer::SyncableService* GetSyncableService(); |
| 275 | 277 |
| 276 // Tell our PrefValueStore to update itself using |command_line|. | 278 // Tell our PrefValueStore to update itself using |command_line|. |
| 277 // Do not call this after having derived an incognito or per tab pref service. | 279 // Do not call this after having derived an incognito or per tab pref service. |
| 278 void UpdateCommandLinePrefStore(CommandLine* command_line); | 280 void UpdateCommandLinePrefStore(CommandLine* command_line); |
| 279 | 281 |
| 282 // We run the callback once, when initialization completes. The bool |
| 283 // parameter will be set to true for successful initialization, |
| 284 // false for unsuccessful. |
| 285 void AddPrefInitObserver(base::Callback<void(bool)> callback); |
| 286 |
| 280 protected: | 287 protected: |
| 281 // Construct a new pref service. This constructor is what | 288 // Construct a new pref service. This constructor is what |
| 282 // factory methods end up calling and what is used for unit tests. | 289 // factory methods end up calling and what is used for unit tests. |
| 283 PrefService(PrefNotifierImpl* pref_notifier, | 290 PrefService(PrefNotifierImpl* pref_notifier, |
| 284 PrefValueStore* pref_value_store, | 291 PrefValueStore* pref_value_store, |
| 285 PersistentPrefStore* user_prefs, | 292 PersistentPrefStore* user_prefs, |
| 286 DefaultPrefStore* default_store, | 293 DefaultPrefStore* default_store, |
| 287 PrefModelAssociator* pref_sync_associator, | 294 PrefModelAssociator* pref_sync_associator, |
| 288 bool async); | 295 bool async); |
| 289 | 296 |
| 290 // The PrefNotifier handles registering and notifying preference observers. | 297 // The PrefNotifier handles registering and notifying preference observers. |
| 291 // It is created and owned by this PrefService. Subclasses may access it for | 298 // It is created and owned by this PrefService. Subclasses may access it for |
| 292 // unit testing. | 299 // unit testing. |
| 293 scoped_ptr<PrefNotifierImpl> pref_notifier_; | 300 scoped_ptr<PrefNotifierImpl> pref_notifier_; |
| 294 | 301 |
| 295 private: | 302 private: |
| 296 // Hash map expected to be fastest here since it minimises expensive | 303 // Hash map expected to be fastest here since it minimises expensive |
| 297 // string comparisons. Order is unimportant, and deletions are rare. | 304 // string comparisons. Order is unimportant, and deletions are rare. |
| 298 // Confirmed on Android where this speeded Chrome startup by roughly 50ms | 305 // Confirmed on Android where this speeded Chrome startup by roughly 50ms |
| 299 // vs. std::map, and by roughly 180ms vs. std::set of Preference pointers. | 306 // vs. std::map, and by roughly 180ms vs. std::set of Preference pointers. |
| 300 typedef base::hash_map<std::string, Preference> PreferenceMap; | 307 typedef base::hash_map<std::string, Preference> PreferenceMap; |
| 301 | 308 |
| 302 friend class PrefServiceMockBuilder; | 309 friend class PrefServiceMockBuilder; |
| 303 | 310 |
| 304 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). | 311 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). |
| 305 friend class subtle::ScopedUserPrefUpdateBase; | 312 friend class subtle::ScopedUserPrefUpdateBase; |
| 306 | 313 |
| 307 // PrefServiceBase implementation (protected in base, private here). | 314 // PrefServiceBase implementation (protected in base, private here). |
| 308 virtual void AddPrefObserver(const char* path, | 315 virtual void AddPrefObserver(const char* path, |
| 309 content::NotificationObserver* obs) OVERRIDE; | 316 PrefObserver* obs) OVERRIDE; |
| 310 virtual void RemovePrefObserver(const char* path, | 317 virtual void RemovePrefObserver(const char* path, |
| 311 content::NotificationObserver* obs) OVERRIDE; | 318 PrefObserver* obs) OVERRIDE; |
| 312 | 319 |
| 313 // Sends notification of a changed preference. This needs to be called by | 320 // Sends notification of a changed preference. This needs to be called by |
| 314 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. | 321 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. |
| 315 void ReportUserPrefChanged(const std::string& key); | 322 void ReportUserPrefChanged(const std::string& key); |
| 316 | 323 |
| 317 // Registers a new preference at |path|. The |default_value| must not be | 324 // Registers a new preference at |path|. The |default_value| must not be |
| 318 // NULL as it determines the preference value's type. | 325 // NULL as it determines the preference value's type. |
| 319 // RegisterPreference must not be called twice for the same path. | 326 // RegisterPreference must not be called twice for the same path. |
| 320 // This method takes ownership of |default_value|. | 327 // This method takes ownership of |default_value|. |
| 321 void RegisterPreference(const char* path, | 328 void RegisterPreference(const char* path, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 // CreatePrefServiceWithPerTabPrefStore() have been called to create a | 367 // CreatePrefServiceWithPerTabPrefStore() have been called to create a |
| 361 // "forked" PrefService. | 368 // "forked" PrefService. |
| 362 bool pref_service_forked_; | 369 bool pref_service_forked_; |
| 363 | 370 |
| 364 ObserverList<PrefServiceObserver> observer_list_; | 371 ObserverList<PrefServiceObserver> observer_list_; |
| 365 | 372 |
| 366 DISALLOW_COPY_AND_ASSIGN(PrefService); | 373 DISALLOW_COPY_AND_ASSIGN(PrefService); |
| 367 }; | 374 }; |
| 368 | 375 |
| 369 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 376 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| OLD | NEW |