OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 5 #ifndef CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
6 #define CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 6 #define CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 service_factory) = 0; | 44 service_factory) = 0; |
45 | 45 |
46 // Remove future access to the service implementing Interface. Existing | 46 // Remove future access to the service implementing Interface. Existing |
47 // connections to the service are unaffected. | 47 // connections to the service are unaffected. |
48 template <typename Interface> | 48 template <typename Interface> |
49 void RemoveService() { | 49 void RemoveService() { |
50 RemoveService(Interface::Name_); | 50 RemoveService(Interface::Name_); |
51 } | 51 } |
52 virtual void RemoveService(const std::string& service_name) = 0; | 52 virtual void RemoveService(const std::string& service_name) = 0; |
53 | 53 |
54 // Connect to an interface provided by the remote service provider. | 54 // Connect to an interface provided by the remote service provider. Creates a |
| 55 // new message pipe for this connection. |
55 template <typename Interface> | 56 template <typename Interface> |
56 void ConnectToRemoteService(mojo::InterfacePtr<Interface>* ptr) { | 57 void ConnectToRemoteService(mojo::InterfacePtr<Interface>* ptr) { |
57 mojo::MessagePipe pipe; | 58 mojo::MessagePipe pipe; |
58 ptr->Bind(pipe.handle0.Pass()); | 59 ptr->Bind(pipe.handle0.Pass()); |
59 ConnectToRemoteService(Interface::Name_, pipe.handle1.Pass()); | 60 ConnectToRemoteService(Interface::Name_, pipe.handle1.Pass()); |
60 } | 61 } |
| 62 |
| 63 // Connect to an interface provided by the remote service provider, using an |
| 64 // existing message pipe. |
| 65 template <typename Interface> |
| 66 void ConnectToRemoteService(mojo::InterfaceRequest<Interface> request) { |
| 67 ConnectToRemoteService(Interface::Name_, request.PassMessagePipe()); |
| 68 } |
| 69 |
61 virtual void ConnectToRemoteService(const base::StringPiece& name, | 70 virtual void ConnectToRemoteService(const base::StringPiece& name, |
62 mojo::ScopedMessagePipeHandle handle) = 0; | 71 mojo::ScopedMessagePipeHandle handle) = 0; |
63 | 72 |
64 private: | 73 private: |
65 template <typename Interface> | 74 template <typename Interface> |
66 static void ForwardToServiceFactory( | 75 static void ForwardToServiceFactory( |
67 const base::Callback<void(mojo::InterfaceRequest<Interface>)> | 76 const base::Callback<void(mojo::InterfaceRequest<Interface>)> |
68 service_factory, | 77 service_factory, |
69 mojo::ScopedMessagePipeHandle handle) { | 78 mojo::ScopedMessagePipeHandle handle) { |
70 service_factory.Run(mojo::MakeRequest<Interface>(handle.Pass())); | 79 service_factory.Run(mojo::MakeRequest<Interface>(handle.Pass())); |
71 } | 80 } |
72 }; | 81 }; |
73 | 82 |
74 } // namespace content | 83 } // namespace content |
75 | 84 |
76 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 85 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
OLD | NEW |