| 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> |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } |
| 115 | 115 |
| 116 return WrapPlatformHandle(mojo::edk::ScopedPlatformHandle( | 116 return WrapPlatformHandle(mojo::edk::ScopedPlatformHandle( |
| 117 mojo::edk::PlatformHandle(file.release())), | 117 mojo::edk::PlatformHandle(file.release())), |
| 118 mojom::SerializedHandle::Type::MOJO_HANDLE, | 118 mojom::SerializedHandle::Type::PLATFORM_FILE, |
| 119 serialized); | 119 serialized); |
| 120 } | 120 } |
| 121 #endif | 121 #endif |
| 122 #if defined(OS_MACOSX) | 122 #if defined(OS_MACOSX) |
| 123 DCHECK_EQ(attachment->GetType(), | 123 DCHECK_EQ(attachment->GetType(), |
| 124 MessageAttachment::TYPE_BROKERABLE_ATTACHMENT); | 124 MessageAttachment::TYPE_BROKERABLE_ATTACHMENT); |
| 125 DCHECK_EQ(static_cast<BrokerableAttachment&>(*attachment).GetBrokerableType(), | 125 DCHECK_EQ(static_cast<BrokerableAttachment&>(*attachment).GetBrokerableType(), |
| 126 BrokerableAttachment::MACH_PORT); | 126 BrokerableAttachment::MACH_PORT); |
| 127 internal::MachPortAttachmentMac& mach_port_attachment = | 127 internal::MachPortAttachmentMac& mach_port_attachment = |
| 128 static_cast<internal::MachPortAttachmentMac&>(*attachment); | 128 static_cast<internal::MachPortAttachmentMac&>(*attachment); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 if (handle->type == mojom::SerializedHandle::Type::MOJO_HANDLE) { | 168 if (handle->type == mojom::SerializedHandle::Type::MOJO_HANDLE) { |
| 169 *attachment = | 169 *attachment = |
| 170 new IPC::internal::MojoHandleAttachment(std::move(handle->the_handle)); | 170 new IPC::internal::MojoHandleAttachment(std::move(handle->the_handle)); |
| 171 return MOJO_RESULT_OK; | 171 return MOJO_RESULT_OK; |
| 172 } | 172 } |
| 173 mojo::edk::ScopedPlatformHandle platform_handle; | 173 mojo::edk::ScopedPlatformHandle platform_handle; |
| 174 MojoResult unwrap_result = mojo::edk::PassWrappedPlatformHandle( | 174 MojoResult unwrap_result = mojo::edk::PassWrappedPlatformHandle( |
| 175 handle->the_handle.release().value(), &platform_handle); | 175 handle->the_handle.release().value(), &platform_handle); |
| 176 if (unwrap_result != MOJO_RESULT_OK) | 176 if (unwrap_result != MOJO_RESULT_OK) |
| 177 return unwrap_result; | 177 return unwrap_result; |
| 178 #if defined(OS_POSIX) |
| 179 if (handle->type == mojom::SerializedHandle::Type::PLATFORM_FILE && |
| 180 platform_handle.get().type == mojo::edk::PlatformHandle::Type::POSIX) { |
| 181 *attachment = new internal::PlatformFileAttachment( |
| 182 platform_handle.release().handle); |
| 183 return MOJO_RESULT_OK; |
| 184 } |
| 185 #endif // defined(OS_POSIX) |
| 178 #if defined(OS_MACOSX) | 186 #if defined(OS_MACOSX) |
| 179 if (handle->type == mojom::SerializedHandle::Type::MACH_PORT && | 187 if (handle->type == mojom::SerializedHandle::Type::MACH_PORT && |
| 180 platform_handle.get().type == mojo::edk::PlatformHandle::Type::MACH) { | 188 platform_handle.get().type == mojo::edk::PlatformHandle::Type::MACH) { |
| 181 *attachment = new internal::MachPortAttachmentMac( | 189 *attachment = new internal::MachPortAttachmentMac( |
| 182 platform_handle.release().port, | 190 platform_handle.release().port, |
| 183 internal::MachPortAttachmentMac::FROM_WIRE); | 191 internal::MachPortAttachmentMac::FROM_WIRE); |
| 184 return MOJO_RESULT_OK; | 192 return MOJO_RESULT_OK; |
| 185 } | 193 } |
| 186 #endif // defined(OS_MACOSX) | 194 #endif // defined(OS_MACOSX) |
| 187 #if defined(OS_WIN) | 195 #if defined(OS_WIN) |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 DCHECK(ok); | 444 DCHECK(ok); |
| 437 if (!ok) { | 445 if (!ok) { |
| 438 LOG(ERROR) << "Failed to add new Mojo handle."; | 446 LOG(ERROR) << "Failed to add new Mojo handle."; |
| 439 return MOJO_RESULT_UNKNOWN; | 447 return MOJO_RESULT_UNKNOWN; |
| 440 } | 448 } |
| 441 } | 449 } |
| 442 return MOJO_RESULT_OK; | 450 return MOJO_RESULT_OK; |
| 443 } | 451 } |
| 444 | 452 |
| 445 } // namespace IPC | 453 } // namespace IPC |
| OLD | NEW |