OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 IPC_IPC_CHANNEL_H_ | 5 #ifndef IPC_IPC_CHANNEL_H_ |
6 #define IPC_IPC_CHANNEL_H_ | 6 #define IPC_IPC_CHANNEL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
16 #include "base/process/process.h" | 16 #include "base/process/process.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "ipc/ipc_channel_handle.h" | 18 #include "ipc/ipc_channel_handle.h" |
19 #include "ipc/ipc_endpoint.h" | 19 #include "ipc/ipc_endpoint.h" |
20 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
21 #include "mojo/public/cpp/bindings/associated_group.h" | |
22 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" | |
23 #include "mojo/public/cpp/bindings/associated_interface_request.h" | |
24 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | |
21 | 25 |
22 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
23 #include <sys/types.h> | 27 #include <sys/types.h> |
24 #endif | 28 #endif |
25 | 29 |
26 namespace IPC { | 30 namespace IPC { |
27 | 31 |
28 class Listener; | 32 class Listener; |
29 | 33 |
30 //------------------------------------------------------------------------------ | 34 //------------------------------------------------------------------------------ |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 | 177 |
174 // Close this Channel explicitly. May be called multiple times. | 178 // Close this Channel explicitly. May be called multiple times. |
175 // On POSIX calling close on an IPC channel that listens for connections will | 179 // On POSIX calling close on an IPC channel that listens for connections will |
176 // cause it to close any accepted connections, and it will stop listening for | 180 // cause it to close any accepted connections, and it will stop listening for |
177 // new connections. If you just want to close the currently accepted | 181 // new connections. If you just want to close the currently accepted |
178 // connection and listen for new ones, use ResetToAcceptingConnectionState. | 182 // connection and listen for new ones, use ResetToAcceptingConnectionState. |
179 virtual void Close() = 0; | 183 virtual void Close() = 0; |
180 | 184 |
181 // Get its own process id. This value is told to the peer. | 185 // Get its own process id. This value is told to the peer. |
182 virtual base::ProcessId GetSelfPID() const = 0; | 186 virtual base::ProcessId GetSelfPID() const = 0; |
183 | 187 |
yzshen1
2016/07/13 17:38:42
It seems cleaner to me to group associated interfa
| |
188 // Accesses the AssociatedGroup used to associate new interface endpoints with | |
189 // this Channel. | |
190 // | |
191 // NOTE: Not all implementations support this. | |
192 virtual mojo::AssociatedGroup* GetAssociatedGroup(); | |
193 | |
194 // Adds an interface factory to this channel for interface |name|. | |
195 // | |
196 // NOTE: Not all implementations support this. | |
197 using GenericAssociatedInterfaceFactory = | |
198 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>; | |
199 virtual void AddGenericAssociatedInterface( | |
200 const std::string& name, | |
201 const GenericAssociatedInterfaceFactory& factory); | |
202 | |
203 template <typename Interface> | |
204 using AssociatedInterfaceFactory = | |
205 base::Callback<void(mojo::AssociatedInterfaceRequest<Interface>)>; | |
206 | |
207 template <typename Interface> | |
208 void AddAssociatedInterface( | |
209 const AssociatedInterfaceFactory<Interface>& factory) { | |
210 AddGenericAssociatedInterface( | |
211 Interface::Name_, | |
212 base::Bind(&BindAssociatedInterfaceRequest<Interface>, factory)); | |
213 } | |
214 | |
215 // Requests an associated interface from the remote endpoint. | |
216 // | |
217 // NOTE: Not all implementations support this. | |
218 virtual void GetGenericRemoteAssociatedInterface( | |
219 const std::string& name, | |
220 mojo::ScopedInterfaceEndpointHandle handle); | |
221 | |
222 // Acquires an associated interface proxied to the remote endpoint. | |
223 template <typename Interface> | |
224 void GetRemoteAssociatedInterface( | |
225 mojo::AssociatedInterfacePtr<Interface>* proxy) { | |
226 mojo::AssociatedInterfaceRequest<Interface> request = | |
227 mojo::GetProxy(proxy, GetAssociatedGroup()); | |
228 GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle()); | |
229 } | |
230 | |
184 // Overridden from ipc::Sender. | 231 // Overridden from ipc::Sender. |
185 // Send a message over the Channel to the listener on the other end. | 232 // Send a message over the Channel to the listener on the other end. |
186 // | 233 // |
187 // |message| must be allocated using operator new. This object will be | 234 // |message| must be allocated using operator new. This object will be |
188 // deleted once the contents of the Message have been sent. | 235 // deleted once the contents of the Message have been sent. |
189 bool Send(Message* message) override = 0; | 236 bool Send(Message* message) override = 0; |
190 | 237 |
191 // IsSendThreadSafe returns true iff it's safe to call |Send| from non-IO | 238 // IsSendThreadSafe returns true iff it's safe to call |Send| from non-IO |
192 // threads. This is constant for the lifetime of the |Channel|. | 239 // threads. This is constant for the lifetime of the |Channel|. |
193 virtual bool IsSendThreadSafe() const; | 240 virtual bool IsSendThreadSafe() const; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 }; | 319 }; |
273 | 320 |
274 // Endpoint overrides. | 321 // Endpoint overrides. |
275 void OnSetAttachmentBrokerEndpoint() override; | 322 void OnSetAttachmentBrokerEndpoint() override; |
276 | 323 |
277 // Subclasses must call this method at the beginning of their implementation | 324 // Subclasses must call this method at the beginning of their implementation |
278 // of Connect(). | 325 // of Connect(). |
279 void WillConnect(); | 326 void WillConnect(); |
280 | 327 |
281 private: | 328 private: |
329 template <typename Interface> | |
330 static void BindAssociatedInterfaceRequest( | |
331 const AssociatedInterfaceFactory<Interface>& factory, | |
332 mojo::ScopedInterfaceEndpointHandle handle) { | |
333 mojo::AssociatedInterfaceRequest<Interface> request; | |
334 request.Bind(std::move(handle)); | |
335 factory.Run(std::move(request)); | |
336 } | |
337 | |
282 bool did_start_connect_ = false; | 338 bool did_start_connect_ = false; |
283 }; | 339 }; |
284 | 340 |
285 #if defined(OS_POSIX) | 341 #if defined(OS_POSIX) |
286 // SocketPair() creates a pair of socket FDs suitable for using with | 342 // SocketPair() creates a pair of socket FDs suitable for using with |
287 // IPC::Channel. | 343 // IPC::Channel. |
288 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); | 344 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); |
289 #endif | 345 #endif |
290 | 346 |
291 } // namespace IPC | 347 } // namespace IPC |
292 | 348 |
293 #endif // IPC_IPC_CHANNEL_H_ | 349 #endif // IPC_IPC_CHANNEL_H_ |
OLD | NEW |