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

Side by Side Diff: mojo/edk/system/channel.cc

Issue 795593004: Update mojo sdk to rev cc531b32182099a5a034a99daff35ed5d38a61c8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More workarounds for MSVC Created 5 years, 11 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 | « mojo/edk/system/channel.h ('k') | mojo/edk/system/core.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/edk/system/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "mojo/edk/embedder/platform_handle_vector.h" 13 #include "mojo/edk/embedder/platform_handle_vector.h"
14 #include "mojo/edk/system/endpoint_relayer.h"
14 #include "mojo/edk/system/transport_data.h" 15 #include "mojo/edk/system/transport_data.h"
15 16
16 namespace mojo { 17 namespace mojo {
17 namespace system { 18 namespace system {
18 19
19 namespace { 20 namespace {
20 21
21 struct SerializedEndpoint { 22 struct SerializedEndpoint {
22 // This is the endpoint ID on the receiving side, and should be a "remote ID". 23 // This is the endpoint ID on the receiving side, and should be a "remote ID".
23 // (The receiving side should already have had an endpoint attached and been 24 // (The receiving side should already have had an endpoint attached and been
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 "ID %u)", 179 "ID %u)",
179 static_cast<unsigned>(local_id.value()), 180 static_cast<unsigned>(local_id.value()),
180 static_cast<unsigned>(remote_id.value()))); 181 static_cast<unsigned>(remote_id.value())));
181 } 182 }
182 } 183 }
183 184
184 size_t Channel::GetSerializedEndpointSize() const { 185 size_t Channel::GetSerializedEndpointSize() const {
185 return sizeof(SerializedEndpoint); 186 return sizeof(SerializedEndpoint);
186 } 187 }
187 188
188 void Channel::SerializeEndpoint(scoped_refptr<ChannelEndpoint> endpoint, 189 void Channel::SerializeEndpointWithClosedPeer(
189 void* destination) { 190 void* destination,
191 MessageInTransitQueue* message_queue) {
192 // We can actually just pass no client to |SerializeEndpointWithLocalPeer()|.
193 SerializeEndpointWithLocalPeer(destination, message_queue, nullptr, 0);
194 }
195
196 scoped_refptr<ChannelEndpoint> Channel::SerializeEndpointWithLocalPeer(
197 void* destination,
198 MessageInTransitQueue* message_queue,
199 ChannelEndpointClient* endpoint_client,
200 unsigned endpoint_client_port) {
201 DCHECK(destination);
202 // Allow |endpoint_client| to be null, for use by
203 // |SerializeEndpointWithClosedPeer()|.
204
205 scoped_refptr<ChannelEndpoint> endpoint(new ChannelEndpoint(
206 endpoint_client, endpoint_client_port, message_queue));
207
190 SerializedEndpoint* s = static_cast<SerializedEndpoint*>(destination); 208 SerializedEndpoint* s = static_cast<SerializedEndpoint*>(destination);
191 s->receiver_endpoint_id = AttachAndRunEndpoint(endpoint); 209 s->receiver_endpoint_id = AttachAndRunEndpoint(endpoint);
192 DVLOG(2) << "Serializing endpoint (remote ID = " << s->receiver_endpoint_id 210 DVLOG(2) << "Serializing endpoint with local or closed peer (remote ID = "
193 << ")"; 211 << s->receiver_endpoint_id << ")";
212
213 return endpoint;
214 }
215
216 void Channel::SerializeEndpointWithRemotePeer(
217 void* destination,
218 MessageInTransitQueue* message_queue,
219 scoped_refptr<ChannelEndpoint> peer_endpoint) {
220 DCHECK(destination);
221 DCHECK(peer_endpoint);
222
223 DLOG(WARNING) << "Direct message pipe passing across multiple channels not "
224 "yet implemented; will proxy";
225 // Create and set up an |EndpointRelayer| to proxy.
226 // TODO(vtl): If we were to own/track the relayer directly (rather than owning
227 // it via its |ChannelEndpoint|s), then we might be able to make
228 // |ChannelEndpoint|'s |client_| pointer a raw pointer.
229 scoped_refptr<EndpointRelayer> relayer(new EndpointRelayer());
230 scoped_refptr<ChannelEndpoint> endpoint(
231 new ChannelEndpoint(relayer.get(), 0, message_queue));
232 relayer->Init(endpoint.get(), peer_endpoint.get());
233 peer_endpoint->ReplaceClient(relayer.get(), 1);
234
235 SerializedEndpoint* s = static_cast<SerializedEndpoint*>(destination);
236 s->receiver_endpoint_id = AttachAndRunEndpoint(endpoint);
237 DVLOG(2) << "Serializing endpoint with remote peer (remote ID = "
238 << s->receiver_endpoint_id << ")";
194 } 239 }
195 240
196 scoped_refptr<IncomingEndpoint> Channel::DeserializeEndpoint( 241 scoped_refptr<IncomingEndpoint> Channel::DeserializeEndpoint(
197 const void* source) { 242 const void* source) {
198 const SerializedEndpoint* s = static_cast<const SerializedEndpoint*>(source); 243 const SerializedEndpoint* s = static_cast<const SerializedEndpoint*>(source);
199 ChannelEndpointId local_id = s->receiver_endpoint_id; 244 ChannelEndpointId local_id = s->receiver_endpoint_id;
200 // No need to check the validity of |local_id| -- if it's not valid, it simply 245 // No need to check the validity of |local_id| -- if it's not valid, it simply
201 // won't be in |incoming_endpoints_|. 246 // won't be in |incoming_endpoints_|.
202 DVLOG_IF(2, !local_id.is_valid() || !local_id.is_remote()) 247 DVLOG_IF(2, !local_id.is_valid() || !local_id.is_remote())
203 << "Attempt to get incoming endpoint for invalid ID " << local_id; 248 << "Attempt to get incoming endpoint for invalid ID " << local_id;
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 << ", local ID " << local_id << ", remote ID " << remote_id; 601 << ", local ID " << local_id << ", remote ID " << remote_id;
557 scoped_ptr<MessageInTransit> message(new MessageInTransit( 602 scoped_ptr<MessageInTransit> message(new MessageInTransit(
558 MessageInTransit::kTypeChannel, subtype, 0, nullptr)); 603 MessageInTransit::kTypeChannel, subtype, 0, nullptr));
559 message->set_source_id(local_id); 604 message->set_source_id(local_id);
560 message->set_destination_id(remote_id); 605 message->set_destination_id(remote_id);
561 return WriteMessage(message.Pass()); 606 return WriteMessage(message.Pass());
562 } 607 }
563 608
564 } // namespace system 609 } // namespace system
565 } // namespace mojo 610 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel.h ('k') | mojo/edk/system/core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698