| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 private: | 60 private: |
| 61 SocketTunnel(std::unique_ptr<net::StreamSocket> socket, | 61 SocketTunnel(std::unique_ptr<net::StreamSocket> socket, |
| 62 const std::string& host, | 62 const std::string& host, |
| 63 int port) | 63 int port) |
| 64 : remote_socket_(std::move(socket)), | 64 : remote_socket_(std::move(socket)), |
| 65 pending_writes_(0), | 65 pending_writes_(0), |
| 66 pending_destruction_(false) { | 66 pending_destruction_(false) { |
| 67 host_resolver_ = net::HostResolver::CreateDefaultResolver(nullptr); | 67 host_resolver_ = net::HostResolver::CreateDefaultResolver(nullptr); |
| 68 net::HostResolver::RequestInfo request_info(net::HostPortPair(host, port)); | 68 net::HostResolver::RequestInfo request_info(net::HostPortPair(host, port)); |
| 69 int result = host_resolver_->Resolve( | 69 int result = host_resolver_->Resolve( |
| 70 request_info, | 70 request_info, net::DEFAULT_PRIORITY, &address_list_, |
| 71 net::DEFAULT_PRIORITY, | |
| 72 &address_list_, | |
| 73 base::Bind(&SocketTunnel::OnResolved, base::Unretained(this)), | 71 base::Bind(&SocketTunnel::OnResolved, base::Unretained(this)), |
| 74 nullptr, | 72 &request_, net::BoundNetLog()); |
| 75 net::BoundNetLog()); | |
| 76 if (result != net::ERR_IO_PENDING) | 73 if (result != net::ERR_IO_PENDING) |
| 77 OnResolved(result); | 74 OnResolved(result); |
| 78 } | 75 } |
| 79 | 76 |
| 80 void OnResolved(int result) { | 77 void OnResolved(int result) { |
| 81 if (result < 0) { | 78 if (result < 0) { |
| 82 SelfDestruct(); | 79 SelfDestruct(); |
| 83 return; | 80 return; |
| 84 } | 81 } |
| 85 | 82 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if (pending_writes_ > 0) { | 176 if (pending_writes_ > 0) { |
| 180 pending_destruction_ = true; | 177 pending_destruction_ = true; |
| 181 return; | 178 return; |
| 182 } | 179 } |
| 183 delete this; | 180 delete this; |
| 184 } | 181 } |
| 185 | 182 |
| 186 std::unique_ptr<net::StreamSocket> remote_socket_; | 183 std::unique_ptr<net::StreamSocket> remote_socket_; |
| 187 std::unique_ptr<net::StreamSocket> host_socket_; | 184 std::unique_ptr<net::StreamSocket> host_socket_; |
| 188 std::unique_ptr<net::HostResolver> host_resolver_; | 185 std::unique_ptr<net::HostResolver> host_resolver_; |
| 186 std::unique_ptr<net::HostResolver::Request> request_; |
| 189 net::AddressList address_list_; | 187 net::AddressList address_list_; |
| 190 int pending_writes_; | 188 int pending_writes_; |
| 191 bool pending_destruction_; | 189 bool pending_destruction_; |
| 192 }; | 190 }; |
| 193 | 191 |
| 194 } // namespace | 192 } // namespace |
| 195 | 193 |
| 196 class PortForwardingController::Connection | 194 class PortForwardingController::Connection |
| 197 : public AndroidDeviceManager::AndroidWebSocket::Delegate { | 195 : public AndroidDeviceManager::AndroidWebSocket::Delegate { |
| 198 public: | 196 public: |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 registry_copy.push_back(it->second); | 490 registry_copy.push_back(it->second); |
| 493 } | 491 } |
| 494 STLDeleteElements(®istry_copy); | 492 STLDeleteElements(®istry_copy); |
| 495 } | 493 } |
| 496 } | 494 } |
| 497 | 495 |
| 498 void PortForwardingController::UpdateConnections() { | 496 void PortForwardingController::UpdateConnections() { |
| 499 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) | 497 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) |
| 500 it->second->UpdateForwardingMap(forwarding_map_); | 498 it->second->UpdateForwardingMap(forwarding_map_); |
| 501 } | 499 } |
| OLD | NEW |