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/ipc_channel_mojo.h" | 5 #include "ipc/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> |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) { | 120 base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) { |
121 return attachment->Owns() ? base::ScopedFD(attachment->TakePlatformFile()) | 121 return attachment->Owns() ? base::ScopedFD(attachment->TakePlatformFile()) |
122 : base::ScopedFD(dup(attachment->file())); | 122 : base::ScopedFD(dup(attachment->file())); |
123 } | 123 } |
124 | 124 |
125 #endif | 125 #endif |
126 | 126 |
127 MojoResult WrapAttachmentImpl(MessageAttachment* attachment, | 127 MojoResult WrapAttachmentImpl(MessageAttachment* attachment, |
128 mojom::SerializedHandlePtr* serialized) { | 128 mojom::SerializedHandlePtr* serialized) { |
129 if (attachment->GetType() == MessageAttachment::Type::MOJO_HANDLE) { | 129 if (attachment->GetType() == MessageAttachment::TYPE_MOJO_HANDLE) { |
130 *serialized = CreateSerializedHandle( | 130 *serialized = CreateSerializedHandle( |
131 static_cast<internal::MojoHandleAttachment&>(*attachment).TakeHandle(), | 131 static_cast<internal::MojoHandleAttachment&>(*attachment).TakeHandle(), |
132 mojom::SerializedHandle::Type::MOJO_HANDLE); | 132 mojom::SerializedHandle::Type::MOJO_HANDLE); |
133 return MOJO_RESULT_OK; | 133 return MOJO_RESULT_OK; |
134 } | 134 } |
135 #if defined(OS_POSIX) | 135 #if defined(OS_POSIX) |
136 if (attachment->GetType() == MessageAttachment::Type::PLATFORM_FILE) { | 136 if (attachment->GetType() == MessageAttachment::TYPE_PLATFORM_FILE) { |
137 // We dup() the handles in IPC::Message to transmit. | 137 // We dup() the handles in IPC::Message to transmit. |
138 // IPC::MessageAttachmentSet has intricate lifecycle semantics | 138 // IPC::MessageAttachmentSet has intricate lifecycle semantics |
139 // of FDs, so just to dup()-and-own them is the safest option. | 139 // of FDs, so just to dup()-and-own them is the safest option. |
140 base::ScopedFD file = TakeOrDupFile( | 140 base::ScopedFD file = TakeOrDupFile( |
141 static_cast<IPC::internal::PlatformFileAttachment*>(attachment)); | 141 static_cast<IPC::internal::PlatformFileAttachment*>(attachment)); |
142 if (!file.is_valid()) { | 142 if (!file.is_valid()) { |
143 DPLOG(WARNING) << "Failed to dup FD to transmit."; | 143 DPLOG(WARNING) << "Failed to dup FD to transmit."; |
144 return MOJO_RESULT_UNKNOWN; | 144 return MOJO_RESULT_UNKNOWN; |
145 } | 145 } |
146 | 146 |
147 return WrapPlatformHandle(file.release(), | 147 return WrapPlatformHandle(file.release(), |
148 mojom::SerializedHandle::Type::PLATFORM_FILE, | 148 mojom::SerializedHandle::Type::PLATFORM_FILE, |
149 serialized); | 149 serialized); |
150 } | 150 } |
151 #endif | 151 #endif |
152 #if defined(OS_MACOSX) | 152 #if defined(OS_MACOSX) |
153 DCHECK_EQ(attachment->GetType(), MessageAttachment::Type::MACH_PORT); | 153 DCHECK_EQ(attachment->GetType(), |
| 154 MessageAttachment::TYPE_BROKERABLE_ATTACHMENT); |
| 155 DCHECK_EQ(static_cast<BrokerableAttachment&>(*attachment).GetBrokerableType(), |
| 156 BrokerableAttachment::MACH_PORT); |
154 internal::MachPortAttachmentMac& mach_port_attachment = | 157 internal::MachPortAttachmentMac& mach_port_attachment = |
155 static_cast<internal::MachPortAttachmentMac&>(*attachment); | 158 static_cast<internal::MachPortAttachmentMac&>(*attachment); |
156 MojoResult result = WrapMachPort(mach_port_attachment.get_mach_port(), | 159 MojoResult result = WrapMachPort(mach_port_attachment.get_mach_port(), |
157 serialized); | 160 serialized); |
158 mach_port_attachment.reset_mach_port_ownership(); | 161 mach_port_attachment.reset_mach_port_ownership(); |
159 return result; | 162 return result; |
160 #elif defined(OS_WIN) | 163 #elif defined(OS_WIN) |
161 DCHECK_EQ(attachment->GetType(), MessageAttachment::Type::WIN_HANDLE); | 164 DCHECK_EQ(attachment->GetType(), |
| 165 MessageAttachment::TYPE_BROKERABLE_ATTACHMENT); |
| 166 DCHECK_EQ(static_cast<BrokerableAttachment&>(*attachment).GetBrokerableType(), |
| 167 BrokerableAttachment::WIN_HANDLE); |
162 internal::HandleAttachmentWin& handle_attachment = | 168 internal::HandleAttachmentWin& handle_attachment = |
163 static_cast<internal::HandleAttachmentWin&>(*attachment); | 169 static_cast<internal::HandleAttachmentWin&>(*attachment); |
164 MojoResult result = WrapPlatformHandle( | 170 MojoResult result = WrapPlatformHandle( |
165 handle_attachment.get_handle(), | 171 handle_attachment.get_handle(), |
166 mojom::SerializedHandle::Type::WIN_HANDLE, serialized); | 172 mojom::SerializedHandle::Type::WIN_HANDLE, serialized); |
167 handle_attachment.reset_handle_ownership(); | 173 handle_attachment.reset_handle_ownership(); |
168 return result; | 174 return result; |
169 #else | 175 #else |
170 NOTREACHED(); | 176 NOTREACHED(); |
171 return MOJO_RESULT_UNKNOWN; | 177 return MOJO_RESULT_UNKNOWN; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 base::Optional<std::vector<mojom::SerializedHandlePtr>>* handles) { | 404 base::Optional<std::vector<mojom::SerializedHandlePtr>>* handles) { |
399 DCHECK(!*handles); | 405 DCHECK(!*handles); |
400 | 406 |
401 MojoResult result = MOJO_RESULT_OK; | 407 MojoResult result = MOJO_RESULT_OK; |
402 if (!message->HasAttachments()) | 408 if (!message->HasAttachments()) |
403 return result; | 409 return result; |
404 | 410 |
405 std::vector<mojom::SerializedHandlePtr> output_handles; | 411 std::vector<mojom::SerializedHandlePtr> output_handles; |
406 MessageAttachmentSet* set = message->attachment_set(); | 412 MessageAttachmentSet* set = message->attachment_set(); |
407 | 413 |
408 for (unsigned i = 0; result == MOJO_RESULT_OK && i < set->size(); ++i) { | 414 for (unsigned i = 0; |
409 result = WrapAttachment(set->GetAttachmentAt(i).get(), &output_handles); | 415 result == MOJO_RESULT_OK && i < set->num_non_brokerable_attachments(); |
| 416 ++i) { |
| 417 result = WrapAttachment(set->GetNonBrokerableAttachmentAt(i).get(), |
| 418 &output_handles); |
410 } | 419 } |
| 420 for (unsigned i = 0; |
| 421 result == MOJO_RESULT_OK && i < set->num_brokerable_attachments(); ++i) { |
| 422 result = WrapAttachment(set->GetBrokerableAttachmentAt(i).get(), |
| 423 &output_handles); |
| 424 } |
| 425 |
411 set->CommitAllDescriptors(); | 426 set->CommitAllDescriptors(); |
412 | 427 |
413 if (!output_handles.empty()) | 428 if (!output_handles.empty()) |
414 *handles = std::move(output_handles); | 429 *handles = std::move(output_handles); |
415 | 430 |
416 return result; | 431 return result; |
417 } | 432 } |
418 | 433 |
419 // static | 434 // static |
420 MojoResult ChannelMojo::WriteToMessageAttachmentSet( | 435 MojoResult ChannelMojo::WriteToMessageAttachmentSet( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 473 } |
459 | 474 |
460 void ChannelMojo::GetGenericRemoteAssociatedInterface( | 475 void ChannelMojo::GetGenericRemoteAssociatedInterface( |
461 const std::string& name, | 476 const std::string& name, |
462 mojo::ScopedInterfaceEndpointHandle handle) { | 477 mojo::ScopedInterfaceEndpointHandle handle) { |
463 if (message_reader_) | 478 if (message_reader_) |
464 message_reader_->GetRemoteInterface(name, std::move(handle)); | 479 message_reader_->GetRemoteInterface(name, std::move(handle)); |
465 } | 480 } |
466 | 481 |
467 } // namespace IPC | 482 } // namespace IPC |
OLD | NEW |