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 MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ | 5 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ |
6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ | 6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "mojo/public/cpp/application/lib/service_connector.h" | 10 #include "mojo/public/cpp/application/lib/service_connector.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 template <typename Interface> | 41 template <typename Interface> |
42 void AddService(InterfaceFactory<Interface>* factory) { | 42 void AddService(InterfaceFactory<Interface>* factory) { |
43 AddServiceConnector( | 43 AddServiceConnector( |
44 new internal::InterfaceFactoryConnector<Interface>(factory)); | 44 new internal::InterfaceFactoryConnector<Interface>(factory)); |
45 } | 45 } |
46 | 46 |
47 // Connect to the service implementing |Interface|. | 47 // Connect to the service implementing |Interface|. |
48 template <typename Interface> | 48 template <typename Interface> |
49 void ConnectToService(InterfacePtr<Interface>* ptr) { | 49 void ConnectToService(InterfacePtr<Interface>* ptr) { |
50 MessagePipe pipe; | 50 if (ServiceProvider* sp = GetServiceProvider()) { |
51 ptr->Bind(pipe.handle0.Pass()); | 51 MessagePipe pipe; |
52 GetServiceProvider()->ConnectToService(Interface::Name_, | 52 ptr->Bind(pipe.handle0.Pass()); |
53 pipe.handle1.Pass()); | 53 sp->ConnectToService(Interface::Name_, pipe.handle1.Pass()); |
| 54 } |
54 } | 55 } |
55 | 56 |
56 // The url identifying the application on the other end of this connection. | 57 // The url identifying the application on the other end of this connection. |
57 virtual const std::string& GetRemoteApplicationURL() = 0; | 58 virtual const std::string& GetRemoteApplicationURL() = 0; |
58 | 59 |
59 // Establishes a new connection to an application. | 60 // Establishes a new connection to an application. |
60 // TODO(davemoore): Would it be better to expose the ApplicationImpl? | 61 // TODO(davemoore): Would it be better to expose the ApplicationImpl? |
61 virtual ApplicationConnection* ConnectToApplication( | 62 virtual ApplicationConnection* ConnectToApplication( |
62 const std::string& url) = 0; | 63 const std::string& url) = 0; |
63 | 64 |
64 // Connect to application identified by |application_url| and connect to | 65 // Connect to application identified by |application_url| and connect to |
65 // the service implementation of the interface identified by |Interface|. | 66 // the service implementation of the interface identified by |Interface|. |
66 template <typename Interface> | 67 template <typename Interface> |
67 void ConnectToService(const std::string& application_url, | 68 void ConnectToService(const std::string& application_url, |
68 InterfacePtr<Interface>* ptr) { | 69 InterfacePtr<Interface>* ptr) { |
69 ConnectToApplication(application_url)->ConnectToService(ptr); | 70 ConnectToApplication(application_url)->ConnectToService(ptr); |
70 } | 71 } |
71 | 72 |
72 // Raw ServiceProvider interface to remote application. | 73 // Raw ServiceProvider interface to remote application. |
73 virtual ServiceProvider* GetServiceProvider() = 0; | 74 virtual ServiceProvider* GetServiceProvider() = 0; |
74 | 75 |
75 private: | 76 private: |
76 virtual void AddServiceConnector( | 77 virtual void AddServiceConnector( |
77 internal::ServiceConnectorBase* service_connector) = 0; | 78 internal::ServiceConnectorBase* service_connector) = 0; |
78 }; | 79 }; |
79 | 80 |
80 } // namespace mojo | 81 } // namespace mojo |
81 | 82 |
82 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ | 83 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ |
OLD | NEW |