OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_ | 5 #ifndef SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_ |
6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_ | 6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "components/prefs/value_map_pref_store.h" | 11 #include "components/prefs/value_map_pref_store.h" |
12 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
13 #include "services/preferences/public/interfaces/preferences.mojom.h" | 13 #include "services/preferences/public/interfaces/preferences.mojom.h" |
14 | 14 |
| 15 namespace preferences { |
| 16 |
15 class PrefObserverStoreTest; | 17 class PrefObserverStoreTest; |
16 | 18 |
17 // An implementation of PrefStore which uses prefs::mojom::PreferenceManager as | 19 // An implementation of PrefStore which uses prefs::mojom::PreferenceManager as |
18 // the backing of the preferences. | 20 // the backing of the preferences. |
19 // | 21 // |
20 // PrefObserverStore caches the values locally to provide synchronous access. | 22 // PrefObserverStore caches the values locally to provide synchronous access. |
21 // The cache is empty until the first notification of OnPreferencesChanged is | 23 // The cache is empty until the first notification of OnPreferencesChanged is |
22 // received from the prefs::mojom::PreferenceManager. Upon recieving an initial | 24 // received from the prefs::mojom::PreferenceManager. Upon recieving an initial |
23 // OnPreferencesChanged initialization will be considered as completed, and any | 25 // OnPreferencesChanged initialization will be considered as completed, and any |
24 // PrefStore::Observer will be notified of OnInitializationCompleted. | 26 // PrefStore::Observer will be notified of OnInitializationCompleted. |
25 // | 27 // |
26 // Currently this does not support RemoveValue. | 28 // Currently this does not support RemoveValue. |
27 class PrefObserverStore : public ValueMapPrefStore, | 29 class PrefObserverStore : public ValueMapPrefStore, |
28 public prefs::mojom::PreferencesObserver { | 30 public prefs::mojom::PreferencesObserver { |
29 public: | 31 public: |
30 explicit PrefObserverStore( | 32 explicit PrefObserverStore( |
31 prefs::mojom::PreferencesManagerPtr prefs_manager_ptr); | 33 prefs::mojom::PreferencesManagerPtr prefs_manager_ptr); |
32 | 34 |
33 // Defines the set of |keys| which PrefOvserverStore will handle. Begins | 35 // Adds a set of |keys| which PrefObserverStore will handle. Begins listening |
34 // listening for changes to these from |prefs_manager_|. | 36 // for changes to these from |prefs_manager_|. |
35 void Init(const std::set<std::string>& keys); | 37 void Subscribe(const std::set<std::string>& keys); |
36 | 38 |
37 // PrefStore: | 39 // PrefStore: |
38 bool GetValue(const std::string& key, | 40 bool GetValue(const std::string& key, |
39 const base::Value** value) const override; | 41 const base::Value** value) const override; |
40 | 42 |
41 // ValueMapPrefStore: | 43 // ValueMapPrefStore: |
42 void SetValue(const std::string& key, | 44 void SetValue(const std::string& key, |
43 std::unique_ptr<base::Value> value, | 45 std::unique_ptr<base::Value> value, |
44 uint32_t flags) override; | 46 uint32_t flags) override; |
45 void RemoveValue(const std::string& key, uint32_t flags) override; | 47 void RemoveValue(const std::string& key, uint32_t flags) override; |
(...skipping 22 matching lines...) Expand all Loading... |
68 prefs::mojom::PreferencesManagerPtr prefs_manager_ptr_; | 70 prefs::mojom::PreferencesManagerPtr prefs_manager_ptr_; |
69 | 71 |
70 std::set<std::string> keys_; | 72 std::set<std::string> keys_; |
71 | 73 |
72 // True upon the first OnPreferencesChanged received after Init. | 74 // True upon the first OnPreferencesChanged received after Init. |
73 bool initialized_; | 75 bool initialized_; |
74 | 76 |
75 DISALLOW_COPY_AND_ASSIGN(PrefObserverStore); | 77 DISALLOW_COPY_AND_ASSIGN(PrefObserverStore); |
76 }; | 78 }; |
77 | 79 |
| 80 } // namespace preferences |
78 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_ | 81 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_ |
OLD | NEW |