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

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: http_stream_factory_impl_job_controller_unittest RequestHandle* to unique_ptr Created 4 years, 4 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_;
jochen (gone - plz use gerrit) 2017/03/08 15:22:10 std::unique_ptr cannot be read atomically, and giv
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8TracingImpl); 331 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8TracingImpl);
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) {
343 CheckIsOnOriginThread(); 342 CheckIsOnOriginThread();
344 } 343 }
345 344
346 void Job::StartCreateV8Resolver( 345 void Job::StartCreateV8Resolver(
347 const scoped_refptr<ProxyResolverScriptData>& script_data, 346 const scoped_refptr<ProxyResolverScriptData>& script_data,
348 std::unique_ptr<ProxyResolverV8>* resolver, 347 std::unique_ptr<ProxyResolverV8>* resolver,
349 const CompletionCallback& callback) { 348 const CompletionCallback& callback) {
350 CheckIsOnOriginThread(); 349 CheckIsOnOriginThread();
351 350
352 resolver_out_ = resolver; 351 resolver_out_ = resolver;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 // (f) The script execution completed entirely, and posted a task to the 386 // (f) The script execution completed entirely, and posted a task to the
388 // origin thread to notify the caller. 387 // origin thread to notify the caller.
389 // 388 //
390 // |cancelled_| is read on both the origin thread and worker thread. The 389 // |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 390 // code that runs on the worker thread is littered with checks on
392 // |cancelled_| to break out early. 391 // |cancelled_| to break out early.
393 cancelled_.Set(); 392 cancelled_.Set();
394 393
395 ReleaseCallback(); 394 ReleaseCallback();
396 395
397 if (pending_dns_) { 396 pending_dns_.reset();
398 host_resolver()->CancelRequest(pending_dns_);
399 pending_dns_ = NULL;
400 }
401 397
402 // The worker thread might be blocked waiting for DNS. 398 // The worker thread might be blocked waiting for DNS.
403 event_.Signal(); 399 event_.Signal();
404 400
405 bindings_.reset(); 401 bindings_.reset();
406 owned_self_reference_ = NULL; 402 owned_self_reference_ = NULL;
407 } 403 }
408 404
409 LoadState Job::GetLoadState() const { 405 LoadState Job::GetLoadState() const {
410 CheckIsOnOriginThread(); 406 CheckIsOnOriginThread();
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 return true; 699 return true;
704 } 700 }
705 701
706 void Job::DoDnsOperation() { 702 void Job::DoDnsOperation() {
707 CheckIsOnOriginThread(); 703 CheckIsOnOriginThread();
708 DCHECK(!pending_dns_); 704 DCHECK(!pending_dns_);
709 705
710 if (cancelled_.IsSet()) 706 if (cancelled_.IsSet())
711 return; 707 return;
712 708
713 HostResolver::RequestHandle dns_request = NULL; 709 std::unique_ptr<HostResolver::Request> dns_request;
714 int result = host_resolver()->Resolve( 710 int result = host_resolver()->Resolve(
715 MakeDnsRequestInfo(pending_dns_host_, pending_dns_op_), DEFAULT_PRIORITY, 711 MakeDnsRequestInfo(pending_dns_host_, pending_dns_op_), DEFAULT_PRIORITY,
716 &pending_dns_addresses_, base::Bind(&Job::OnDnsOperationComplete, this), 712 &pending_dns_addresses_, base::Bind(&Job::OnDnsOperationComplete, this),
717 &dns_request, bindings_->GetBoundNetLog()); 713 &dns_request, bindings_->GetBoundNetLog());
718 714
719 pending_dns_completed_synchronously_ = result != ERR_IO_PENDING; 715 pending_dns_completed_synchronously_ = result != ERR_IO_PENDING;
720 716
721 // Check if the request was cancelled as a side-effect of calling into the 717 // 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 718 // HostResolver. This isn't the ordinary execution flow, however it is
723 // exercised by unit-tests. 719 // exercised by unit-tests.
724 if (cancelled_.IsSet()) 720 if (cancelled_.IsSet())
725 return; 721 return;
726 722
727 if (pending_dns_completed_synchronously_) { 723 if (pending_dns_completed_synchronously_) {
728 OnDnsOperationComplete(result); 724 OnDnsOperationComplete(result);
729 } else { 725 } else {
730 DCHECK(dns_request); 726 DCHECK(dns_request);
731 pending_dns_ = dns_request; 727 pending_dns_ = std::move(dns_request);
732 // OnDnsOperationComplete() will be called by host resolver on completion. 728 // OnDnsOperationComplete() will be called by host resolver on completion.
733 } 729 }
734 730
735 if (!blocking_dns_) { 731 if (!blocking_dns_) {
736 // The worker thread always blocks waiting to see if the result can be 732 // The worker thread always blocks waiting to see if the result can be
737 // serviced from cache before restarting. 733 // serviced from cache before restarting.
738 event_.Signal(); 734 event_.Signal();
739 } 735 }
740 } 736 }
741 737
742 void Job::OnDnsOperationComplete(int result) { 738 void Job::OnDnsOperationComplete(int result) {
743 CheckIsOnOriginThread(); 739 CheckIsOnOriginThread();
744 740
745 DCHECK(!cancelled_.IsSet()); 741 DCHECK(!cancelled_.IsSet());
746 DCHECK(pending_dns_completed_synchronously_ == (pending_dns_ == NULL)); 742 DCHECK(pending_dns_completed_synchronously_ == (pending_dns_ == NULL));
747 743
748 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result, 744 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result,
749 pending_dns_addresses_); 745 pending_dns_addresses_);
750 pending_dns_ = NULL; 746 pending_dns_.reset();
751 747
752 if (blocking_dns_) { 748 if (blocking_dns_) {
753 event_.Signal(); 749 event_.Signal();
754 return; 750 return;
755 } 751 }
756 752
757 if (!blocking_dns_ && !pending_dns_completed_synchronously_) { 753 if (!blocking_dns_ && !pending_dns_completed_synchronously_) {
758 // Restart. This time it should make more progress due to having 754 // Restart. This time it should make more progress due to having
759 // cached items. 755 // cached items.
760 worker_task_runner()->PostTask(FROM_HERE, 756 worker_task_runner()->PostTask(FROM_HERE,
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 1093
1098 } // namespace 1094 } // namespace
1099 1095
1100 // static 1096 // static
1101 std::unique_ptr<ProxyResolverV8TracingFactory> 1097 std::unique_ptr<ProxyResolverV8TracingFactory>
1102 ProxyResolverV8TracingFactory::Create() { 1098 ProxyResolverV8TracingFactory::Create() {
1103 return base::WrapUnique(new ProxyResolverV8TracingFactoryImpl()); 1099 return base::WrapUnique(new ProxyResolverV8TracingFactoryImpl());
1104 } 1100 }
1105 1101
1106 } // namespace net 1102 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_factory_mojo_unittest.cc ('k') | net/proxy/proxy_resolver_v8_tracing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698