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

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

Issue 2791903003: Pref service: have Mash and Chrome connect to the right pref stores (Closed)
Patch Set: ProfilePrefStoreManagerTest: explicit list stores to connect to Created 3 years, 8 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 25 matching lines...) Expand all
36 class PrefStoreManagerImpl 36 class PrefStoreManagerImpl
37 : public mojom::PrefStoreRegistry, 37 : public mojom::PrefStoreRegistry,
38 public mojom::PrefStoreConnector, 38 public mojom::PrefStoreConnector,
39 public service_manager::InterfaceFactory<mojom::PrefStoreConnector>, 39 public service_manager::InterfaceFactory<mojom::PrefStoreConnector>,
40 public service_manager::InterfaceFactory<mojom::PrefStoreRegistry>, 40 public service_manager::InterfaceFactory<mojom::PrefStoreRegistry>,
41 public mojom::PrefServiceControl, 41 public mojom::PrefServiceControl,
42 public service_manager::InterfaceFactory<mojom::PrefServiceControl>, 42 public service_manager::InterfaceFactory<mojom::PrefServiceControl>,
43 public service_manager::Service { 43 public service_manager::Service {
44 public: 44 public:
45 // Only replies to Connect calls when all |expected_pref_stores| have 45 // Only replies to Connect calls when all |expected_pref_stores| have
46 // registered. 46 // registered. |expected_pref_stores| must contain
47 // PrefValueStore::DEFAULT_STORE and PrefValueStore::USER_STORE for
48 // consistency, as the service always registers these
49 // internally. |worker_pool| is used for any I/O performed by the service.
47 PrefStoreManagerImpl( 50 PrefStoreManagerImpl(
48 std::set<PrefValueStore::PrefStoreType> expected_pref_stores, 51 std::set<PrefValueStore::PrefStoreType> expected_pref_stores,
49 scoped_refptr<base::SequencedWorkerPool> worker_pool); 52 scoped_refptr<base::SequencedWorkerPool> worker_pool);
50 ~PrefStoreManagerImpl() override; 53 ~PrefStoreManagerImpl() override;
51 54
52 private: 55 private:
53 using PrefStorePtrs = 56 struct PendingConnect;
54 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>;
55 57
56 // mojom::PrefStoreRegistry: 58 // mojom::PrefStoreRegistry:
57 void Register(PrefValueStore::PrefStoreType type, 59 void Register(PrefValueStore::PrefStoreType type,
58 mojom::PrefStorePtr pref_store_ptr) override; 60 mojom::PrefStorePtr pref_store_ptr) override;
59 61
60 // mojom::PrefStoreConnector: 62 // mojom::PrefStoreConnector: |already_connected_types| must not include
61 void Connect(mojom::PrefRegistryPtr pref_registry, 63 // PrefValueStore::DEFAULT_STORE and PrefValueStore::USER_STORE as these must
62 const ConnectCallback& callback) override; 64 // always be accessed through the service.
65 void Connect(
66 mojom::PrefRegistryPtr pref_registry,
67 const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
68 const ConnectCallback& callback) override;
63 69
64 // service_manager::InterfaceFactory<PrefStoreConnector>: 70 // service_manager::InterfaceFactory<PrefStoreConnector>:
65 void Create(const service_manager::Identity& remote_identity, 71 void Create(const service_manager::Identity& remote_identity,
66 prefs::mojom::PrefStoreConnectorRequest request) override; 72 prefs::mojom::PrefStoreConnectorRequest request) override;
67 73
68 // service_manager::InterfaceFactory<PrefStoreRegistry>: 74 // service_manager::InterfaceFactory<PrefStoreRegistry>:
69 void Create(const service_manager::Identity& remote_identity, 75 void Create(const service_manager::Identity& remote_identity,
70 prefs::mojom::PrefStoreRegistryRequest request) override; 76 prefs::mojom::PrefStoreRegistryRequest request) override;
71 77
72 // service_manager::InterfaceFactory<PrefServiceControl>: 78 // service_manager::InterfaceFactory<PrefServiceControl>:
73 void Create(const service_manager::Identity& remote_identity, 79 void Create(const service_manager::Identity& remote_identity,
74 prefs::mojom::PrefServiceControlRequest request) override; 80 prefs::mojom::PrefServiceControlRequest request) override;
75 81
76 // PrefServiceControl: 82 // PrefServiceControl:
77 void Init(mojom::PersistentPrefStoreConfigurationPtr configuration) override; 83 void Init(mojom::PersistentPrefStoreConfigurationPtr configuration) override;
78 84
79 // service_manager::Service: 85 // service_manager::Service:
80 void OnStart() override; 86 void OnStart() override;
81 bool OnConnect(const service_manager::ServiceInfo& remote_info, 87 bool OnConnect(const service_manager::ServiceInfo& remote_info,
82 service_manager::InterfaceRegistry* registry) override; 88 service_manager::InterfaceRegistry* registry) override;
83 89
84 // Called when a PrefStore previously registered using |Register| disconnects. 90 // Called when a PrefStore previously registered using |Register| disconnects.
85 void OnPrefStoreDisconnect(PrefValueStore::PrefStoreType type); 91 void OnPrefStoreDisconnect(PrefValueStore::PrefStoreType type);
86 92
87 // Have all the expected PrefStores connected? 93 // Have all the expected PrefStores connected?
88 bool AllConnected() const; 94 bool AllConnected() const;
89 95
90 void ProcessPendingConnects(); 96 void ProcessPendingConnects();
91 97
92 void ConnectImpl(mojom::PrefRegistryPtr pref_registry, 98 void ConnectImpl(
93 const ConnectCallback& callback); 99 mojom::PrefRegistryPtr pref_registry,
100 const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
101 const ConnectCallback& callback);
94 102
95 void OnPersistentPrefStoreReady(); 103 void OnPersistentPrefStoreReady();
96 104
97 // PrefStores that need to register before replying to any Connect calls. 105 // PrefStores that need to register before replying to any Connect calls. This
106 // does not include the PersistentPrefStore, which is handled separately.
98 std::set<PrefValueStore::PrefStoreType> expected_pref_stores_; 107 std::set<PrefValueStore::PrefStoreType> expected_pref_stores_;
99 108
100 // Registered pref stores. 109 // Registered pref stores.
101 PrefStorePtrs pref_store_ptrs_; 110 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>
111 pref_store_ptrs_;
102 112
103 // We hold on to the connection request callbacks until all expected 113 // We hold on to the connection request callbacks until all expected
104 // PrefStores have registered. 114 // PrefStores have registered.
105 std::vector<std::pair<ConnectCallback, mojom::PrefRegistryPtr>> 115 std::vector<PendingConnect> pending_connects_;
106 pending_connects_;
107 116
108 mojo::BindingSet<mojom::PrefStoreConnector> connector_bindings_; 117 mojo::BindingSet<mojom::PrefStoreConnector> connector_bindings_;
109 mojo::BindingSet<mojom::PrefStoreRegistry> registry_bindings_; 118 mojo::BindingSet<mojom::PrefStoreRegistry> registry_bindings_;
110 std::unique_ptr<PersistentPrefStoreImpl> persistent_pref_store_; 119 std::unique_ptr<PersistentPrefStoreImpl> persistent_pref_store_;
111 mojo::Binding<mojom::PrefServiceControl> init_binding_; 120 mojo::Binding<mojom::PrefServiceControl> init_binding_;
112 121
113 const scoped_refptr<DefaultPrefStore> defaults_; 122 const scoped_refptr<DefaultPrefStore> defaults_;
114 const std::unique_ptr<PrefStoreImpl> defaults_wrapper_; 123 const std::unique_ptr<PrefStoreImpl> defaults_wrapper_;
115 124
116 const scoped_refptr<base::SequencedWorkerPool> worker_pool_; 125 const scoped_refptr<base::SequencedWorkerPool> worker_pool_;
117 126
118 DISALLOW_COPY_AND_ASSIGN(PrefStoreManagerImpl); 127 DISALLOW_COPY_AND_ASSIGN(PrefStoreManagerImpl);
119 }; 128 };
120 129
121 } // namespace prefs 130 } // namespace prefs
122 131
123 #endif // SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_ 132 #endif // SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_
OLDNEW
« no previous file with comments | « services/preferences/pref_service_factory_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