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

Side by Side Diff: chrome/browser/devtools/device/tcp_device_provider.cc

Issue 2116983002: Change HostResolver::Resolve() to take an std::unique_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke's comments and rebasing Created 4 years, 5 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
OLDNEW
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 18 matching lines...) Expand all
29 callback.Run(result, std::move(socket)); 29 callback.Run(result, std::move(socket));
30 } 30 }
31 31
32 class ResolveHostAndOpenSocket final { 32 class ResolveHostAndOpenSocket final {
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 std::unique_ptr<net::HostResolver::Request> request;
mmenke 2016/07/21 16:00:40 Not needed (Note that there's also a bug below - y
maksims (do not use this acc) 2016/07/22 10:16:00 Ops...
39 int result = host_resolver_->Resolve( 40 int result = host_resolver_->Resolve(
40 request_info, net::DEFAULT_PRIORITY, &address_list_, 41 request_info, net::DEFAULT_PRIORITY, &address_list_,
41 base::Bind(&ResolveHostAndOpenSocket::OnResolved, 42 base::Bind(&ResolveHostAndOpenSocket::OnResolved,
42 base::Unretained(this)), 43 base::Unretained(this)),
43 nullptr, net::BoundNetLog()); 44 &request_, net::BoundNetLog());
44 if (result != net::ERR_IO_PENDING) 45 if (result != net::ERR_IO_PENDING)
45 OnResolved(result); 46 OnResolved(result);
47 else if (result == net::ERR_IO_PENDING)
48 request_ = std::move(request);
46 } 49 }
47 50
48 private: 51 private:
49 void OnResolved(int result) { 52 void OnResolved(int result) {
50 if (result < 0) { 53 if (result < 0) {
51 RunSocketCallback(callback_, nullptr, result); 54 RunSocketCallback(callback_, nullptr, result);
52 delete this; 55 delete this;
53 return; 56 return;
54 } 57 }
55 std::unique_ptr<net::StreamSocket> socket(new net::TCPClientSocket( 58 std::unique_ptr<net::StreamSocket> socket(new net::TCPClientSocket(
56 address_list_, NULL, NULL, net::NetLog::Source())); 59 address_list_, NULL, NULL, net::NetLog::Source()));
57 socket->Connect( 60 socket->Connect(
58 base::Bind(&RunSocketCallback, callback_, base::Passed(&socket))); 61 base::Bind(&RunSocketCallback, callback_, base::Passed(&socket)));
59 delete this; 62 delete this;
60 } 63 }
61 64
62 std::unique_ptr<net::HostResolver> host_resolver_; 65 std::unique_ptr<net::HostResolver> host_resolver_;
66 std::unique_ptr<net::HostResolver::Request> request_;
63 net::AddressList address_list_; 67 net::AddressList address_list_;
64 AdbClientSocket::SocketCallback callback_; 68 AdbClientSocket::SocketCallback callback_;
65 }; 69 };
66 70
67 } // namespace 71 } // namespace
68 72
69 scoped_refptr<TCPDeviceProvider> TCPDeviceProvider::CreateForLocalhost( 73 scoped_refptr<TCPDeviceProvider> TCPDeviceProvider::CreateForLocalhost(
70 uint16_t port) { 74 uint16_t port) {
71 TCPDeviceProvider::HostPortSet targets; 75 TCPDeviceProvider::HostPortSet targets;
72 targets.insert(net::HostPortPair("127.0.0.1", port)); 76 targets.insert(net::HostPortPair("127.0.0.1", port));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 release_callback_.Run(); 129 release_callback_.Run();
126 } 130 }
127 131
128 void TCPDeviceProvider::set_release_callback_for_test( 132 void TCPDeviceProvider::set_release_callback_for_test(
129 const base::Closure& callback) { 133 const base::Closure& callback) {
130 release_callback_ = callback; 134 release_callback_ = callback;
131 } 135 }
132 136
133 TCPDeviceProvider::~TCPDeviceProvider() { 137 TCPDeviceProvider::~TCPDeviceProvider() {
134 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698