| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 FROM_HERE, | 202 FROM_HERE, |
| 203 base::Bind(&NodeController::ConnectToChildOnIOThread, | 203 base::Bind(&NodeController::ConnectToChildOnIOThread, |
| 204 base::Unretained(this), | 204 base::Unretained(this), |
| 205 process_handle, | 205 process_handle, |
| 206 base::Passed(&platform_handle), | 206 base::Passed(&platform_handle), |
| 207 node_name, | 207 node_name, |
| 208 process_error_callback)); | 208 process_error_callback)); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void NodeController::CloseChildPorts(const std::string& child_token) { | 211 void NodeController::CloseChildPorts(const std::string& child_token) { |
| 212 if (g_extra_debugging) |
| 213 LOG(ERROR) << "boliu NodeController::CloseChildPorts token:" << child_token; |
| 212 std::vector<ports::PortRef> ports_to_close; | 214 std::vector<ports::PortRef> ports_to_close; |
| 213 { | 215 { |
| 214 std::vector<std::string> port_tokens; | 216 std::vector<std::string> port_tokens; |
| 215 base::AutoLock lock(reserved_ports_lock_); | 217 base::AutoLock lock(reserved_ports_lock_); |
| 216 for (const auto& port : reserved_ports_) { | 218 for (const auto& port : reserved_ports_) { |
| 217 if (port.second.child_token == child_token) { | 219 if (port.second.child_token == child_token) { |
| 218 DVLOG(1) << "Closing reserved port " << port.second.port.name(); | 220 DVLOG(1) << "Closing reserved port " << port.second.port.name(); |
| 219 ports_to_close.push_back(port.second.port); | 221 ports_to_close.push_back(port.second.port); |
| 220 port_tokens.push_back(port.first); | 222 port_tokens.push_back(port.first); |
| 221 } | 223 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 ports::ScopedMessage ports_message(message.release()); | 291 ports::ScopedMessage ports_message(message.release()); |
| 290 int rv = node_->SendMessage(port, std::move(ports_message)); | 292 int rv = node_->SendMessage(port, std::move(ports_message)); |
| 291 | 293 |
| 292 AcceptIncomingMessages(); | 294 AcceptIncomingMessages(); |
| 293 return rv; | 295 return rv; |
| 294 } | 296 } |
| 295 | 297 |
| 296 void NodeController::ReservePort(const std::string& token, | 298 void NodeController::ReservePort(const std::string& token, |
| 297 const ports::PortRef& port, | 299 const ports::PortRef& port, |
| 298 const std::string& child_token) { | 300 const std::string& child_token) { |
| 299 DVLOG(2) << "Reserving port " << port.name() << "@" << name_ << " for token " | 301 if (g_extra_debugging) |
| 302 LOG(ERROR) << "boliu NodeController::ReservePort Reserving port " << port.name
() << "@" << name_ << " for token " |
| 300 << token; | 303 << token; |
| 301 | 304 |
| 302 base::AutoLock lock(reserved_ports_lock_); | 305 base::AutoLock lock(reserved_ports_lock_); |
| 303 auto result = reserved_ports_.insert( | 306 auto result = reserved_ports_.insert( |
| 304 std::make_pair(token, ReservedPort{port, child_token})); | 307 std::make_pair(token, ReservedPort{port, child_token})); |
| 305 DCHECK(result.second); | 308 DCHECK(result.second); |
| 306 } | 309 } |
| 307 | 310 |
| 308 void NodeController::MergePortIntoParent(const std::string& token, | 311 void NodeController::MergePortIntoParent(const std::string& token, |
| 309 const ports::PortRef& port) { | 312 const ports::PortRef& port) { |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 node_->AcceptMessage(ports::ScopedMessage(ports_message.release())); | 1089 node_->AcceptMessage(ports::ScopedMessage(ports_message.release())); |
| 1087 AcceptIncomingMessages(); | 1090 AcceptIncomingMessages(); |
| 1088 } | 1091 } |
| 1089 | 1092 |
| 1090 void NodeController::OnRequestPortMerge( | 1093 void NodeController::OnRequestPortMerge( |
| 1091 const ports::NodeName& from_node, | 1094 const ports::NodeName& from_node, |
| 1092 const ports::PortName& connector_port_name, | 1095 const ports::PortName& connector_port_name, |
| 1093 const std::string& token) { | 1096 const std::string& token) { |
| 1094 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 1097 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 1095 | 1098 |
| 1096 DVLOG(2) << "Node " << name_ << " received RequestPortMerge for token " | 1099 if (g_extra_debugging) |
| 1097 << token << " and port " << connector_port_name << "@" << from_node; | 1100 LOG(ERROR) << "boliu NodeController::OnRequestPortMerge Node " << name_ << " r
eceived RequestPortMerge for token " |
| 1101 << token << " and port " << connector_port_name << "@" << from_node; |
| 1098 | 1102 |
| 1099 ports::PortRef local_port; | 1103 ports::PortRef local_port; |
| 1100 { | 1104 { |
| 1101 base::AutoLock lock(reserved_ports_lock_); | 1105 base::AutoLock lock(reserved_ports_lock_); |
| 1102 auto it = reserved_ports_.find(token); | 1106 auto it = reserved_ports_.find(token); |
| 1103 if (it == reserved_ports_.end()) { | 1107 if (it == reserved_ports_.end()) { |
| 1104 DVLOG(1) << "Ignoring request to connect to port for unknown token " | 1108 |
| 1105 << token; | 1109 if (g_extra_debugging) |
| 1110 LOG(ERROR) << "boliu Ignoring request to connect to port for unknown token " |
| 1111 << token; |
| 1106 return; | 1112 return; |
| 1107 } | 1113 } |
| 1108 local_port = it->second.port; | 1114 local_port = it->second.port; |
| 1109 } | 1115 } |
| 1110 | 1116 |
| 1111 int rv = node_->MergePorts(local_port, from_node, connector_port_name); | 1117 int rv = node_->MergePorts(local_port, from_node, connector_port_name); |
| 1112 if (rv != ports::OK) | 1118 if (rv != ports::OK && g_extra_debugging) |
| 1113 DLOG(ERROR) << "MergePorts failed: " << rv; | 1119 LOG(ERROR) << "boliu MergePorts failed: " << rv; |
| 1114 | 1120 |
| 1115 AcceptIncomingMessages(); | 1121 AcceptIncomingMessages(); |
| 1116 } | 1122 } |
| 1117 | 1123 |
| 1118 void NodeController::OnRequestIntroduction(const ports::NodeName& from_node, | 1124 void NodeController::OnRequestIntroduction(const ports::NodeName& from_node, |
| 1119 const ports::NodeName& name) { | 1125 const ports::NodeName& name) { |
| 1120 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 1126 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 1121 | 1127 |
| 1122 scoped_refptr<NodeChannel> requestor = GetPeerChannel(from_node); | 1128 scoped_refptr<NodeChannel> requestor = GetPeerChannel(from_node); |
| 1123 if (from_node == name || name == ports::kInvalidNodeName || !requestor) { | 1129 if (from_node == name || name == ports::kInvalidNodeName || !requestor) { |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 shutdown_callback_flag_.Set(false); | 1376 shutdown_callback_flag_.Set(false); |
| 1371 } | 1377 } |
| 1372 | 1378 |
| 1373 DCHECK(!callback.is_null()); | 1379 DCHECK(!callback.is_null()); |
| 1374 | 1380 |
| 1375 callback.Run(); | 1381 callback.Run(); |
| 1376 } | 1382 } |
| 1377 | 1383 |
| 1378 } // namespace edk | 1384 } // namespace edk |
| 1379 } // namespace mojo | 1385 } // namespace mojo |
| OLD | NEW |