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 BASE_PREFS_PREF_SERVICE_H_ | 11 #ifndef BASE_PREFS_PREF_SERVICE_H_ |
12 #define BASE_PREFS_PREF_SERVICE_H_ | 12 #define BASE_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/callback.h" |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/containers/hash_tables.h" | 19 #include "base/containers/hash_tables.h" |
| 20 #include "base/containers/scoped_ptr_hash_map.h" |
20 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
21 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
22 #include "base/observer_list.h" | 23 #include "base/observer_list.h" |
23 #include "base/prefs/base_prefs_export.h" | 24 #include "base/prefs/base_prefs_export.h" |
24 #include "base/prefs/persistent_pref_store.h" | 25 #include "base/prefs/persistent_pref_store.h" |
25 #include "base/threading/non_thread_safe.h" | 26 #include "base/threading/non_thread_safe.h" |
26 #include "base/values.h" | 27 #include "base/values.h" |
27 | 28 |
28 class PrefNotifier; | 29 class PrefNotifier; |
29 class PrefNotifierImpl; | 30 class PrefNotifierImpl; |
30 class PrefObserver; | 31 class PrefObserver; |
31 class PrefRegistry; | 32 class PrefRegistry; |
32 class PrefValueStore; | 33 class PrefValueStore; |
33 class PrefStore; | 34 class PrefStore; |
34 | 35 |
35 namespace base { | 36 namespace base { |
36 class FilePath; | 37 class FilePath; |
37 } | 38 } |
38 | 39 |
39 namespace subtle { | 40 namespace subtle { |
40 class PrefMemberBase; | 41 class PrefMemberBase; |
41 class ScopedUserPrefUpdateBase; | 42 class ScopedUserPrefUpdateBase; |
42 } | 43 } |
43 | 44 |
| 45 // Base class for caches associated with the PrefService. |
| 46 class BASE_PREFS_EXPORT PrefServiceCache { |
| 47 }; |
| 48 |
44 // Base class for PrefServices. You can use the base class to read and | 49 // Base class for PrefServices. You can use the base class to read and |
45 // interact with preferences, but not to register new preferences; for | 50 // interact with preferences, but not to register new preferences; for |
46 // that see e.g. PrefRegistrySimple. | 51 // that see e.g. PrefRegistrySimple. |
47 // | 52 // |
48 // Settings and storage accessed through this class represent | 53 // Settings and storage accessed through this class represent |
49 // user-selected preferences and information and MUST not be | 54 // user-selected preferences and information and MUST not be |
50 // extracted, overwritten or modified except through the defined APIs. | 55 // extracted, overwritten or modified except through the defined APIs. |
51 class BASE_PREFS_EXPORT PrefService : public base::NonThreadSafe { | 56 class BASE_PREFS_EXPORT PrefService : public base::NonThreadSafe { |
52 public: | 57 public: |
53 enum PrefInitializationStatus { | 58 enum PrefInitializationStatus { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // register all preferences for a class Xyz up front in a static | 268 // register all preferences for a class Xyz up front in a static |
264 // Xyz::RegisterPrefs function, which gets invoked early in the | 269 // Xyz::RegisterPrefs function, which gets invoked early in the |
265 // application's start-up, before a PrefService is created. | 270 // application's start-up, before a PrefService is created. |
266 // | 271 // |
267 // As an example, prefs registration in Chrome is triggered by the | 272 // As an example, prefs registration in Chrome is triggered by the |
268 // functions chrome::RegisterPrefs (for global preferences) and | 273 // functions chrome::RegisterPrefs (for global preferences) and |
269 // chrome::RegisterProfilePrefs (for user-specific preferences) | 274 // chrome::RegisterProfilePrefs (for user-specific preferences) |
270 // implemented in chrome/browser/prefs/browser_prefs.cc. | 275 // implemented in chrome/browser/prefs/browser_prefs.cc. |
271 PrefRegistry* DeprecatedGetPrefRegistry(); | 276 PrefRegistry* DeprecatedGetPrefRegistry(); |
272 | 277 |
| 278 base::ScopedPtrHashMap<const char*, PrefServiceCache>* GetPrefsCaches() { |
| 279 return &prefs_caches_; |
| 280 } |
| 281 |
273 protected: | 282 protected: |
274 // The PrefNotifier handles registering and notifying preference observers. | 283 // The PrefNotifier handles registering and notifying preference observers. |
275 // It is created and owned by this PrefService. Subclasses may access it for | 284 // It is created and owned by this PrefService. Subclasses may access it for |
276 // unit testing. | 285 // unit testing. |
277 scoped_ptr<PrefNotifierImpl> pref_notifier_; | 286 scoped_ptr<PrefNotifierImpl> pref_notifier_; |
278 | 287 |
279 // The PrefValueStore provides prioritized preference values. It is owned by | 288 // The PrefValueStore provides prioritized preference values. It is owned by |
280 // this PrefService. Subclasses may access it for unit testing. | 289 // this PrefService. Subclasses may access it for unit testing. |
281 scoped_ptr<PrefValueStore> pref_value_store_; | 290 scoped_ptr<PrefValueStore> pref_value_store_; |
282 | 291 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 // not need to find or create a Preference object to get the | 355 // not need to find or create a Preference object to get the |
347 // value (GetValue() calls back though the preference service to | 356 // value (GetValue() calls back though the preference service to |
348 // actually get the value.). | 357 // actually get the value.). |
349 const base::Value* GetPreferenceValue(const std::string& path) const; | 358 const base::Value* GetPreferenceValue(const std::string& path) const; |
350 | 359 |
351 // Local cache of registered Preference objects. The pref_registry_ | 360 // Local cache of registered Preference objects. The pref_registry_ |
352 // is authoritative with respect to what the types and default values | 361 // is authoritative with respect to what the types and default values |
353 // of registered preferences are. | 362 // of registered preferences are. |
354 mutable PreferenceMap prefs_map_; | 363 mutable PreferenceMap prefs_map_; |
355 | 364 |
| 365 // General purpose caches. |
| 366 base::ScopedPtrHashMap<const char*, PrefServiceCache> prefs_caches_; |
| 367 |
356 DISALLOW_COPY_AND_ASSIGN(PrefService); | 368 DISALLOW_COPY_AND_ASSIGN(PrefService); |
357 }; | 369 }; |
358 | 370 |
359 #endif // BASE_PREFS_PREF_SERVICE_H_ | 371 #endif // BASE_PREFS_PREF_SERVICE_H_ |
OLD | NEW |