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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 public: | 29 public: |
30 // 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. |
31 virtual void OnPrefValueChanged(const std::string& key) = 0; | 31 virtual void OnPrefValueChanged(const std::string& key) = 0; |
32 // Notification about the PrefStore being fully initialized. | 32 // Notification about the PrefStore being fully initialized. |
33 virtual void OnInitializationCompleted(bool succeeded) = 0; | 33 virtual void OnInitializationCompleted(bool succeeded) = 0; |
34 | 34 |
35 protected: | 35 protected: |
36 virtual ~Observer() {} | 36 virtual ~Observer() {} |
37 }; | 37 }; |
38 | 38 |
39 // Return values for GetValue(). | |
40 enum ReadResult { | |
41 // Value found and returned. | |
42 READ_OK, | |
43 // No value present, but skip other pref stores and use default. | |
44 READ_USE_DEFAULT, | |
45 // No value present. | |
46 READ_NO_VALUE, | |
47 }; | |
48 | |
49 PrefStore() {} | 39 PrefStore() {} |
50 | 40 |
51 // Add and remove observers. | 41 // Add and remove observers. |
52 virtual void AddObserver(Observer* observer) {} | 42 virtual void AddObserver(Observer* observer) {} |
53 virtual void RemoveObserver(Observer* observer) {} | 43 virtual void RemoveObserver(Observer* observer) {} |
54 virtual size_t NumberOfObservers() const; | 44 virtual size_t NumberOfObservers() const; |
55 | 45 |
56 // Whether the store has completed all asynchronous initialization. | 46 // Whether the store has completed all asynchronous initialization. |
57 virtual bool IsInitializationComplete() const; | 47 virtual bool IsInitializationComplete() const; |
58 | 48 |
59 // Get the value for a given preference |key| and stores it in |*result|. | 49 // Get the value for a given preference |key| and stores it in |*result|. |
60 // |*result| is only modified if the return value is READ_OK and if |result| | 50 // |*result| is only modified if the return value is true and if |result| |
61 // is not NULL. Ownership of the |*result| value remains with the PrefStore. | 51 // is not NULL. Ownership of the |*result| value remains with the PrefStore. |
62 virtual ReadResult GetValue(const std::string& key, | 52 virtual bool GetValue(const std::string& key, |
63 const base::Value** result) const = 0; | 53 const base::Value** result) const = 0; |
64 | 54 |
65 protected: | 55 protected: |
66 friend class base::RefCounted<PrefStore>; | 56 friend class base::RefCounted<PrefStore>; |
67 virtual ~PrefStore() {} | 57 virtual ~PrefStore() {} |
68 | 58 |
69 private: | 59 private: |
70 DISALLOW_COPY_AND_ASSIGN(PrefStore); | 60 DISALLOW_COPY_AND_ASSIGN(PrefStore); |
71 }; | 61 }; |
72 | 62 |
73 #endif // BASE_PREFS_PREF_STORE_H_ | 63 #endif // BASE_PREFS_PREF_STORE_H_ |
OLD | NEW |