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/interface_factory_connector.h" | 10 #include "mojo/public/cpp/application/lib/interface_factory_connector.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 // Makes Interface available as a service to the remote application. | 41 // Makes Interface available as a service to the remote application. |
42 // |factory| will create implementations of Interface on demand. | 42 // |factory| will create implementations of Interface on demand. |
43 template <typename Interface> | 43 template <typename Interface> |
44 void AddService(InterfaceFactory<Interface>* factory) { | 44 void AddService(InterfaceFactory<Interface>* factory) { |
45 SetServiceConnectorForName( | 45 SetServiceConnectorForName( |
46 new internal::InterfaceFactoryConnector<Interface>(factory), | 46 new internal::InterfaceFactoryConnector<Interface>(factory), |
47 Interface::Name_); | 47 Interface::Name_); |
48 } | 48 } |
49 | 49 |
50 // Binds |ptr| to an implemention of Interface in the remote application. | |
51 // |ptr| can immediately be used to start sending requests to the remote | |
52 // service. | |
53 template <typename Interface> | |
54 void ConnectToService(InterfacePtr<Interface>* ptr) { | |
55 if (ServiceProvider* sp = GetServiceProvider()) { | |
56 MessagePipe pipe; | |
57 ptr->Bind(InterfaceHandle<Interface>(pipe.handle0.Pass(), 0u)); | |
58 sp->ConnectToService(Interface::Name_, pipe.handle1.Pass()); | |
59 } | |
60 } | |
61 | |
62 // Returns the URL that was used by the source application to establish a | 50 // Returns the URL that was used by the source application to establish a |
63 // connection to the destination application. | 51 // connection to the destination application. |
64 // | 52 // |
65 // When ApplicationConnection is representing an incoming connection this can | 53 // When ApplicationConnection is representing an incoming connection this can |
66 // be different than the URL the application was initially loaded from, if the | 54 // be different than the URL the application was initially loaded from, if the |
67 // application handles multiple URLs. Note that this is the URL after all | 55 // application handles multiple URLs. Note that this is the URL after all |
68 // URL rewriting and HTTP redirects have been performed. | 56 // URL rewriting and HTTP redirects have been performed. |
69 // | 57 // |
70 // When ApplicationConnection is representing and outgoing connection, this | 58 // When ApplicationConnection is representing and outgoing connection, this |
71 // will be the same as the value returned by GetRemoveApplicationURL(). | 59 // will be the same as the value returned by GetRemoveApplicationURL(). |
72 virtual const std::string& GetConnectionURL() = 0; | 60 virtual const std::string& GetConnectionURL() = 0; |
73 | 61 |
74 // Returns the URL identifying the remote application on this connection. | 62 // Returns the URL identifying the remote application on this connection. |
75 virtual const std::string& GetRemoteApplicationURL() = 0; | 63 virtual const std::string& GetRemoteApplicationURL() = 0; |
76 | 64 |
77 // Returns the raw proxy to the remote application's ServiceProvider | 65 // Returns the raw proxy to the remote application's ServiceProvider |
78 // interface. Most applications will just use ConnectToService() instead. | 66 // interface. Most applications will just use ConnectToService() instead. |
79 // Caller does not take ownership. | 67 // Caller does not take ownership. |
80 virtual ServiceProvider* GetServiceProvider() = 0; | 68 virtual ServiceProvider* GetServiceProvider() = 0; |
81 | 69 |
82 private: | 70 private: |
83 virtual void SetServiceConnectorForName(ServiceConnector* service_connector, | 71 virtual void SetServiceConnectorForName(ServiceConnector* service_connector, |
84 const std::string& name) = 0; | 72 const std::string& name) = 0; |
85 }; | 73 }; |
86 | 74 |
87 } // namespace mojo | 75 } // namespace mojo |
88 | 76 |
89 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ | 77 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ |
OLD | NEW |