| 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 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 // We run the callback once, when initialization completes. The bool |
| 277 // parameter will be set to true for successful initialization, |
| 278 // false for unsuccessful. |
| 279 void AddPrefInitObserver(base::Callback<void(bool)> callback); |
| 280 |
| 274 protected: | 281 protected: |
| 275 // Construct a new pref service. This constructor is what | 282 // Construct a new pref service. This constructor is what |
| 276 // factory methods end up calling and what is used for unit tests. | 283 // factory methods end up calling and what is used for unit tests. |
| 277 PrefService(PrefNotifierImpl* pref_notifier, | 284 PrefService(PrefNotifierImpl* pref_notifier, |
| 278 PrefValueStore* pref_value_store, | 285 PrefValueStore* pref_value_store, |
| 279 PersistentPrefStore* user_prefs, | 286 PersistentPrefStore* user_prefs, |
| 280 DefaultPrefStore* default_store, | 287 DefaultPrefStore* default_store, |
| 281 PrefModelAssociator* pref_sync_associator, | 288 PrefModelAssociator* pref_sync_associator, |
| 282 bool async); | 289 bool async); |
| 283 | 290 |
| 284 // The PrefNotifier handles registering and notifying preference observers. | 291 // The PrefNotifier handles registering and notifying preference observers. |
| 285 // It is created and owned by this PrefService. Subclasses may access it for | 292 // It is created and owned by this PrefService. Subclasses may access it for |
| 286 // unit testing. | 293 // unit testing. |
| 287 scoped_ptr<PrefNotifierImpl> pref_notifier_; | 294 scoped_ptr<PrefNotifierImpl> pref_notifier_; |
| 288 | 295 |
| 289 private: | 296 private: |
| 290 // Hash map expected to be fastest here since it minimises expensive | 297 // Hash map expected to be fastest here since it minimises expensive |
| 291 // string comparisons. Order is unimportant, and deletions are rare. | 298 // string comparisons. Order is unimportant, and deletions are rare. |
| 292 // Confirmed on Android where this speeded Chrome startup by roughly 50ms | 299 // 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. | 300 // vs. std::map, and by roughly 180ms vs. std::set of Preference pointers. |
| 294 typedef base::hash_map<std::string, Preference> PreferenceMap; | 301 typedef base::hash_map<std::string, Preference> PreferenceMap; |
| 295 | 302 |
| 296 friend class PrefServiceMockBuilder; | 303 friend class PrefServiceMockBuilder; |
| 297 | 304 |
| 298 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). | 305 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). |
| 299 friend class subtle::ScopedUserPrefUpdateBase; | 306 friend class subtle::ScopedUserPrefUpdateBase; |
| 300 | 307 |
| 301 // PrefServiceBase implementation (protected in base, private here). | 308 // PrefServiceBase implementation (protected in base, private here). |
| 302 virtual void AddPrefObserver(const char* path, | 309 virtual void AddPrefObserver(const char* path, |
| 303 content::NotificationObserver* obs) OVERRIDE; | 310 PrefObserver* obs) OVERRIDE; |
| 304 virtual void RemovePrefObserver(const char* path, | 311 virtual void RemovePrefObserver(const char* path, |
| 305 content::NotificationObserver* obs) OVERRIDE; | 312 PrefObserver* obs) OVERRIDE; |
| 306 | 313 |
| 307 // Sends notification of a changed preference. This needs to be called by | 314 // Sends notification of a changed preference. This needs to be called by |
| 308 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. | 315 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. |
| 309 void ReportUserPrefChanged(const std::string& key); | 316 void ReportUserPrefChanged(const std::string& key); |
| 310 | 317 |
| 311 // Registers a new preference at |path|. The |default_value| must not be | 318 // Registers a new preference at |path|. The |default_value| must not be |
| 312 // NULL as it determines the preference value's type. | 319 // NULL as it determines the preference value's type. |
| 313 // RegisterPreference must not be called twice for the same path. | 320 // RegisterPreference must not be called twice for the same path. |
| 314 // This method takes ownership of |default_value|. | 321 // This method takes ownership of |default_value|. |
| 315 void RegisterPreference(const char* path, | 322 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 | 361 // CreatePrefServiceWithPerTabPrefStore() have been called to create a |
| 355 // "forked" PrefService. | 362 // "forked" PrefService. |
| 356 bool pref_service_forked_; | 363 bool pref_service_forked_; |
| 357 | 364 |
| 358 ObserverList<PrefServiceObserver> observer_list_; | 365 ObserverList<PrefServiceObserver> observer_list_; |
| 359 | 366 |
| 360 DISALLOW_COPY_AND_ASSIGN(PrefService); | 367 DISALLOW_COPY_AND_ASSIGN(PrefService); |
| 361 }; | 368 }; |
| 362 | 369 |
| 363 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 370 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| OLD | NEW |