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

Side by Side Diff: ipc/ipc_message_pipe_reader.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, 3 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/ipc_message_pipe_reader.h ('k') | mojo/public/cpp/bindings/array_traits_stl.h » ('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/ipc_message_pipe_reader.h" 5 #include "ipc/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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 sender_.reset(); 79 sender_.reset();
80 if (binding_.is_bound()) 80 if (binding_.is_bound())
81 binding_.Close(); 81 binding_.Close();
82 } 82 }
83 83
84 bool MessagePipeReader::Send(std::unique_ptr<Message> message) { 84 bool MessagePipeReader::Send(std::unique_ptr<Message> message) {
85 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), 85 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"),
86 "MessagePipeReader::Send", 86 "MessagePipeReader::Send",
87 message->flags(), 87 message->flags(),
88 TRACE_EVENT_FLAG_FLOW_OUT); 88 TRACE_EVENT_FLAG_FLOW_OUT);
89 mojo::Array<mojom::SerializedHandlePtr> handles(nullptr); 89 base::Optional<std::vector<mojom::SerializedHandlePtr>> handles;
90 MojoResult result = MOJO_RESULT_OK; 90 MojoResult result = MOJO_RESULT_OK;
91 result = ChannelMojo::ReadFromMessageAttachmentSet(message.get(), &handles); 91 result = ChannelMojo::ReadFromMessageAttachmentSet(message.get(), &handles);
92 if (result != MOJO_RESULT_OK) 92 if (result != MOJO_RESULT_OK)
93 return false; 93 return false;
94 94
95 mojo::Array<uint8_t> data(message->size()); 95 std::vector<uint8_t> data(message->size());
96 std::copy(reinterpret_cast<const uint8_t*>(message->data()), 96 std::copy(reinterpret_cast<const uint8_t*>(message->data()),
97 reinterpret_cast<const uint8_t*>(message->data()) + message->size(), 97 reinterpret_cast<const uint8_t*>(message->data()) + message->size(),
98 &data[0]); 98 data.data());
99 99
100 MessageSerializer serializer; 100 MessageSerializer serializer;
101 mojom::ChannelProxy proxy(&serializer); 101 mojom::ChannelProxy proxy(&serializer);
102 proxy.Receive(std::move(data), std::move(handles)); 102 proxy.Receive(data, std::move(handles));
103 mojo::Message* mojo_message = serializer.message(); 103 mojo::Message* mojo_message = serializer.message();
104 104
105 size_t num_handles = mojo_message->handles()->size(); 105 size_t num_handles = mojo_message->handles()->size();
106 DCHECK_LE(num_handles, std::numeric_limits<uint32_t>::max()); 106 DCHECK_LE(num_handles, std::numeric_limits<uint32_t>::max());
107 107
108 mojo_message->set_interface_id(sender_interface_id_); 108 mojo_message->set_interface_id(sender_interface_id_);
109 result = mojo::WriteMessageNew(sender_pipe_, mojo_message->TakeMojoMessage(), 109 result = mojo::WriteMessageNew(sender_pipe_, mojo_message->TakeMojoMessage(),
110 MOJO_WRITE_MESSAGE_FLAG_NONE); 110 MOJO_WRITE_MESSAGE_FLAG_NONE);
111 111
112 DVLOG(4) << "Send " << message->type() << ": " << message->size(); 112 DVLOG(4) << "Send " << message->type() << ": " << message->size();
113 return result == MOJO_RESULT_OK; 113 return result == MOJO_RESULT_OK;
114 } 114 }
115 115
116 void MessagePipeReader::GetRemoteInterface( 116 void MessagePipeReader::GetRemoteInterface(
117 const std::string& name, 117 const std::string& name,
118 mojo::ScopedInterfaceEndpointHandle handle) { 118 mojo::ScopedInterfaceEndpointHandle handle) {
119 if (!sender_.is_bound()) 119 if (!sender_.is_bound())
120 return; 120 return;
121 mojom::GenericInterfaceAssociatedRequest request; 121 mojom::GenericInterfaceAssociatedRequest request;
122 request.Bind(std::move(handle)); 122 request.Bind(std::move(handle));
123 sender_->GetAssociatedInterface(name, std::move(request)); 123 sender_->GetAssociatedInterface(name, std::move(request));
124 } 124 }
125 125
126 void MessagePipeReader::SetPeerPid(int32_t peer_pid) { 126 void MessagePipeReader::SetPeerPid(int32_t peer_pid) {
127 peer_pid_ = peer_pid; 127 peer_pid_ = peer_pid;
128 delegate_->OnPeerPidReceived(); 128 delegate_->OnPeerPidReceived();
129 } 129 }
130 130
131 void MessagePipeReader::Receive( 131 void MessagePipeReader::Receive(
132 mojo::Array<uint8_t> data, 132 const std::vector<uint8_t>& data,
133 mojo::Array<mojom::SerializedHandlePtr> handles) { 133 base::Optional<std::vector<mojom::SerializedHandlePtr>> handles) {
134 DCHECK_NE(peer_pid_, base::kNullProcessId); 134 DCHECK_NE(peer_pid_, base::kNullProcessId);
135 Message message( 135 Message message(
136 data.size() == 0 ? "" : reinterpret_cast<const char*>(&data[0]), 136 data.empty() ? "" : reinterpret_cast<const char*>(data.data()),
137 static_cast<uint32_t>(data.size())); 137 static_cast<uint32_t>(data.size()));
138 message.set_sender_pid(peer_pid_); 138 message.set_sender_pid(peer_pid_);
139 139
140 DVLOG(4) << "Receive " << message.type() << ": " << message.size(); 140 DVLOG(4) << "Receive " << message.type() << ": " << message.size();
141 MojoResult write_result = 141 MojoResult write_result =
142 ChannelMojo::WriteToMessageAttachmentSet(std::move(handles), &message); 142 ChannelMojo::WriteToMessageAttachmentSet(std::move(handles), &message);
143 if (write_result != MOJO_RESULT_OK) { 143 if (write_result != MOJO_RESULT_OK) {
144 OnPipeError(write_result); 144 OnPipeError(write_result);
145 return; 145 return;
146 } 146 }
147 147
148 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), 148 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"),
149 "MessagePipeReader::Receive", 149 "MessagePipeReader::Receive",
150 message.flags(), 150 message.flags(),
151 TRACE_EVENT_FLAG_FLOW_IN); 151 TRACE_EVENT_FLAG_FLOW_IN);
152 delegate_->OnMessageReceived(message); 152 delegate_->OnMessageReceived(message);
153 } 153 }
154 154
155 void MessagePipeReader::GetAssociatedInterface( 155 void MessagePipeReader::GetAssociatedInterface(
156 const mojo::String& name, 156 const std::string& name,
157 mojom::GenericInterfaceAssociatedRequest request) { 157 mojom::GenericInterfaceAssociatedRequest request) {
158 DCHECK(thread_checker_.CalledOnValidThread()); 158 DCHECK(thread_checker_.CalledOnValidThread());
159 if (delegate_) 159 if (delegate_)
160 delegate_->OnAssociatedInterfaceRequest(name, request.PassHandle()); 160 delegate_->OnAssociatedInterfaceRequest(name, request.PassHandle());
161 } 161 }
162 162
163 void MessagePipeReader::OnPipeError(MojoResult error) { 163 void MessagePipeReader::OnPipeError(MojoResult error) {
164 DCHECK(thread_checker_.CalledOnValidThread()); 164 DCHECK(thread_checker_.CalledOnValidThread());
165 165
166 Close(); 166 Close();
167 167
168 // NOTE: The delegate call below may delete |this|. 168 // NOTE: The delegate call below may delete |this|.
169 if (delegate_) 169 if (delegate_)
170 delegate_->OnPipeError(); 170 delegate_->OnPipeError();
171 } 171 }
172 172
173 } // namespace internal 173 } // namespace internal
174 } // namespace IPC 174 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message_pipe_reader.h ('k') | mojo/public/cpp/bindings/array_traits_stl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698