OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_COMMON_PREF_STORE_H_ | 5 #ifndef CHROME_COMMON_PREF_STORE_H_ |
6 #define CHROME_COMMON_PREF_STORE_H_ | 6 #define CHROME_COMMON_PREF_STORE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/ref_counted.h" | |
12 | 13 |
13 class Value; | 14 class Value; |
14 | 15 |
15 // This is an abstract interface for reading and writing from/to a persistent | 16 // This is an abstract interface for reading and writing from/to a persistent |
16 // preference store, used by PrefService. An implementation using a JSON file | 17 // preference store, used by PrefService. An implementation using a JSON file |
17 // can be found in JsonPrefStore, while an implementation without any backing | 18 // can be found in JsonPrefStore, while an implementation without any backing |
18 // store for testing can be found in TestingPrefStore. Furthermore, there is | 19 // store for testing can be found in TestingPrefStore. Furthermore, there is |
19 // CommandLinePrefStore, which bridges command line options to preferences and | 20 // CommandLinePrefStore, which bridges command line options to preferences and |
20 // ConfigurationPolicyPrefStore, which is used for hooking up configuration | 21 // ConfigurationPolicyPrefStore, which is used for hooking up configuration |
21 // policy with the preference subsystem. | 22 // policy with the preference subsystem. |
22 class PrefStore { | 23 class PrefStore : public base::RefCounted<PrefStore> { |
23 public: | 24 public: |
24 // Observer interface for monitoring PrefStore. | 25 // Observer interface for monitoring PrefStore. |
25 class Observer { | 26 class Observer { |
26 public: | 27 public: |
27 virtual ~Observer() {} | 28 virtual ~Observer() {} |
28 | 29 |
29 // Called when the value for the given |key| in the store changes. | 30 // Called when the value for the given |key| in the store changes. |
30 virtual void OnPrefValueChanged(const std::string& key) = 0; | 31 virtual void OnPrefValueChanged(const std::string& key) = 0; |
31 // Notification about the PrefStore being fully initialized. | 32 // Notification about the PrefStore being fully initialized. |
32 virtual void OnInitializationCompleted() = 0; | 33 virtual void OnInitializationCompleted() = 0; |
33 }; | 34 }; |
34 | 35 |
35 // Return values for GetValue(). | 36 // Return values for GetValue(). |
36 enum ReadResult { | 37 enum ReadResult { |
37 // Value found and returned. | 38 // Value found and returned. |
38 READ_OK, | 39 READ_OK, |
39 // No value present, but skip other pref stores and use default. | 40 // No value present, but skip other pref stores and use default. |
40 READ_USE_DEFAULT, | 41 READ_USE_DEFAULT, |
41 // No value present. | 42 // No value present. |
42 READ_NO_VALUE, | 43 READ_NO_VALUE, |
43 }; | 44 }; |
44 | 45 |
45 PrefStore() {} | 46 PrefStore() {} |
46 virtual ~PrefStore() {} | |
47 | 47 |
48 // Add and remove observers. | 48 // Add and remove observers. |
49 virtual void AddObserver(Observer* observer) {} | 49 virtual void AddObserver(Observer* observer) {} |
50 virtual void RemoveObserver(Observer* observer) {} | 50 virtual void RemoveObserver(Observer* observer) {} |
51 | 51 |
52 // Whether the store has completed all asynchronous initialization. | 52 // Whether the store has completed all asynchronous initialization. |
53 virtual bool IsInitializationComplete() const; | 53 virtual bool IsInitializationComplete() const; |
54 | 54 |
55 // Get the value for a given preference |key| and stores it in |result|. | 55 // Get the value for a given preference |key| and stores it in |result|. |
56 // |result| is only modified if the return value is READ_OK. Ownership of the | 56 // |result| is only modified if the return value is READ_OK. Ownership of the |
57 // |result| value remains with the PrefStore. | 57 // |result| value remains with the PrefStore. |
58 virtual ReadResult GetValue(const std::string& key, Value** result) const = 0; | 58 virtual ReadResult GetValue(const std::string& key, Value** result) const = 0; |
59 | 59 |
60 protected: | |
61 friend class base::RefCounted<PrefStore>; | |
Mattias Nissler (ping if slow)
2010/12/22 12:09:03
Why not move these to the private section?
battre
2010/12/22 18:34:53
PrefStore is a base class. Derived classes need to
| |
62 | |
63 virtual ~PrefStore() {} | |
64 | |
65 private: | |
60 DISALLOW_COPY_AND_ASSIGN(PrefStore); | 66 DISALLOW_COPY_AND_ASSIGN(PrefStore); |
61 }; | 67 }; |
62 | 68 |
63 #endif // CHROME_COMMON_PREF_STORE_H_ | 69 #endif // CHROME_COMMON_PREF_STORE_H_ |
OLD | NEW |