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

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

Issue 2743563003: Pref service: add persistent pref store frontend and backend. (Closed)
Patch Set: rebase 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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_PREF_STORE_CLIENT_H_ 5 #ifndef SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_
6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_ 6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_
7 7
8 #include <string>
9
10 #include "base/macros.h" 8 #include "base/macros.h"
11 #include "base/observer_list.h"
12 #include "base/values.h"
13 #include "components/prefs/pref_store.h" 9 #include "components/prefs/pref_store.h"
14 #include "components/prefs/pref_value_map.h" 10 #include "services/preferences/public/cpp/pref_store_client_mixin.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" 11 #include "services/preferences/public/interfaces/preferences.mojom.h"
18 12
19 namespace prefs { 13 namespace prefs {
20 14
21 // TODO(tibell): Make PrefObserverStore use PrefStoreClient as a base class. 15 // TODO(tibell): Make PrefObserverStore use PrefStoreClient as a base class.
22 16
23 // An implementation of PrefStore which uses prefs::mojom::PrefStore as 17 // An implementation of PrefStore which uses prefs::mojom::PrefStore as
24 // the backing store of the preferences. 18 // the backing store of the preferences.
25 // 19 //
26 // PrefStoreClient provides synchronous access to the preferences stored by the 20 // PrefStoreClient provides synchronous access to the preferences stored by the
27 // backing store by caching them locally. 21 // backing store by caching them locally.
28 class PrefStoreClient : public ::PrefStore, public mojom::PrefStoreObserver { 22 class PrefStoreClient : public PrefStoreClientMixin<::PrefStore> {
29 public: 23 public:
30 explicit PrefStoreClient(mojom::PrefStoreConnectionPtr connection); 24 explicit PrefStoreClient(mojom::PrefStoreConnectionPtr connection);
31 25
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: 26 private:
42 friend class PrefStoreClientTest;
43
44 ~PrefStoreClient() override; 27 ~PrefStoreClient() override;
45 28
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); 29 DISALLOW_COPY_AND_ASSIGN(PrefStoreClient);
62 }; 30 };
63 31
64 } // namespace prefs 32 } // namespace prefs
65 33
66 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_ 34 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_
OLDNEW
« no previous file with comments | « services/preferences/public/cpp/persistent_pref_store_client.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