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

Side by Side Diff: extensions/browser/api/socket/socket_api.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: 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 "extensions/browser/api/socket/socket_api.h" 5 #include "extensions/browser/api/socket/socket_api.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 resource_context_ = browser_context()->GetResourceContext(); 196 resource_context_ = browser_context()->GetResourceContext();
197 return resource_context_ != NULL; 197 return resource_context_ != NULL;
198 } 198 }
199 199
200 void SocketExtensionWithDnsLookupFunction::StartDnsLookup( 200 void SocketExtensionWithDnsLookupFunction::StartDnsLookup(
201 const net::HostPortPair& host_port_pair) { 201 const net::HostPortPair& host_port_pair) {
202 net::HostResolver* host_resolver = 202 net::HostResolver* host_resolver =
203 HostResolverWrapper::GetInstance()->GetHostResolver(resource_context_); 203 HostResolverWrapper::GetInstance()->GetHostResolver(resource_context_);
204 DCHECK(host_resolver); 204 DCHECK(host_resolver);
205 205
206 // RequestHandle is not needed because we never need to cancel requests.
207 net::HostResolver::RequestHandle request_handle;
208
209 net::HostResolver::RequestInfo request_info(host_port_pair); 206 net::HostResolver::RequestInfo request_info(host_port_pair);
210 int resolve_result = host_resolver->Resolve( 207 int resolve_result = host_resolver->Resolve(
211 request_info, net::DEFAULT_PRIORITY, &addresses_, 208 request_info, net::DEFAULT_PRIORITY, &addresses_,
212 base::Bind(&SocketExtensionWithDnsLookupFunction::OnDnsLookup, this), 209 base::Bind(&SocketExtensionWithDnsLookupFunction::OnDnsLookup, this),
213 &request_handle, net::BoundNetLog()); 210 &request_handle_, net::BoundNetLog());
214 211
215 if (resolve_result != net::ERR_IO_PENDING) 212 if (resolve_result != net::ERR_IO_PENDING)
216 OnDnsLookup(resolve_result); 213 OnDnsLookup(resolve_result);
217 } 214 }
218 215
219 void SocketExtensionWithDnsLookupFunction::OnDnsLookup(int resolve_result) { 216 void SocketExtensionWithDnsLookupFunction::OnDnsLookup(int resolve_result) {
220 if (resolve_result == net::OK) { 217 if (resolve_result == net::OK) {
221 DCHECK(!addresses_.empty()); 218 DCHECK(!addresses_.empty());
222 } else { 219 } else {
223 error_ = kDnsLookupFailedError; 220 error_ = kDnsLookupFailedError;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 StartDnsLookup(net::HostPortPair(hostname_, port_)); 323 StartDnsLookup(net::HostPortPair(hostname_, port_));
327 } 324 }
328 325
329 void SocketConnectFunction::AfterDnsLookup(int lookup_result) { 326 void SocketConnectFunction::AfterDnsLookup(int lookup_result) {
330 if (lookup_result == net::OK) { 327 if (lookup_result == net::OK) {
331 StartConnect(); 328 StartConnect();
332 } else { 329 } else {
333 SetResult(base::MakeUnique<base::FundamentalValue>(lookup_result)); 330 SetResult(base::MakeUnique<base::FundamentalValue>(lookup_result));
334 AsyncWorkCompleted(); 331 AsyncWorkCompleted();
335 } 332 }
333 // TODO(maksims): investigate why std::unique_ptr<HostResolver::Request>'s
334 // destructor is not called automatically.
335 request_handle_.reset();
Devlin 2016/07/12 15:04:51 ditto
maksims (do not use this acc) 2016/07/19 15:00:25 Done.
336 } 336 }
337 337
338 void SocketConnectFunction::StartConnect() { 338 void SocketConnectFunction::StartConnect() {
339 Socket* socket = GetSocket(socket_id_); 339 Socket* socket = GetSocket(socket_id_);
340 if (!socket) { 340 if (!socket) {
341 error_ = kSocketNotFoundError; 341 error_ = kSocketNotFoundError;
342 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); 342 SetResult(base::MakeUnique<base::FundamentalValue>(-1));
343 AsyncWorkCompleted(); 343 AsyncWorkCompleted();
344 return; 344 return;
345 } 345 }
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 StartDnsLookup(net::HostPortPair(hostname_, port_)); 658 StartDnsLookup(net::HostPortPair(hostname_, port_));
659 } 659 }
660 660
661 void SocketSendToFunction::AfterDnsLookup(int lookup_result) { 661 void SocketSendToFunction::AfterDnsLookup(int lookup_result) {
662 if (lookup_result == net::OK) { 662 if (lookup_result == net::OK) {
663 StartSendTo(); 663 StartSendTo();
664 } else { 664 } else {
665 SetResult(base::MakeUnique<base::FundamentalValue>(lookup_result)); 665 SetResult(base::MakeUnique<base::FundamentalValue>(lookup_result));
666 AsyncWorkCompleted(); 666 AsyncWorkCompleted();
667 } 667 }
668
669 // TODO(maksims): investigate why std::unique_ptr<HostResolver::Request>'s
670 // destructor is not called automatically.
671 request_handle_.reset();
668 } 672 }
669 673
670 void SocketSendToFunction::StartSendTo() { 674 void SocketSendToFunction::StartSendTo() {
671 Socket* socket = GetSocket(socket_id_); 675 Socket* socket = GetSocket(socket_id_);
672 if (!socket) { 676 if (!socket) {
673 error_ = kSocketNotFoundError; 677 error_ = kSocketNotFoundError;
674 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); 678 SetResult(base::MakeUnique<base::FundamentalValue>(-1));
675 AsyncWorkCompleted(); 679 AsyncWorkCompleted();
676 return; 680 return;
677 } 681 }
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 } else { 1096 } else {
1093 RemoveSocket(params_->socket_id); 1097 RemoveSocket(params_->socket_id);
1094 error_ = net::ErrorToString(result); 1098 error_ = net::ErrorToString(result);
1095 } 1099 }
1096 1100
1097 results_ = api::socket::Secure::Results::Create(result); 1101 results_ = api::socket::Secure::Results::Create(result);
1098 AsyncWorkCompleted(); 1102 AsyncWorkCompleted();
1099 } 1103 }
1100 1104
1101 } // namespace extensions 1105 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698