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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/synchronization/cancellation_flag.h" | 10 #include "base/synchronization/cancellation_flag.h" |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 } | 652 } |
653 | 653 |
654 void ProxyResolverV8Tracing::Job::DoDnsOperation( | 654 void ProxyResolverV8Tracing::Job::DoDnsOperation( |
655 const std::string& host, ResolveDnsOperation op, bool* out_cache_hit) { | 655 const std::string& host, ResolveDnsOperation op, bool* out_cache_hit) { |
656 CheckIsOnOriginThread(); | 656 CheckIsOnOriginThread(); |
657 DCHECK(!pending_dns_); | 657 DCHECK(!pending_dns_); |
658 | 658 |
659 if (cancelled_.IsSet()) | 659 if (cancelled_.IsSet()) |
660 return; | 660 return; |
661 | 661 |
| 662 HostResolver::RequestHandle dns_request = NULL; |
662 int result = host_resolver()->Resolve( | 663 int result = host_resolver()->Resolve( |
663 MakeDnsRequestInfo(host, op), | 664 MakeDnsRequestInfo(host, op), |
664 &pending_dns_addresses_, | 665 &pending_dns_addresses_, |
665 base::Bind(&Job::OnDnsOperationComplete, this), | 666 base::Bind(&Job::OnDnsOperationComplete, this), |
666 &pending_dns_, | 667 &dns_request, |
667 bound_net_log_); | 668 bound_net_log_); |
668 | 669 |
669 bool completed_synchronously = result != ERR_IO_PENDING; | 670 bool completed_synchronously = result != ERR_IO_PENDING; |
670 | 671 |
| 672 // Check if the request was cancelled as a side-effect of calling into the |
| 673 // HostResolver. This isn't the ordinary execution flow, however it is |
| 674 // exercised by unit-tests. |
| 675 if (cancelled_.IsSet()) { |
| 676 if (!completed_synchronously) |
| 677 host_resolver()->CancelRequest(dns_request); |
| 678 return; |
| 679 } |
| 680 |
| 681 if (!completed_synchronously) { |
| 682 DCHECK(dns_request); |
| 683 pending_dns_ = dns_request; |
| 684 } |
| 685 |
671 if (!blocking_dns_) { | 686 if (!blocking_dns_) { |
672 // Check if the DNS result can be serviced directly from the cache. | 687 // Check if the DNS result can be serviced directly from the cache. |
673 // (The worker thread is blocked waiting for this information). | 688 // (The worker thread is blocked waiting for this information). |
674 if (completed_synchronously) { | 689 if (completed_synchronously) |
675 SaveDnsToLocalCache(host, op, result, pending_dns_addresses_); | 690 SaveDnsToLocalCache(host, op, result, pending_dns_addresses_); |
676 pending_dns_ = NULL; | |
677 } | |
678 | 691 |
679 // Important: Do not read/write |out_cache_hit| after signalling, since | 692 // Important: Do not read/write |out_cache_hit| after signalling, since |
680 // the memory may no longer be valid. | 693 // the memory may no longer be valid. |
681 *out_cache_hit = completed_synchronously; | 694 *out_cache_hit = completed_synchronously; |
682 event_.Signal(); | 695 event_.Signal(); |
683 | 696 |
684 if (completed_synchronously) | 697 if (completed_synchronously) |
685 return; | 698 return; |
686 } | 699 } |
687 | 700 |
688 pending_dns_host_ = host; | 701 pending_dns_host_ = host; |
689 pending_dns_op_ = op; | 702 pending_dns_op_ = op; |
690 | 703 |
691 if (completed_synchronously) | 704 if (completed_synchronously) |
692 OnDnsOperationComplete(result); | 705 OnDnsOperationComplete(result); |
693 } | 706 } |
694 | 707 |
695 void ProxyResolverV8Tracing::Job::OnDnsOperationComplete(int result) { | 708 void ProxyResolverV8Tracing::Job::OnDnsOperationComplete(int result) { |
696 CheckIsOnOriginThread(); | 709 CheckIsOnOriginThread(); |
697 | 710 |
698 DCHECK(pending_dns_); | |
699 DCHECK(!cancelled_.IsSet()); | 711 DCHECK(!cancelled_.IsSet()); |
700 | 712 |
701 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result, | 713 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result, |
702 pending_dns_addresses_); | 714 pending_dns_addresses_); |
703 pending_dns_ = NULL; | 715 pending_dns_ = NULL; |
704 | 716 |
705 if (!blocking_dns_) { | 717 if (!blocking_dns_) { |
706 // Restart. This time it should make more progress due to having | 718 // Restart. This time it should make more progress due to having |
707 // cached items. | 719 // cached items. |
708 worker_loop()->PostTask(FROM_HERE, | 720 worker_loop()->PostTask(FROM_HERE, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 DCHECK(!set_pac_script_job_); | 987 DCHECK(!set_pac_script_job_); |
976 CHECK_EQ(0, num_outstanding_callbacks_); | 988 CHECK_EQ(0, num_outstanding_callbacks_); |
977 | 989 |
978 set_pac_script_job_ = new Job(this); | 990 set_pac_script_job_ = new Job(this); |
979 set_pac_script_job_->StartSetPacScript(script_data, callback); | 991 set_pac_script_job_->StartSetPacScript(script_data, callback); |
980 | 992 |
981 return ERR_IO_PENDING; | 993 return ERR_IO_PENDING; |
982 } | 994 } |
983 | 995 |
984 } // namespace net | 996 } // namespace net |
OLD | NEW |