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

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: 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 {
Sam McNally 2017/04/03 10:09:31 Could this be defined in the .cc file?
tibell 2017/04/04 04:05:59 Done.
54 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>; 54 PendingConnect(
55 mojom::PrefRegistryPtr pref_registry_in,
56 std::vector<PrefValueStore::PrefStoreType> already_connected_types_in,
57 const ConnectCallback& callback_in);
58 PendingConnect(PendingConnect&& other);
59 ~PendingConnect();
60
61 mojom::PrefRegistryPtr pref_registry;
62 // Pref stores the caller already is connected to (and hence we won't
63 // connect to these).
64 std::vector<PrefValueStore::PrefStoreType> already_connected_types;
65 ConnectCallback callback;
66 };
55 67
56 // mojom::PrefStoreRegistry: 68 // mojom::PrefStoreRegistry:
57 void Register(PrefValueStore::PrefStoreType type, 69 void Register(PrefValueStore::PrefStoreType type,
58 mojom::PrefStorePtr pref_store_ptr) override; 70 mojom::PrefStorePtr pref_store_ptr) override;
59 71
60 // mojom::PrefStoreConnector: 72 // mojom::PrefStoreConnector:
61 void Connect(mojom::PrefRegistryPtr pref_registry, 73 void Connect(
62 const ConnectCallback& callback) override; 74 mojom::PrefRegistryPtr pref_registry,
75 const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
76 const ConnectCallback& callback) override;
63 77
64 // service_manager::InterfaceFactory<PrefStoreConnector>: 78 // service_manager::InterfaceFactory<PrefStoreConnector>:
65 void Create(const service_manager::Identity& remote_identity, 79 void Create(const service_manager::Identity& remote_identity,
66 prefs::mojom::PrefStoreConnectorRequest request) override; 80 prefs::mojom::PrefStoreConnectorRequest request) override;
67 81
68 // service_manager::InterfaceFactory<PrefStoreRegistry>: 82 // service_manager::InterfaceFactory<PrefStoreRegistry>:
69 void Create(const service_manager::Identity& remote_identity, 83 void Create(const service_manager::Identity& remote_identity,
70 prefs::mojom::PrefStoreRegistryRequest request) override; 84 prefs::mojom::PrefStoreRegistryRequest request) override;
71 85
72 // service_manager::InterfaceFactory<PrefServiceControl>: 86 // service_manager::InterfaceFactory<PrefServiceControl>:
73 void Create(const service_manager::Identity& remote_identity, 87 void Create(const service_manager::Identity& remote_identity,
74 prefs::mojom::PrefServiceControlRequest request) override; 88 prefs::mojom::PrefServiceControlRequest request) override;
75 89
76 // PrefServiceControl: 90 // PrefServiceControl:
77 void Init(mojom::PersistentPrefStoreConfigurationPtr configuration) override; 91 void Init(mojom::PersistentPrefStoreConfigurationPtr configuration) override;
78 92
79 // service_manager::Service: 93 // service_manager::Service:
80 void OnStart() override; 94 void OnStart() override;
81 bool OnConnect(const service_manager::ServiceInfo& remote_info, 95 bool OnConnect(const service_manager::ServiceInfo& remote_info,
82 service_manager::InterfaceRegistry* registry) override; 96 service_manager::InterfaceRegistry* registry) override;
83 97
84 // Called when a PrefStore previously registered using |Register| disconnects. 98 // Called when a PrefStore previously registered using |Register| disconnects.
85 void OnPrefStoreDisconnect(PrefValueStore::PrefStoreType type); 99 void OnPrefStoreDisconnect(PrefValueStore::PrefStoreType type);
86 100
87 // Have all the expected PrefStores connected? 101 // Have all the expected PrefStores connected?
88 bool AllConnected() const; 102 bool AllConnected() const;
89 103
90 void ProcessPendingConnects(); 104 void ProcessPendingConnects();
91 105
92 void ConnectImpl(mojom::PrefRegistryPtr pref_registry, 106 void ConnectImpl(
93 const ConnectCallback& callback); 107 mojom::PrefRegistryPtr pref_registry,
108 const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
109 const ConnectCallback& callback);
94 110
95 void OnPersistentPrefStoreReady(); 111 void OnPersistentPrefStoreReady();
96 112
97 // PrefStores that need to register before replying to any Connect calls. 113 // PrefStores that need to register before replying to any Connect calls.
98 std::set<PrefValueStore::PrefStoreType> expected_pref_stores_; 114 std::set<PrefValueStore::PrefStoreType> expected_pref_stores_;
99 115
100 // Registered pref stores. 116 // Registered pref stores.
101 PrefStorePtrs pref_store_ptrs_; 117 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>
118 pref_store_ptrs_;
102 119
103 // We hold on to the connection request callbacks until all expected 120 // We hold on to the connection request callbacks until all expected
104 // PrefStores have registered. 121 // PrefStores have registered.
105 std::vector<std::pair<ConnectCallback, mojom::PrefRegistryPtr>> 122 std::vector<PendingConnect> pending_connects_;
106 pending_connects_;
107 123
108 mojo::BindingSet<mojom::PrefStoreConnector> connector_bindings_; 124 mojo::BindingSet<mojom::PrefStoreConnector> connector_bindings_;
109 mojo::BindingSet<mojom::PrefStoreRegistry> registry_bindings_; 125 mojo::BindingSet<mojom::PrefStoreRegistry> registry_bindings_;
110 std::unique_ptr<PersistentPrefStoreImpl> persistent_pref_store_; 126 std::unique_ptr<PersistentPrefStoreImpl> persistent_pref_store_;
111 mojo::Binding<mojom::PrefServiceControl> init_binding_; 127 mojo::Binding<mojom::PrefServiceControl> init_binding_;
112 128
113 const scoped_refptr<DefaultPrefStore> defaults_; 129 const scoped_refptr<DefaultPrefStore> defaults_;
114 const std::unique_ptr<PrefStoreImpl> defaults_wrapper_; 130 const std::unique_ptr<PrefStoreImpl> defaults_wrapper_;
115 131
116 const scoped_refptr<base::SequencedWorkerPool> worker_pool_; 132 const scoped_refptr<base::SequencedWorkerPool> worker_pool_;
117 133
118 DISALLOW_COPY_AND_ASSIGN(PrefStoreManagerImpl); 134 DISALLOW_COPY_AND_ASSIGN(PrefStoreManagerImpl);
119 }; 135 };
120 136
121 } // namespace prefs 137 } // namespace prefs
122 138
123 #endif // SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_ 139 #endif // SERVICES_PREFERENCES_PREF_STORE_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698