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

Side by Side Diff: ipc/mojo/ipc_message_pipe_reader.cc

Issue 1932083002: Mojo: Use new message APIs to reduce copying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | mojo/mojo_public.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_message_pipe_reader.h" 5 #include "ipc/mojo/ipc_message_pipe_reader.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 MessageSerializer serializer; 102 MessageSerializer serializer;
103 mojom::ChannelProxy proxy(&serializer); 103 mojom::ChannelProxy proxy(&serializer);
104 proxy.Receive(std::move(data), std::move(handles)); 104 proxy.Receive(std::move(data), std::move(handles));
105 mojo::Message* mojo_message = serializer.message(); 105 mojo::Message* mojo_message = serializer.message();
106 106
107 size_t num_handles = mojo_message->handles()->size(); 107 size_t num_handles = mojo_message->handles()->size();
108 DCHECK_LE(num_handles, std::numeric_limits<uint32_t>::max()); 108 DCHECK_LE(num_handles, std::numeric_limits<uint32_t>::max());
109 109
110 mojo_message->set_interface_id(sender_interface_id_); 110 mojo_message->set_interface_id(sender_interface_id_);
111 result = mojo::WriteMessageRaw( 111 result = mojo::WriteMessageNew(sender_pipe_, mojo_message->TakeMojoMessage(),
112 sender_pipe_, mojo_message->data(), mojo_message->data_num_bytes(), 112 MOJO_WRITE_MESSAGE_FLAG_NONE);
113 reinterpret_cast<const MojoHandle*>(mojo_message->handles()->data()),
114 static_cast<uint32_t>(num_handles), MOJO_WRITE_MESSAGE_FLAG_NONE);
115
116 // If the write was successful, the handles have been transferred and they
117 // should not be closed when the message is destroyed.
118 if (result == MOJO_RESULT_OK)
119 mojo_message->mutable_handles()->clear();
120 113
121 DVLOG(4) << "Send " << message->type() << ": " << message->size(); 114 DVLOG(4) << "Send " << message->type() << ": " << message->size();
122 return result == MOJO_RESULT_OK; 115 return result == MOJO_RESULT_OK;
123 } 116 }
124 117
125 void MessagePipeReader::Receive( 118 void MessagePipeReader::Receive(
126 mojo::Array<uint8_t> data, 119 mojo::Array<uint8_t> data,
127 mojo::Array<mojom::SerializedHandlePtr> handles) { 120 mojo::Array<mojom::SerializedHandlePtr> handles) {
128 Message message( 121 Message message(
129 data.size() == 0 ? "" : reinterpret_cast<const char*>(&data[0]), 122 data.size() == 0 ? "" : reinterpret_cast<const char*>(&data[0]),
(...skipping 24 matching lines...) Expand all
154 147
155 void MessagePipeReader::DelayedDeleter::operator()( 148 void MessagePipeReader::DelayedDeleter::operator()(
156 MessagePipeReader* ptr) const { 149 MessagePipeReader* ptr) const {
157 ptr->Close(); 150 ptr->Close();
158 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 151 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
159 base::Bind(&DeleteNow, ptr)); 152 base::Bind(&DeleteNow, ptr));
160 } 153 }
161 154
162 } // namespace internal 155 } // namespace internal
163 } // namespace IPC 156 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | mojo/mojo_public.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698