| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 ServiceConnector_h | |
| 6 #define ServiceConnector_h | |
| 7 | |
| 8 #include "mojo/public/cpp/bindings/binding.h" | |
| 9 #include "public/platform/Platform.h" | |
| 10 #include "services/service_manager/public/interfaces/connector.mojom-blink.h" | |
| 11 #include "wtf/StdLibExtras.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 // ServiceConnector supports connecting to Mojo services by name. | |
| 16 class ServiceConnector { | |
| 17 public: | |
| 18 static ServiceConnector& instance() { | |
| 19 DEFINE_STATIC_LOCAL(ServiceConnector, instance, ()); | |
| 20 return instance; | |
| 21 } | |
| 22 | |
| 23 template <typename Interface> | |
| 24 void connectToInterface(const char* serviceName, | |
| 25 mojo::InterfaceRequest<Interface> request) { | |
| 26 if (!m_connector.is_bound()) | |
| 27 Platform::current()->bindServiceConnector(mojo::GetProxy(&m_connector)); | |
| 28 | |
| 29 if (m_connector.encountered_error()) | |
| 30 return; | |
| 31 | |
| 32 service_manager::mojom::blink::IdentityPtr remoteIdentity( | |
| 33 service_manager::mojom::blink::Identity::New()); | |
| 34 remoteIdentity->name = serviceName; | |
| 35 remoteIdentity->user_id = service_manager::mojom::blink::kInheritUserID; | |
| 36 remoteIdentity->instance = ""; | |
| 37 | |
| 38 service_manager::mojom::blink::InterfaceProviderPtr remoteInterfaces; | |
| 39 m_connector->Connect(std::move(remoteIdentity), GetProxy(&remoteInterfaces), | |
| 40 nullptr, | |
| 41 base::Bind(&ServiceConnector::onConnectionCompleted)); | |
| 42 | |
| 43 remoteInterfaces->GetInterface(Interface::Name_, request.PassMessagePipe()); | |
| 44 } | |
| 45 | |
| 46 private: | |
| 47 ServiceConnector() {} | |
| 48 | |
| 49 static void onConnectionCompleted( | |
| 50 service_manager::mojom::ConnectResult result, | |
| 51 const WTF::String& targetUserID) {} | |
| 52 | |
| 53 service_manager::mojom::blink::ConnectorPtr m_connector; | |
| 54 }; | |
| 55 | |
| 56 } // namespace blink | |
| 57 | |
| 58 #endif // ServiceConnector_h | |
| OLD | NEW |