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

Side by Side Diff: services/preferences/public/cpp/pref_observer_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_
6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_
7
8 #include <set>
9
10 #include "base/macros.h"
11 #include "components/prefs/value_map_pref_store.h"
12 #include "mojo/public/cpp/bindings/binding.h"
13 #include "services/preferences/public/interfaces/preferences.mojom.h"
14
15 namespace preferences {
16
17 class PrefObserverStoreTest;
18
19 // An implementation of PrefStore which uses prefs::mojom::PreferenceManager as
20 // the backing of the preferences.
21 //
22 // PrefObserverStore caches the values locally to provide synchronous access.
23 // The cache is empty until the first notification of OnPreferencesChanged is
24 // received from the prefs::mojom::PreferenceManager. Upon recieving an initial
25 // OnPreferencesChanged initialization will be considered as completed, and any
26 // PrefStore::Observer will be notified of OnInitializationCompleted.
27 //
28 // Currently this does not support RemoveValue.
29 class PrefObserverStore : public ValueMapPrefStore,
30 public prefs::mojom::PreferencesObserver {
31 public:
32 explicit PrefObserverStore(
33 prefs::mojom::PreferencesFactoryPtr pref_factory_ptr);
34
35 // Adds a set of |keys| which PrefObserverStore will handle. Begins listening
36 // for changes to these from |prefs_manager_|.
37 void Subscribe(const std::set<std::string>& keys);
38
39 // PrefStore:
40 bool GetValue(const std::string& key,
41 const base::Value** value) const override;
42
43 // ValueMapPrefStore:
44 void SetValue(const std::string& key,
45 std::unique_ptr<base::Value> value,
46 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;
49 void ReportValueChanged(const std::string& key, uint32_t flags) override;
50 void SetValueSilently(const std::string& key,
51 std::unique_ptr<base::Value> value,
52 uint32_t flags) override;
53
54 protected:
55 // base::RefCounted<PrefStore>:
56 ~PrefObserverStore() override;
57
58 private:
59 friend class PrefObserverStoreTest;
60
61 // Notifies |prefs_manager_| of the change in |key| - |value| pair.
62 void SetValueOnPreferenceManager(const std::string& key,
63 base::Value const & value);
64
65 // prefs::mojom::PreferenceObserver:
66 void OnPreferencesChanged(
67 std::unique_ptr<base::DictionaryValue> preferences) override;
68
69 mojo::Binding<prefs::mojom::PreferencesObserver> prefs_binding_;
70 prefs::mojom::PreferencesFactoryPtr pref_factory_ptr_;
71 prefs::mojom::PreferencesManagerPtr prefs_manager_ptr_;
72
73 std::set<std::string> keys_;
74
75 // True upon the first OnPreferencesChanged received after Init.
76 bool initialized_;
77
78 DISALLOW_COPY_AND_ASSIGN(PrefObserverStore);
79 };
80
81 } // namespace preferences
82 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_
OLDNEW
« no previous file with comments | « services/preferences/public/cpp/pref_client_store.cc ('k') | services/preferences/public/cpp/pref_observer_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698