| 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/tcp_device_provider.h" | 5 #include "chrome/browser/devtools/device/tcp_device_provider.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 public: | 33 public: |
| 34 ResolveHostAndOpenSocket(const net::HostPortPair& address, | 34 ResolveHostAndOpenSocket(const net::HostPortPair& address, |
| 35 const AdbClientSocket::SocketCallback& callback) | 35 const AdbClientSocket::SocketCallback& callback) |
| 36 : callback_(callback) { | 36 : callback_(callback) { |
| 37 host_resolver_ = net::HostResolver::CreateDefaultResolver(nullptr); | 37 host_resolver_ = net::HostResolver::CreateDefaultResolver(nullptr); |
| 38 net::HostResolver::RequestInfo request_info(address); | 38 net::HostResolver::RequestInfo request_info(address); |
| 39 int result = host_resolver_->Resolve( | 39 int result = host_resolver_->Resolve( |
| 40 request_info, net::DEFAULT_PRIORITY, &address_list_, | 40 request_info, net::DEFAULT_PRIORITY, &address_list_, |
| 41 base::Bind(&ResolveHostAndOpenSocket::OnResolved, | 41 base::Bind(&ResolveHostAndOpenSocket::OnResolved, |
| 42 base::Unretained(this)), | 42 base::Unretained(this)), |
| 43 nullptr, net::BoundNetLog()); | 43 &request_, net::BoundNetLog()); |
| 44 if (result != net::ERR_IO_PENDING) | 44 if (result != net::ERR_IO_PENDING) |
| 45 OnResolved(result); | 45 OnResolved(result); |
| 46 } | 46 } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 void OnResolved(int result) { | 49 void OnResolved(int result) { |
| 50 if (result < 0) { | 50 if (result < 0) { |
| 51 RunSocketCallback(callback_, nullptr, result); | 51 RunSocketCallback(callback_, nullptr, result); |
| 52 delete this; | 52 delete this; |
| 53 return; | 53 return; |
| 54 } | 54 } |
| 55 std::unique_ptr<net::StreamSocket> socket(new net::TCPClientSocket( | 55 std::unique_ptr<net::StreamSocket> socket(new net::TCPClientSocket( |
| 56 address_list_, NULL, NULL, net::NetLog::Source())); | 56 address_list_, NULL, NULL, net::NetLog::Source())); |
| 57 socket->Connect( | 57 socket->Connect( |
| 58 base::Bind(&RunSocketCallback, callback_, base::Passed(&socket))); | 58 base::Bind(&RunSocketCallback, callback_, base::Passed(&socket))); |
| 59 delete this; | 59 delete this; |
| 60 } | 60 } |
| 61 | 61 |
| 62 std::unique_ptr<net::HostResolver> host_resolver_; | 62 std::unique_ptr<net::HostResolver> host_resolver_; |
| 63 std::unique_ptr<net::HostResolver::Request> request_; |
| 63 net::AddressList address_list_; | 64 net::AddressList address_list_; |
| 64 AdbClientSocket::SocketCallback callback_; | 65 AdbClientSocket::SocketCallback callback_; |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 } // namespace | 68 } // namespace |
| 68 | 69 |
| 69 scoped_refptr<TCPDeviceProvider> TCPDeviceProvider::CreateForLocalhost( | 70 scoped_refptr<TCPDeviceProvider> TCPDeviceProvider::CreateForLocalhost( |
| 70 uint16_t port) { | 71 uint16_t port) { |
| 71 TCPDeviceProvider::HostPortSet targets; | 72 TCPDeviceProvider::HostPortSet targets; |
| 72 targets.insert(net::HostPortPair("127.0.0.1", port)); | 73 targets.insert(net::HostPortPair("127.0.0.1", port)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 release_callback_.Run(); | 126 release_callback_.Run(); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void TCPDeviceProvider::set_release_callback_for_test( | 129 void TCPDeviceProvider::set_release_callback_for_test( |
| 129 const base::Closure& callback) { | 130 const base::Closure& callback) { |
| 130 release_callback_ = callback; | 131 release_callback_ = callback; |
| 131 } | 132 } |
| 132 | 133 |
| 133 TCPDeviceProvider::~TCPDeviceProvider() { | 134 TCPDeviceProvider::~TCPDeviceProvider() { |
| 134 } | 135 } |
| OLD | NEW |