| 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 mojo::Array<mojom::SerializedHandlePtr>* handles) { | 182 std::vector<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 mojo::Array<mojom::SerializedHandlePtr>* handles) { | 412 base::Optional<std::vector<mojom::SerializedHandlePtr>>* handles) { |
| 413 if (message->HasAttachments()) { | 413 DCHECK(!*handles); |
| 414 MessageAttachmentSet* set = message->attachment_set(); | 414 |
| 415 for (unsigned i = 0; i < set->num_non_brokerable_attachments(); ++i) { | 415 MojoResult result = MOJO_RESULT_OK; |
| 416 MojoResult result = WrapAttachment( | 416 if (!message->HasAttachments()) |
| 417 set->GetNonBrokerableAttachmentAt(i).get(), handles); | 417 return result; |
| 418 if (result != MOJO_RESULT_OK) { | 418 |
| 419 set->CommitAllDescriptors(); | 419 std::vector<mojom::SerializedHandlePtr> output_handles; |
| 420 return result; | 420 MessageAttachmentSet* set = message->attachment_set(); |
| 421 } | 421 |
| 422 } | 422 for (unsigned i = 0; |
| 423 for (unsigned i = 0; i < set->num_brokerable_attachments(); ++i) { | 423 result == MOJO_RESULT_OK && i < set->num_non_brokerable_attachments(); |
| 424 MojoResult result = | 424 ++i) { |
| 425 WrapAttachment(set->GetBrokerableAttachmentAt(i).get(), handles); | 425 result = WrapAttachment(set->GetNonBrokerableAttachmentAt(i).get(), |
| 426 if (result != MOJO_RESULT_OK) { | 426 &output_handles); |
| 427 set->CommitAllDescriptors(); | |
| 428 return result; | |
| 429 } | |
| 430 } | |
| 431 set->CommitAllDescriptors(); | |
| 432 } | 427 } |
| 433 return MOJO_RESULT_OK; | 428 for (unsigned i = 0; |
| 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; |
| 434 } | 440 } |
| 435 | 441 |
| 436 // static | 442 // static |
| 437 MojoResult ChannelMojo::WriteToMessageAttachmentSet( | 443 MojoResult ChannelMojo::WriteToMessageAttachmentSet( |
| 438 mojo::Array<mojom::SerializedHandlePtr> handle_buffer, | 444 base::Optional<std::vector<mojom::SerializedHandlePtr>> handle_buffer, |
| 439 Message* message) { | 445 Message* message) { |
| 440 for (size_t i = 0; i < handle_buffer.size(); ++i) { | 446 if (!handle_buffer) |
| 447 return MOJO_RESULT_OK; |
| 448 for (size_t i = 0; i < handle_buffer->size(); ++i) { |
| 441 scoped_refptr<MessageAttachment> unwrapped_attachment; | 449 scoped_refptr<MessageAttachment> unwrapped_attachment; |
| 442 MojoResult unwrap_result = UnwrapAttachment(std::move(handle_buffer[i]), | 450 MojoResult unwrap_result = |
| 443 &unwrapped_attachment); | 451 UnwrapAttachment(std::move((*handle_buffer)[i]), &unwrapped_attachment); |
| 444 if (unwrap_result != MOJO_RESULT_OK) { | 452 if (unwrap_result != MOJO_RESULT_OK) { |
| 445 LOG(WARNING) << "Pipe failed to unwrap handles. Closing: " | 453 LOG(WARNING) << "Pipe failed to unwrap handles. Closing: " |
| 446 << unwrap_result; | 454 << unwrap_result; |
| 447 return unwrap_result; | 455 return unwrap_result; |
| 448 } | 456 } |
| 449 DCHECK(unwrapped_attachment); | 457 DCHECK(unwrapped_attachment); |
| 450 | 458 |
| 451 bool ok = message->attachment_set()->AddAttachment( | 459 bool ok = message->attachment_set()->AddAttachment( |
| 452 std::move(unwrapped_attachment)); | 460 std::move(unwrapped_attachment)); |
| 453 DCHECK(ok); | 461 DCHECK(ok); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 473 } | 481 } |
| 474 | 482 |
| 475 void ChannelMojo::GetGenericRemoteAssociatedInterface( | 483 void ChannelMojo::GetGenericRemoteAssociatedInterface( |
| 476 const std::string& name, | 484 const std::string& name, |
| 477 mojo::ScopedInterfaceEndpointHandle handle) { | 485 mojo::ScopedInterfaceEndpointHandle handle) { |
| 478 if (message_reader_) | 486 if (message_reader_) |
| 479 message_reader_->GetRemoteInterface(name, std::move(handle)); | 487 message_reader_->GetRemoteInterface(name, std::move(handle)); |
| 480 } | 488 } |
| 481 | 489 |
| 482 } // namespace IPC | 490 } // namespace IPC |
| OLD | NEW |