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

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

Issue 2010783004: [mojo-edk] Revert port reservation timeout behavior (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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/node_controller.h ('k') | no next file » | 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 183 }
184 184
185 void NodeController::ReservePort(const std::string& token, 185 void NodeController::ReservePort(const std::string& token,
186 const ports::PortRef& port) { 186 const ports::PortRef& port) {
187 DVLOG(2) << "Reserving port " << port.name() << "@" << name_ << " for token " 187 DVLOG(2) << "Reserving port " << port.name() << "@" << name_ << " for token "
188 << token; 188 << token;
189 189
190 base::AutoLock lock(reserved_ports_lock_); 190 base::AutoLock lock(reserved_ports_lock_);
191 auto result = reserved_ports_.insert(std::make_pair(token, port)); 191 auto result = reserved_ports_.insert(std::make_pair(token, port));
192 DCHECK(result.second); 192 DCHECK(result.second);
193
194 // Safeguard against unpredictable and exceptional cases where a reservation
195 // holder may disappear without ever claiming their reservation.
196 io_task_runner_->PostDelayedTask(
197 FROM_HERE,
198 base::Bind(&NodeController::CancelReservation,
199 base::Unretained(this), token),
200 base::TimeDelta::FromMinutes(1));
201 } 193 }
202 194
203 void NodeController::MergePortIntoParent(const std::string& token, 195 void NodeController::MergePortIntoParent(const std::string& token,
204 const ports::PortRef& port) { 196 const ports::PortRef& port) {
205 bool was_merged = false; 197 bool was_merged = false;
206 { 198 {
207 // This request may be coming from within the process that reserved the 199 // This request may be coming from within the process that reserved the
208 // "parent" side (e.g. for Chrome single-process mode), so if this token is 200 // "parent" side (e.g. for Chrome single-process mode), so if this token is
209 // reserved locally, merge locally instead. 201 // reserved locally, merge locally instead.
210 base::AutoLock lock(reserved_ports_lock_); 202 base::AutoLock lock(reserved_ports_lock_);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 pending_peer_messages_.clear(); 532 pending_peer_messages_.clear();
541 } 533 }
542 534
543 for (const auto& peer : all_peers) 535 for (const auto& peer : all_peers)
544 peer->ShutDown(); 536 peer->ShutDown();
545 537
546 if (destroy_on_io_thread_shutdown_) 538 if (destroy_on_io_thread_shutdown_)
547 delete this; 539 delete this;
548 } 540 }
549 541
550 void NodeController::CancelReservation(const std::string& token) {
551 ports::PortRef reserved_port;
552 {
553 base::AutoLock lock(reserved_ports_lock_);
554 auto iter = reserved_ports_.find(token);
555 if (iter == reserved_ports_.end()) // Already claimed!
556 return;
557 reserved_port = iter->second;
558 reserved_ports_.erase(iter);
559 }
560 node_->ClosePort(reserved_port);
561 }
562
563 void NodeController::GenerateRandomPortName(ports::PortName* port_name) { 542 void NodeController::GenerateRandomPortName(ports::PortName* port_name) {
564 GenerateRandomName(port_name); 543 GenerateRandomName(port_name);
565 } 544 }
566 545
567 void NodeController::AllocMessage(size_t num_header_bytes, 546 void NodeController::AllocMessage(size_t num_header_bytes,
568 ports::ScopedMessage* message) { 547 ports::ScopedMessage* message) {
569 message->reset(new PortsMessage(num_header_bytes, 0, 0, nullptr)); 548 message->reset(new PortsMessage(num_header_bytes, 0, 0, nullptr));
570 } 549 }
571 550
572 void NodeController::ForwardMessage(const ports::NodeName& node, 551 void NodeController::ForwardMessage(const ports::NodeName& node,
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 shutdown_callback_flag_.Set(false); 1009 shutdown_callback_flag_.Set(false);
1031 } 1010 }
1032 1011
1033 DCHECK(!callback.is_null()); 1012 DCHECK(!callback.is_null());
1034 1013
1035 callback.Run(); 1014 callback.Run();
1036 } 1015 }
1037 1016
1038 } // namespace edk 1017 } // namespace edk
1039 } // namespace mojo 1018 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/node_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698