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

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

Issue 1809323002: ChannelMojo: Remove intermediate Message struct (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « ipc/mojo/ipc_message_pipe_reader.h ('k') | no next file » | 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 void MessagePipeReader::CloseWithError(MojoResult error) { 51 void MessagePipeReader::CloseWithError(MojoResult error) {
52 DCHECK(thread_checker_.CalledOnValidThread()); 52 DCHECK(thread_checker_.CalledOnValidThread());
53 OnPipeError(error); 53 OnPipeError(error);
54 } 54 }
55 55
56 bool MessagePipeReader::Send(scoped_ptr<Message> message) { 56 bool MessagePipeReader::Send(scoped_ptr<Message> message) {
57 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), 57 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"),
58 "MessagePipeReader::Send", 58 "MessagePipeReader::Send",
59 message->flags(), 59 message->flags(),
60 TRACE_EVENT_FLAG_FLOW_OUT); 60 TRACE_EVENT_FLAG_FLOW_OUT);
61 mojom::MessagePtr ipc_message = mojom::Message::New(); 61 mojo::Array<mojom::SerializedHandlePtr> handles(nullptr);
62 MojoResult result = MOJO_RESULT_OK; 62 MojoResult result = MOJO_RESULT_OK;
63 result = ChannelMojo::ReadFromMessageAttachmentSet(message.get(), 63 result = ChannelMojo::ReadFromMessageAttachmentSet(message.get(), &handles);
64 &ipc_message->handles);
65 if (result != MOJO_RESULT_OK) { 64 if (result != MOJO_RESULT_OK) {
66 CloseWithError(result); 65 CloseWithError(result);
67 return false; 66 return false;
68 } 67 }
69 ipc_message->data.resize(message->size()); 68 mojo::Array<uint8_t> data(message->size());
70 std::copy(reinterpret_cast<const uint8_t*>(message->data()), 69 std::copy(reinterpret_cast<const uint8_t*>(message->data()),
71 reinterpret_cast<const uint8_t*>(message->data()) + message->size(), 70 reinterpret_cast<const uint8_t*>(message->data()) + message->size(),
72 &ipc_message->data[0]); 71 &data[0]);
73 sender_->Receive(std::move(ipc_message)); 72 sender_->Receive(std::move(data), std::move(handles));
74 DVLOG(4) << "Send " << message->type() << ": " << message->size(); 73 DVLOG(4) << "Send " << message->type() << ": " << message->size();
75 return true; 74 return true;
76 } 75 }
77 76
78 void MessagePipeReader::Receive(mojom::MessagePtr ipc_message) { 77 void MessagePipeReader::Receive(
79 Message message(ipc_message->data.size() == 0 78 mojo::Array<uint8_t> data,
80 ? "" 79 mojo::Array<mojom::SerializedHandlePtr> handles) {
81 : reinterpret_cast<const char*>(&ipc_message->data[0]), 80 Message message(
82 static_cast<uint32_t>(ipc_message->data.size())); 81 data.size() == 0 ? "" : reinterpret_cast<const char*>(&data[0]),
82 static_cast<uint32_t>(data.size()));
83 message.set_sender_pid(peer_pid_); 83 message.set_sender_pid(peer_pid_);
84 84
85 DVLOG(4) << "Receive " << message.type() << ": " << message.size(); 85 DVLOG(4) << "Receive " << message.type() << ": " << message.size();
86 MojoResult write_result = ChannelMojo::WriteToMessageAttachmentSet( 86 MojoResult write_result =
87 std::move(ipc_message->handles), &message); 87 ChannelMojo::WriteToMessageAttachmentSet(std::move(handles), &message);
88 if (write_result != MOJO_RESULT_OK) { 88 if (write_result != MOJO_RESULT_OK) {
89 CloseWithError(write_result); 89 CloseWithError(write_result);
90 return; 90 return;
91 } 91 }
92 92
93 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), 93 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"),
94 "MessagePipeReader::OnMessageReceived", 94 "MessagePipeReader::OnMessageReceived",
95 message.flags(), 95 message.flags(),
96 TRACE_EVENT_FLAG_FLOW_IN); 96 TRACE_EVENT_FLAG_FLOW_IN);
97 delegate_->OnMessageReceived(message); 97 delegate_->OnMessageReceived(message);
(...skipping 16 matching lines...) Expand all
114 114
115 void MessagePipeReader::DelayedDeleter::operator()( 115 void MessagePipeReader::DelayedDeleter::operator()(
116 MessagePipeReader* ptr) const { 116 MessagePipeReader* ptr) const {
117 ptr->Close(); 117 ptr->Close();
118 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 118 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
119 base::Bind(&DeleteNow, ptr)); 119 base::Bind(&DeleteNow, ptr));
120 } 120 }
121 121
122 } // namespace internal 122 } // namespace internal
123 } // namespace IPC 123 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/mojo/ipc_message_pipe_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698