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

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: Don't require clients to specify the default store, but allow it 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
47 PrefStoreManagerImpl( 47 PrefStoreManagerImpl(
48 std::set<PrefValueStore::PrefStoreType> expected_pref_stores, 48 std::set<PrefValueStore::PrefStoreType> expected_pref_stores,
49 scoped_refptr<base::SequencedWorkerPool> worker_pool); 49 scoped_refptr<base::SequencedWorkerPool> worker_pool);
50 ~PrefStoreManagerImpl() override; 50 ~PrefStoreManagerImpl() override;
51 51
52 private: 52 private:
53 using PrefStorePtrs = 53 struct PendingConnect;
54 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>;
55 54
56 // mojom::PrefStoreRegistry: 55 // mojom::PrefStoreRegistry:
57 void Register(PrefValueStore::PrefStoreType type, 56 void Register(PrefValueStore::PrefStoreType type,
58 mojom::PrefStorePtr pref_store_ptr) override; 57 mojom::PrefStorePtr pref_store_ptr) override;
59 58
60 // mojom::PrefStoreConnector: 59 // mojom::PrefStoreConnector:
61 void Connect(mojom::PrefRegistryPtr pref_registry, 60 void Connect(
62 const ConnectCallback& callback) override; 61 mojom::PrefRegistryPtr pref_registry,
62 const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
63 const ConnectCallback& callback) override;
63 64
64 // service_manager::InterfaceFactory<PrefStoreConnector>: 65 // service_manager::InterfaceFactory<PrefStoreConnector>:
65 void Create(const service_manager::Identity& remote_identity, 66 void Create(const service_manager::Identity& remote_identity,
66 prefs::mojom::PrefStoreConnectorRequest request) override; 67 prefs::mojom::PrefStoreConnectorRequest request) override;
67 68
68 // service_manager::InterfaceFactory<PrefStoreRegistry>: 69 // service_manager::InterfaceFactory<PrefStoreRegistry>:
69 void Create(const service_manager::Identity& remote_identity, 70 void Create(const service_manager::Identity& remote_identity,
70 prefs::mojom::PrefStoreRegistryRequest request) override; 71 prefs::mojom::PrefStoreRegistryRequest request) override;
71 72
72 // service_manager::InterfaceFactory<PrefServiceControl>: 73 // service_manager::InterfaceFactory<PrefServiceControl>:
73 void Create(const service_manager::Identity& remote_identity, 74 void Create(const service_manager::Identity& remote_identity,
74 prefs::mojom::PrefServiceControlRequest request) override; 75 prefs::mojom::PrefServiceControlRequest request) override;
75 76
76 // PrefServiceControl: 77 // PrefServiceControl:
77 void Init(mojom::PersistentPrefStoreConfigurationPtr configuration) override; 78 void Init(mojom::PersistentPrefStoreConfigurationPtr configuration) override;
78 79
79 // service_manager::Service: 80 // service_manager::Service:
80 void OnStart() override; 81 void OnStart() override;
81 bool OnConnect(const service_manager::ServiceInfo& remote_info, 82 bool OnConnect(const service_manager::ServiceInfo& remote_info,
82 service_manager::InterfaceRegistry* registry) override; 83 service_manager::InterfaceRegistry* registry) override;
83 84
84 // Called when a PrefStore previously registered using |Register| disconnects. 85 // Called when a PrefStore previously registered using |Register| disconnects.
85 void OnPrefStoreDisconnect(PrefValueStore::PrefStoreType type); 86 void OnPrefStoreDisconnect(PrefValueStore::PrefStoreType type);
86 87
87 // Have all the expected PrefStores connected? 88 // Have all the expected PrefStores connected?
88 bool AllConnected() const; 89 bool AllConnected() const;
89 90
90 void ProcessPendingConnects(); 91 void ProcessPendingConnects();
91 92
92 void ConnectImpl(mojom::PrefRegistryPtr pref_registry, 93 void ConnectImpl(
93 const ConnectCallback& callback); 94 mojom::PrefRegistryPtr pref_registry,
95 const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
96 const ConnectCallback& callback);
94 97
95 void OnPersistentPrefStoreReady(); 98 void OnPersistentPrefStoreReady();
96 99
97 // PrefStores that need to register before replying to any Connect calls. 100 // PrefStores that need to register before replying to any Connect calls. This
101 // does not include the PersistentPrefStore, which is handled separately.
98 std::set<PrefValueStore::PrefStoreType> expected_pref_stores_; 102 std::set<PrefValueStore::PrefStoreType> expected_pref_stores_;
99 103
100 // Registered pref stores. 104 // Registered pref stores.
101 PrefStorePtrs pref_store_ptrs_; 105 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>
106 pref_store_ptrs_;
102 107
103 // We hold on to the connection request callbacks until all expected 108 // We hold on to the connection request callbacks until all expected
104 // PrefStores have registered. 109 // PrefStores have registered.
105 std::vector<std::pair<ConnectCallback, mojom::PrefRegistryPtr>> 110 std::vector<PendingConnect> pending_connects_;
106 pending_connects_;
107 111
108 mojo::BindingSet<mojom::PrefStoreConnector> connector_bindings_; 112 mojo::BindingSet<mojom::PrefStoreConnector> connector_bindings_;
109 mojo::BindingSet<mojom::PrefStoreRegistry> registry_bindings_; 113 mojo::BindingSet<mojom::PrefStoreRegistry> registry_bindings_;
110 std::unique_ptr<PersistentPrefStoreImpl> persistent_pref_store_; 114 std::unique_ptr<PersistentPrefStoreImpl> persistent_pref_store_;
111 mojo::Binding<mojom::PrefServiceControl> init_binding_; 115 mojo::Binding<mojom::PrefServiceControl> init_binding_;
112 116
113 const scoped_refptr<DefaultPrefStore> defaults_; 117 const scoped_refptr<DefaultPrefStore> defaults_;
114 const std::unique_ptr<PrefStoreImpl> defaults_wrapper_; 118 const std::unique_ptr<PrefStoreImpl> defaults_wrapper_;
115 119
116 const scoped_refptr<base::SequencedWorkerPool> worker_pool_; 120 const scoped_refptr<base::SequencedWorkerPool> worker_pool_;
117 121
118 DISALLOW_COPY_AND_ASSIGN(PrefStoreManagerImpl); 122 DISALLOW_COPY_AND_ASSIGN(PrefStoreManagerImpl);
119 }; 123 };
120 124
121 } // namespace prefs 125 } // namespace prefs
122 126
123 #endif // SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_ 127 #endif // SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698