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