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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "ipc/ipc_listener.h" | 21 #include "ipc/ipc_listener.h" |
22 #include "ipc/ipc_logging.h" | 22 #include "ipc/ipc_logging.h" |
23 #include "ipc/ipc_message_attachment_set.h" | 23 #include "ipc/ipc_message_attachment_set.h" |
24 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
25 #include "ipc/mojo/ipc_mojo_bootstrap.h" | 25 #include "ipc/mojo/ipc_mojo_bootstrap.h" |
26 #include "ipc/mojo/ipc_mojo_handle_attachment.h" | 26 #include "ipc/mojo/ipc_mojo_handle_attachment.h" |
27 #include "mojo/edk/embedder/embedder.h" | 27 #include "mojo/edk/embedder/embedder.h" |
28 #include "mojo/public/cpp/bindings/binding.h" | 28 #include "mojo/public/cpp/bindings/binding.h" |
29 | 29 |
30 #if defined(OS_POSIX) && !defined(OS_NACL) | 30 #if defined(OS_POSIX) |
31 #include "ipc/ipc_platform_file_attachment_posix.h" | 31 #include "ipc/ipc_platform_file_attachment_posix.h" |
32 #endif | 32 #endif |
33 | 33 |
34 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
35 #include "ipc/mach_port_attachment_mac.h" | 35 #include "ipc/mach_port_attachment_mac.h" |
36 #endif | 36 #endif |
37 | 37 |
38 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
39 #include "ipc/handle_attachment_win.h" | 39 #include "ipc/handle_attachment_win.h" |
40 #endif | 40 #endif |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 MojoResult wrap_result = mojo::edk::CreatePlatformHandleWrapper( | 77 MojoResult wrap_result = mojo::edk::CreatePlatformHandleWrapper( |
78 std::move(handle), &wrapped_handle); | 78 std::move(handle), &wrapped_handle); |
79 if (wrap_result != MOJO_RESULT_OK) | 79 if (wrap_result != MOJO_RESULT_OK) |
80 return wrap_result; | 80 return wrap_result; |
81 | 81 |
82 *serialized = CreateSerializedHandle( | 82 *serialized = CreateSerializedHandle( |
83 mojo::MakeScopedHandle(mojo::Handle(wrapped_handle)), type); | 83 mojo::MakeScopedHandle(mojo::Handle(wrapped_handle)), type); |
84 return MOJO_RESULT_OK; | 84 return MOJO_RESULT_OK; |
85 } | 85 } |
86 | 86 |
87 #if defined(OS_POSIX) && !defined(OS_NACL) | 87 #if defined(OS_POSIX) |
88 | 88 |
89 base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) { | 89 base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) { |
90 return attachment->Owns() ? base::ScopedFD(attachment->TakePlatformFile()) | 90 return attachment->Owns() ? base::ScopedFD(attachment->TakePlatformFile()) |
91 : base::ScopedFD(dup(attachment->file())); | 91 : base::ScopedFD(dup(attachment->file())); |
92 } | 92 } |
93 | 93 |
94 #endif | 94 #endif |
95 | 95 |
96 MojoResult WrapAttachmentImpl(MessageAttachment* attachment, | 96 MojoResult WrapAttachmentImpl(MessageAttachment* attachment, |
97 mojom::SerializedHandlePtr* serialized) { | 97 mojom::SerializedHandlePtr* serialized) { |
98 if (attachment->GetType() == MessageAttachment::TYPE_MOJO_HANDLE) { | 98 if (attachment->GetType() == MessageAttachment::TYPE_MOJO_HANDLE) { |
99 *serialized = CreateSerializedHandle( | 99 *serialized = CreateSerializedHandle( |
100 static_cast<internal::MojoHandleAttachment&>(*attachment).TakeHandle(), | 100 static_cast<internal::MojoHandleAttachment&>(*attachment).TakeHandle(), |
101 mojom::SerializedHandle::Type::MOJO_HANDLE); | 101 mojom::SerializedHandle::Type::MOJO_HANDLE); |
102 return MOJO_RESULT_OK; | 102 return MOJO_RESULT_OK; |
103 } | 103 } |
104 #if defined(OS_POSIX) && !defined(OS_NACL) | 104 #if defined(OS_POSIX) |
105 if (attachment->GetType() == MessageAttachment::TYPE_PLATFORM_FILE) { | 105 if (attachment->GetType() == MessageAttachment::TYPE_PLATFORM_FILE) { |
106 // We dup() the handles in IPC::Message to transmit. | 106 // We dup() the handles in IPC::Message to transmit. |
107 // IPC::MessageAttachmentSet has intricate lifecycle semantics | 107 // IPC::MessageAttachmentSet has intricate lifecycle semantics |
108 // of FDs, so just to dup()-and-own them is the safest option. | 108 // of FDs, so just to dup()-and-own them is the safest option. |
109 base::ScopedFD file = TakeOrDupFile( | 109 base::ScopedFD file = TakeOrDupFile( |
110 static_cast<IPC::internal::PlatformFileAttachment*>(attachment)); | 110 static_cast<IPC::internal::PlatformFileAttachment*>(attachment)); |
111 if (!file.is_valid()) { | 111 if (!file.is_valid()) { |
112 DPLOG(WARNING) << "Failed to dup FD to transmit."; | 112 DPLOG(WARNING) << "Failed to dup FD to transmit."; |
113 return MOJO_RESULT_UNKNOWN; | 113 return MOJO_RESULT_UNKNOWN; |
114 } | 114 } |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 "line", IPC_MESSAGE_ID_LINE(message.type())); | 372 "line", IPC_MESSAGE_ID_LINE(message.type())); |
373 if (AttachmentBroker* broker = AttachmentBroker::GetGlobal()) { | 373 if (AttachmentBroker* broker = AttachmentBroker::GetGlobal()) { |
374 if (broker->OnMessageReceived(message)) | 374 if (broker->OnMessageReceived(message)) |
375 return; | 375 return; |
376 } | 376 } |
377 listener_->OnMessageReceived(message); | 377 listener_->OnMessageReceived(message); |
378 if (message.dispatch_error()) | 378 if (message.dispatch_error()) |
379 listener_->OnBadMessageReceived(message); | 379 listener_->OnBadMessageReceived(message); |
380 } | 380 } |
381 | 381 |
382 #if defined(OS_POSIX) && !defined(OS_NACL) | 382 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) |
383 int ChannelMojo::GetClientFileDescriptor() const { | 383 int ChannelMojo::GetClientFileDescriptor() const { |
384 return -1; | 384 return -1; |
385 } | 385 } |
386 | 386 |
387 base::ScopedFD ChannelMojo::TakeClientFileDescriptor() { | 387 base::ScopedFD ChannelMojo::TakeClientFileDescriptor() { |
388 return base::ScopedFD(GetClientFileDescriptor()); | 388 return base::ScopedFD(GetClientFileDescriptor()); |
389 } | 389 } |
390 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 390 #endif // defined(OS_POSIX) && !defined(OS_NACL_SFI) |
391 | 391 |
392 // static | 392 // static |
393 MojoResult ChannelMojo::ReadFromMessageAttachmentSet( | 393 MojoResult ChannelMojo::ReadFromMessageAttachmentSet( |
394 Message* message, | 394 Message* message, |
395 mojo::Array<mojom::SerializedHandlePtr>* handles) { | 395 mojo::Array<mojom::SerializedHandlePtr>* handles) { |
396 if (message->HasAttachments()) { | 396 if (message->HasAttachments()) { |
397 MessageAttachmentSet* set = message->attachment_set(); | 397 MessageAttachmentSet* set = message->attachment_set(); |
398 for (unsigned i = 0; i < set->num_non_brokerable_attachments(); ++i) { | 398 for (unsigned i = 0; i < set->num_non_brokerable_attachments(); ++i) { |
399 MojoResult result = WrapAttachment( | 399 MojoResult result = WrapAttachment( |
400 set->GetNonBrokerableAttachmentAt(i).get(), handles); | 400 set->GetNonBrokerableAttachmentAt(i).get(), handles); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 DCHECK(ok); | 436 DCHECK(ok); |
437 if (!ok) { | 437 if (!ok) { |
438 LOG(ERROR) << "Failed to add new Mojo handle."; | 438 LOG(ERROR) << "Failed to add new Mojo handle."; |
439 return MOJO_RESULT_UNKNOWN; | 439 return MOJO_RESULT_UNKNOWN; |
440 } | 440 } |
441 } | 441 } |
442 return MOJO_RESULT_OK; | 442 return MOJO_RESULT_OK; |
443 } | 443 } |
444 | 444 |
445 } // namespace IPC | 445 } // namespace IPC |
OLD | NEW |