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

Side by Side Diff: mojo/edk/system/ports/node.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/ports/name.cc ('k') | mojo/edk/system/ports_message.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/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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 return rv; 401 return rv;
402 } 402 }
403 403
404 int Node::LostConnectionToNode(const NodeName& node_name) { 404 int Node::LostConnectionToNode(const NodeName& node_name) {
405 // We can no longer send events to the given node. We also can't expect any 405 // We can no longer send events to the given node. We also can't expect any
406 // PortAccepted events. 406 // PortAccepted events.
407 407
408 DVLOG(1) << "Observing lost connection from node " << name_ 408 DVLOG(1) << "Observing lost connection from node " << name_
409 << " to node " << node_name; 409 << " to node " << node_name;
410 410
411 DestroyAllPortsWithPeer(node_name, kInvalidPortName); 411 DestroyAllPortsWithPeer(node_name, constants::kInvalidPortName);
412 return OK; 412 return OK;
413 } 413 }
414 414
415 int Node::OnUserMessage(ScopedMessage message) { 415 int Node::OnUserMessage(ScopedMessage message) {
416 PortName port_name = GetEventHeader(*message)->port_name; 416 PortName port_name = GetEventHeader(*message)->port_name;
417 const auto* event = GetEventData<UserEventData>(*message); 417 const auto* event = GetEventData<UserEventData>(*message);
418 418
419 #if DCHECK_IS_ON() 419 #if DCHECK_IS_ON()
420 std::ostringstream ports_buf; 420 std::ostringstream ports_buf;
421 for (size_t i = 0; i < message->num_ports(); ++i) { 421 for (size_t i = 0; i < message->num_ports(); ++i) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 502
503 DVLOG(2) << "PortAccepted at " << port_name << "@" << name_ 503 DVLOG(2) << "PortAccepted at " << port_name << "@" << name_
504 << " pointing to " 504 << " pointing to "
505 << port->peer_port_name << "@" << port->peer_node_name; 505 << port->peer_port_name << "@" << port->peer_node_name;
506 506
507 return BeginProxying(PortRef(port_name, port)); 507 return BeginProxying(PortRef(port_name, port));
508 } 508 }
509 509
510 int Node::OnObserveProxy(const PortName& port_name, 510 int Node::OnObserveProxy(const PortName& port_name,
511 const ObserveProxyEventData& event) { 511 const ObserveProxyEventData& event) {
512 if (port_name == kInvalidPortName) { 512 if (port_name == constants::kInvalidPortName) {
513 // An ObserveProxy with an invalid target port name is a broadcast used to 513 // An ObserveProxy with an invalid target port name is a broadcast used to
514 // inform ports when their peer (which was itself a proxy) has become 514 // inform ports when their peer (which was itself a proxy) has become
515 // defunct due to unexpected node disconnection. 515 // defunct due to unexpected node disconnection.
516 // 516 //
517 // Receiving ports affected by this treat it as equivalent to peer closure. 517 // Receiving ports affected by this treat it as equivalent to peer closure.
518 // Proxies affected by this can be removed and will in turn broadcast their 518 // Proxies affected by this can be removed and will in turn broadcast their
519 // own death with a similar message. 519 // own death with a similar message.
520 CHECK_EQ(event.proxy_to_node_name, kInvalidNodeName); 520 CHECK_EQ(event.proxy_to_node_name, constants::kInvalidNodeName);
521 CHECK_EQ(event.proxy_to_port_name, kInvalidPortName); 521 CHECK_EQ(event.proxy_to_port_name, constants::kInvalidPortName);
522 DestroyAllPortsWithPeer(event.proxy_node_name, event.proxy_port_name); 522 DestroyAllPortsWithPeer(event.proxy_node_name, event.proxy_port_name);
523 return OK; 523 return OK;
524 } 524 }
525 525
526 // The port may have already been closed locally, in which case the 526 // The port may have already been closed locally, in which case the
527 // ObserveClosure message will contain the last_sequence_num field. 527 // ObserveClosure message will contain the last_sequence_num field.
528 // We can then silently ignore this message. 528 // We can then silently ignore this message.
529 scoped_refptr<Port> port = GetPort(port_name); 529 scoped_refptr<Port> port = GetPort(port_name);
530 if (!port) { 530 if (!port) {
531 DVLOG(1) << "ObserveProxy: " << port_name << "@" << name_ << " not found"; 531 DVLOG(1) << "ObserveProxy: " << port_name << "@" << name_ << " not found";
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 1286
1287 { 1287 {
1288 base::AutoLock ports_lock(ports_lock_); 1288 base::AutoLock ports_lock(ports_lock_);
1289 1289
1290 for (auto iter = ports_.begin(); iter != ports_.end(); ++iter) { 1290 for (auto iter = ports_.begin(); iter != ports_.end(); ++iter) {
1291 Port* port = iter->second.get(); 1291 Port* port = iter->second.get();
1292 { 1292 {
1293 base::AutoLock port_lock(port->lock); 1293 base::AutoLock port_lock(port->lock);
1294 1294
1295 if (port->peer_node_name == node_name && 1295 if (port->peer_node_name == node_name &&
1296 (port_name == kInvalidPortName || 1296 (port_name == constants::kInvalidPortName ||
1297 port->peer_port_name == port_name)) { 1297 port->peer_port_name == port_name)) {
1298 if (!port->peer_closed) { 1298 if (!port->peer_closed) {
1299 // Treat this as immediate peer closure. It's an exceptional 1299 // Treat this as immediate peer closure. It's an exceptional
1300 // condition akin to a broken pipe, so we don't care about losing 1300 // condition akin to a broken pipe, so we don't care about losing
1301 // messages. 1301 // messages.
1302 1302
1303 port->peer_closed = true; 1303 port->peer_closed = true;
1304 port->last_sequence_num_to_receive = 1304 port->last_sequence_num_to_receive =
1305 port->message_queue.next_sequence_num() - 1; 1305 port->message_queue.next_sequence_num() - 1;
1306 1306
1307 if (port->state == Port::kReceiving) 1307 if (port->state == Port::kReceiving)
(...skipping 23 matching lines...) Expand all
1331 1331
1332 // Wake up any receiving ports who have just observed simulated peer closure. 1332 // Wake up any receiving ports who have just observed simulated peer closure.
1333 for (const auto& port : ports_to_notify) 1333 for (const auto& port : ports_to_notify)
1334 delegate_->PortStatusChanged(port); 1334 delegate_->PortStatusChanged(port);
1335 1335
1336 for (const auto& proxy_name : dead_proxies_to_broadcast) { 1336 for (const auto& proxy_name : dead_proxies_to_broadcast) {
1337 // Broadcast an event signifying that this proxy is no longer functioning. 1337 // Broadcast an event signifying that this proxy is no longer functioning.
1338 ObserveProxyEventData event; 1338 ObserveProxyEventData event;
1339 event.proxy_node_name = name_; 1339 event.proxy_node_name = name_;
1340 event.proxy_port_name = proxy_name; 1340 event.proxy_port_name = proxy_name;
1341 event.proxy_to_node_name = kInvalidNodeName; 1341 event.proxy_to_node_name = constants::kInvalidNodeName;
1342 event.proxy_to_port_name = kInvalidPortName; 1342 event.proxy_to_port_name = constants::kInvalidPortName;
1343 delegate_->BroadcastMessage(NewInternalMessage( 1343 delegate_->BroadcastMessage(NewInternalMessage(
1344 kInvalidPortName, EventType::kObserveProxy, event)); 1344 constants::kInvalidPortName, EventType::kObserveProxy, event));
1345 1345
1346 // Also process death locally since the port that points this closed one 1346 // Also process death locally since the port that points this closed one
1347 // could be on the current node. 1347 // could be on the current node.
1348 // Note: Although this is recursive, only a single port is involved which 1348 // Note: Although this is recursive, only a single port is involved which
1349 // limits the expected branching to 1. 1349 // limits the expected branching to 1.
1350 DestroyAllPortsWithPeer(name_, proxy_name); 1350 DestroyAllPortsWithPeer(name_, proxy_name);
1351 } 1351 }
1352 1352
1353 // Close any ports referenced by the closed proxies. 1353 // Close any ports referenced by the closed proxies.
1354 for (const auto& name : referenced_port_names) { 1354 for (const auto& name : referenced_port_names) {
(...skipping 17 matching lines...) Expand all
1372 1372
1373 if (num_data_bytes) 1373 if (num_data_bytes)
1374 memcpy(header + 1, data, num_data_bytes); 1374 memcpy(header + 1, data, num_data_bytes);
1375 1375
1376 return message; 1376 return message;
1377 } 1377 }
1378 1378
1379 } // namespace ports 1379 } // namespace ports
1380 } // namespace edk 1380 } // namespace edk
1381 } // namespace mojo 1381 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/ports/name.cc ('k') | mojo/edk/system/ports_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698