| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ | 5 #ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ |
| 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ | 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "services/service_manager/public/cpp/connection.h" | 10 #include "services/service_manager/public/cpp/connection.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 public: | 36 public: |
| 37 virtual ~Connector() {} | 37 virtual ~Connector() {} |
| 38 | 38 |
| 39 // Creates a new Connector instance and fills in |*request| with a request | 39 // Creates a new Connector instance and fills in |*request| with a request |
| 40 // for the other end the Connector's interface. | 40 // for the other end the Connector's interface. |
| 41 static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request); | 41 static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request); |
| 42 | 42 |
| 43 // Creates an instance of a service for |identity| in a process started by the | 43 // Creates an instance of a service for |identity| in a process started by the |
| 44 // client (or someone else). Must be called before Connect() may be called to | 44 // client (or someone else). Must be called before Connect() may be called to |
| 45 // |identity|. | 45 // |identity|. |
| 46 virtual void Start( | 46 virtual void StartService( |
| 47 const Identity& identity, | 47 const Identity& identity, |
| 48 mojom::ServicePtr service, | 48 mojom::ServicePtr service, |
| 49 mojom::PIDReceiverRequest pid_receiver_request) = 0; | 49 mojom::PIDReceiverRequest pid_receiver_request) = 0; |
| 50 | 50 |
| 51 // Requests a new connection to a service. Returns a pointer to the | 51 // Requests a new connection to a service. Returns a pointer to the |
| 52 // connection if the connection is permitted by that service, nullptr | 52 // connection if the connection is permitted by that service, nullptr |
| 53 // otherwise. Once this method is called, this object is bound to the thread | 53 // otherwise. Once this method is called, this object is bound to the thread |
| 54 // on which the call took place. To pass to another thread, call Clone() and | 54 // on which the call took place. To pass to another thread, call Clone() and |
| 55 // pass the result. | 55 // pass the result. |
| 56 virtual std::unique_ptr<Connection> Connect(const std::string& name) = 0; | 56 virtual std::unique_ptr<Connection> Connect(const std::string& name) = 0; |
| 57 virtual std::unique_ptr<Connection> Connect(const Identity& target) = 0; | 57 virtual std::unique_ptr<Connection> Connect(const Identity& target) = 0; |
| 58 | 58 |
| 59 // Connect to |target| & request to bind |Interface|. Does not retain a | 59 // Connect to |target| & request to bind |Interface|. |
| 60 // connection to |target|. | |
| 61 template <typename Interface> | 60 template <typename Interface> |
| 62 void ConnectToInterface(const Identity& target, | 61 void BindInterface(const Identity& target, |
| 63 mojo::InterfacePtr<Interface>* ptr) { | 62 mojo::InterfacePtr<Interface>* ptr) { |
| 64 std::unique_ptr<Connection> connection = Connect(target); | 63 mojo::MessagePipe pipe; |
| 65 if (connection) | 64 ptr->Bind(mojo::InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u)); |
| 66 connection->GetInterface(ptr); | 65 BindInterface(target, Interface::Name_, std::move(pipe.handle1)); |
| 67 } | 66 } |
| 68 template <typename Interface> | 67 template <typename Interface> |
| 69 void ConnectToInterface(const std::string& name, | 68 void BindInterface(const std::string& name, |
| 70 mojo::InterfacePtr<Interface>* ptr) { | 69 mojo::InterfacePtr<Interface>* ptr) { |
| 71 return ConnectToInterface(Identity(name, mojom::kInheritUserID), ptr); | 70 return BindInterface(Identity(name, mojom::kInheritUserID), ptr); |
| 72 } | 71 } |
| 72 virtual void BindInterface(const Identity& target, |
| 73 const std::string& interface_name, |
| 74 mojo::ScopedMessagePipeHandle interface_pipe) = 0; |
| 73 | 75 |
| 74 // Creates a new instance of this class which may be passed to another thread. | 76 // Creates a new instance of this class which may be passed to another thread. |
| 75 // The returned object may be passed multiple times until Connect() is called, | 77 // The returned object may be passed multiple times until Connect() is called, |
| 76 // at which point this method must be called again to pass again. | 78 // at which point this method must be called again to pass again. |
| 77 virtual std::unique_ptr<Connector> Clone() = 0; | 79 virtual std::unique_ptr<Connector> Clone() = 0; |
| 78 | 80 |
| 79 // Binds a Connector request to the other end of this Connector. | 81 // Binds a Connector request to the other end of this Connector. |
| 80 virtual void BindRequest(mojom::ConnectorRequest request) = 0; | 82 virtual void BindConnectorRequest(mojom::ConnectorRequest request) = 0; |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 } // namespace service_manager | 85 } // namespace service_manager |
| 84 | 86 |
| 85 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ | 87 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ |
| OLD | NEW |