| 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" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 for (size_t i = 0; i < handle_buffer.size(); ++i) { | 241 for (size_t i = 0; i < handle_buffer.size(); ++i) { |
| 242 mojo::embedder::ScopedPlatformHandle platform_handle; | 242 mojo::embedder::ScopedPlatformHandle platform_handle; |
| 243 MojoResult unwrap_result = mojo::embedder::PassWrappedPlatformHandle( | 243 MojoResult unwrap_result = mojo::embedder::PassWrappedPlatformHandle( |
| 244 handle_buffer[i], &platform_handle); | 244 handle_buffer[i], &platform_handle); |
| 245 if (unwrap_result != MOJO_RESULT_OK) { | 245 if (unwrap_result != MOJO_RESULT_OK) { |
| 246 DLOG(WARNING) << "Pipe failed to covert handles. Closing: " | 246 DLOG(WARNING) << "Pipe failed to covert handles. Closing: " |
| 247 << unwrap_result; | 247 << unwrap_result; |
| 248 return unwrap_result; | 248 return unwrap_result; |
| 249 } | 249 } |
| 250 | 250 |
| 251 bool ok = message->file_descriptor_set()->Add(platform_handle.release().fd); | 251 bool ok = message->file_descriptor_set()->AddToOwn( |
| 252 base::ScopedFD(platform_handle.release().fd)); |
| 252 DCHECK(ok); | 253 DCHECK(ok); |
| 253 } | 254 } |
| 254 | 255 |
| 255 return MOJO_RESULT_OK; | 256 return MOJO_RESULT_OK; |
| 256 } | 257 } |
| 257 | 258 |
| 258 // static | 259 // static |
| 259 MojoResult ChannelMojo::ReadFromFileDescriptorSet( | 260 MojoResult ChannelMojo::ReadFromFileDescriptorSet( |
| 260 const Message& message, | 261 Message* message, |
| 261 std::vector<MojoHandle>* handles) { | 262 std::vector<MojoHandle>* handles) { |
| 262 // We dup() the handles in IPC::Message to transmit. | 263 // We dup() the handles in IPC::Message to transmit. |
| 263 // IPC::FileDescriptorSet has intricate lifecycle semantics | 264 // IPC::FileDescriptorSet has intricate lifecycle semantics |
| 264 // of FDs, so just to dup()-and-own them is the safest option. | 265 // of FDs, so just to dup()-and-own them is the safest option. |
| 265 if (message.HasFileDescriptors()) { | 266 if (message->HasFileDescriptors()) { |
| 266 const FileDescriptorSet* fdset = message.file_descriptor_set(); | 267 FileDescriptorSet* fdset = message->file_descriptor_set(); |
| 267 for (size_t i = 0; i < fdset->size(); ++i) { | 268 std::vector<base::PlatformFile> fds_to_send(fdset->size()); |
| 268 int fd_to_send = dup(fdset->GetDescriptorAt(i)); | 269 fdset->PeekDescriptors(&fds_to_send[0]); |
| 270 for (size_t i = 0; i < fds_to_send.size(); ++i) { |
| 271 int fd_to_send = dup(fds_to_send[i]); |
| 269 if (-1 == fd_to_send) { | 272 if (-1 == fd_to_send) { |
| 270 DPLOG(WARNING) << "Failed to dup FD to transmit."; | 273 DPLOG(WARNING) << "Failed to dup FD to transmit."; |
| 274 fdset->CommitAll(); |
| 271 return MOJO_RESULT_UNKNOWN; | 275 return MOJO_RESULT_UNKNOWN; |
| 272 } | 276 } |
| 273 | 277 |
| 274 MojoHandle wrapped_handle; | 278 MojoHandle wrapped_handle; |
| 275 MojoResult wrap_result = CreatePlatformHandleWrapper( | 279 MojoResult wrap_result = CreatePlatformHandleWrapper( |
| 276 mojo::embedder::ScopedPlatformHandle( | 280 mojo::embedder::ScopedPlatformHandle( |
| 277 mojo::embedder::PlatformHandle(fd_to_send)), | 281 mojo::embedder::PlatformHandle(fd_to_send)), |
| 278 &wrapped_handle); | 282 &wrapped_handle); |
| 279 if (MOJO_RESULT_OK != wrap_result) { | 283 if (MOJO_RESULT_OK != wrap_result) { |
| 280 DLOG(WARNING) << "Pipe failed to wrap handles. Closing: " | 284 DLOG(WARNING) << "Pipe failed to wrap handles. Closing: " |
| 281 << wrap_result; | 285 << wrap_result; |
| 286 fdset->CommitAll(); |
| 282 return wrap_result; | 287 return wrap_result; |
| 283 } | 288 } |
| 284 | 289 |
| 285 handles->push_back(wrapped_handle); | 290 handles->push_back(wrapped_handle); |
| 286 } | 291 } |
| 292 |
| 293 fdset->CommitAll(); |
| 287 } | 294 } |
| 288 | 295 |
| 289 return MOJO_RESULT_OK; | 296 return MOJO_RESULT_OK; |
| 290 } | 297 } |
| 291 | 298 |
| 292 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 299 #endif // defined(OS_POSIX) && !defined(OS_NACL) |
| 293 | 300 |
| 294 } // namespace IPC | 301 } // namespace IPC |
| OLD | NEW |