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

Side by Side Diff: services/preferences/public/cpp/pref_store_manager_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_MANAGER_IMPL_H_
6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_MANAGER_IMPL_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "components/prefs/pref_value_store.h"
12 #include "mojo/public/cpp/bindings/binding_set.h"
13 #include "services/preferences/public/interfaces/preferences.mojom.h"
14 #include "services/service_manager/public/cpp/interface_factory.h"
15 #include "services/service_manager/public/cpp/service.h"
16
17 namespace prefs {
18
19 // This class mediates the connection of clients who wants to read preferences
20 // and the pref stores that store those preferences. Pref stores use the
21 // |PrefStoreRegistry| interface to register themselves with the manager and
22 // clients use the |PrefStoreConnector| interface to connect to these stores.
23 class PrefStoreManagerImpl
24 : public mojom::PrefStoreRegistry,
25 public mojom::PrefStoreConnector,
26 public service_manager::InterfaceFactory<mojom::PrefStoreConnector>,
27 public service_manager::InterfaceFactory<mojom::PrefStoreRegistry>,
28 public service_manager::Service {
29 public:
30 using PrefStoreTypes = std::set<PrefValueStore::PrefStoreType>;
31
32 // Only replies to Connect calls when all |expected_pref_stores| have
33 // registered.
34 PrefStoreManagerImpl(PrefStoreTypes expected_pref_stores);
Sam McNally 2017/03/03 03:47:58 explicit
tibell 2017/03/07 00:52:52 Done.
35 ~PrefStoreManagerImpl() override;
36
37 // PrefStores used by Chrome by default.
Sam McNally 2017/03/03 03:47:58 That's a layering violation. This should be somewh
tibell 2017/03/07 00:52:52 Done. I just removed this for now. We'll do the s
38 static PrefStoreTypes DefaultStores();
39
40 private:
41 // mojom::PrefStoreRegistry:
42 void Register(PrefValueStore::PrefStoreType type,
43 mojom::PrefStorePtr pref_store_ptr) override;
44
45 // mojom::PrefStoreConnector:
46 void Connect(const ConnectCallback& callback) override;
47
48 // service_manager::InterfaceFactory<PrefStoreConnector>:
49 void Create(const service_manager::Identity& remote_identity,
50 prefs::mojom::PrefStoreConnectorRequest request) override;
51
52 // service_manager::InterfaceFactory<PrefStoreRegistry>:
53 void Create(const service_manager::Identity& remote_identity,
54 prefs::mojom::PrefStoreRegistryRequest request) override;
55
56 // service_manager::Service:
57 void OnStart() override;
58 bool OnConnect(const service_manager::ServiceInfo& remote_info,
59 service_manager::InterfaceRegistry* registry) override;
60
61 // Called when a PrefStore previously registered using |Register| disconnects.
62 void OnPrefStoreDisconnect(PrefValueStore::PrefStoreType type);
63
64 // Have all the expected PrefStores connected?
65 bool AllConnected() const;
66
67 // PrefStores that need to register before replying to any Connect calls.
68 PrefStoreTypes expected_pref_stores_;
69
70 using PrefStorePtrs =
Sam McNally 2017/03/03 03:47:58 Types before methods.
tibell 2017/03/07 00:52:52 Done.
71 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>;
72
73 // Registered pref stores.
74 PrefStorePtrs pref_store_ptrs_;
75
76 mojo::BindingSet<mojom::PrefStoreConnector> connector_bindings_;
77 mojo::BindingSet<mojom::PrefStoreRegistry> registry_bindings_;
78
79 // We hold on to the connection request callbacks until all expected
80 // PrefStores have registered.
81 std::vector<ConnectCallback> pending_callbacks_;
82
83 DISALLOW_COPY_AND_ASSIGN(PrefStoreManagerImpl);
84 };
85
86 } // namespace prefs
87
88 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698