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

Side by Side Diff: services/preferences/pref_store_manager_impl.h

Issue 2767743003: Pref service: Merge connectors and send a PrefRegistry in Connect(). (Closed)
Patch Set: 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_PREF_STORE_MANAGER_IMPL_H_ 5 #ifndef SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_
6 #define SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_ 6 #define SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <unordered_map> 10 #include <unordered_map>
(...skipping 17 matching lines...) Expand all
28 28
29 // This class mediates the connection of clients who wants to read preferences 29 // This class mediates the connection of clients who wants to read preferences
30 // and the pref stores that store those preferences. Pref stores use the 30 // and the pref stores that store those preferences. Pref stores use the
31 // |PrefStoreRegistry| interface to register themselves with the manager and 31 // |PrefStoreRegistry| interface to register themselves with the manager and
32 // clients use the |PrefStoreConnector| interface to connect to these stores. 32 // clients use the |PrefStoreConnector| interface to connect to these stores.
33 class PrefStoreManagerImpl 33 class PrefStoreManagerImpl
34 : public mojom::PrefStoreRegistry, 34 : public mojom::PrefStoreRegistry,
35 public mojom::PrefStoreConnector, 35 public mojom::PrefStoreConnector,
36 public service_manager::InterfaceFactory<mojom::PrefStoreConnector>, 36 public service_manager::InterfaceFactory<mojom::PrefStoreConnector>,
37 public service_manager::InterfaceFactory<mojom::PrefStoreRegistry>, 37 public service_manager::InterfaceFactory<mojom::PrefStoreRegistry>,
38 public service_manager::InterfaceFactory<
39 mojom::PersistentPrefStoreConnector>,
40 public mojom::PrefServiceControl, 38 public mojom::PrefServiceControl,
41 public service_manager::InterfaceFactory<mojom::PrefServiceControl>, 39 public service_manager::InterfaceFactory<mojom::PrefServiceControl>,
42 public service_manager::Service { 40 public service_manager::Service {
43 public: 41 public:
44 // Only replies to Connect calls when all |expected_pref_stores| have 42 // Only replies to Connect calls when all |expected_pref_stores| have
45 // registered. 43 // registered.
46 PrefStoreManagerImpl( 44 PrefStoreManagerImpl(
47 std::set<PrefValueStore::PrefStoreType> expected_pref_stores, 45 std::set<PrefValueStore::PrefStoreType> expected_pref_stores,
48 scoped_refptr<base::SequencedWorkerPool> worker_pool); 46 scoped_refptr<base::SequencedWorkerPool> worker_pool);
49 ~PrefStoreManagerImpl() override; 47 ~PrefStoreManagerImpl() override;
50 48
51 private: 49 private:
52 using PrefStorePtrs = 50 using PrefStorePtrs =
53 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>; 51 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>;
54 52
55 // mojom::PrefStoreRegistry: 53 // mojom::PrefStoreRegistry:
56 void Register(PrefValueStore::PrefStoreType type, 54 void Register(PrefValueStore::PrefStoreType type,
57 mojom::PrefStorePtr pref_store_ptr) override; 55 mojom::PrefStorePtr pref_store_ptr) override;
58 56
59 // mojom::PrefStoreConnector: 57 // mojom::PrefStoreConnector:
60 void Connect(const ConnectCallback& callback) override; 58 void Connect(mojom::PrefRegistryPtr pref_registry,
59 const ConnectCallback& callback) override;
61 60
62 // service_manager::InterfaceFactory<PrefStoreConnector>: 61 // service_manager::InterfaceFactory<PrefStoreConnector>:
63 void Create(const service_manager::Identity& remote_identity, 62 void Create(const service_manager::Identity& remote_identity,
64 prefs::mojom::PrefStoreConnectorRequest request) override; 63 prefs::mojom::PrefStoreConnectorRequest request) override;
65 64
66 // service_manager::InterfaceFactory<PrefStoreRegistry>: 65 // service_manager::InterfaceFactory<PrefStoreRegistry>:
67 void Create(const service_manager::Identity& remote_identity, 66 void Create(const service_manager::Identity& remote_identity,
68 prefs::mojom::PrefStoreRegistryRequest request) override; 67 prefs::mojom::PrefStoreRegistryRequest request) override;
69 68
70 // service_manager::InterfaceFactory<PersistentPrefStoreConnector>:
71 void Create(
72 const service_manager::Identity& remote_identity,
73 prefs::mojom::PersistentPrefStoreConnectorRequest request) override;
74
75 // service_manager::InterfaceFactory<PrefServiceControl>: 69 // service_manager::InterfaceFactory<PrefServiceControl>:
76 void Create(const service_manager::Identity& remote_identity, 70 void Create(const service_manager::Identity& remote_identity,
77 prefs::mojom::PrefServiceControlRequest request) override; 71 prefs::mojom::PrefServiceControlRequest request) override;
78 72
79 // PrefServiceControl: 73 // PrefServiceControl:
80 void Init(mojom::PersistentPrefStoreConfigurationPtr configuration) override; 74 void Init(mojom::PersistentPrefStoreConfigurationPtr configuration) override;
81 75
82 // service_manager::Service: 76 // service_manager::Service:
83 void OnStart() override; 77 void OnStart() override;
84 bool OnConnect(const service_manager::ServiceInfo& remote_info, 78 bool OnConnect(const service_manager::ServiceInfo& remote_info,
85 service_manager::InterfaceRegistry* registry) override; 79 service_manager::InterfaceRegistry* registry) override;
86 80
87 // Called when a PrefStore previously registered using |Register| disconnects. 81 // Called when a PrefStore previously registered using |Register| disconnects.
88 void OnPrefStoreDisconnect(PrefValueStore::PrefStoreType type); 82 void OnPrefStoreDisconnect(PrefValueStore::PrefStoreType type);
89 83
90 // Have all the expected PrefStores connected? 84 // Have all the expected PrefStores connected?
91 bool AllConnected() const; 85 bool AllConnected() const;
92 86
87 void ProcessQueuedConnects();
88
89 void ConnectImpl(mojom::PrefRegistryPtr pref_registry,
90 const ConnectCallback& callback);
91
92 void OnPersistentPrefStoreReady();
93
93 // PrefStores that need to register before replying to any Connect calls. 94 // PrefStores that need to register before replying to any Connect calls.
94 std::set<PrefValueStore::PrefStoreType> expected_pref_stores_; 95 std::set<PrefValueStore::PrefStoreType> expected_pref_stores_;
95 96
96 // Registered pref stores. 97 // Registered pref stores.
97 PrefStorePtrs pref_store_ptrs_; 98 PrefStorePtrs pref_store_ptrs_;
98 99
99 mojo::BindingSet<mojom::PrefStoreConnector> connector_bindings_; 100 mojo::BindingSet<mojom::PrefStoreConnector> connector_bindings_;
100 mojo::BindingSet<mojom::PrefStoreRegistry> registry_bindings_; 101 mojo::BindingSet<mojom::PrefStoreRegistry> registry_bindings_;
101 std::unique_ptr<PersistentPrefStoreImpl> persistent_pref_store_; 102 std::unique_ptr<PersistentPrefStoreImpl> persistent_pref_store_;
102 mojo::BindingSet<mojom::PersistentPrefStoreConnector>
103 persistent_pref_store_bindings_;
104 mojo::Binding<mojom::PrefServiceControl> init_binding_; 103 mojo::Binding<mojom::PrefServiceControl> init_binding_;
105 104
106 // Requests made to connect to the service before it has been initialized.
107 // These will be handled when initialization completes.
108 std::vector<mojom::PersistentPrefStoreConnectorRequest>
109 pending_persistent_pref_store_requests_;
110
111 scoped_refptr<base::SequencedWorkerPool> worker_pool_; 105 scoped_refptr<base::SequencedWorkerPool> worker_pool_;
112 106
113 // We hold on to the connection request callbacks until all expected 107 // We hold on to the connection request callbacks until all expected
114 // PrefStores have registered. 108 // PrefStores have registered.
115 std::vector<ConnectCallback> pending_callbacks_; 109 std::vector<std::pair<ConnectCallback, mojom::PrefRegistryPtr>>
110 pending_connects_;
116 111
117 DISALLOW_COPY_AND_ASSIGN(PrefStoreManagerImpl); 112 DISALLOW_COPY_AND_ASSIGN(PrefStoreManagerImpl);
118 }; 113 };
119 114
120 } // namespace prefs 115 } // namespace prefs
121 116
122 #endif // SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_ 117 #endif // SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_
OLDNEW
« no previous file with comments | « services/preferences/persistent_pref_store_impl_unittest.cc ('k') | services/preferences/pref_store_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698