OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_PREFS_HASHED_PREF_STORE_H_ | |
6 #define CHROME_BROWSER_PREFS_HASHED_PREF_STORE_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/observer_list.h" | |
15 #include "base/prefs/persistent_pref_store.h" | |
16 #include "base/prefs/pref_store.h" | |
17 | |
18 class PrefHashStore; | |
19 | |
20 namespace base { | |
21 class Value; | |
22 } // namespace base | |
23 | |
24 // This interface is complementary to the PrefStore interface, declaring | |
25 // additional functionality that adds support for setting values and persisting | |
26 // the data to some backing store. | |
27 class HashedPrefStore : public PersistentPrefStore { | |
28 public: | |
29 HashedPrefStore(const scoped_refptr<PersistentPrefStore>& pref_store, | |
30 scoped_ptr<PrefHashStore> pref_hash_store); | |
31 | |
32 virtual bool GetMutableValue(const std::string& key, | |
gab
2013/11/29 04:05:51
Having to override all of these methods just to fo
gab
2013/11/29 04:17:10
Actually, even simpler than a delegate would be to
| |
33 base::Value** result) OVERRIDE; | |
34 virtual void ReportValueChanged(const std::string& key) OVERRIDE; | |
35 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; | |
36 virtual void SetValueSilently(const std::string& key, base::Value* value) | |
37 OVERRIDE; | |
38 virtual void RemoveValue(const std::string& key) OVERRIDE; | |
39 virtual void MarkNeedsEmptyValue(const std::string& key) OVERRIDE; | |
40 virtual bool ReadOnly() const OVERRIDE; | |
41 virtual PrefReadError GetReadError() const OVERRIDE; | |
42 virtual PrefReadError ReadPrefs() OVERRIDE; | |
43 virtual void ReadPrefsAsync( | |
44 PersistentPrefStore::ReadErrorDelegate* error_delegate) OVERRIDE; | |
45 virtual void CommitPendingWrite() OVERRIDE; | |
46 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; | |
47 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; | |
48 virtual bool HasObservers() const OVERRIDE; | |
49 virtual bool IsInitializationComplete() const OVERRIDE; | |
50 virtual bool GetValue(const std::string& key, | |
51 const base::Value** result) const OVERRIDE; | |
52 | |
53 protected: | |
54 virtual ~HashedPrefStore() {} | |
55 | |
56 private: | |
57 class PrefStoreObserver : public PrefStore::Observer { | |
58 public: | |
59 PrefStoreObserver( | |
60 const scoped_refptr<PersistentPrefStore>& wrapped_pref_store, | |
61 scoped_ptr<PrefHashStore> pref_hash_store); | |
62 virtual ~PrefStoreObserver(); | |
63 | |
64 // PrefStore::Observer implementation. | |
65 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE; | |
66 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; | |
67 | |
68 PersistentPrefStore* wrapped_pref_store() { | |
69 return wrapped_pref_store_; | |
70 } | |
71 const PersistentPrefStore* wrapped_pref_store() const { | |
72 return wrapped_pref_store_; | |
73 } | |
74 ObserverList<PrefStore::Observer, true>& observers() { | |
gab
2013/11/29 04:05:51
I don't think we allow return by non-const ref in
| |
75 return observers_; | |
76 } | |
77 const ObserverList<PrefStore::Observer, true>& observers() const { | |
78 return observers_; | |
79 } | |
80 | |
81 private: | |
82 bool initialized_; | |
83 | |
84 scoped_refptr<PersistentPrefStore> wrapped_pref_store_; | |
85 | |
86 ObserverList<PrefStore::Observer, true> observers_; | |
87 scoped_ptr<PrefHashStore> pref_hash_store_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(PrefStoreObserver); | |
90 }; | |
91 | |
92 PrefStoreObserver internal_observer_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(HashedPrefStore); | |
95 }; | |
96 | |
97 #endif // CHROME_BROWSER_PREFS_HASHED_PREF_STORE_H_ | |
OLD | NEW |