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 #ifndef BASE_PREFS_PREF_STORE_H_ | 5 #ifndef BASE_PREFS_PREF_STORE_H_ |
6 #define BASE_PREFS_PREF_STORE_H_ | 6 #define BASE_PREFS_PREF_STORE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/prefs/base_prefs_export.h" | 12 #include "base/prefs/base_prefs_export.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class Value; | 15 class Value; |
16 } | 16 } |
17 | 17 |
18 // This is an abstract interface for reading and writing from/to a persistent | 18 // This is an abstract interface for reading and writing from/to a persistent |
19 // preference store, used by PrefService. An implementation using a JSON file | 19 // preference store, used by PrefService. An implementation using a JSON file |
20 // can be found in JsonPrefStore, while an implementation without any backing | 20 // can be found in JsonPrefStore, while an implementation without any backing |
21 // store for testing can be found in TestingPrefStore. Furthermore, there is | 21 // store for testing can be found in TestingPrefStore. Furthermore, there is |
22 // CommandLinePrefStore, which bridges command line options to preferences and | 22 // CommandLinePrefStore, which bridges command line options to preferences and |
23 // ConfigurationPolicyPrefStore, which is used for hooking up configuration | 23 // ConfigurationPolicyPrefStore, which is used for hooking up configuration |
24 // policy with the preference subsystem. | 24 // policy with the preference subsystem. |
25 class BASE_PREFS_EXPORT PrefStore : public base::RefCounted<PrefStore> { | 25 class BASE_PREFS_EXPORT PrefStore : public base::RefCounted<PrefStore> { |
26 public: | 26 public: |
27 // Observer interface for monitoring PrefStore. | 27 // Observer interface for monitoring PrefStore. |
28 class BASE_PREFS_EXPORT Observer { | 28 class BASE_PREFS_EXPORT Observer { |
29 public: | 29 public: |
| 30 virtual ~Observer() {} |
| 31 |
30 // Called when the value for the given |key| in the store changes. | 32 // Called when the value for the given |key| in the store changes. |
31 virtual void OnPrefValueChanged(const std::string& key) = 0; | 33 virtual void OnPrefValueChanged(const std::string& key) = 0; |
32 // Notification about the PrefStore being fully initialized. | 34 // Notification about the PrefStore being fully initialized. |
33 virtual void OnInitializationCompleted(bool succeeded) = 0; | 35 virtual void OnInitializationCompleted(bool succeeded) = 0; |
34 | |
35 protected: | |
36 virtual ~Observer() {} | |
37 }; | 36 }; |
38 | 37 |
39 PrefStore() {} | 38 PrefStore() {} |
40 | 39 |
41 // Add and remove observers. | 40 // Add and remove observers. |
42 virtual void AddObserver(Observer* observer) {} | 41 virtual void AddObserver(Observer* observer) {} |
43 virtual void RemoveObserver(Observer* observer) {} | 42 virtual void RemoveObserver(Observer* observer) {} |
44 virtual bool HasObservers() const; | 43 virtual bool HasObservers() const; |
45 | 44 |
46 // Whether the store has completed all asynchronous initialization. | 45 // Whether the store has completed all asynchronous initialization. |
47 virtual bool IsInitializationComplete() const; | 46 virtual bool IsInitializationComplete() const; |
48 | 47 |
49 // Get the value for a given preference |key| and stores it in |*result|. | 48 // Get the value for a given preference |key| and stores it in |*result|. |
50 // |*result| is only modified if the return value is true and if |result| | 49 // |*result| is only modified if the return value is true and if |result| |
51 // is not NULL. Ownership of the |*result| value remains with the PrefStore. | 50 // is not NULL. Ownership of the |*result| value remains with the PrefStore. |
52 virtual bool GetValue(const std::string& key, | 51 virtual bool GetValue(const std::string& key, |
53 const base::Value** result) const = 0; | 52 const base::Value** result) const = 0; |
54 | 53 |
55 protected: | 54 protected: |
56 friend class base::RefCounted<PrefStore>; | 55 friend class base::RefCounted<PrefStore>; |
57 virtual ~PrefStore() {} | 56 virtual ~PrefStore() {} |
58 | 57 |
59 private: | 58 private: |
60 DISALLOW_COPY_AND_ASSIGN(PrefStore); | 59 DISALLOW_COPY_AND_ASSIGN(PrefStore); |
61 }; | 60 }; |
62 | 61 |
63 #endif // BASE_PREFS_PREF_STORE_H_ | 62 #endif // BASE_PREFS_PREF_STORE_H_ |
OLD | NEW |