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

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

Issue 2512753002: Move const PortName data out of header file (Closed)
Patch Set: Created 4 years, 1 month 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/core.cc ('k') | mojo/edk/system/ports/name.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_controller.h" 5 #include "mojo/edk/system/node_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 443
444 channel->AcceptChild(name_, token); 444 channel->AcceptChild(name_, token);
445 } 445 }
446 446
447 void NodeController::ConnectToParentOnIOThread( 447 void NodeController::ConnectToParentOnIOThread(
448 ScopedPlatformHandle platform_handle) { 448 ScopedPlatformHandle platform_handle) {
449 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 449 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
450 450
451 { 451 {
452 base::AutoLock lock(parent_lock_); 452 base::AutoLock lock(parent_lock_);
453 DCHECK(parent_name_ == ports::kInvalidNodeName); 453 DCHECK(parent_name_ == ports::constants::kInvalidNodeName);
454 454
455 // At this point we don't know the parent's name, so we can't yet insert it 455 // At this point we don't know the parent's name, so we can't yet insert it
456 // into our |peers_| map. That will happen as soon as we receive an 456 // into our |peers_| map. That will happen as soon as we receive an
457 // AcceptChild message from them. 457 // AcceptChild message from them.
458 bootstrap_parent_channel_ = 458 bootstrap_parent_channel_ =
459 NodeChannel::Create(this, std::move(platform_handle), io_task_runner_, 459 NodeChannel::Create(this, std::move(platform_handle), io_task_runner_,
460 ProcessErrorCallback()); 460 ProcessErrorCallback());
461 // Prevent the parent pipe handle from being closed on shutdown. Pipe 461 // Prevent the parent pipe handle from being closed on shutdown. Pipe
462 // closure is used by the parent to detect the child process has exited. 462 // closure is used by the parent to detect the child process has exited.
463 // Relying on message pipes to be closed is not enough because the parent 463 // Relying on message pipes to be closed is not enough because the parent
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 broker_name = broker_name_; 524 broker_name = broker_name_;
525 } 525 }
526 return GetPeerChannel(broker_name); 526 return GetPeerChannel(broker_name);
527 } 527 }
528 528
529 void NodeController::AddPeer(const ports::NodeName& name, 529 void NodeController::AddPeer(const ports::NodeName& name,
530 scoped_refptr<NodeChannel> channel, 530 scoped_refptr<NodeChannel> channel,
531 bool start_channel) { 531 bool start_channel) {
532 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 532 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
533 533
534 DCHECK(name != ports::kInvalidNodeName); 534 DCHECK(name != ports::constants::kInvalidNodeName);
535 DCHECK(channel); 535 DCHECK(channel);
536 536
537 channel->SetRemoteNodeName(name); 537 channel->SetRemoteNodeName(name);
538 538
539 OutgoingMessageQueue pending_messages; 539 OutgoingMessageQueue pending_messages;
540 { 540 {
541 base::AutoLock lock(peers_lock_); 541 base::AutoLock lock(peers_lock_);
542 if (peers_.find(name) != peers_.end()) { 542 if (peers_.find(name) != peers_.end()) {
543 // This can happen normally if two nodes race to be introduced to each 543 // This can happen normally if two nodes race to be introduced to each
544 // other. The losing pipe will be silently closed and introduction should 544 // other. The losing pipe will be silently closed and introduction should
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 } 669 }
670 } 670 }
671 #elif defined(OS_MACOSX) && !defined(OS_IOS) 671 #elif defined(OS_MACOSX) && !defined(OS_IOS)
672 if (channel_message->has_mach_ports()) { 672 if (channel_message->has_mach_ports()) {
673 // Messages containing Mach ports are always routed through the broker, even 673 // Messages containing Mach ports are always routed through the broker, even
674 // if the broker process is the intended recipient. 674 // if the broker process is the intended recipient.
675 bool use_broker = false; 675 bool use_broker = false;
676 { 676 {
677 base::AutoLock lock(parent_lock_); 677 base::AutoLock lock(parent_lock_);
678 use_broker = (bootstrap_parent_channel_ || 678 use_broker = (bootstrap_parent_channel_ ||
679 parent_name_ != ports::kInvalidNodeName); 679 parent_name_ != ports::constants::kInvalidNodeName);
680 } 680 }
681 if (use_broker) { 681 if (use_broker) {
682 scoped_refptr<NodeChannel> broker = GetBrokerChannel(); 682 scoped_refptr<NodeChannel> broker = GetBrokerChannel();
683 if (broker) { 683 if (broker) {
684 broker->RelayPortsMessage(name, std::move(channel_message)); 684 broker->RelayPortsMessage(name, std::move(channel_message));
685 } else { 685 } else {
686 base::AutoLock lock(broker_lock_); 686 base::AutoLock lock(broker_lock_);
687 pending_relay_messages_[name].emplace(std::move(channel_message)); 687 pending_relay_messages_[name].emplace(std::move(channel_message));
688 } 688 }
689 return; 689 return;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 } 874 }
875 875
876 void NodeController::OnAcceptChild(const ports::NodeName& from_node, 876 void NodeController::OnAcceptChild(const ports::NodeName& from_node,
877 const ports::NodeName& parent_name, 877 const ports::NodeName& parent_name,
878 const ports::NodeName& token) { 878 const ports::NodeName& token) {
879 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 879 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
880 880
881 scoped_refptr<NodeChannel> parent; 881 scoped_refptr<NodeChannel> parent;
882 { 882 {
883 base::AutoLock lock(parent_lock_); 883 base::AutoLock lock(parent_lock_);
884 if (bootstrap_parent_channel_ && parent_name_ == ports::kInvalidNodeName) { 884 if (bootstrap_parent_channel_ &&
885 parent_name_ == ports::constants::kInvalidNodeName) {
885 parent_name_ = parent_name; 886 parent_name_ = parent_name;
886 parent = bootstrap_parent_channel_; 887 parent = bootstrap_parent_channel_;
887 } 888 }
888 } 889 }
889 890
890 if (!parent) { 891 if (!parent) {
891 DLOG(ERROR) << "Unexpected AcceptChild message from " << from_node; 892 DLOG(ERROR) << "Unexpected AcceptChild message from " << from_node;
892 DropPeer(from_node, nullptr); 893 DropPeer(from_node, nullptr);
893 return; 894 return;
894 } 895 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 1036
1036 std::queue<ports::NodeName> pending_broker_clients; 1037 std::queue<ports::NodeName> pending_broker_clients;
1037 std::unordered_map<ports::NodeName, OutgoingMessageQueue> 1038 std::unordered_map<ports::NodeName, OutgoingMessageQueue>
1038 pending_relay_messages; 1039 pending_relay_messages;
1039 { 1040 {
1040 base::AutoLock lock(broker_lock_); 1041 base::AutoLock lock(broker_lock_);
1041 broker_name_ = broker_name; 1042 broker_name_ = broker_name;
1042 std::swap(pending_broker_clients, pending_broker_clients_); 1043 std::swap(pending_broker_clients, pending_broker_clients_);
1043 std::swap(pending_relay_messages, pending_relay_messages_); 1044 std::swap(pending_relay_messages, pending_relay_messages_);
1044 } 1045 }
1045 DCHECK(broker_name != ports::kInvalidNodeName); 1046 DCHECK(broker_name != ports::constants::kInvalidNodeName);
1046 1047
1047 // It's now possible to add both the broker and the parent as peers. 1048 // It's now possible to add both the broker and the parent as peers.
1048 // Note that the broker and parent may be the same node. 1049 // Note that the broker and parent may be the same node.
1049 scoped_refptr<NodeChannel> broker; 1050 scoped_refptr<NodeChannel> broker;
1050 if (broker_name == parent_name) { 1051 if (broker_name == parent_name) {
1051 DCHECK(!broker_channel.is_valid()); 1052 DCHECK(!broker_channel.is_valid());
1052 broker = parent; 1053 broker = parent;
1053 } else { 1054 } else {
1054 DCHECK(broker_channel.is_valid()); 1055 DCHECK(broker_channel.is_valid());
1055 broker = NodeChannel::Create(this, std::move(broker_channel), 1056 broker = NodeChannel::Create(this, std::move(broker_channel),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 DLOG(ERROR) << "MergePorts failed: " << rv; 1142 DLOG(ERROR) << "MergePorts failed: " << rv;
1142 1143
1143 AcceptIncomingMessages(); 1144 AcceptIncomingMessages();
1144 } 1145 }
1145 1146
1146 void NodeController::OnRequestIntroduction(const ports::NodeName& from_node, 1147 void NodeController::OnRequestIntroduction(const ports::NodeName& from_node,
1147 const ports::NodeName& name) { 1148 const ports::NodeName& name) {
1148 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 1149 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
1149 1150
1150 scoped_refptr<NodeChannel> requestor = GetPeerChannel(from_node); 1151 scoped_refptr<NodeChannel> requestor = GetPeerChannel(from_node);
1151 if (from_node == name || name == ports::kInvalidNodeName || !requestor) { 1152 if (from_node == name || name == ports::constants::kInvalidNodeName ||
1153 !requestor) {
1152 DLOG(ERROR) << "Rejecting invalid OnRequestIntroduction message from " 1154 DLOG(ERROR) << "Rejecting invalid OnRequestIntroduction message from "
1153 << from_node; 1155 << from_node;
1154 DropPeer(from_node, nullptr); 1156 DropPeer(from_node, nullptr);
1155 return; 1157 return;
1156 } 1158 }
1157 1159
1158 scoped_refptr<NodeChannel> new_friend = GetPeerChannel(name); 1160 scoped_refptr<NodeChannel> new_friend = GetPeerChannel(name);
1159 if (!new_friend) { 1161 if (!new_friend) {
1160 // We don't know who they're talking about! 1162 // We don't know who they're talking about!
1161 requestor->Introduce(name, ScopedPlatformHandle()); 1163 requestor->Introduce(name, ScopedPlatformHandle());
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 base::Bind(&NodeController::OnChannelError, base::Unretained(this), 1352 base::Bind(&NodeController::OnChannelError, base::Unretained(this),
1351 from_node, channel)); 1353 from_node, channel));
1352 } 1354 }
1353 } 1355 }
1354 1356
1355 #if defined(OS_MACOSX) && !defined(OS_IOS) 1357 #if defined(OS_MACOSX) && !defined(OS_IOS)
1356 MachPortRelay* NodeController::GetMachPortRelay() { 1358 MachPortRelay* NodeController::GetMachPortRelay() {
1357 { 1359 {
1358 base::AutoLock lock(parent_lock_); 1360 base::AutoLock lock(parent_lock_);
1359 // Return null if we're not the root. 1361 // Return null if we're not the root.
1360 if (bootstrap_parent_channel_ || parent_name_ != ports::kInvalidNodeName) 1362 if (bootstrap_parent_channel_ ||
1363 parent_name_ != ports::constants::kInvalidNodeName)
1361 return nullptr; 1364 return nullptr;
1362 } 1365 }
1363 1366
1364 base::AutoLock lock(mach_port_relay_lock_); 1367 base::AutoLock lock(mach_port_relay_lock_);
1365 return mach_port_relay_.get(); 1368 return mach_port_relay_.get();
1366 } 1369 }
1367 #endif 1370 #endif
1368 1371
1369 void NodeController::CancelPendingPortMerges() { 1372 void NodeController::CancelPendingPortMerges() {
1370 std::vector<ports::PortRef> ports_to_close; 1373 std::vector<ports::PortRef> ports_to_close;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 NodeController::PeerConnection::~PeerConnection() = default; 1430 NodeController::PeerConnection::~PeerConnection() = default;
1428 1431
1429 NodeController::PeerConnection& NodeController::PeerConnection:: 1432 NodeController::PeerConnection& NodeController::PeerConnection::
1430 operator=(const PeerConnection& other) = default; 1433 operator=(const PeerConnection& other) = default;
1431 1434
1432 NodeController::PeerConnection& NodeController::PeerConnection:: 1435 NodeController::PeerConnection& NodeController::PeerConnection::
1433 operator=(PeerConnection&& other) = default; 1436 operator=(PeerConnection&& other) = default;
1434 1437
1435 } // namespace edk 1438 } // namespace edk
1436 } // namespace mojo 1439 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/core.cc ('k') | mojo/edk/system/ports/name.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698