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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 if (!pending_dns_completed_synchronously_) | 700 if (!pending_dns_completed_synchronously_) |
| 701 host_resolver()->CancelRequest(dns_request); | 701 host_resolver()->CancelRequest(dns_request); |
| 702 return; | 702 return; |
| 703 } | 703 } |
| 704 | 704 |
| 705 if (pending_dns_completed_synchronously_) { | 705 if (pending_dns_completed_synchronously_) { |
| 706 OnDnsOperationComplete(result); | 706 OnDnsOperationComplete(result); |
| 707 } else { | 707 } else { |
| 708 DCHECK(dns_request); | 708 DCHECK(dns_request); |
| 709 pending_dns_ = dns_request; | 709 pending_dns_ = dns_request; |
| 710 if (!parent_->on_load_state_changed_.is_null()) { | |
| 711 parent_->on_load_state_changed_.Run( | |
| 712 this, LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT); | |
| 713 } | |
| 710 // OnDnsOperationComplete() will be called by host resolver on completion. | 714 // OnDnsOperationComplete() will be called by host resolver on completion. |
| 711 } | 715 } |
| 712 | 716 |
| 713 if (!blocking_dns_) { | 717 if (!blocking_dns_) { |
| 714 // The worker thread always blocks waiting to see if the result can be | 718 // The worker thread always blocks waiting to see if the result can be |
| 715 // serviced from cache before restarting. | 719 // serviced from cache before restarting. |
| 716 event_.Signal(); | 720 event_.Signal(); |
| 717 } | 721 } |
| 718 } | 722 } |
| 719 | 723 |
| 720 void ProxyResolverV8Tracing::Job::OnDnsOperationComplete(int result) { | 724 void ProxyResolverV8Tracing::Job::OnDnsOperationComplete(int result) { |
| 721 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. | 725 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. |
| 722 tracked_objects::ScopedTracker tracking_profile( | 726 tracked_objects::ScopedTracker tracking_profile( |
| 723 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 727 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 724 "436634 ProxyResolverV8Tracing::Job::OnDnsOperationComplete")); | 728 "436634 ProxyResolverV8Tracing::Job::OnDnsOperationComplete")); |
| 725 | 729 |
| 726 CheckIsOnOriginThread(); | 730 CheckIsOnOriginThread(); |
| 727 | 731 |
| 728 DCHECK(!cancelled_.IsSet()); | 732 DCHECK(!cancelled_.IsSet()); |
| 729 DCHECK(pending_dns_completed_synchronously_ == (pending_dns_ == NULL)); | 733 DCHECK(pending_dns_completed_synchronously_ == (pending_dns_ == NULL)); |
| 730 | 734 |
| 731 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result, | 735 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result, |
| 732 pending_dns_addresses_); | 736 pending_dns_addresses_); |
| 733 pending_dns_ = NULL; | 737 pending_dns_ = NULL; |
| 734 | 738 |
| 739 if (!pending_dns_completed_synchronously_ && !cancelled_.IsSet() && | |
| 740 !parent_->on_load_state_changed_.is_null()) { | |
|
eroman
2015/03/06 05:13:02
nit: can you move this check to be the first?
Sam McNally
2015/03/06 09:33:02
Done.
| |
| 741 parent_->on_load_state_changed_.Run(this, | |
| 742 LOAD_STATE_RESOLVING_PROXY_FOR_URL); | |
| 743 } | |
| 744 | |
| 735 if (blocking_dns_) { | 745 if (blocking_dns_) { |
| 736 event_.Signal(); | 746 event_.Signal(); |
| 737 return; | 747 return; |
| 738 } | 748 } |
| 739 | 749 |
| 740 if (!blocking_dns_ && !pending_dns_completed_synchronously_) { | 750 if (!blocking_dns_ && !pending_dns_completed_synchronously_) { |
| 741 // Restart. This time it should make more progress due to having | 751 // Restart. This time it should make more progress due to having |
| 742 // cached items. | 752 // cached items. |
| 743 worker_loop()->PostTask(FROM_HERE, | 753 worker_loop()->PostTask(FROM_HERE, |
| 744 base::Bind(&Job::ExecuteNonBlocking, this)); | 754 base::Bind(&Job::ExecuteNonBlocking, this)); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 927 | 937 |
| 928 // Emit to the global NetLog event stream. | 938 // Emit to the global NetLog event stream. |
| 929 if (net_log()) | 939 if (net_log()) |
| 930 net_log()->AddGlobalEntry(type, parameters_callback); | 940 net_log()->AddGlobalEntry(type, parameters_callback); |
| 931 } | 941 } |
| 932 | 942 |
| 933 ProxyResolverV8Tracing::ProxyResolverV8Tracing( | 943 ProxyResolverV8Tracing::ProxyResolverV8Tracing( |
| 934 HostResolver* host_resolver, | 944 HostResolver* host_resolver, |
| 935 ProxyResolverErrorObserver* error_observer, | 945 ProxyResolverErrorObserver* error_observer, |
| 936 NetLog* net_log) | 946 NetLog* net_log) |
| 947 : ProxyResolverV8Tracing(host_resolver, | |
| 948 error_observer, | |
| 949 net_log, | |
| 950 LoadStateChangedCallback<RequestHandle>()) { | |
| 951 } | |
| 952 | |
| 953 ProxyResolverV8Tracing::ProxyResolverV8Tracing( | |
| 954 HostResolver* host_resolver, | |
| 955 ProxyResolverErrorObserver* error_observer, | |
| 956 NetLog* net_log, | |
| 957 const LoadStateChangedCallback<RequestHandle>& on_load_state_changed) | |
| 937 : ProxyResolver(true /*expects_pac_bytes*/), | 958 : ProxyResolver(true /*expects_pac_bytes*/), |
| 938 host_resolver_(host_resolver), | 959 host_resolver_(host_resolver), |
| 939 error_observer_(error_observer), | 960 error_observer_(error_observer), |
| 940 net_log_(net_log), | 961 net_log_(net_log), |
| 941 num_outstanding_callbacks_(0) { | 962 num_outstanding_callbacks_(0), |
| 963 on_load_state_changed_(on_load_state_changed) { | |
| 942 DCHECK(host_resolver); | 964 DCHECK(host_resolver); |
| 943 // Start up the thread. | 965 // Start up the thread. |
| 944 thread_.reset(new base::Thread("Proxy resolver")); | 966 thread_.reset(new base::Thread("Proxy resolver")); |
| 945 base::Thread::Options options; | 967 base::Thread::Options options; |
| 946 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 968 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 947 CHECK(thread_->StartWithOptions(options)); | 969 CHECK(thread_->StartWithOptions(options)); |
| 948 | 970 |
| 949 v8_resolver_.reset(new ProxyResolverV8); | 971 v8_resolver_.reset(new ProxyResolverV8); |
| 950 } | 972 } |
| 951 | 973 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 DCHECK(!set_pac_script_job_.get()); | 1029 DCHECK(!set_pac_script_job_.get()); |
| 1008 CHECK_EQ(0, num_outstanding_callbacks_); | 1030 CHECK_EQ(0, num_outstanding_callbacks_); |
| 1009 | 1031 |
| 1010 set_pac_script_job_ = new Job(this); | 1032 set_pac_script_job_ = new Job(this); |
| 1011 set_pac_script_job_->StartSetPacScript(script_data, callback); | 1033 set_pac_script_job_->StartSetPacScript(script_data, callback); |
| 1012 | 1034 |
| 1013 return ERR_IO_PENDING; | 1035 return ERR_IO_PENDING; |
| 1014 } | 1036 } |
| 1015 | 1037 |
| 1016 } // namespace net | 1038 } // namespace net |
| OLD | NEW |