Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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_() { |
|
mmenke
2016/07/19 19:03:56
Not needed.
maksims (do not use this acc)
2016/07/21 07:12:46
Done.
| |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 // (f) The script execution completed entirely, and posted a task to the | 387 // (f) The script execution completed entirely, and posted a task to the |
| 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_) |
|
mmenke
2016/07/19 19:03:56
Can get rid of this check
maksims (do not use this acc)
2016/07/21 07:12:46
Done.
| |
| 398 host_resolver()->CancelRequest(pending_dns_); | 398 pending_dns_.reset(); |
| 399 pending_dns_ = NULL; | |
| 400 } | |
| 401 | 399 |
| 402 // The worker thread might be blocked waiting for DNS. | 400 // The worker thread might be blocked waiting for DNS. |
| 403 event_.Signal(); | 401 event_.Signal(); |
| 404 | 402 |
| 405 bindings_.reset(); | 403 bindings_.reset(); |
| 406 owned_self_reference_ = NULL; | 404 owned_self_reference_ = NULL; |
| 407 } | 405 } |
| 408 | 406 |
| 409 LoadState Job::GetLoadState() const { | 407 LoadState Job::GetLoadState() const { |
| 410 CheckIsOnOriginThread(); | 408 CheckIsOnOriginThread(); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 return true; | 701 return true; |
| 704 } | 702 } |
| 705 | 703 |
| 706 void Job::DoDnsOperation() { | 704 void Job::DoDnsOperation() { |
| 707 CheckIsOnOriginThread(); | 705 CheckIsOnOriginThread(); |
| 708 DCHECK(!pending_dns_); | 706 DCHECK(!pending_dns_); |
| 709 | 707 |
| 710 if (cancelled_.IsSet()) | 708 if (cancelled_.IsSet()) |
| 711 return; | 709 return; |
| 712 | 710 |
| 713 HostResolver::RequestHandle dns_request = NULL; | 711 std::unique_ptr<HostResolver::Request> dns_request; |
| 714 int result = host_resolver()->Resolve( | 712 int result = host_resolver()->Resolve( |
| 715 MakeDnsRequestInfo(pending_dns_host_, pending_dns_op_), DEFAULT_PRIORITY, | 713 MakeDnsRequestInfo(pending_dns_host_, pending_dns_op_), DEFAULT_PRIORITY, |
| 716 &pending_dns_addresses_, base::Bind(&Job::OnDnsOperationComplete, this), | 714 &pending_dns_addresses_, base::Bind(&Job::OnDnsOperationComplete, this), |
| 717 &dns_request, bindings_->GetBoundNetLog()); | 715 &dns_request, bindings_->GetBoundNetLog()); |
| 718 | 716 |
| 719 pending_dns_completed_synchronously_ = result != ERR_IO_PENDING; | 717 pending_dns_completed_synchronously_ = result != ERR_IO_PENDING; |
| 720 | 718 |
| 721 // Check if the request was cancelled as a side-effect of calling into the | 719 // 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 | 720 // HostResolver. This isn't the ordinary execution flow, however it is |
| 723 // exercised by unit-tests. | 721 // exercised by unit-tests. |
| 724 if (cancelled_.IsSet()) | 722 if (cancelled_.IsSet()) |
| 725 return; | 723 return; |
| 726 | 724 |
| 727 if (pending_dns_completed_synchronously_) { | 725 if (pending_dns_completed_synchronously_) { |
| 728 OnDnsOperationComplete(result); | 726 OnDnsOperationComplete(result); |
| 729 } else { | 727 } else { |
| 730 DCHECK(dns_request); | 728 DCHECK(dns_request); |
| 731 pending_dns_ = dns_request; | 729 pending_dns_ = std::move(dns_request); |
| 732 // OnDnsOperationComplete() will be called by host resolver on completion. | 730 // OnDnsOperationComplete() will be called by host resolver on completion. |
| 733 } | 731 } |
| 734 | 732 |
| 735 if (!blocking_dns_) { | 733 if (!blocking_dns_) { |
| 736 // The worker thread always blocks waiting to see if the result can be | 734 // The worker thread always blocks waiting to see if the result can be |
| 737 // serviced from cache before restarting. | 735 // serviced from cache before restarting. |
| 738 event_.Signal(); | 736 event_.Signal(); |
| 739 } | 737 } |
| 740 } | 738 } |
| 741 | 739 |
| 742 void Job::OnDnsOperationComplete(int result) { | 740 void Job::OnDnsOperationComplete(int result) { |
| 743 CheckIsOnOriginThread(); | 741 CheckIsOnOriginThread(); |
| 744 | 742 |
| 745 DCHECK(!cancelled_.IsSet()); | 743 DCHECK(!cancelled_.IsSet()); |
| 746 DCHECK(pending_dns_completed_synchronously_ == (pending_dns_ == NULL)); | 744 DCHECK(pending_dns_completed_synchronously_ == (pending_dns_ == NULL)); |
| 747 | 745 |
| 748 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result, | 746 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result, |
| 749 pending_dns_addresses_); | 747 pending_dns_addresses_); |
| 750 pending_dns_ = NULL; | 748 pending_dns_.reset(); |
| 751 | 749 |
| 752 if (blocking_dns_) { | 750 if (blocking_dns_) { |
| 753 event_.Signal(); | 751 event_.Signal(); |
| 754 return; | 752 return; |
| 755 } | 753 } |
| 756 | 754 |
| 757 if (!blocking_dns_ && !pending_dns_completed_synchronously_) { | 755 if (!blocking_dns_ && !pending_dns_completed_synchronously_) { |
| 758 // Restart. This time it should make more progress due to having | 756 // Restart. This time it should make more progress due to having |
| 759 // cached items. | 757 // cached items. |
| 760 worker_task_runner()->PostTask(FROM_HERE, | 758 worker_task_runner()->PostTask(FROM_HERE, |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1097 | 1095 |
| 1098 } // namespace | 1096 } // namespace |
| 1099 | 1097 |
| 1100 // static | 1098 // static |
| 1101 std::unique_ptr<ProxyResolverV8TracingFactory> | 1099 std::unique_ptr<ProxyResolverV8TracingFactory> |
| 1102 ProxyResolverV8TracingFactory::Create() { | 1100 ProxyResolverV8TracingFactory::Create() { |
| 1103 return base::WrapUnique(new ProxyResolverV8TracingFactoryImpl()); | 1101 return base::WrapUnique(new ProxyResolverV8TracingFactoryImpl()); |
| 1104 } | 1102 } |
| 1105 | 1103 |
| 1106 } // namespace net | 1104 } // namespace net |
| OLD | NEW |