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

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

Issue 2635153002: Pref service: expose all read-only PrefStores through Mojo (Closed)
Patch Set: Address bauerb's review comments Created 3 years, 9 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 2017 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_PREF_STORE_CLIENT_H_
6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_
7
8 #include <string>
9
10 #include "base/macros.h"
11 #include "base/observer_list.h"
12 #include "base/values.h"
13 #include "components/prefs/pref_store.h"
14 #include "components/prefs/pref_value_map.h"
15 #include "mojo/public/cpp/bindings/binding.h"
16 #include "services/preferences/public/cpp/pref_store_manager_impl.h"
17 #include "services/preferences/public/interfaces/preferences.mojom.h"
18
19 namespace prefs {
20
21 // TODO(tibell): Make PrefObserverStore use PrefStoreClient as a base class.
22
23 // An implementation of PrefStore which uses prefs::mojom::PrefStore as
24 // the backing store of the preferences.
25 //
26 // PrefStoreClient provides synchronous access to the preferences stored by the
27 // backing store by caching them locally.
28 class PrefStoreClient : public ::PrefStore, public mojom::PrefStoreObserver {
29 public:
30 explicit PrefStoreClient(mojom::PrefStoreConnectionPtr connection);
31
32 // PrefStore:
33 void AddObserver(PrefStore::Observer* observer) override;
34 void RemoveObserver(PrefStore::Observer* observer) override;
35 bool HasObservers() const override;
36 bool IsInitializationComplete() const override;
37 bool GetValue(const std::string& key,
38 const base::Value** result) const override;
39 std::unique_ptr<base::DictionaryValue> GetValues() const override;
40
41 private:
42 friend class PrefStoreClientTest;
43
44 ~PrefStoreClient() override;
45
46 // prefs::mojom::PreferenceObserver:
47 void OnPrefChanged(const std::string& key,
48 std::unique_ptr<base::Value> value) override;
49 void OnInitializationCompleted(bool succeeded) override;
50
51 // Cached preferences.
52 std::unique_ptr<base::DictionaryValue> cached_prefs_;
53
54 base::ObserverList<PrefStore::Observer, true> observers_;
55
56 // Has the PrefStore we're observing been initialized?
57 bool initialized_;
58
59 mojo::Binding<mojom::PrefStoreObserver> observer_binding_;
60
61 DISALLOW_COPY_AND_ASSIGN(PrefStoreClient);
62 };
63
64 } // namespace prefs
65
66 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_
OLDNEW
« no previous file with comments | « services/preferences/public/cpp/pref_store_adapter.cc ('k') | services/preferences/public/cpp/pref_store_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698