| 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/ports/node.h" | 5 #include "mojo/edk/system/ports/node.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 265 |
| 266 int Node::GetMessage(const PortRef& port_ref, ScopedMessage* message) { | 266 int Node::GetMessage(const PortRef& port_ref, ScopedMessage* message) { |
| 267 return GetMessageIf(port_ref, nullptr, message); | 267 return GetMessageIf(port_ref, nullptr, message); |
| 268 } | 268 } |
| 269 | 269 |
| 270 int Node::GetMessageIf(const PortRef& port_ref, | 270 int Node::GetMessageIf(const PortRef& port_ref, |
| 271 std::function<bool(const Message&)> selector, | 271 std::function<bool(const Message&)> selector, |
| 272 ScopedMessage* message) { | 272 ScopedMessage* message) { |
| 273 *message = nullptr; | 273 *message = nullptr; |
| 274 | 274 |
| 275 DVLOG(2) << "GetMessageIf for " << port_ref.name() << "@" << name_; | 275 DVLOG(4) << "GetMessageIf for " << port_ref.name() << "@" << name_; |
| 276 | 276 |
| 277 Port* port = port_ref.port(); | 277 Port* port = port_ref.port(); |
| 278 { | 278 { |
| 279 base::AutoLock lock(port->lock); | 279 base::AutoLock lock(port->lock); |
| 280 | 280 |
| 281 // This could also be treated like the port being unknown since the | 281 // This could also be treated like the port being unknown since the |
| 282 // embedder should no longer be referring to a port that has been sent. | 282 // embedder should no longer be referring to a port that has been sent. |
| 283 if (port->state != Port::kReceiving) | 283 if (port->state != Port::kReceiving) |
| 284 return ERROR_PORT_STATE_UNEXPECTED; | 284 return ERROR_PORT_STATE_UNEXPECTED; |
| 285 | 285 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 const auto* event = GetEventData<UserEventData>(*message); | 421 const auto* event = GetEventData<UserEventData>(*message); |
| 422 | 422 |
| 423 #if DCHECK_IS_ON() | 423 #if DCHECK_IS_ON() |
| 424 std::ostringstream ports_buf; | 424 std::ostringstream ports_buf; |
| 425 for (size_t i = 0; i < message->num_ports(); ++i) { | 425 for (size_t i = 0; i < message->num_ports(); ++i) { |
| 426 if (i > 0) | 426 if (i > 0) |
| 427 ports_buf << ","; | 427 ports_buf << ","; |
| 428 ports_buf << message->ports()[i]; | 428 ports_buf << message->ports()[i]; |
| 429 } | 429 } |
| 430 | 430 |
| 431 DVLOG(2) << "AcceptMessage " << event->sequence_num | 431 DVLOG(4) << "AcceptMessage " << event->sequence_num |
| 432 << " [ports=" << ports_buf.str() << "] at " | 432 << " [ports=" << ports_buf.str() << "] at " |
| 433 << port_name << "@" << name_; | 433 << port_name << "@" << name_; |
| 434 #endif | 434 #endif |
| 435 | 435 |
| 436 scoped_refptr<Port> port = GetPort(port_name); | 436 scoped_refptr<Port> port = GetPort(port_name); |
| 437 | 437 |
| 438 // Even if this port does not exist, cannot receive anymore messages or is | 438 // Even if this port does not exist, cannot receive anymore messages or is |
| 439 // buffering or proxying messages, we still need these ports to be bound to | 439 // buffering or proxying messages, we still need these ports to be bound to |
| 440 // this node. When the message is forwarded, these ports will get transferred | 440 // this node. When the message is forwarded, these ports will get transferred |
| 441 // following the usual method. If the message cannot be accepted, then the | 441 // following the usual method. If the message cannot be accepted, then the |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 port->peer_node_name, | 1071 port->peer_node_name, |
| 1072 message->mutable_ports() + i, | 1072 message->mutable_ports() + i, |
| 1073 port_descriptors + i); | 1073 port_descriptors + i); |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 for (size_t i = 0; i < message->num_ports(); ++i) | 1076 for (size_t i = 0; i < message->num_ports(); ++i) |
| 1077 ports[i]->lock.Release(); | 1077 ports[i]->lock.Release(); |
| 1078 } | 1078 } |
| 1079 | 1079 |
| 1080 #if DCHECK_IS_ON() | 1080 #if DCHECK_IS_ON() |
| 1081 DVLOG(2) << "Sending message " | 1081 DVLOG(4) << "Sending message " |
| 1082 << GetEventData<UserEventData>(*message)->sequence_num | 1082 << GetEventData<UserEventData>(*message)->sequence_num |
| 1083 << " [ports=" << ports_buf.str() << "]" | 1083 << " [ports=" << ports_buf.str() << "]" |
| 1084 << " from " << port_name << "@" << name_ | 1084 << " from " << port_name << "@" << name_ |
| 1085 << " to " << port->peer_port_name << "@" << port->peer_node_name; | 1085 << " to " << port->peer_port_name << "@" << port->peer_node_name; |
| 1086 #endif | 1086 #endif |
| 1087 | 1087 |
| 1088 GetMutableEventHeader(message)->port_name = port->peer_port_name; | 1088 GetMutableEventHeader(message)->port_name = port->peer_port_name; |
| 1089 return OK; | 1089 return OK; |
| 1090 } | 1090 } |
| 1091 | 1091 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 | 1376 |
| 1377 if (num_data_bytes) | 1377 if (num_data_bytes) |
| 1378 memcpy(header + 1, data, num_data_bytes); | 1378 memcpy(header + 1, data, num_data_bytes); |
| 1379 | 1379 |
| 1380 return message; | 1380 return message; |
| 1381 } | 1381 } |
| 1382 | 1382 |
| 1383 } // namespace ports | 1383 } // namespace ports |
| 1384 } // namespace edk | 1384 } // namespace edk |
| 1385 } // namespace mojo | 1385 } // namespace mojo |
| OLD | NEW |