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

Side by Side Diff: net/proxy/proxy_resolver_v8_tracing.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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "net/proxy/proxy_resolver_v8_tracing.h" 5 #include "net/proxy/proxy_resolver_v8_tracing.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // Whether the current execution needs to be restarted in blocking mode. 277 // Whether the current execution needs to be restarted in blocking mode.
278 bool should_restart_with_blocking_dns_; 278 bool should_restart_with_blocking_dns_;
279 279
280 // --------------------------------------------------------------------------- 280 // ---------------------------------------------------------------------------
281 // State for pending DNS request. 281 // State for pending DNS request.
282 // --------------------------------------------------------------------------- 282 // ---------------------------------------------------------------------------
283 283
284 // Handle to the outstanding request in the HostResolver, or NULL. 284 // Handle to the outstanding request in the HostResolver, or NULL.
285 // This is mutated and used on the origin thread, however it may be read by 285 // This is mutated and used on the origin thread, however it may be read by
286 // the worker thread for some DCHECKS(). 286 // the worker thread for some DCHECKS().
287 HostResolver::RequestHandle pending_dns_; 287 std::unique_ptr<HostResolver::Request> pending_dns_;
288 288
289 // Indicates if the outstanding DNS request completed synchronously. Written 289 // Indicates if the outstanding DNS request completed synchronously. Written
290 // on the origin thread, and read by the worker thread. 290 // on the origin thread, and read by the worker thread.
291 bool pending_dns_completed_synchronously_; 291 bool pending_dns_completed_synchronously_;
292 292
293 // These are the inputs to DoDnsOperation(). Written on the worker thread, 293 // These are the inputs to DoDnsOperation(). Written on the worker thread,
294 // read by the origin thread. 294 // read by the origin thread.
295 std::string pending_dns_host_; 295 std::string pending_dns_host_;
296 ResolveDnsOperation pending_dns_op_; 296 ResolveDnsOperation pending_dns_op_;
297 297
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 }; 332 };
333 333
334 Job::Job(const Job::Params* params, 334 Job::Job(const Job::Params* params,
335 std::unique_ptr<ProxyResolverV8Tracing::Bindings> bindings) 335 std::unique_ptr<ProxyResolverV8Tracing::Bindings> bindings)
336 : origin_runner_(base::ThreadTaskRunnerHandle::Get()), 336 : origin_runner_(base::ThreadTaskRunnerHandle::Get()),
337 params_(params), 337 params_(params),
338 bindings_(std::move(bindings)), 338 bindings_(std::move(bindings)),
339 event_(base::WaitableEvent::ResetPolicy::MANUAL, 339 event_(base::WaitableEvent::ResetPolicy::MANUAL,
340 base::WaitableEvent::InitialState::NOT_SIGNALED), 340 base::WaitableEvent::InitialState::NOT_SIGNALED),
341 last_num_dns_(0), 341 last_num_dns_(0),
342 pending_dns_(NULL) { 342 pending_dns_(nullptr) {
343 CheckIsOnOriginThread(); 343 CheckIsOnOriginThread();
344 } 344 }
345 345
346 void Job::StartCreateV8Resolver( 346 void Job::StartCreateV8Resolver(
347 const scoped_refptr<ProxyResolverScriptData>& script_data, 347 const scoped_refptr<ProxyResolverScriptData>& script_data,
348 std::unique_ptr<ProxyResolverV8>* resolver, 348 std::unique_ptr<ProxyResolverV8>* resolver,
349 const CompletionCallback& callback) { 349 const CompletionCallback& callback) {
350 CheckIsOnOriginThread(); 350 CheckIsOnOriginThread();
351 351
352 resolver_out_ = resolver; 352 resolver_out_ = resolver;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 // origin thread to notify the caller. 388 // origin thread to notify the caller.
389 // 389 //
390 // |cancelled_| is read on both the origin thread and worker thread. The 390 // |cancelled_| is read on both the origin thread and worker thread. The
391 // code that runs on the worker thread is littered with checks on 391 // code that runs on the worker thread is littered with checks on
392 // |cancelled_| to break out early. 392 // |cancelled_| to break out early.
393 cancelled_.Set(); 393 cancelled_.Set();
394 394
395 ReleaseCallback(); 395 ReleaseCallback();
396 396
397 if (pending_dns_) { 397 if (pending_dns_) {
398 host_resolver()->CancelRequest(pending_dns_); 398 pending_dns_.reset();
399 pending_dns_ = NULL;
400 } 399 }
401 400
402 // The worker thread might be blocked waiting for DNS. 401 // The worker thread might be blocked waiting for DNS.
403 event_.Signal(); 402 event_.Signal();
404 403
405 bindings_.reset(); 404 bindings_.reset();
406 owned_self_reference_ = NULL; 405 owned_self_reference_ = NULL;
407 } 406 }
408 407
409 LoadState Job::GetLoadState() const { 408 LoadState Job::GetLoadState() const {
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 return true; 702 return true;
704 } 703 }
705 704
706 void Job::DoDnsOperation() { 705 void Job::DoDnsOperation() {
707 CheckIsOnOriginThread(); 706 CheckIsOnOriginThread();
708 DCHECK(!pending_dns_); 707 DCHECK(!pending_dns_);
709 708
710 if (cancelled_.IsSet()) 709 if (cancelled_.IsSet())
711 return; 710 return;
712 711
713 HostResolver::RequestHandle dns_request = NULL; 712 std::unique_ptr<HostResolver::Request> dns_request;
714 int result = host_resolver()->Resolve( 713 int result = host_resolver()->Resolve(
715 MakeDnsRequestInfo(pending_dns_host_, pending_dns_op_), DEFAULT_PRIORITY, 714 MakeDnsRequestInfo(pending_dns_host_, pending_dns_op_), DEFAULT_PRIORITY,
716 &pending_dns_addresses_, base::Bind(&Job::OnDnsOperationComplete, this), 715 &pending_dns_addresses_, base::Bind(&Job::OnDnsOperationComplete, this),
717 &dns_request, bindings_->GetBoundNetLog()); 716 &dns_request, bindings_->GetBoundNetLog());
718 717
719 pending_dns_completed_synchronously_ = result != ERR_IO_PENDING; 718 pending_dns_completed_synchronously_ = result != ERR_IO_PENDING;
720 719
721 // Check if the request was cancelled as a side-effect of calling into the 720 // Check if the request was cancelled as a side-effect of calling into the
722 // HostResolver. This isn't the ordinary execution flow, however it is 721 // HostResolver. This isn't the ordinary execution flow, however it is
723 // exercised by unit-tests. 722 // exercised by unit-tests.
724 if (cancelled_.IsSet()) 723 if (cancelled_.IsSet())
725 return; 724 return;
726 725
727 if (pending_dns_completed_synchronously_) { 726 if (pending_dns_completed_synchronously_) {
728 OnDnsOperationComplete(result); 727 OnDnsOperationComplete(result);
729 } else { 728 } else {
730 DCHECK(dns_request); 729 DCHECK(dns_request);
731 pending_dns_ = dns_request; 730 pending_dns_ = std::move(dns_request);
732 // OnDnsOperationComplete() will be called by host resolver on completion. 731 // OnDnsOperationComplete() will be called by host resolver on completion.
733 } 732 }
734 733
735 if (!blocking_dns_) { 734 if (!blocking_dns_) {
736 // The worker thread always blocks waiting to see if the result can be 735 // The worker thread always blocks waiting to see if the result can be
737 // serviced from cache before restarting. 736 // serviced from cache before restarting.
738 event_.Signal(); 737 event_.Signal();
739 } 738 }
740 } 739 }
741 740
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 1096
1098 } // namespace 1097 } // namespace
1099 1098
1100 // static 1099 // static
1101 std::unique_ptr<ProxyResolverV8TracingFactory> 1100 std::unique_ptr<ProxyResolverV8TracingFactory>
1102 ProxyResolverV8TracingFactory::Create() { 1101 ProxyResolverV8TracingFactory::Create() {
1103 return base::WrapUnique(new ProxyResolverV8TracingFactoryImpl()); 1102 return base::WrapUnique(new ProxyResolverV8TracingFactoryImpl());
1104 } 1103 }
1105 1104
1106 } // namespace net 1105 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698