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