| Index: ipc/ipc_channel_mojo.cc
|
| diff --git a/ipc/ipc_channel_mojo.cc b/ipc/ipc_channel_mojo.cc
|
| index 9ce2e661bd145a204ca7f62dfa7e68b494c029ed..627efc1dc54f1b7abd9aba0add6247bcce0cce88 100644
|
| --- a/ipc/ipc_channel_mojo.cc
|
| +++ b/ipc/ipc_channel_mojo.cc
|
| @@ -179,7 +179,7 @@ MojoResult WrapAttachmentImpl(MessageAttachment* attachment,
|
| }
|
|
|
| MojoResult WrapAttachment(MessageAttachment* attachment,
|
| - mojo::Array<mojom::SerializedHandlePtr>* handles) {
|
| + std::vector<mojom::SerializedHandlePtr>* handles) {
|
| mojom::SerializedHandlePtr serialized_handle;
|
| MojoResult wrap_result = WrapAttachmentImpl(attachment, &serialized_handle);
|
| if (wrap_result != MOJO_RESULT_OK) {
|
| @@ -409,38 +409,46 @@ base::ScopedFD ChannelMojo::TakeClientFileDescriptor() {
|
| // static
|
| MojoResult ChannelMojo::ReadFromMessageAttachmentSet(
|
| Message* message,
|
| - mojo::Array<mojom::SerializedHandlePtr>* handles) {
|
| - if (message->HasAttachments()) {
|
| - MessageAttachmentSet* set = message->attachment_set();
|
| - for (unsigned i = 0; i < set->num_non_brokerable_attachments(); ++i) {
|
| - MojoResult result = WrapAttachment(
|
| - set->GetNonBrokerableAttachmentAt(i).get(), handles);
|
| - if (result != MOJO_RESULT_OK) {
|
| - set->CommitAllDescriptors();
|
| - return result;
|
| - }
|
| - }
|
| - for (unsigned i = 0; i < set->num_brokerable_attachments(); ++i) {
|
| - MojoResult result =
|
| - WrapAttachment(set->GetBrokerableAttachmentAt(i).get(), handles);
|
| - if (result != MOJO_RESULT_OK) {
|
| - set->CommitAllDescriptors();
|
| - return result;
|
| - }
|
| - }
|
| - set->CommitAllDescriptors();
|
| + base::Optional<std::vector<mojom::SerializedHandlePtr>>* handles) {
|
| + DCHECK(!*handles);
|
| +
|
| + MojoResult result = MOJO_RESULT_OK;
|
| + if (!message->HasAttachments())
|
| + return result;
|
| +
|
| + std::vector<mojom::SerializedHandlePtr> output_handles;
|
| + MessageAttachmentSet* set = message->attachment_set();
|
| +
|
| + for (unsigned i = 0;
|
| + result == MOJO_RESULT_OK && i < set->num_non_brokerable_attachments();
|
| + ++i) {
|
| + result = WrapAttachment(set->GetNonBrokerableAttachmentAt(i).get(),
|
| + &output_handles);
|
| }
|
| - return MOJO_RESULT_OK;
|
| + for (unsigned i = 0;
|
| + result == MOJO_RESULT_OK && i < set->num_brokerable_attachments(); ++i) {
|
| + result = WrapAttachment(set->GetBrokerableAttachmentAt(i).get(),
|
| + &output_handles);
|
| + }
|
| +
|
| + set->CommitAllDescriptors();
|
| +
|
| + if (!output_handles.empty())
|
| + *handles = std::move(output_handles);
|
| +
|
| + return result;
|
| }
|
|
|
| // static
|
| MojoResult ChannelMojo::WriteToMessageAttachmentSet(
|
| - mojo::Array<mojom::SerializedHandlePtr> handle_buffer,
|
| + base::Optional<std::vector<mojom::SerializedHandlePtr>> handle_buffer,
|
| Message* message) {
|
| - for (size_t i = 0; i < handle_buffer.size(); ++i) {
|
| + if (!handle_buffer)
|
| + return MOJO_RESULT_OK;
|
| + for (size_t i = 0; i < handle_buffer->size(); ++i) {
|
| scoped_refptr<MessageAttachment> unwrapped_attachment;
|
| - MojoResult unwrap_result = UnwrapAttachment(std::move(handle_buffer[i]),
|
| - &unwrapped_attachment);
|
| + MojoResult unwrap_result =
|
| + UnwrapAttachment(std::move((*handle_buffer)[i]), &unwrapped_attachment);
|
| if (unwrap_result != MOJO_RESULT_OK) {
|
| LOG(WARNING) << "Pipe failed to unwrap handles. Closing: "
|
| << unwrap_result;
|
|
|