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

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

Issue 2635153002: Pref service: expose all read-only PrefStores through Mojo (Closed)
Patch Set: Merge 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_IMPL_H_
6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_
7
8 #include <vector>
9
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "components/prefs/pref_store.h"
13 #include "components/prefs/pref_value_store.h"
14 #include "mojo/public/cpp/bindings/binding.h"
15 #include "services/preferences/public/interfaces/preferences.mojom.h"
16
17 namespace prefs {
18
19 // Wraps an actual PrefStore implementation and exposes it as a
20 // mojom::PrefStore interface.
21 class PrefStoreImpl : public ::PrefStore::Observer, public mojom::PrefStore {
22 public:
23 // The created instance is registered in and owned by the
24 // |mojom::PrefStoreRegistry|.
25 static std::unique_ptr<PrefStoreImpl> Create(
Sam McNally 2017/03/03 03:47:58 Methods after destructors.
tibell 2017/03/07 00:52:52 Done.
26 mojom::PrefStoreRegistryPtr registry_ptr,
27 scoped_refptr<::PrefStore> pref_store,
28 PrefValueStore::PrefStoreType type);
29
30 PrefStoreImpl(scoped_refptr<::PrefStore> pref_store,
31 mojom::PrefStoreRequest request);
32 ~PrefStoreImpl() override;
33
34 private:
35 // PrefStore::Observer:
36 void OnPrefValueChanged(const std::string& key) override;
37 void OnInitializationCompleted(bool succeeded) override;
38
39 // prefs::mojom::PrefStore:
40 void AddObserver(const AddObserverCallback& callback) override;
41
42 // The backing store we observer for changes. This a |WeakPtr| because if we
Sam McNally 2017/03/03 03:47:58 I think this comment is mostly no longer necessary
tibell 2017/03/07 00:52:52 Done.
43 // hold on to the |PrefStore| until this is torned down we mess up shutdown
44 // order, which e.g. depends on when the |Profile| is deleted. This is quite
45 // unsatisfactory.
46 scoped_refptr<::PrefStore> backing_pref_store_;
47
48 // Observers we notify when |backing_pref_store_| changes.
49 std::vector<mojom::PrefStoreObserverPtr> observers_;
50
51 // True when the |backing_pref_store_| is initialized, either because it was
52 // passed already initialized in the constructor or after
53 // OnInitializationCompleted was called.
54 bool initialized_;
Sam McNally 2017/03/03 03:47:58 How about naming this |backing_pref_store_initiali
tibell 2017/03/07 00:52:52 Done.
55
56 mojo::Binding<mojom::PrefStore> binding_;
57
58 DISALLOW_COPY_AND_ASSIGN(PrefStoreImpl);
59 };
60
61 } // namespace prefs
62
63 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698