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

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: Update ReportValueChanged Created 4 years, 1 month 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/common/common_custom_types.mojom.h"
13 #include "mojo/public/cpp/bindings/binding.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 recieving an initial
28 // OnPreferencesChanged initialization will be considered as completed, and any
29 // PrefStore::Observer will be notified of OnInitializationCompleted.
30 //
31 // Currently this does not support RemoveValue.
32 class PrefObserverStore : public ValueMapPrefStore,
33 public prefs::mojom::PreferencesObserver {
34 public:
35 explicit PrefObserverStore(
36 prefs::mojom::PreferencesManagerPtr prefs_manager_ptr);
37
38 // Defines the set of |keys| which PrefOvserverStore will handle. Begins
39 // listening for changes to these from |prefs_manager_|.
40 void Init(const std::set<std::string>& keys);
41
42 // PrefStore:
43 bool GetValue(const std::string& key,
44 const base::Value** value) const override;
45
46 // ValueMapPrefStore:
47 void SetValue(const std::string& key,
48 std::unique_ptr<base::Value> value,
49 uint32_t flags) override;
50 void RemoveValue(const std::string& key, uint32_t flags) override;
51 bool GetMutableValue(const std::string& key, base::Value** value) override;
52 void ReportValueChanged(const std::string& key, uint32_t flags) override;
53 void SetValueSilently(const std::string& key,
54 std::unique_ptr<base::Value> value,
55 uint32_t flags) override;
56
57 protected:
58 // base::RefCounted<PrefStore>:
59 ~PrefObserverStore() override;
60
61 private:
62 friend class PrefObserverStoreTest;
63
64 // Notifies |prefs_manager_| of the change in |key| - |value| pair.
65 void SetValueOnPreferenceManager(const std::string& key,
66 const base::Value* value);
dcheng 2016/11/01 18:04:38 Nit: might be nice to pass this as a const ref
jonross 2016/11/01 23:40:22 Done.
67
68 // prefs::mojom::PreferenceObserver:
69 void OnPreferencesChanged(const base::DictionaryValue& preferences) override;
70
71 mojo::Binding<prefs::mojom::PreferencesObserver> prefs_binding_;
72 prefs::mojom::PreferencesManagerPtr prefs_manager_ptr_;
73
74 std::set<std::string> keys_;
75
76 // True upon the first OnPreferencesChanged received after Init.
77 bool initialized_;
78
79 DISALLOW_COPY_AND_ASSIGN(PrefObserverStore);
80 };
81
82 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_OBSERVER_STORE_H_
OLDNEW
« no previous file with comments | « services/preferences/public/cpp/DEPS ('k') | services/preferences/public/cpp/pref_observer_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698