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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 mojom::SerializedHandle::Type::WIN_HANDLE, serialized); | 172 mojom::SerializedHandle::Type::WIN_HANDLE, serialized); |
173 handle_attachment.reset_handle_ownership(); | 173 handle_attachment.reset_handle_ownership(); |
174 return result; | 174 return result; |
175 #else | 175 #else |
176 NOTREACHED(); | 176 NOTREACHED(); |
177 return MOJO_RESULT_UNKNOWN; | 177 return MOJO_RESULT_UNKNOWN; |
178 #endif // defined(OS_MACOSX) | 178 #endif // defined(OS_MACOSX) |
179 } | 179 } |
180 | 180 |
181 MojoResult WrapAttachment(MessageAttachment* attachment, | 181 MojoResult WrapAttachment(MessageAttachment* attachment, |
182 std::vector<mojom::SerializedHandlePtr>* handles) { | 182 mojo::Array<mojom::SerializedHandlePtr>* handles) { |
183 mojom::SerializedHandlePtr serialized_handle; | 183 mojom::SerializedHandlePtr serialized_handle; |
184 MojoResult wrap_result = WrapAttachmentImpl(attachment, &serialized_handle); | 184 MojoResult wrap_result = WrapAttachmentImpl(attachment, &serialized_handle); |
185 if (wrap_result != MOJO_RESULT_OK) { | 185 if (wrap_result != MOJO_RESULT_OK) { |
186 LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result; | 186 LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result; |
187 return wrap_result; | 187 return wrap_result; |
188 } | 188 } |
189 handles->push_back(std::move(serialized_handle)); | 189 handles->push_back(std::move(serialized_handle)); |
190 return MOJO_RESULT_OK; | 190 return MOJO_RESULT_OK; |
191 } | 191 } |
192 | 192 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 402 } |
403 | 403 |
404 base::ScopedFD ChannelMojo::TakeClientFileDescriptor() { | 404 base::ScopedFD ChannelMojo::TakeClientFileDescriptor() { |
405 return base::ScopedFD(GetClientFileDescriptor()); | 405 return base::ScopedFD(GetClientFileDescriptor()); |
406 } | 406 } |
407 #endif // defined(OS_POSIX) && !defined(OS_NACL_SFI) | 407 #endif // defined(OS_POSIX) && !defined(OS_NACL_SFI) |
408 | 408 |
409 // static | 409 // static |
410 MojoResult ChannelMojo::ReadFromMessageAttachmentSet( | 410 MojoResult ChannelMojo::ReadFromMessageAttachmentSet( |
411 Message* message, | 411 Message* message, |
412 base::Optional<std::vector<mojom::SerializedHandlePtr>>* handles) { | 412 mojo::Array<mojom::SerializedHandlePtr>* handles) { |
413 DCHECK(!*handles); | 413 if (message->HasAttachments()) { |
414 | 414 MessageAttachmentSet* set = message->attachment_set(); |
415 MojoResult result = MOJO_RESULT_OK; | 415 for (unsigned i = 0; i < set->num_non_brokerable_attachments(); ++i) { |
416 if (!message->HasAttachments()) | 416 MojoResult result = WrapAttachment( |
417 return result; | 417 set->GetNonBrokerableAttachmentAt(i).get(), handles); |
418 | 418 if (result != MOJO_RESULT_OK) { |
419 std::vector<mojom::SerializedHandlePtr> output_handles; | 419 set->CommitAllDescriptors(); |
420 MessageAttachmentSet* set = message->attachment_set(); | 420 return result; |
421 | 421 } |
422 for (unsigned i = 0; | 422 } |
423 result == MOJO_RESULT_OK && i < set->num_non_brokerable_attachments(); | 423 for (unsigned i = 0; i < set->num_brokerable_attachments(); ++i) { |
424 ++i) { | 424 MojoResult result = |
425 result = WrapAttachment(set->GetNonBrokerableAttachmentAt(i).get(), | 425 WrapAttachment(set->GetBrokerableAttachmentAt(i).get(), handles); |
426 &output_handles); | 426 if (result != MOJO_RESULT_OK) { |
| 427 set->CommitAllDescriptors(); |
| 428 return result; |
| 429 } |
| 430 } |
| 431 set->CommitAllDescriptors(); |
427 } | 432 } |
428 for (unsigned i = 0; | 433 return MOJO_RESULT_OK; |
429 result == MOJO_RESULT_OK && i < set->num_brokerable_attachments(); ++i) { | |
430 result = WrapAttachment(set->GetBrokerableAttachmentAt(i).get(), | |
431 &output_handles); | |
432 } | |
433 | |
434 set->CommitAllDescriptors(); | |
435 | |
436 if (!output_handles.empty()) | |
437 *handles = std::move(output_handles); | |
438 | |
439 return result; | |
440 } | 434 } |
441 | 435 |
442 // static | 436 // static |
443 MojoResult ChannelMojo::WriteToMessageAttachmentSet( | 437 MojoResult ChannelMojo::WriteToMessageAttachmentSet( |
444 base::Optional<std::vector<mojom::SerializedHandlePtr>> handle_buffer, | 438 mojo::Array<mojom::SerializedHandlePtr> handle_buffer, |
445 Message* message) { | 439 Message* message) { |
446 if (!handle_buffer) | 440 for (size_t i = 0; i < handle_buffer.size(); ++i) { |
447 return MOJO_RESULT_OK; | |
448 for (size_t i = 0; i < handle_buffer->size(); ++i) { | |
449 scoped_refptr<MessageAttachment> unwrapped_attachment; | 441 scoped_refptr<MessageAttachment> unwrapped_attachment; |
450 MojoResult unwrap_result = | 442 MojoResult unwrap_result = UnwrapAttachment(std::move(handle_buffer[i]), |
451 UnwrapAttachment(std::move((*handle_buffer)[i]), &unwrapped_attachment); | 443 &unwrapped_attachment); |
452 if (unwrap_result != MOJO_RESULT_OK) { | 444 if (unwrap_result != MOJO_RESULT_OK) { |
453 LOG(WARNING) << "Pipe failed to unwrap handles. Closing: " | 445 LOG(WARNING) << "Pipe failed to unwrap handles. Closing: " |
454 << unwrap_result; | 446 << unwrap_result; |
455 return unwrap_result; | 447 return unwrap_result; |
456 } | 448 } |
457 DCHECK(unwrapped_attachment); | 449 DCHECK(unwrapped_attachment); |
458 | 450 |
459 bool ok = message->attachment_set()->AddAttachment( | 451 bool ok = message->attachment_set()->AddAttachment( |
460 std::move(unwrapped_attachment)); | 452 std::move(unwrapped_attachment)); |
461 DCHECK(ok); | 453 DCHECK(ok); |
(...skipping 19 matching lines...) Expand all Loading... |
481 } | 473 } |
482 | 474 |
483 void ChannelMojo::GetGenericRemoteAssociatedInterface( | 475 void ChannelMojo::GetGenericRemoteAssociatedInterface( |
484 const std::string& name, | 476 const std::string& name, |
485 mojo::ScopedInterfaceEndpointHandle handle) { | 477 mojo::ScopedInterfaceEndpointHandle handle) { |
486 if (message_reader_) | 478 if (message_reader_) |
487 message_reader_->GetRemoteInterface(name, std::move(handle)); | 479 message_reader_->GetRemoteInterface(name, std::move(handle)); |
488 } | 480 } |
489 | 481 |
490 } // namespace IPC | 482 } // namespace IPC |
OLD | NEW |