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

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

Issue 2092453002: Mojom interface for Preferences (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use new wrapper types Created 4 years, 4 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/cpp/preferences_export.h"
14 #include "services/preferences/public/interfaces/preferences.mojom.h"
15
16 namespace shell {
17 class Connector;
18 }
19
20 class PrefObserverStoreTest;
21
22 // An implementation of PrefStore which uses prefs::mojom::PreferenceManager as
23 // the backing of the preferences.
24 //
25 // PrefObserverStore caches the values locally to provide synchronous access.
26 // The cache is empty until the first notification of OnPreferencesChanged is
27 // received from the prefs::mojom::PreferenceManager. Upon this completion any
28 // PrefStore::Observer will be notified of OnInitializationCompleted.
29 //
30 // Currently this does not support RemoveValue or GetMutableValue.
Elliot Glaysher 2016/07/26 21:11:58 In the case of GetMutableValue, there are few enou
31 class SERVICES_PREFERENCES_EXPORT PrefObserverStore
32 : public ValueMapPrefStore,
33 public prefs::mojom::PreferenceObserver {
34 public:
35 PrefObserverStore(prefs::mojom::PreferenceManagerPtr prefs_manager_ptr);
36
37 // Defines the set of |keys| which PrefOvserverStore will handle. Begins
38 // listening for changes to these from |prefs_manager_|.
39 void Init(const std::set<std::string>& keys);
40
41 // PrefStore:
42 bool GetValue(const std::string& key,
43 const base::Value** value) const override;
44
45 // ValueMapPrefStore:
46 void SetValue(const std::string& key,
47 std::unique_ptr<base::Value> value,
48 uint32_t flags) override;
49 void RemoveValue(const std::string& key, uint32_t flags) override;
50 bool GetMutableValue(const std::string& key, base::Value** value) override;
51 void ReportValueChanged(const std::string& key, uint32_t flags) override;
52 void SetValueSilently(const std::string& key,
53 std::unique_ptr<base::Value> value,
54 uint32_t flags) override;
55
56 protected:
57 // base::RefCounted<PrefStore>:
58 ~PrefObserverStore() override;
59
60 private:
61 friend class PrefObserverStoreTest;
62
63 // Notifies |prefs_manager_| of the change in |key| - |value| pair.
64 void SetValueOnPreferenceManager(const std::string& key, base::Value* value);
65
66 // prefs::mojom::PreferenceObserver:
67 void OnPreferencesChanged(
68 std::unordered_map<std::string, prefs::mojom::PreferencePtr> preferences)
69 override;
70
71 mojo::Binding<prefs::mojom::PreferenceObserver> prefs_binding_;
72 prefs::mojom::PreferenceManagerPtr prefs_manager_ptr_;
73 // Typically contained in |prefs_manager_ptr_| however tests may override.
74 prefs::mojom::PreferenceManager* prefs_manager_;
75
76 std::set<std::string> keys_;
77
78 // True upon the first OnPreferencesChanged received after Init.
79 bool initialized_;
80
81 DISALLOW_COPY_AND_ASSIGN(PrefObserverStore);
82 };
83
84 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698