Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
|
Ken Rockot(use gerrit already)
2016/12/05 20:54:18
nit: 2016
blundell
2016/12/15 17:04:52
Done. Hopefully this lands before it needs to be c
| |
| 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, | |
|
esprehn
2016/12/02 02:23:14
These should all be lowerCase() for now.
blundell
2016/12/15 17:04:52
Done.
| |
| 25 mojo::InterfaceRequest<Interface> interfacePtr) { | |
|
Noel Gordon
2016/12/07 07:09:26
|interfacePtr| ?? Isn't the argument a request?
blundell
2016/12/15 17:04:52
Great catch, thanks. Done.
| |
| 26 InitializeIfNecessary(); | |
| 27 | |
| 28 if (!m_connector.is_bound()) | |
| 29 return; | |
| 30 | |
| 31 service_manager::mojom::blink::IdentityPtr remoteIdentity( | |
| 32 service_manager::mojom::blink::Identity::New()); | |
| 33 remoteIdentity->name = serviceName; | |
| 34 remoteIdentity->user_id = service_manager::mojom::blink::kInheritUserID; | |
| 35 remoteIdentity->instance = ""; | |
| 36 | |
| 37 service_manager::mojom::blink::InterfaceProviderPtr remoteInterfaces; | |
| 38 m_connector->Connect(std::move(remoteIdentity), GetProxy(&remoteInterfaces), | |
| 39 nullptr, | |
| 40 base::Bind(&ServiceConnector::OnConnectionCompleted)); | |
| 41 | |
| 42 remoteInterfaces->GetInterface(Interface::Name_, | |
| 43 interfacePtr.PassMessagePipe()); | |
| 44 } | |
| 45 | |
| 46 private: | |
| 47 ServiceConnector() : m_initialized(false) {} | |
|
Noel Gordon
2016/12/07 07:09:26
Is this needed? Could we init the class fully at c
blundell
2016/12/15 17:04:51
The recommended practice in Mojo is to set up all
| |
| 48 | |
| 49 void InitializeIfNecessary() { | |
|
esprehn
2016/12/02 02:23:14
initializeIfNeeded()
blundell
2016/12/15 17:04:52
Done.
| |
| 50 if (m_initialized) | |
| 51 return; | |
| 52 | |
| 53 m_connector = Platform::current()->serviceConnector(); | |
| 54 m_initialized = true; | |
| 55 } | |
| 56 | |
| 57 static void OnConnectionCompleted( | |
| 58 service_manager::mojom::ConnectResult result, | |
| 59 const WTF::String& targetUserID) {} | |
| 60 | |
| 61 bool m_initialized; | |
| 62 service_manager::mojom::blink::ConnectorPtr m_connector; | |
| 63 }; | |
| 64 | |
| 65 } // namespace blink | |
| 66 | |
| 67 #endif // ServiceConnector_h | |
| OLD | NEW |