| OLD | NEW |
| 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 reserved_ports_.erase(token); | 538 reserved_ports_.erase(token); |
| 539 | 539 |
| 540 pending_child_tokens_.erase(it); | 540 pending_child_tokens_.erase(it); |
| 541 } | 541 } |
| 542 } | 542 } |
| 543 | 543 |
| 544 for (const auto& port : ports_to_close) | 544 for (const auto& port : ports_to_close) |
| 545 node_->ClosePort(port); | 545 node_->ClosePort(port); |
| 546 | 546 |
| 547 node_->LostConnectionToNode(name); | 547 node_->LostConnectionToNode(name); |
| 548 |
| 549 AcceptIncomingMessages(); |
| 548 } | 550 } |
| 549 | 551 |
| 550 void NodeController::SendPeerMessage(const ports::NodeName& name, | 552 void NodeController::SendPeerMessage(const ports::NodeName& name, |
| 551 ports::ScopedMessage message) { | 553 ports::ScopedMessage message) { |
| 552 Channel::MessagePtr channel_message = | 554 Channel::MessagePtr channel_message = |
| 553 static_cast<PortsMessage*>(message.get())->TakeChannelMessage(); | 555 static_cast<PortsMessage*>(message.get())->TakeChannelMessage(); |
| 554 | 556 |
| 555 scoped_refptr<NodeChannel> peer = GetPeerChannel(name); | 557 scoped_refptr<NodeChannel> peer = GetPeerChannel(name); |
| 556 #if defined(OS_WIN) | 558 #if defined(OS_WIN) |
| 557 if (channel_message->has_handles()) { | 559 if (channel_message->has_handles()) { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 } | 735 } |
| 734 | 736 |
| 735 void NodeController::OnAcceptChild(const ports::NodeName& from_node, | 737 void NodeController::OnAcceptChild(const ports::NodeName& from_node, |
| 736 const ports::NodeName& parent_name, | 738 const ports::NodeName& parent_name, |
| 737 const ports::NodeName& token) { | 739 const ports::NodeName& token) { |
| 738 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 740 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 739 | 741 |
| 740 scoped_refptr<NodeChannel> parent; | 742 scoped_refptr<NodeChannel> parent; |
| 741 { | 743 { |
| 742 base::AutoLock lock(parent_lock_); | 744 base::AutoLock lock(parent_lock_); |
| 743 if (!bootstrap_parent_channel_ || parent_name_ != ports::kInvalidNodeName) { | 745 if (bootstrap_parent_channel_ && parent_name_ == ports::kInvalidNodeName) { |
| 744 DLOG(ERROR) << "Unexpected AcceptChild message from " << from_node; | 746 parent_name_ = parent_name; |
| 745 DropPeer(from_node); | 747 parent = bootstrap_parent_channel_; |
| 746 return; | |
| 747 } | 748 } |
| 749 } |
| 748 | 750 |
| 749 parent_name_ = parent_name; | 751 if (!parent) { |
| 750 parent = bootstrap_parent_channel_; | 752 DLOG(ERROR) << "Unexpected AcceptChild message from " << from_node; |
| 753 DropPeer(from_node); |
| 754 return; |
| 751 } | 755 } |
| 752 | 756 |
| 753 parent->SetRemoteNodeName(parent_name); | 757 parent->SetRemoteNodeName(parent_name); |
| 754 parent->AcceptParent(token, name_); | 758 parent->AcceptParent(token, name_); |
| 755 | 759 |
| 756 // NOTE: The child does not actually add its parent as a peer until | 760 // NOTE: The child does not actually add its parent as a peer until |
| 757 // receiving an AcceptBrokerClient message from the broker. The parent | 761 // receiving an AcceptBrokerClient message from the broker. The parent |
| 758 // will request that said message be sent upon receiving AcceptParent. | 762 // will request that said message be sent upon receiving AcceptParent. |
| 759 | 763 |
| 760 DVLOG(1) << "Child " << name_ << " accepting parent " << parent_name; | 764 DVLOG(1) << "Child " << name_ << " accepting parent " << parent_name; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 DVLOG(1) << "Ignoring request to connect to port for unknown token " | 993 DVLOG(1) << "Ignoring request to connect to port for unknown token " |
| 990 << token; | 994 << token; |
| 991 return; | 995 return; |
| 992 } | 996 } |
| 993 local_port = it->second.port; | 997 local_port = it->second.port; |
| 994 } | 998 } |
| 995 | 999 |
| 996 int rv = node_->MergePorts(local_port, from_node, connector_port_name); | 1000 int rv = node_->MergePorts(local_port, from_node, connector_port_name); |
| 997 if (rv != ports::OK) | 1001 if (rv != ports::OK) |
| 998 DLOG(ERROR) << "MergePorts failed: " << rv; | 1002 DLOG(ERROR) << "MergePorts failed: " << rv; |
| 1003 |
| 1004 AcceptIncomingMessages(); |
| 999 } | 1005 } |
| 1000 | 1006 |
| 1001 void NodeController::OnRequestIntroduction(const ports::NodeName& from_node, | 1007 void NodeController::OnRequestIntroduction(const ports::NodeName& from_node, |
| 1002 const ports::NodeName& name) { | 1008 const ports::NodeName& name) { |
| 1003 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 1009 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 1004 | 1010 |
| 1005 scoped_refptr<NodeChannel> requestor = GetPeerChannel(from_node); | 1011 scoped_refptr<NodeChannel> requestor = GetPeerChannel(from_node); |
| 1006 if (from_node == name || name == ports::kInvalidNodeName || !requestor) { | 1012 if (from_node == name || name == ports::kInvalidNodeName || !requestor) { |
| 1007 DLOG(ERROR) << "Rejecting invalid OnRequestIntroduction message from " | 1013 DLOG(ERROR) << "Rejecting invalid OnRequestIntroduction message from " |
| 1008 << from_node; | 1014 << from_node; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 shutdown_callback_flag_.Set(false); | 1209 shutdown_callback_flag_.Set(false); |
| 1204 } | 1210 } |
| 1205 | 1211 |
| 1206 DCHECK(!callback.is_null()); | 1212 DCHECK(!callback.is_null()); |
| 1207 | 1213 |
| 1208 callback.Run(); | 1214 callback.Run(); |
| 1209 } | 1215 } |
| 1210 | 1216 |
| 1211 } // namespace edk | 1217 } // namespace edk |
| 1212 } // namespace mojo | 1218 } // namespace mojo |
| OLD | NEW |