OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/devtools/device/port_forwarding_controller.h" | 5 #include "chrome/browser/devtools/device/port_forwarding_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 } | 460 } |
461 } else { | 461 } else { |
462 status.push_back(std::make_pair(rit->second->browser(), | 462 status.push_back(std::make_pair(rit->second->browser(), |
463 rit->second->GetPortStatusMap())); | 463 rit->second->GetPortStatusMap())); |
464 } | 464 } |
465 } | 465 } |
466 return status; | 466 return status; |
467 } | 467 } |
468 | 468 |
469 void PortForwardingController::CloseAllConnections() { | 469 void PortForwardingController::CloseAllConnections() { |
470 std::vector<Connection*> registry_copy; | |
471 Registry copy(registry_); | 470 Registry copy(registry_); |
472 base::STLDeleteValues(©); | 471 for (auto& entry : copy) |
| 472 delete entry.second; |
473 } | 473 } |
474 | 474 |
475 void PortForwardingController::OnPrefsChange() { | 475 void PortForwardingController::OnPrefsChange() { |
476 forwarding_map_.clear(); | 476 forwarding_map_.clear(); |
477 | 477 |
478 if (pref_service_->GetBoolean(prefs::kDevToolsPortForwardingEnabled)) { | 478 if (pref_service_->GetBoolean(prefs::kDevToolsPortForwardingEnabled)) { |
479 const base::DictionaryValue* dict = | 479 const base::DictionaryValue* dict = |
480 pref_service_->GetDictionary(prefs::kDevToolsPortForwardingConfig); | 480 pref_service_->GetDictionary(prefs::kDevToolsPortForwardingConfig); |
481 for (base::DictionaryValue::Iterator it(*dict); | 481 for (base::DictionaryValue::Iterator it(*dict); |
482 !it.IsAtEnd(); it.Advance()) { | 482 !it.IsAtEnd(); it.Advance()) { |
483 int port_num; | 483 int port_num; |
484 std::string location; | 484 std::string location; |
485 if (base::StringToInt(it.key(), &port_num) && | 485 if (base::StringToInt(it.key(), &port_num) && |
486 dict->GetString(it.key(), &location)) | 486 dict->GetString(it.key(), &location)) |
487 forwarding_map_[port_num] = location; | 487 forwarding_map_[port_num] = location; |
488 } | 488 } |
489 } | 489 } |
490 | 490 |
491 if (!forwarding_map_.empty()) | 491 if (!forwarding_map_.empty()) |
492 UpdateConnections(); | 492 UpdateConnections(); |
493 else | 493 else |
494 CloseAllConnections(); | 494 CloseAllConnections(); |
495 } | 495 } |
496 | 496 |
497 void PortForwardingController::UpdateConnections() { | 497 void PortForwardingController::UpdateConnections() { |
498 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) | 498 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) |
499 it->second->UpdateForwardingMap(forwarding_map_); | 499 it->second->UpdateForwardingMap(forwarding_map_); |
500 } | 500 } |
OLD | NEW |