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 16 matching lines...) Expand all Loading... |
27 // To use this interface on another thread, call Clone() and pass the new | 27 // To use this interface on another thread, call Clone() and pass the new |
28 // instance to the desired thread before calling Connect(). | 28 // instance to the desired thread before calling Connect(). |
29 // | 29 // |
30 // While instances of this object are owned by the caller, the underlying | 30 // While instances of this object are owned by the caller, the underlying |
31 // connection with the service manager is bound to the lifetime of the instance | 31 // connection with the service manager is bound to the lifetime of the instance |
32 // that | 32 // that |
33 // created it, i.e. when the application is terminated the Connector pipe is | 33 // created it, i.e. when the application is terminated the Connector pipe is |
34 // closed. | 34 // closed. |
35 class Connector { | 35 class Connector { |
36 public: | 36 public: |
| 37 class TestApi { |
| 38 public: |
| 39 using Binder = base::Callback<void(mojo::ScopedMessagePipeHandle)>; |
| 40 explicit TestApi(Connector* connector) : connector_(connector) {} |
| 41 // Allows caller to specify a callback to bind requests for |interface_name| |
| 42 // locally, rather than passing the request through the Service Manager. |
| 43 void OverrideBinderForTesting(const std::string& interface_name, |
| 44 const Binder& binder) { |
| 45 connector_->OverrideBinderForTesting(interface_name, binder); |
| 46 } |
| 47 void ClearBinderOverrides() { connector_->ClearBinderOverrides(); } |
| 48 |
| 49 private: |
| 50 Connector* connector_; |
| 51 }; |
| 52 |
37 virtual ~Connector() {} | 53 virtual ~Connector() {} |
38 | 54 |
39 // Creates a new Connector instance and fills in |*request| with a request | 55 // Creates a new Connector instance and fills in |*request| with a request |
40 // for the other end the Connector's interface. | 56 // for the other end the Connector's interface. |
41 static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request); | 57 static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request); |
42 | 58 |
43 // Creates an instance of a service for |identity| in a process started by the | 59 // 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 | 60 // client (or someone else). Must be called before Connect() may be called to |
45 // |identity|. | 61 // |identity|. |
46 virtual void StartService( | 62 virtual void StartService( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const std::string& interface_name, | 95 const std::string& interface_name, |
80 mojo::ScopedMessagePipeHandle interface_pipe) = 0; | 96 mojo::ScopedMessagePipeHandle interface_pipe) = 0; |
81 | 97 |
82 // Creates a new instance of this class which may be passed to another thread. | 98 // Creates a new instance of this class which may be passed to another thread. |
83 // The returned object may be passed multiple times until Connect() is called, | 99 // The returned object may be passed multiple times until Connect() is called, |
84 // at which point this method must be called again to pass again. | 100 // at which point this method must be called again to pass again. |
85 virtual std::unique_ptr<Connector> Clone() = 0; | 101 virtual std::unique_ptr<Connector> Clone() = 0; |
86 | 102 |
87 // Binds a Connector request to the other end of this Connector. | 103 // Binds a Connector request to the other end of this Connector. |
88 virtual void BindConnectorRequest(mojom::ConnectorRequest request) = 0; | 104 virtual void BindConnectorRequest(mojom::ConnectorRequest request) = 0; |
| 105 |
| 106 virtual base::WeakPtr<Connector> GetWeakPtr() = 0; |
| 107 |
| 108 protected: |
| 109 virtual void OverrideBinderForTesting(const std::string& interface_name, |
| 110 const TestApi::Binder& binder) = 0; |
| 111 virtual void ClearBinderOverrides() = 0; |
89 }; | 112 }; |
90 | 113 |
91 } // namespace service_manager | 114 } // namespace service_manager |
92 | 115 |
93 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ | 116 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ |
OLD | NEW |