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

Unified Diff: services/preferences/public/cpp/pref_service_factory.cc

Issue 2771723002: Pref service: Merge PrefStoreConnector interfaces. (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 side-by-side diff with in-line comments
Download patch
Index: services/preferences/public/cpp/pref_service_factory.cc
diff --git a/services/preferences/public/cpp/pref_service_factory.cc b/services/preferences/public/cpp/pref_service_factory.cc
index 27067c6e8516175b6f82b5e30541981d9b6001dd..a22df8aad4e098c919d60ad06cb83840ffbfdfb2 100644
--- a/services/preferences/public/cpp/pref_service_factory.cc
+++ b/services/preferences/public/cpp/pref_service_factory.cc
@@ -37,33 +37,6 @@ class RefCountedInterfacePtr
void DoNothingHandleReadError(PersistentPrefStore::PrefReadError error) {}
-class ConnectionBarrier : public base::RefCounted<ConnectionBarrier> {
- public:
- static void Create(service_manager::Connector* connector,
- scoped_refptr<PrefRegistry> pref_registry,
- ConnectCallback callback);
-
- private:
- friend class base::RefCounted<ConnectionBarrier>;
- ConnectionBarrier(scoped_refptr<PrefRegistry> pref_registry,
- scoped_refptr<PersistentPrefStore> persistent_pref_store,
- ConnectCallback callback);
- ~ConnectionBarrier() = default;
-
- void OnConnect(
- scoped_refptr<RefCountedInterfacePtr<mojom::PrefStoreConnector>> unused,
- scoped_refptr<PrefRegistry> pref_registry,
- std::unordered_map<PrefValueStore::PrefStoreType,
- mojom::PrefStoreConnectionPtr> connections);
-
- void OnConnectError(
- scoped_refptr<RefCountedInterfacePtr<mojom::PrefStoreConnector>> unused);
-
- scoped_refptr<PrefRegistry> pref_registry_;
- scoped_refptr<PersistentPrefStore> persistent_pref_store_;
- ConnectCallback callback_;
-};
-
scoped_refptr<PrefStore> CreatePrefStore(
PrefValueStore::PrefStoreType store_type,
std::unordered_map<PrefValueStore::PrefStoreType,
@@ -77,18 +50,12 @@ scoped_refptr<PrefStore> CreatePrefStore(
}
}
-ConnectionBarrier::ConnectionBarrier(
- scoped_refptr<PrefRegistry> pref_registry,
- scoped_refptr<PersistentPrefStore> persistent_pref_store,
- ConnectCallback callback)
- : pref_registry_(std::move(pref_registry)),
- persistent_pref_store_(std::move(persistent_pref_store)),
- callback_(std::move(callback)) {}
-
-void ConnectionBarrier::OnConnect(
+void OnConnect(
scoped_refptr<RefCountedInterfacePtr<mojom::PrefStoreConnector>>
connector_ptr,
scoped_refptr<PrefRegistry> pref_registry,
+ ConnectCallback callback,
+ mojom::PersistentPrefStoreConnectionPtr persistent_pref_store_connection,
std::unordered_map<PrefValueStore::PrefStoreType,
mojom::PrefStoreConnectionPtr> connections) {
scoped_refptr<PrefStore> managed_prefs =
@@ -103,56 +70,41 @@ void ConnectionBarrier::OnConnect(
CreatePrefStore(PrefValueStore::RECOMMENDED_STORE, &connections);
scoped_refptr<PrefStore> default_prefs =
CreatePrefStore(PrefValueStore::DEFAULT_STORE, &connections);
+ scoped_refptr<PersistentPrefStore> persistent_pref_store(
+ new PersistentPrefStoreClient(
+ std::move(persistent_pref_store_connection)));
PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
auto* pref_value_store = new PrefValueStore(
managed_prefs.get(), supervised_user_prefs.get(), extension_prefs.get(),
- command_line_prefs.get(), persistent_pref_store_.get(),
+ command_line_prefs.get(), persistent_pref_store.get(),
recommended_prefs.get(), default_prefs.get(), pref_notifier);
- base::ResetAndReturn(&callback_)
- .Run(base::MakeUnique<::PrefService>(
- pref_notifier, pref_value_store, persistent_pref_store_.get(),
- pref_registry_.get(), base::Bind(&DoNothingHandleReadError), true));
+ callback.Run(base::MakeUnique<::PrefService>(
+ pref_notifier, pref_value_store, persistent_pref_store.get(),
+ pref_registry.get(), base::Bind(&DoNothingHandleReadError), true));
connector_ptr->reset();
}
-void ConnectionBarrier::OnConnectError(
+void OnConnectError(
scoped_refptr<RefCountedInterfacePtr<mojom::PrefStoreConnector>>
- connector_ptr) {
- callback_.Run(nullptr);
+ connector_ptr,
+ ConnectCallback callback) {
+ callback.Run(nullptr);
connector_ptr->reset();
}
-// static
-void ConnectionBarrier::Create(service_manager::Connector* connector,
- scoped_refptr<PrefRegistry> pref_registry,
- ConnectCallback callback) {
- // Connect to user pref store.
- mojom::PersistentPrefStoreConnectorPtr persistent_connector_ptr;
- connector->BindInterface(mojom::kPrefStoreServiceName,
- &persistent_connector_ptr);
- auto barrier = make_scoped_refptr(new ConnectionBarrier(
- std::move(pref_registry),
- make_scoped_refptr(
- new PersistentPrefStoreClient(std::move(persistent_connector_ptr))),
- std::move(callback)));
-
- // Connect to all other pref stores.
- auto connector_ptr = make_scoped_refptr(
- new RefCountedInterfacePtr<mojom::PrefStoreConnector>());
- connector->BindInterface(mojom::kPrefStoreServiceName, &connector_ptr->get());
- connector_ptr->get().set_connection_error_handler(
- base::Bind(&ConnectionBarrier::OnConnectError, barrier, connector_ptr));
- connector_ptr->get()->Connect(base::Bind(&ConnectionBarrier::OnConnect,
- barrier, connector_ptr,
- std::move(pref_registry)));
-}
-
} // namespace
void ConnectToPrefService(service_manager::Connector* connector,
scoped_refptr<PrefRegistry> pref_registry,
- const ConnectCallback& callback) {
- ConnectionBarrier::Create(connector, std::move(pref_registry), callback);
+ ConnectCallback callback) {
+ auto connector_ptr = make_scoped_refptr(
+ new RefCountedInterfacePtr<mojom::PrefStoreConnector>());
+ connector->BindInterface(mojom::kPrefStoreServiceName, &connector_ptr->get());
+ connector_ptr->get().set_connection_error_handler(base::Bind(
+ &OnConnectError, connector_ptr, base::Passed(ConnectCallback{callback})));
+ connector_ptr->get()->Connect(base::Bind(&OnConnect, connector_ptr,
+ base::Passed(&pref_registry),
+ base::Passed(&callback)));
}
} // namespace prefs
« no previous file with comments | « services/preferences/public/cpp/pref_service_factory.h ('k') | services/preferences/public/cpp/preferences.typemap » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698