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_SHELL_PUBLIC_CPP_CONNECTION_H_ | 5 #ifndef MOJO_SHELL_PUBLIC_CPP_CONNECTION_H_ |
6 #define MOJO_SHELL_PUBLIC_CPP_CONNECTION_H_ | 6 #define MOJO_SHELL_PUBLIC_CPP_CONNECTION_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 14 matching lines...) Expand all Loading... |
25 // To use, define a class that implements your specific service API (e.g., | 25 // To use, define a class that implements your specific service API (e.g., |
26 // FooImpl to implement a service named Foo). Then implement an | 26 // FooImpl to implement a service named Foo). Then implement an |
27 // InterfaceFactory<Foo> that binds instances of FooImpl to | 27 // InterfaceFactory<Foo> that binds instances of FooImpl to |
28 // InterfaceRequest<Foo>s and register that on the connection like this: | 28 // InterfaceRequest<Foo>s and register that on the connection like this: |
29 // | 29 // |
30 // connection->AddService(&factory); | 30 // connection->AddService(&factory); |
31 // | 31 // |
32 // Or, if you have multiple factories implemented by the same type, explicitly | 32 // Or, if you have multiple factories implemented by the same type, explicitly |
33 // specify the interface to register the factory for: | 33 // specify the interface to register the factory for: |
34 // | 34 // |
35 // connection->AddService<Foo>(&my_foo_and_bar_factory_); | 35 // connection->AddInterface<Foo>(&my_foo_and_bar_factory_); |
36 // connection->AddService<Bar>(&my_foo_and_bar_factory_); | 36 // connection->AddInterface<Bar>(&my_foo_and_bar_factory_); |
37 // | 37 // |
38 // The InterfaceFactory must outlive the Connection. | 38 // The InterfaceFactory must outlive the Connection. |
39 // | 39 // |
40 // Additionally you specify a InterfaceBinder. If a InterfaceBinder has | 40 // Additionally you specify a InterfaceBinder. If a InterfaceBinder has |
41 // been set and an InterfaceFactory has not been registered for the interface | 41 // been set and an InterfaceFactory has not been registered for the interface |
42 // request, than the interface request is sent to the InterfaceBinder. | 42 // request, than the interface request is sent to the InterfaceBinder. |
43 // | 43 // |
44 // Just as with InterfaceFactory, InterfaceBinder must outlive Connection. | 44 // Just as with InterfaceFactory, InterfaceBinder must outlive Connection. |
45 // | 45 // |
46 // An Connection's lifetime is managed by an ShellConnection. To close a | 46 // An Connection's lifetime is managed by an ShellConnection. To close a |
(...skipping 14 matching lines...) Expand all Loading... |
61 }; | 61 }; |
62 | 62 |
63 // See class description for details. | 63 // See class description for details. |
64 virtual void SetDefaultInterfaceBinder(InterfaceBinder* binder) = 0; | 64 virtual void SetDefaultInterfaceBinder(InterfaceBinder* binder) = 0; |
65 | 65 |
66 // Makes Interface available as a service to the remote application. | 66 // Makes Interface available as a service to the remote application. |
67 // |factory| will create implementations of Interface on demand. | 67 // |factory| will create implementations of Interface on demand. |
68 // Returns true if the service was exposed, false if capability filtering | 68 // Returns true if the service was exposed, false if capability filtering |
69 // from the shell prevented the service from being exposed. | 69 // from the shell prevented the service from being exposed. |
70 template <typename Interface> | 70 template <typename Interface> |
71 bool AddService(InterfaceFactory<Interface>* factory) { | 71 bool AddInterface(InterfaceFactory<Interface>* factory) { |
72 return SetInterfaceBinderForName( | 72 return SetInterfaceBinderForName( |
73 new internal::InterfaceFactoryBinder<Interface>(factory), | 73 new internal::InterfaceFactoryBinder<Interface>(factory), |
74 Interface::Name_); | 74 Interface::Name_); |
75 } | 75 } |
76 | 76 |
77 // Binds |ptr| to an implemention of Interface in the remote application. | 77 // Binds |ptr| to an implemention of Interface in the remote application. |
78 // |ptr| can immediately be used to start sending requests to the remote | 78 // |ptr| can immediately be used to start sending requests to the remote |
79 // service. | 79 // service. |
80 template <typename Interface> | 80 template <typename Interface> |
81 void ConnectToService(InterfacePtr<Interface>* ptr) { | 81 void GetInterface(InterfacePtr<Interface>* ptr) { |
82 if (ServiceProvider* sp = GetServiceProvider()) { | 82 if (ServiceProvider* sp = GetRemoteInterfaces()) { |
83 MessagePipe pipe; | 83 MessagePipe pipe; |
84 ptr->Bind(InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u)); | 84 ptr->Bind(InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u)); |
85 sp->ConnectToService(Interface::Name_, std::move(pipe.handle1)); | 85 sp->ConnectToService(Interface::Name_, std::move(pipe.handle1)); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 // Returns the URL that was used by the source application to establish a | 89 // Returns the URL that was used by the source application to establish a |
90 // connection to the destination application. | 90 // connection to the destination application. |
91 // | 91 // |
92 // When Connection is representing an incoming connection this can be | 92 // When Connection is representing an incoming connection this can be |
93 // different than the URL the application was initially loaded from, if the | 93 // different than the URL the application was initially loaded from, if the |
94 // application handles multiple URLs. Note that this is the URL after all | 94 // application handles multiple URLs. Note that this is the URL after all |
95 // URL rewriting and HTTP redirects have been performed. | 95 // URL rewriting and HTTP redirects have been performed. |
96 // | 96 // |
97 // When Connection is representing and outgoing connection, this will be the | 97 // When Connection is representing and outgoing connection, this will be the |
98 // same as the value returned by GetRemoveApplicationURL(). | 98 // same as the value returned by GetRemoveApplicationURL(). |
99 virtual const std::string& GetConnectionURL() = 0; | 99 virtual const std::string& GetConnectionURL() = 0; |
100 | 100 |
101 // Returns the URL identifying the remote application on this connection. | 101 // Returns the URL identifying the remote application on this connection. |
102 virtual const std::string& GetRemoteApplicationURL() = 0; | 102 virtual const std::string& GetRemoteApplicationURL() = 0; |
103 | 103 |
104 // Returns the raw proxy to the remote application's ServiceProvider | 104 // Returns the raw proxy to the remote application's ServiceProvider |
105 // interface. Most applications will just use ConnectToService() instead. | 105 // interface. Most applications will just use ConnectToService() instead. |
106 // Caller does not take ownership. | 106 // Caller does not take ownership. |
107 virtual ServiceProvider* GetServiceProvider() = 0; | 107 virtual ServiceProvider* GetRemoteInterfaces() = 0; |
108 | 108 |
109 // Returns the local application's ServiceProvider interface. The return | 109 // Returns the local application's ServiceProvider interface. The return |
110 // value is owned by this connection. | 110 // value is owned by this connection. |
111 virtual ServiceProvider* GetLocalServiceProvider() = 0; | 111 virtual ServiceProvider* GetLocalInterfaces() = 0; |
112 | 112 |
113 // Register a handler to receive an error notification on the pipe to the | 113 // Register a handler to receive an error notification on the pipe to the |
114 // remote application's service provider. | 114 // remote application's service provider. |
115 virtual void SetRemoteServiceProviderConnectionErrorHandler( | 115 virtual void SetRemoteServiceProviderConnectionErrorHandler( |
116 const Closure& handler) = 0; | 116 const Closure& handler) = 0; |
117 | 117 |
118 // Returns the id of the remote application. For Connections created via | 118 // Returns the id of the remote application. For Connections created via |
119 // Shell::Connect(), this will not be determined until Connect()'s callback is | 119 // Shell::Connect(), this will not be determined until Connect()'s callback is |
120 // run, and this function will return false. Use AddRemoteIDCallback() to | 120 // run, and this function will return false. Use AddRemoteIDCallback() to |
121 // schedule a callback to be run when the remote application id is available. | 121 // schedule a callback to be run when the remote application id is available. |
(...skipping 17 matching lines...) Expand all Loading... |
139 // some filtering policy preventing this interface from being exposed). | 139 // some filtering policy preventing this interface from being exposed). |
140 virtual bool SetInterfaceBinderForName(InterfaceBinder* binder, | 140 virtual bool SetInterfaceBinderForName(InterfaceBinder* binder, |
141 const std::string& name) = 0; | 141 const std::string& name) = 0; |
142 | 142 |
143 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; | 143 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; |
144 }; | 144 }; |
145 | 145 |
146 } // namespace mojo | 146 } // namespace mojo |
147 | 147 |
148 #endif // MOJO_SHELL_PUBLIC_CPP_CONNECTION_H_ | 148 #endif // MOJO_SHELL_PUBLIC_CPP_CONNECTION_H_ |
OLD | NEW |