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

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

Issue 1675603002: [mojo-edk] Simplify multiprocess pipe bootstrap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix some callers to work with sync APIs Created 4 years, 10 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/node_channel.h ('k') | mojo/edk/system/node_controller.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/node_channel.h" 5 #include "mojo/edk/system/node_channel.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 #include <limits> 8 #include <limits>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 11 matching lines...) Expand all
22 return t + (k - (t % k)) % k; 22 return t + (k - (t % k)) % k;
23 } 23 }
24 24
25 enum class MessageType : uint32_t { 25 enum class MessageType : uint32_t {
26 ACCEPT_CHILD, 26 ACCEPT_CHILD,
27 ACCEPT_PARENT, 27 ACCEPT_PARENT,
28 ADD_BROKER_CLIENT, 28 ADD_BROKER_CLIENT,
29 BROKER_CLIENT_ADDED, 29 BROKER_CLIENT_ADDED,
30 ACCEPT_BROKER_CLIENT, 30 ACCEPT_BROKER_CLIENT,
31 PORTS_MESSAGE, 31 PORTS_MESSAGE,
32 REQUEST_PORT_CONNECTION, 32 REQUEST_PORT_MERGE,
33 CONNECT_TO_PORT,
34 REQUEST_INTRODUCTION, 33 REQUEST_INTRODUCTION,
35 INTRODUCE, 34 INTRODUCE,
36 #if defined(OS_WIN) 35 #if defined(OS_WIN)
37 RELAY_PORTS_MESSAGE, 36 RELAY_PORTS_MESSAGE,
38 #endif 37 #endif
39 }; 38 };
40 39
41 struct Header { 40 struct Header {
42 MessageType type; 41 MessageType type;
43 uint32_t padding; 42 uint32_t padding;
(...skipping 23 matching lines...) Expand all
67 }; 66 };
68 67
69 // This data may be followed by a platform channel handle to the broker. If not, 68 // This data may be followed by a platform channel handle to the broker. If not,
70 // then the parent is the broker and its channel should be used as such. 69 // then the parent is the broker and its channel should be used as such.
71 struct AcceptBrokerClientData { 70 struct AcceptBrokerClientData {
72 ports::NodeName broker_name; 71 ports::NodeName broker_name;
73 }; 72 };
74 73
75 // This is followed by arbitrary payload data which is interpreted as a token 74 // This is followed by arbitrary payload data which is interpreted as a token
76 // string for port location. 75 // string for port location.
77 struct RequestPortConnectionData { 76 struct RequestPortMergeData {
78 ports::PortName connector_port_name; 77 ports::PortName connector_port_name;
79 }; 78 };
80 79
81 struct ConnectToPortData {
82 ports::PortName connector_port_name;
83 ports::PortName connectee_port_name;
84 };
85
86 // Used for both REQUEST_INTRODUCTION and INTRODUCE. 80 // Used for both REQUEST_INTRODUCTION and INTRODUCE.
87 // 81 //
88 // For INTRODUCE the message also includes a valid platform handle for a channel 82 // For INTRODUCE the message also includes a valid platform handle for a channel
89 // the receiver may use to communicate with the named node directly, or an 83 // the receiver may use to communicate with the named node directly, or an
90 // invalid platform handle if the node is unknown to the sender or otherwise 84 // invalid platform handle if the node is unknown to the sender or otherwise
91 // cannot be introduced. 85 // cannot be introduced.
92 struct IntroductionData { 86 struct IntroductionData {
93 ports::NodeName name; 87 ports::NodeName name;
94 }; 88 };
95 89
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 handles->size(), &data); 254 handles->size(), &data);
261 message->SetHandles(std::move(handles)); 255 message->SetHandles(std::move(handles));
262 data->broker_name = broker_name; 256 data->broker_name = broker_name;
263 WriteChannelMessage(std::move(message)); 257 WriteChannelMessage(std::move(message));
264 } 258 }
265 259
266 void NodeChannel::PortsMessage(Channel::MessagePtr message) { 260 void NodeChannel::PortsMessage(Channel::MessagePtr message) {
267 WriteChannelMessage(std::move(message)); 261 WriteChannelMessage(std::move(message));
268 } 262 }
269 263
270 void NodeChannel::RequestPortConnection( 264 void NodeChannel::RequestPortMerge(const ports::PortName& connector_port_name,
271 const ports::PortName& connector_port_name, 265 const std::string& token) {
272 const std::string& token) { 266 RequestPortMergeData* data;
273 RequestPortConnectionData* data;
274 Channel::MessagePtr message = CreateMessage( 267 Channel::MessagePtr message = CreateMessage(
275 MessageType::REQUEST_PORT_CONNECTION, 268 MessageType::REQUEST_PORT_MERGE,
276 sizeof(RequestPortConnectionData) + token.size(), 0, &data); 269 sizeof(RequestPortMergeData) + token.size(), 0, &data);
277 data->connector_port_name = connector_port_name; 270 data->connector_port_name = connector_port_name;
278 memcpy(data + 1, token.data(), token.size()); 271 memcpy(data + 1, token.data(), token.size());
279 WriteChannelMessage(std::move(message)); 272 WriteChannelMessage(std::move(message));
280 } 273 }
281 274
282 void NodeChannel::ConnectToPort(const ports::PortName& connector_port_name,
283 const ports::PortName& connectee_port_name) {
284 ConnectToPortData* data;
285 Channel::MessagePtr message = CreateMessage(
286 MessageType::CONNECT_TO_PORT, sizeof(ConnectToPortData), 0, &data);
287 data->connector_port_name = connector_port_name;
288 data->connectee_port_name = connectee_port_name;
289 WriteChannelMessage(std::move(message));
290 }
291
292 void NodeChannel::RequestIntroduction(const ports::NodeName& name) { 275 void NodeChannel::RequestIntroduction(const ports::NodeName& name) {
293 IntroductionData* data; 276 IntroductionData* data;
294 Channel::MessagePtr message = CreateMessage( 277 Channel::MessagePtr message = CreateMessage(
295 MessageType::REQUEST_INTRODUCTION, sizeof(IntroductionData), 0, &data); 278 MessageType::REQUEST_INTRODUCTION, sizeof(IntroductionData), 0, &data);
296 data->name = name; 279 data->name = name;
297 WriteChannelMessage(std::move(message)); 280 WriteChannelMessage(std::move(message));
298 } 281 }
299 282
300 void NodeChannel::Introduce(const ports::NodeName& name, 283 void NodeChannel::Introduce(const ports::NodeName& name,
301 ScopedPlatformHandle channel_handle) { 284 ScopedPlatformHandle channel_handle) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 case MessageType::PORTS_MESSAGE: { 428 case MessageType::PORTS_MESSAGE: {
446 size_t num_handles = handles ? handles->size() : 0; 429 size_t num_handles = handles ? handles->size() : 0;
447 Channel::MessagePtr message( 430 Channel::MessagePtr message(
448 new Channel::Message(payload_size, num_handles)); 431 new Channel::Message(payload_size, num_handles));
449 message->SetHandles(std::move(handles)); 432 message->SetHandles(std::move(handles));
450 memcpy(message->mutable_payload(), payload, payload_size); 433 memcpy(message->mutable_payload(), payload, payload_size);
451 delegate_->OnPortsMessage(std::move(message)); 434 delegate_->OnPortsMessage(std::move(message));
452 break; 435 break;
453 } 436 }
454 437
455 case MessageType::REQUEST_PORT_CONNECTION: { 438 case MessageType::REQUEST_PORT_MERGE: {
456 const RequestPortConnectionData* data; 439 const RequestPortMergeData* data;
457 GetMessagePayload(payload, &data); 440 GetMessagePayload(payload, &data);
458 441
459 const char* token_data = reinterpret_cast<const char*>(data + 1); 442 const char* token_data = reinterpret_cast<const char*>(data + 1);
460 const size_t token_size = payload_size - sizeof(*data) - sizeof(Header); 443 const size_t token_size = payload_size - sizeof(*data) - sizeof(Header);
461 std::string token(token_data, token_size); 444 std::string token(token_data, token_size);
462 445
463 delegate_->OnRequestPortConnection(remote_node_name_, 446 delegate_->OnRequestPortMerge(remote_node_name_,
464 data->connector_port_name, token); 447 data->connector_port_name, token);
465 break; 448 break;
466 } 449 }
467 450
468 case MessageType::CONNECT_TO_PORT: {
469 const ConnectToPortData* data;
470 GetMessagePayload(payload, &data);
471 delegate_->OnConnectToPort(remote_node_name_, data->connector_port_name,
472 data->connectee_port_name);
473 break;
474 }
475
476 case MessageType::REQUEST_INTRODUCTION: { 451 case MessageType::REQUEST_INTRODUCTION: {
477 const IntroductionData* data; 452 const IntroductionData* data;
478 GetMessagePayload(payload, &data); 453 GetMessagePayload(payload, &data);
479 delegate_->OnRequestIntroduction(remote_node_name_, data->name); 454 delegate_->OnRequestIntroduction(remote_node_name_, data->name);
480 break; 455 break;
481 } 456 }
482 457
483 case MessageType::INTRODUCE: { 458 case MessageType::INTRODUCE: {
484 const IntroductionData* data; 459 const IntroductionData* data;
485 GetMessagePayload(payload, &data); 460 GetMessagePayload(payload, &data);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 542
568 base::AutoLock lock(channel_lock_); 543 base::AutoLock lock(channel_lock_);
569 if (!channel_) 544 if (!channel_)
570 DLOG(ERROR) << "Dropping message on closed channel."; 545 DLOG(ERROR) << "Dropping message on closed channel.";
571 else 546 else
572 channel_->Write(std::move(message)); 547 channel_->Write(std::move(message));
573 } 548 }
574 549
575 } // namespace edk 550 } // namespace edk
576 } // namespace mojo 551 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/node_channel.h ('k') | mojo/edk/system/node_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698