Chromium Code Reviews| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 59 |
| 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 std::unique_ptr<net::HostResolver::Request> request; | |
|
mmenke
2016/07/21 16:00:40
You don't need this - if result != ERR_IO_PENDING,
maksims (do not use this acc)
2016/07/22 10:16:00
Done.
| |
| 69 int result = host_resolver_->Resolve( | 70 int result = host_resolver_->Resolve( |
| 70 request_info, | 71 request_info, net::DEFAULT_PRIORITY, &address_list_, |
| 71 net::DEFAULT_PRIORITY, | 72 base::Bind(&SocketTunnel::OnResolved, base::Unretained(this)), &request, |
| 72 &address_list_, | |
| 73 base::Bind(&SocketTunnel::OnResolved, base::Unretained(this)), | |
| 74 nullptr, | |
| 75 net::BoundNetLog()); | 73 net::BoundNetLog()); |
| 76 if (result != net::ERR_IO_PENDING) | 74 if (result != net::ERR_IO_PENDING) |
| 77 OnResolved(result); | 75 OnResolved(result); |
| 76 else if (result == net::ERR_IO_PENDING) | |
| 77 request_ = std::move(request); | |
| 78 } | 78 } |
| 79 | 79 |
| 80 void OnResolved(int result) { | 80 void OnResolved(int result) { |
| 81 if (result < 0) { | 81 if (result < 0) { |
| 82 SelfDestruct(); | 82 SelfDestruct(); |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 | 85 |
| 86 host_socket_.reset(new net::TCPClientSocket(address_list_, nullptr, nullptr, | 86 host_socket_.reset(new net::TCPClientSocket(address_list_, nullptr, nullptr, |
| 87 net::NetLog::Source())); | 87 net::NetLog::Source())); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 if (pending_writes_ > 0) { | 179 if (pending_writes_ > 0) { |
| 180 pending_destruction_ = true; | 180 pending_destruction_ = true; |
| 181 return; | 181 return; |
| 182 } | 182 } |
| 183 delete this; | 183 delete this; |
| 184 } | 184 } |
| 185 | 185 |
| 186 std::unique_ptr<net::StreamSocket> remote_socket_; | 186 std::unique_ptr<net::StreamSocket> remote_socket_; |
| 187 std::unique_ptr<net::StreamSocket> host_socket_; | 187 std::unique_ptr<net::StreamSocket> host_socket_; |
| 188 std::unique_ptr<net::HostResolver> host_resolver_; | 188 std::unique_ptr<net::HostResolver> host_resolver_; |
| 189 std::unique_ptr<net::HostResolver::Request> request_; | |
| 189 net::AddressList address_list_; | 190 net::AddressList address_list_; |
| 190 int pending_writes_; | 191 int pending_writes_; |
| 191 bool pending_destruction_; | 192 bool pending_destruction_; |
| 192 }; | 193 }; |
| 193 | 194 |
| 194 } // namespace | 195 } // namespace |
| 195 | 196 |
| 196 class PortForwardingController::Connection | 197 class PortForwardingController::Connection |
| 197 : public AndroidDeviceManager::AndroidWebSocket::Delegate { | 198 : public AndroidDeviceManager::AndroidWebSocket::Delegate { |
| 198 public: | 199 public: |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 registry_copy.push_back(it->second); | 493 registry_copy.push_back(it->second); |
| 493 } | 494 } |
| 494 STLDeleteElements(®istry_copy); | 495 STLDeleteElements(®istry_copy); |
| 495 } | 496 } |
| 496 } | 497 } |
| 497 | 498 |
| 498 void PortForwardingController::UpdateConnections() { | 499 void PortForwardingController::UpdateConnections() { |
| 499 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) | 500 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) |
| 500 it->second->UpdateForwardingMap(forwarding_map_); | 501 it->second->UpdateForwardingMap(forwarding_map_); |
| 501 } | 502 } |
| OLD | NEW |