| OLD | NEW |
| (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 <memory> | |
| 9 #include <set> | |
| 10 #include <unordered_map> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/compiler_specific.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "components/prefs/pref_value_store.h" | |
| 17 #include "mojo/public/cpp/bindings/binding_set.h" | |
| 18 #include "services/preferences/public/interfaces/preferences.mojom.h" | |
| 19 #include "services/service_manager/public/cpp/interface_factory.h" | |
| 20 #include "services/service_manager/public/cpp/service.h" | |
| 21 | |
| 22 namespace base { | |
| 23 class SequencedWorkerPool; | |
| 24 } | |
| 25 | |
| 26 namespace prefs { | |
| 27 class PersistentPrefStoreImpl; | |
| 28 | |
| 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 | |
| 31 // |PrefStoreRegistry| interface to register themselves with the manager and | |
| 32 // clients use the |PrefStoreConnector| interface to connect to these stores. | |
| 33 class PrefStoreManagerImpl | |
| 34 : public mojom::PrefStoreRegistry, | |
| 35 public mojom::PrefStoreConnector, | |
| 36 public service_manager::InterfaceFactory<mojom::PrefStoreConnector>, | |
| 37 public service_manager::InterfaceFactory<mojom::PrefStoreRegistry>, | |
| 38 public service_manager::InterfaceFactory< | |
| 39 mojom::PersistentPrefStoreConnector>, | |
| 40 public mojom::PrefServiceControl, | |
| 41 public service_manager::InterfaceFactory<mojom::PrefServiceControl>, | |
| 42 public service_manager::Service { | |
| 43 public: | |
| 44 using PrefStoreTypes = std::set<PrefValueStore::PrefStoreType>; | |
| 45 | |
| 46 // Only replies to Connect calls when all |expected_pref_stores| have | |
| 47 // registered. | |
| 48 PrefStoreManagerImpl(PrefStoreTypes expected_pref_stores, | |
| 49 scoped_refptr<base::SequencedWorkerPool> worker_pool); | |
| 50 ~PrefStoreManagerImpl() override; | |
| 51 | |
| 52 private: | |
| 53 using PrefStorePtrs = | |
| 54 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>; | |
| 55 | |
| 56 // mojom::PrefStoreRegistry: | |
| 57 void Register(PrefValueStore::PrefStoreType type, | |
| 58 mojom::PrefStorePtr pref_store_ptr) override; | |
| 59 | |
| 60 // mojom::PrefStoreConnector: | |
| 61 void Connect(const ConnectCallback& callback) override; | |
| 62 | |
| 63 // service_manager::InterfaceFactory<PrefStoreConnector>: | |
| 64 void Create(const service_manager::Identity& remote_identity, | |
| 65 prefs::mojom::PrefStoreConnectorRequest request) override; | |
| 66 | |
| 67 // service_manager::InterfaceFactory<PrefStoreRegistry>: | |
| 68 void Create(const service_manager::Identity& remote_identity, | |
| 69 prefs::mojom::PrefStoreRegistryRequest request) override; | |
| 70 | |
| 71 // service_manager::InterfaceFactory<PersistentPrefStoreConnector>: | |
| 72 void Create( | |
| 73 const service_manager::Identity& remote_identity, | |
| 74 prefs::mojom::PersistentPrefStoreConnectorRequest request) override; | |
| 75 | |
| 76 // service_manager::InterfaceFactory<PrefServiceControl>: | |
| 77 void Create(const service_manager::Identity& remote_identity, | |
| 78 prefs::mojom::PrefServiceControlRequest request) override; | |
| 79 | |
| 80 // PrefServiceControl: | |
| 81 void Init(mojom::PersistentPrefStoreConfigurationPtr configuration) override; | |
| 82 | |
| 83 // service_manager::Service: | |
| 84 void OnStart() override; | |
| 85 bool OnConnect(const service_manager::ServiceInfo& remote_info, | |
| 86 service_manager::InterfaceRegistry* registry) override; | |
| 87 | |
| 88 // Called when a PrefStore previously registered using |Register| disconnects. | |
| 89 void OnPrefStoreDisconnect(PrefValueStore::PrefStoreType type); | |
| 90 | |
| 91 // Have all the expected PrefStores connected? | |
| 92 bool AllConnected() const; | |
| 93 | |
| 94 // PrefStores that need to register before replying to any Connect calls. | |
| 95 PrefStoreTypes expected_pref_stores_; | |
| 96 | |
| 97 // Registered pref stores. | |
| 98 PrefStorePtrs pref_store_ptrs_; | |
| 99 | |
| 100 // We hold on to the connection request callbacks until all expected | |
| 101 // PrefStores have registered. | |
| 102 std::vector<ConnectCallback> pending_callbacks_; | |
| 103 | |
| 104 mojo::BindingSet<mojom::PrefStoreConnector> connector_bindings_; | |
| 105 mojo::BindingSet<mojom::PrefStoreRegistry> registry_bindings_; | |
| 106 std::unique_ptr<PersistentPrefStoreImpl> persistent_pref_store_; | |
| 107 mojo::BindingSet<mojom::PersistentPrefStoreConnector> | |
| 108 persistent_pref_store_bindings_; | |
| 109 mojo::Binding<mojom::PrefServiceControl> init_binding_; | |
| 110 | |
| 111 // Requests made to connect to the service before it has been initialized. | |
| 112 // These will be handled when initialization completes. | |
| 113 std::vector<mojom::PersistentPrefStoreConnectorRequest> | |
| 114 pending_persistent_pref_store_requests_; | |
| 115 | |
| 116 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | |
| 117 | |
| 118 DISALLOW_COPY_AND_ASSIGN(PrefStoreManagerImpl); | |
| 119 }; | |
| 120 | |
| 121 } // namespace prefs | |
| 122 | |
| 123 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_MANAGER_IMPL_H_ | |
| OLD | NEW |