OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 // Returns true if Cancel() has been called. | 861 // Returns true if Cancel() has been called. |
862 bool was_cancelled() const { | 862 bool was_cancelled() const { |
863 return user_callback_.is_null(); | 863 return user_callback_.is_null(); |
864 } | 864 } |
865 | 865 |
866 // Helper to call after ProxyResolver completion (both synchronous and | 866 // Helper to call after ProxyResolver completion (both synchronous and |
867 // asynchronous). Fixes up the result that is to be returned to user. | 867 // asynchronous). Fixes up the result that is to be returned to user. |
868 int QueryDidComplete(int result_code) { | 868 int QueryDidComplete(int result_code) { |
869 DCHECK(!was_cancelled()); | 869 DCHECK(!was_cancelled()); |
870 | 870 |
| 871 // Clear |resolve_job_| so is_started() returns false while |
| 872 // DidFinishResolvingProxy() runs. |
| 873 resolve_job_ = nullptr; |
| 874 |
871 // Note that DidFinishResolvingProxy might modify |results_|. | 875 // Note that DidFinishResolvingProxy might modify |results_|. |
872 int rv = service_->DidFinishResolvingProxy(url_, load_flags_, | 876 int rv = service_->DidFinishResolvingProxy(url_, load_flags_, |
873 network_delegate_, results_, | 877 network_delegate_, results_, |
874 result_code, net_log_); | 878 result_code, net_log_); |
875 | 879 |
876 // Make a note in the results which configuration was in use at the | 880 // Make a note in the results which configuration was in use at the |
877 // time of the resolve. | 881 // time of the resolve. |
878 results_->config_id_ = config_id_; | 882 results_->config_id_ = config_id_; |
879 results_->config_source_ = config_source_; | 883 results_->config_source_ = config_source_; |
880 results_->did_use_pac_script_ = true; | 884 results_->did_use_pac_script_ = true; |
881 results_->proxy_resolve_start_time_ = proxy_resolve_start_time_; | 885 results_->proxy_resolve_start_time_ = proxy_resolve_start_time_; |
882 results_->proxy_resolve_end_time_ = TimeTicks::Now(); | 886 results_->proxy_resolve_end_time_ = TimeTicks::Now(); |
883 | 887 |
884 // Reset the state associated with in-progress-resolve. | 888 // Reset the state associated with in-progress-resolve. |
885 resolve_job_ = NULL; | |
886 config_id_ = ProxyConfig::kInvalidConfigID; | 889 config_id_ = ProxyConfig::kInvalidConfigID; |
887 config_source_ = PROXY_CONFIG_SOURCE_UNKNOWN; | 890 config_source_ = PROXY_CONFIG_SOURCE_UNKNOWN; |
888 | 891 |
889 return rv; | 892 return rv; |
890 } | 893 } |
891 | 894 |
892 BoundNetLog* net_log() { return &net_log_; } | 895 BoundNetLog* net_log() { return &net_log_; } |
893 | 896 |
894 LoadState GetLoadState() const { | 897 LoadState GetLoadState() const { |
895 if (is_started()) | 898 if (is_started()) |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 if (net_log.GetCaptureMode().enabled()) { | 1395 if (net_log.GetCaptureMode().enabled()) { |
1393 net_log.AddEvent( | 1396 net_log.AddEvent( |
1394 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 1397 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, |
1395 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); | 1398 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); |
1396 } | 1399 } |
1397 result->DeprioritizeBadProxies(proxy_retry_info_); | 1400 result->DeprioritizeBadProxies(proxy_retry_info_); |
1398 } else { | 1401 } else { |
1399 net_log.AddEventWithNetErrorCode( | 1402 net_log.AddEventWithNetErrorCode( |
1400 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, result_code); | 1403 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, result_code); |
1401 | 1404 |
| 1405 bool reset_config = result_code == ERR_PAC_SCRIPT_TERMINATED; |
1402 if (!config_.pac_mandatory()) { | 1406 if (!config_.pac_mandatory()) { |
1403 // Fall-back to direct when the proxy resolver fails. This corresponds | 1407 // Fall-back to direct when the proxy resolver fails. This corresponds |
1404 // with a javascript runtime error in the PAC script. | 1408 // with a javascript runtime error in the PAC script. |
1405 // | 1409 // |
1406 // This implicit fall-back to direct matches Firefox 3.5 and | 1410 // This implicit fall-back to direct matches Firefox 3.5 and |
1407 // Internet Explorer 8. For more information, see: | 1411 // Internet Explorer 8. For more information, see: |
1408 // | 1412 // |
1409 // http://www.chromium.org/developers/design-documents/proxy-settings-fall
back | 1413 // http://www.chromium.org/developers/design-documents/proxy-settings-fall
back |
1410 result->UseDirect(); | 1414 result->UseDirect(); |
1411 result_code = OK; | 1415 result_code = OK; |
1412 | 1416 |
1413 // Allow the network delegate to interpose on the resolution decision, | 1417 // Allow the network delegate to interpose on the resolution decision, |
1414 // possibly modifying the ProxyInfo. | 1418 // possibly modifying the ProxyInfo. |
1415 if (network_delegate) | 1419 if (network_delegate) |
1416 network_delegate->NotifyResolveProxy(url, load_flags, *this, result); | 1420 network_delegate->NotifyResolveProxy(url, load_flags, *this, result); |
1417 } else { | 1421 } else { |
1418 result_code = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED; | 1422 result_code = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED; |
1419 } | 1423 } |
| 1424 if (reset_config) { |
| 1425 ResetProxyConfig(false); |
| 1426 // If the ProxyResolver crashed, force it to be re-initialized for the |
| 1427 // next request by resetting the proxy config. If there are other pending |
| 1428 // requests, trigger the recreation immediately so those requests retry. |
| 1429 if (pending_requests_.size() > 1) |
| 1430 ApplyProxyConfigIfAvailable(); |
| 1431 } |
1420 } | 1432 } |
1421 | 1433 |
1422 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE); | 1434 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE); |
1423 return result_code; | 1435 return result_code; |
1424 } | 1436 } |
1425 | 1437 |
1426 void ProxyService::SetProxyScriptFetchers( | 1438 void ProxyService::SetProxyScriptFetchers( |
1427 ProxyScriptFetcher* proxy_script_fetcher, | 1439 ProxyScriptFetcher* proxy_script_fetcher, |
1428 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher) { | 1440 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher) { |
1429 DCHECK(CalledOnValidThread()); | 1441 DCHECK(CalledOnValidThread()); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 State previous_state = ResetProxyConfig(false); | 1643 State previous_state = ResetProxyConfig(false); |
1632 if (previous_state != STATE_NONE) | 1644 if (previous_state != STATE_NONE) |
1633 ApplyProxyConfigIfAvailable(); | 1645 ApplyProxyConfigIfAvailable(); |
1634 } | 1646 } |
1635 | 1647 |
1636 void ProxyService::OnDNSChanged() { | 1648 void ProxyService::OnDNSChanged() { |
1637 OnIPAddressChanged(); | 1649 OnIPAddressChanged(); |
1638 } | 1650 } |
1639 | 1651 |
1640 } // namespace net | 1652 } // namespace net |
OLD | NEW |