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 #include "ipc/mojo/ipc_channel_mojo.h" | 5 #include "ipc/mojo/ipc_channel_mojo.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "ipc/ipc_listener.h" | 10 #include "ipc/ipc_listener.h" |
11 #include "ipc/ipc_logging.h" | 11 #include "ipc/ipc_logging.h" |
12 #include "ipc/ipc_message_attachment_set.h" | 12 #include "ipc/ipc_message_attachment_set.h" |
13 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
14 #include "ipc/mojo/client_channel.mojom.h" | 14 #include "ipc/mojo/client_channel.mojom.h" |
15 #include "ipc/mojo/ipc_mojo_bootstrap.h" | 15 #include "ipc/mojo/ipc_mojo_bootstrap.h" |
16 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | 16 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" | 17 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" |
18 | 18 |
| 19 #if defined(OS_POSIX) && !defined(OS_NACL) |
| 20 #include "ipc/ipc_platform_file_attachment_posix.h" |
| 21 #endif |
| 22 |
19 namespace IPC { | 23 namespace IPC { |
20 | 24 |
21 namespace { | 25 namespace { |
22 | 26 |
23 class MojoChannelFactory : public ChannelFactory { | 27 class MojoChannelFactory : public ChannelFactory { |
24 public: | 28 public: |
25 MojoChannelFactory(ChannelMojo::Delegate* delegate, | 29 MojoChannelFactory(ChannelMojo::Delegate* delegate, |
26 ChannelHandle channel_handle, | 30 ChannelHandle channel_handle, |
27 Channel::Mode mode) | 31 Channel::Mode mode) |
28 : delegate_(delegate), channel_handle_(channel_handle), mode_(mode) {} | 32 : delegate_(delegate), channel_handle_(channel_handle), mode_(mode) {} |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 for (size_t i = 0; i < handle_buffer.size(); ++i) { | 349 for (size_t i = 0; i < handle_buffer.size(); ++i) { |
346 mojo::embedder::ScopedPlatformHandle platform_handle; | 350 mojo::embedder::ScopedPlatformHandle platform_handle; |
347 MojoResult unwrap_result = mojo::embedder::PassWrappedPlatformHandle( | 351 MojoResult unwrap_result = mojo::embedder::PassWrappedPlatformHandle( |
348 handle_buffer[i], &platform_handle); | 352 handle_buffer[i], &platform_handle); |
349 if (unwrap_result != MOJO_RESULT_OK) { | 353 if (unwrap_result != MOJO_RESULT_OK) { |
350 DLOG(WARNING) << "Pipe failed to covert handles. Closing: " | 354 DLOG(WARNING) << "Pipe failed to covert handles. Closing: " |
351 << unwrap_result; | 355 << unwrap_result; |
352 return unwrap_result; | 356 return unwrap_result; |
353 } | 357 } |
354 | 358 |
355 bool ok = message->attachment_set()->AddToOwn( | 359 bool ok = message->attachment_set()->AddAttachment( |
356 base::ScopedFD(platform_handle.release().fd)); | 360 new internal::PlatformFileAttachment( |
| 361 base::ScopedFD(platform_handle.release().fd))); |
357 DCHECK(ok); | 362 DCHECK(ok); |
358 } | 363 } |
359 | 364 |
360 return MOJO_RESULT_OK; | 365 return MOJO_RESULT_OK; |
361 } | 366 } |
362 | 367 |
363 // static | 368 // static |
364 MojoResult ChannelMojo::ReadFromMessageAttachmentSet( | 369 MojoResult ChannelMojo::ReadFromMessageAttachmentSet( |
365 Message* message, | 370 Message* message, |
366 std::vector<MojoHandle>* handles) { | 371 std::vector<MojoHandle>* handles) { |
367 // We dup() the handles in IPC::Message to transmit. | 372 // We dup() the handles in IPC::Message to transmit. |
368 // IPC::MessageAttachmentSet has intricate lifecycle semantics | 373 // IPC::MessageAttachmentSet has intricate lifecycle semantics |
369 // of FDs, so just to dup()-and-own them is the safest option. | 374 // of FDs, so just to dup()-and-own them is the safest option. |
370 if (message->HasFileDescriptors()) { | 375 if (message->HasAttachments()) { |
371 MessageAttachmentSet* fdset = message->attachment_set(); | 376 MessageAttachmentSet* fdset = message->attachment_set(); |
372 std::vector<base::PlatformFile> fds_to_send(fdset->size()); | 377 std::vector<base::PlatformFile> fds_to_send(fdset->size()); |
373 fdset->PeekDescriptors(&fds_to_send[0]); | 378 fdset->PeekDescriptors(&fds_to_send[0]); |
374 for (size_t i = 0; i < fds_to_send.size(); ++i) { | 379 for (size_t i = 0; i < fds_to_send.size(); ++i) { |
375 int fd_to_send = dup(fds_to_send[i]); | 380 int fd_to_send = dup(fds_to_send[i]); |
376 if (-1 == fd_to_send) { | 381 if (-1 == fd_to_send) { |
377 DPLOG(WARNING) << "Failed to dup FD to transmit."; | 382 DPLOG(WARNING) << "Failed to dup FD to transmit."; |
378 fdset->CommitAll(); | 383 fdset->CommitAll(); |
379 return MOJO_RESULT_UNKNOWN; | 384 return MOJO_RESULT_UNKNOWN; |
380 } | 385 } |
(...skipping 15 matching lines...) Expand all Loading... |
396 | 401 |
397 fdset->CommitAll(); | 402 fdset->CommitAll(); |
398 } | 403 } |
399 | 404 |
400 return MOJO_RESULT_OK; | 405 return MOJO_RESULT_OK; |
401 } | 406 } |
402 | 407 |
403 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 408 #endif // defined(OS_POSIX) && !defined(OS_NACL) |
404 | 409 |
405 } // namespace IPC | 410 } // namespace IPC |
OLD | NEW |