| 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 (!parent_->on_load_state_changed_.is_null() && |
| 740 !pending_dns_completed_synchronously_ && !cancelled_.IsSet()) { |
| 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()) { |
| 951 } |
| 952 |
| 953 ProxyResolverV8Tracing::ProxyResolverV8Tracing( |
| 954 HostResolver* host_resolver, |
| 955 ProxyResolverErrorObserver* error_observer, |
| 956 NetLog* net_log, |
| 957 const LoadStateChangedCallback& 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 // TODO(eroman): Remove once crbug.com/454983 is fixed. | 964 // TODO(eroman): Remove once crbug.com/454983 is fixed. |
| 943 tracked_objects::ScopedTracker tracking_profile( | 965 tracked_objects::ScopedTracker tracking_profile( |
| 944 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 966 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 945 "454983 ProxyResolverV8Tracing::ProxyResolverV8Tracing")); | 967 "454983 ProxyResolverV8Tracing::ProxyResolverV8Tracing")); |
| 946 | 968 |
| 947 DCHECK(host_resolver); | 969 DCHECK(host_resolver); |
| 948 // Start up the thread. | 970 // Start up the thread. |
| 949 thread_.reset(new base::Thread("Proxy resolver")); | 971 thread_.reset(new base::Thread("Proxy resolver")); |
| 950 base::Thread::Options options; | 972 base::Thread::Options options; |
| 951 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 973 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 DCHECK(!set_pac_script_job_.get()); | 1034 DCHECK(!set_pac_script_job_.get()); |
| 1013 CHECK_EQ(0, num_outstanding_callbacks_); | 1035 CHECK_EQ(0, num_outstanding_callbacks_); |
| 1014 | 1036 |
| 1015 set_pac_script_job_ = new Job(this); | 1037 set_pac_script_job_ = new Job(this); |
| 1016 set_pac_script_job_->StartSetPacScript(script_data, callback); | 1038 set_pac_script_job_->StartSetPacScript(script_data, callback); |
| 1017 | 1039 |
| 1018 return ERR_IO_PENDING; | 1040 return ERR_IO_PENDING; |
| 1019 } | 1041 } |
| 1020 | 1042 |
| 1021 } // namespace net | 1043 } // namespace net |
| OLD | NEW |