Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Unified Diff: ipc/ipc_channel_mojo.cc

Issue 2181443002: Mojo C++ bindings: make ipc/ mojom targets to use STL string/vector types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make further change to array_traits_stl.h to make MSan build happy. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/ipc_channel_mojo.h ('k') | ipc/ipc_message_pipe_reader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « ipc/ipc_channel_mojo.h ('k') | ipc/ipc_message_pipe_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698