Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: services/preferences/public/cpp/pref_client_store.h

Issue 2644893003: Unify Preferences Mojom Naming to PreferencesService (Closed)
Patch Set: / Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_CLIENT_STORE_H_
6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_ 6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_CLIENT_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 { 15 namespace preferences {
16 16
17 class PrefObserverStoreTest; 17 class PrefClientStoreTest;
18 18
19 // An implementation of PrefStore which uses prefs::mojom::PreferenceManager as 19 // An implementation of PrefStore which uses prefs::mojom::PreferenceManager as
20 // the backing of the preferences. 20 // the backing of the preferences.
21 // 21 //
22 // PrefObserverStore caches the values locally to provide synchronous access. 22 // PrefClientStore caches the values locally to provide synchronous access.
23 // The cache is empty until the first notification of OnPreferencesChanged is 23 // The cache is empty until the first notification of OnPreferencesChanged is
24 // received from the prefs::mojom::PreferenceManager. Upon recieving an initial 24 // received from the prefs::mojom::PreferenceManager. Upon recieving an initial
25 // OnPreferencesChanged initialization will be considered as completed, and any 25 // OnPreferencesChanged initialization will be considered as completed, and any
26 // PrefStore::Observer will be notified of OnInitializationCompleted. 26 // PrefStore::Observer will be notified of OnInitializationCompleted.
27 // 27 //
28 // Currently this does not support RemoveValue. 28 // Currently this does not support RemoveValue.
29 class PrefObserverStore : public ValueMapPrefStore, 29 class PrefClientStore : public ValueMapPrefStore,
30 public prefs::mojom::PreferencesObserver { 30 public prefs::mojom::PreferencesServiceClient {
31 public: 31 public:
32 explicit PrefObserverStore( 32 explicit PrefClientStore(
33 prefs::mojom::PreferencesFactoryPtr pref_factory_ptr); 33 prefs::mojom::PreferencesServiceFactoryPtr pref_factory_ptr);
34 34
35 // Adds a set of |keys| which PrefObserverStore will handle. Begins listening 35 // Adds a set of |keys| which PrefClientStore will handle. Begins listening
36 // for changes to these from |prefs_manager_|. 36 // for changes to these from |prefs_service_|.
37 void Subscribe(const std::set<std::string>& keys); 37 void Subscribe(const std::set<std::string>& keys);
38 38
39 // PrefStore: 39 // PrefStore:
40 bool GetValue(const std::string& key, 40 bool GetValue(const std::string& key,
41 const base::Value** value) const override; 41 const base::Value** value) const override;
42 42
43 // ValueMapPrefStore: 43 // ValueMapPrefStore:
44 void SetValue(const std::string& key, 44 void SetValue(const std::string& key,
45 std::unique_ptr<base::Value> value, 45 std::unique_ptr<base::Value> value,
46 uint32_t flags) override; 46 uint32_t flags) override;
47 void RemoveValue(const std::string& key, uint32_t flags) override; 47 void RemoveValue(const std::string& key, uint32_t flags) override;
48 bool GetMutableValue(const std::string& key, base::Value** value) override; 48 bool GetMutableValue(const std::string& key, base::Value** value) override;
49 void ReportValueChanged(const std::string& key, uint32_t flags) override; 49 void ReportValueChanged(const std::string& key, uint32_t flags) override;
50 void SetValueSilently(const std::string& key, 50 void SetValueSilently(const std::string& key,
51 std::unique_ptr<base::Value> value, 51 std::unique_ptr<base::Value> value,
52 uint32_t flags) override; 52 uint32_t flags) override;
53 53
54 protected: 54 protected:
55 // base::RefCounted<PrefStore>: 55 // base::RefCounted<PrefStore>:
56 ~PrefObserverStore() override; 56 ~PrefClientStore() override;
57 57
58 private: 58 private:
59 friend class PrefObserverStoreTest; 59 friend class PrefClientStoreTest;
60 60
61 // Notifies |prefs_manager_| of the change in |key| - |value| pair. 61 // Notifies |prefs_service_| of the change in |key| - |value| pair.
62 void SetValueOnPreferenceManager(const std::string& key, 62 void SetValueOnPreferenceManager(const std::string& key,
63 base::Value const & value); 63 base::Value const& value);
64 64
65 // prefs::mojom::PreferenceObserver: 65 // prefs::mojom::PreferencesServiceClient:
66 void OnPreferencesChanged( 66 void OnPreferencesChanged(
67 std::unique_ptr<base::DictionaryValue> preferences) override; 67 std::unique_ptr<base::DictionaryValue> preferences) override;
68 68
69 mojo::Binding<prefs::mojom::PreferencesObserver> prefs_binding_; 69 mojo::Binding<prefs::mojom::PreferencesServiceClient> prefs_binding_;
70 prefs::mojom::PreferencesFactoryPtr pref_factory_ptr_; 70 prefs::mojom::PreferencesServiceFactoryPtr pref_factory_ptr_;
71 prefs::mojom::PreferencesManagerPtr prefs_manager_ptr_; 71 prefs::mojom::PreferencesServicePtr prefs_service_ptr_;
72 72
73 std::set<std::string> keys_; 73 std::set<std::string> keys_;
74 74
75 // True upon the first OnPreferencesChanged received after Init. 75 // True upon the first OnPreferencesChanged received after Init.
76 bool initialized_; 76 bool initialized_;
77 77
78 DISALLOW_COPY_AND_ASSIGN(PrefObserverStore); 78 DISALLOW_COPY_AND_ASSIGN(PrefClientStore);
79 }; 79 };
80 80
81 } // namespace preferences 81 } // namespace preferences
82 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_ 82 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_CLIENT_STORE_H_
OLDNEW
« no previous file with comments | « services/preferences/public/cpp/BUILD.gn ('k') | services/preferences/public/cpp/pref_client_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698