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

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

Issue 2227553002: Support mojo connections between unrelated peer processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 29 matching lines...) Expand all
40 REQUEST_PORT_MERGE, 40 REQUEST_PORT_MERGE,
41 REQUEST_INTRODUCTION, 41 REQUEST_INTRODUCTION,
42 INTRODUCE, 42 INTRODUCE,
43 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) 43 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
44 RELAY_PORTS_MESSAGE, 44 RELAY_PORTS_MESSAGE,
45 #endif 45 #endif
46 BROADCAST, 46 BROADCAST,
47 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) 47 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
48 PORTS_MESSAGE_FROM_RELAY, 48 PORTS_MESSAGE_FROM_RELAY,
49 #endif 49 #endif
50 ACCEPT_PEER,
50 }; 51 };
51 52
52 struct Header { 53 struct Header {
53 MessageType type; 54 MessageType type;
54 uint32_t padding; 55 uint32_t padding;
55 }; 56 };
56 57
57 static_assert(sizeof(Header) % kChannelMessageAlignment == 0, 58 static_assert(sizeof(Header) % kChannelMessageAlignment == 0,
58 "Invalid header size."); 59 "Invalid header size.");
59 60
60 struct AcceptChildData { 61 struct AcceptChildData {
61 ports::NodeName parent_name; 62 ports::NodeName parent_name;
62 ports::NodeName token; 63 ports::NodeName token;
63 }; 64 };
64 65
65 struct AcceptParentData { 66 struct AcceptParentData {
66 ports::NodeName token; 67 ports::NodeName token;
67 ports::NodeName child_name; 68 ports::NodeName child_name;
68 }; 69 };
69 70
71 struct AcceptPeerData {
72 ports::NodeName token;
73 ports::NodeName peer_name;
74 ports::PortName port_name;
75 };
76
70 // This message may include a process handle on plaforms that require it. 77 // This message may include a process handle on plaforms that require it.
71 struct AddBrokerClientData { 78 struct AddBrokerClientData {
72 ports::NodeName client_name; 79 ports::NodeName client_name;
73 #if !defined(OS_WIN) 80 #if !defined(OS_WIN)
74 uint32_t process_handle; 81 uint32_t process_handle;
75 uint32_t padding; 82 uint32_t padding;
76 #endif 83 #endif
77 }; 84 };
78 85
79 #if !defined(OS_WIN) 86 #if !defined(OS_WIN)
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 void NodeChannel::AcceptParent(const ports::NodeName& token, 282 void NodeChannel::AcceptParent(const ports::NodeName& token,
276 const ports::NodeName& child_name) { 283 const ports::NodeName& child_name) {
277 AcceptParentData* data; 284 AcceptParentData* data;
278 Channel::MessagePtr message = CreateMessage( 285 Channel::MessagePtr message = CreateMessage(
279 MessageType::ACCEPT_PARENT, sizeof(AcceptParentData), 0, &data); 286 MessageType::ACCEPT_PARENT, sizeof(AcceptParentData), 0, &data);
280 data->token = token; 287 data->token = token;
281 data->child_name = child_name; 288 data->child_name = child_name;
282 WriteChannelMessage(std::move(message)); 289 WriteChannelMessage(std::move(message));
283 } 290 }
284 291
292 void NodeChannel::AcceptPeer(const ports::NodeName& sender_name,
293 const ports::NodeName& token,
294 const ports::PortName& port_name) {
295 AcceptPeerData* data;
296 Channel::MessagePtr message =
297 CreateMessage(MessageType::ACCEPT_PEER, sizeof(AcceptPeerData), 0, &data);
298 data->token = token;
299 data->peer_name = sender_name;
300 data->port_name = port_name;
301 WriteChannelMessage(std::move(message));
302 }
303
285 void NodeChannel::AddBrokerClient(const ports::NodeName& client_name, 304 void NodeChannel::AddBrokerClient(const ports::NodeName& client_name,
286 base::ProcessHandle process_handle) { 305 base::ProcessHandle process_handle) {
287 AddBrokerClientData* data; 306 AddBrokerClientData* data;
288 ScopedPlatformHandleVectorPtr handles(new PlatformHandleVector()); 307 ScopedPlatformHandleVectorPtr handles(new PlatformHandleVector());
289 #if defined(OS_WIN) 308 #if defined(OS_WIN)
290 handles->push_back(PlatformHandle(process_handle)); 309 handles->push_back(PlatformHandle(process_handle));
291 #endif 310 #endif
292 Channel::MessagePtr message = CreateMessage( 311 Channel::MessagePtr message = CreateMessage(
293 MessageType::ADD_BROKER_CLIENT, sizeof(AddBrokerClientData), 312 MessageType::ADD_BROKER_CLIENT, sizeof(AddBrokerClientData),
294 handles->size(), &data); 313 handles->size(), &data);
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 if (num_bytes) 740 if (num_bytes)
722 memcpy(message->mutable_payload(), data + 1, num_bytes); 741 memcpy(message->mutable_payload(), data + 1, num_bytes);
723 delegate_->OnPortsMessageFromRelay( 742 delegate_->OnPortsMessageFromRelay(
724 remote_node_name_, data->source, std::move(message)); 743 remote_node_name_, data->source, std::move(message));
725 return; 744 return;
726 } 745 }
727 break; 746 break;
728 747
729 #endif // defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) 748 #endif // defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
730 749
750 case MessageType::ACCEPT_PEER: {
751 const AcceptPeerData* data;
752 if (GetMessagePayload(payload, payload_size, &data)) {
753 delegate_->OnAcceptPeer(remote_node_name_, data->token, data->peer_name,
754 data->port_name);
755 return;
756 }
757 break;
758 }
759
731 default: 760 default:
732 break; 761 break;
733 } 762 }
734 763
735 DLOG(ERROR) << "Received invalid message. Closing channel."; 764 DLOG(ERROR) << "Received invalid message. Closing channel.";
736 delegate_->OnChannelError(remote_node_name_, this); 765 delegate_->OnChannelError(remote_node_name_, this);
737 } 766 }
738 767
739 void NodeChannel::OnChannelError() { 768 void NodeChannel::OnChannelError() {
740 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 769 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 895
867 base::AutoLock lock(channel_lock_); 896 base::AutoLock lock(channel_lock_);
868 if (!channel_) 897 if (!channel_)
869 DLOG(ERROR) << "Dropping message on closed channel."; 898 DLOG(ERROR) << "Dropping message on closed channel.";
870 else 899 else
871 channel_->Write(std::move(message)); 900 channel_->Write(std::move(message));
872 } 901 }
873 902
874 } // namespace edk 903 } // namespace edk
875 } // namespace mojo 904 } // 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