| 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 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 25 #include "base/values.h" | 25 #include "base/values.h" |
| 26 #include "net/base/completion_callback.h" | 26 #include "net/base/completion_callback.h" |
| 27 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 28 #include "net/base/proxy_delegate.h" | 28 #include "net/base/proxy_delegate.h" |
| 29 #include "net/base/url_util.h" | 29 #include "net/base/url_util.h" |
| 30 #include "net/log/net_log.h" | 30 #include "net/log/net_log.h" |
| 31 #include "net/log/net_log_event_type.h" |
| 31 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 32 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
| 32 #include "net/proxy/multi_threaded_proxy_resolver.h" | 33 #include "net/proxy/multi_threaded_proxy_resolver.h" |
| 33 #include "net/proxy/proxy_config_service_fixed.h" | 34 #include "net/proxy/proxy_config_service_fixed.h" |
| 34 #include "net/proxy/proxy_resolver.h" | 35 #include "net/proxy/proxy_resolver.h" |
| 35 #include "net/proxy/proxy_resolver_factory.h" | 36 #include "net/proxy/proxy_resolver_factory.h" |
| 36 #include "net/proxy/proxy_script_decider.h" | 37 #include "net/proxy/proxy_script_decider.h" |
| 37 #include "net/proxy/proxy_script_fetcher.h" | 38 #include "net/proxy/proxy_script_fetcher.h" |
| 38 #include "net/url_request/url_request_context.h" | 39 #include "net/url_request/url_request_context.h" |
| 39 #include "url/gurl.h" | 40 #include "url/gurl.h" |
| 40 | 41 |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 | 839 |
| 839 void CancelResolveJob() { | 840 void CancelResolveJob() { |
| 840 DCHECK(is_started()); | 841 DCHECK(is_started()); |
| 841 // The request may already be running in the resolver. | 842 // The request may already be running in the resolver. |
| 842 resolver()->CancelRequest(resolve_job_); | 843 resolver()->CancelRequest(resolve_job_); |
| 843 resolve_job_ = NULL; | 844 resolve_job_ = NULL; |
| 844 DCHECK(!is_started()); | 845 DCHECK(!is_started()); |
| 845 } | 846 } |
| 846 | 847 |
| 847 void Cancel() { | 848 void Cancel() { |
| 848 net_log_.AddEvent(NetLog::TYPE_CANCELLED); | 849 net_log_.AddEvent(NetLogEventType::CANCELLED); |
| 849 | 850 |
| 850 if (is_started()) | 851 if (is_started()) |
| 851 CancelResolveJob(); | 852 CancelResolveJob(); |
| 852 | 853 |
| 853 // Mark as cancelled, to prevent accessing this again later. | 854 // Mark as cancelled, to prevent accessing this again later. |
| 854 service_ = NULL; | 855 service_ = NULL; |
| 855 user_callback_.Reset(); | 856 user_callback_.Reset(); |
| 856 results_ = NULL; | 857 results_ = NULL; |
| 857 | 858 |
| 858 net_log_.EndEvent(NetLog::TYPE_PROXY_SERVICE); | 859 net_log_.EndEvent(NetLogEventType::PROXY_SERVICE); |
| 859 } | 860 } |
| 860 | 861 |
| 861 // Returns true if Cancel() has been called. | 862 // Returns true if Cancel() has been called. |
| 862 bool was_cancelled() const { | 863 bool was_cancelled() const { |
| 863 return user_callback_.is_null(); | 864 return user_callback_.is_null(); |
| 864 } | 865 } |
| 865 | 866 |
| 866 // Helper to call after ProxyResolver completion (both synchronous and | 867 // Helper to call after ProxyResolver completion (both synchronous and |
| 867 // asynchronous). Fixes up the result that is to be returned to user. | 868 // asynchronous). Fixes up the result that is to be returned to user. |
| 868 int QueryDidComplete(int result_code) { | 869 int QueryDidComplete(int result_code) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 | 1048 |
| 1048 int ProxyService::ResolveProxyHelper(const GURL& raw_url, | 1049 int ProxyService::ResolveProxyHelper(const GURL& raw_url, |
| 1049 const std::string& method, | 1050 const std::string& method, |
| 1050 ProxyInfo* result, | 1051 ProxyInfo* result, |
| 1051 const CompletionCallback& callback, | 1052 const CompletionCallback& callback, |
| 1052 PacRequest** pac_request, | 1053 PacRequest** pac_request, |
| 1053 ProxyDelegate* proxy_delegate, | 1054 ProxyDelegate* proxy_delegate, |
| 1054 const BoundNetLog& net_log) { | 1055 const BoundNetLog& net_log) { |
| 1055 DCHECK(CalledOnValidThread()); | 1056 DCHECK(CalledOnValidThread()); |
| 1056 | 1057 |
| 1057 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE); | 1058 net_log.BeginEvent(NetLogEventType::PROXY_SERVICE); |
| 1058 | 1059 |
| 1059 // Notify our polling-based dependencies that a resolve is taking place. | 1060 // Notify our polling-based dependencies that a resolve is taking place. |
| 1060 // This way they can schedule their polls in response to network activity. | 1061 // This way they can schedule their polls in response to network activity. |
| 1061 config_service_->OnLazyPoll(); | 1062 config_service_->OnLazyPoll(); |
| 1062 if (script_poller_.get()) | 1063 if (script_poller_.get()) |
| 1063 script_poller_->OnLazyPoll(); | 1064 script_poller_->OnLazyPoll(); |
| 1064 | 1065 |
| 1065 if (current_state_ == STATE_NONE) | 1066 if (current_state_ == STATE_NONE) |
| 1066 ApplyProxyConfigIfAvailable(); | 1067 ApplyProxyConfigIfAvailable(); |
| 1067 | 1068 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1086 | 1087 |
| 1087 scoped_refptr<PacRequest> req(new PacRequest( | 1088 scoped_refptr<PacRequest> req(new PacRequest( |
| 1088 this, url, method, proxy_delegate, result, callback, net_log)); | 1089 this, url, method, proxy_delegate, result, callback, net_log)); |
| 1089 | 1090 |
| 1090 if (current_state_ == STATE_READY) { | 1091 if (current_state_ == STATE_READY) { |
| 1091 // Start the resolve request. | 1092 // Start the resolve request. |
| 1092 rv = req->Start(); | 1093 rv = req->Start(); |
| 1093 if (rv != ERR_IO_PENDING) | 1094 if (rv != ERR_IO_PENDING) |
| 1094 return req->QueryDidComplete(rv); | 1095 return req->QueryDidComplete(rv); |
| 1095 } else { | 1096 } else { |
| 1096 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); | 1097 req->net_log()->BeginEvent( |
| 1098 NetLogEventType::PROXY_SERVICE_WAITING_FOR_INIT_PAC); |
| 1097 } | 1099 } |
| 1098 | 1100 |
| 1099 DCHECK_EQ(ERR_IO_PENDING, rv); | 1101 DCHECK_EQ(ERR_IO_PENDING, rv); |
| 1100 DCHECK(!ContainsPendingRequest(req.get())); | 1102 DCHECK(!ContainsPendingRequest(req.get())); |
| 1101 pending_requests_.insert(req); | 1103 pending_requests_.insert(req); |
| 1102 | 1104 |
| 1103 // Completion will be notified through |callback|, unless the caller cancels | 1105 // Completion will be notified through |callback|, unless the caller cancels |
| 1104 // the request using |pac_request|. | 1106 // the request using |pac_request|. |
| 1105 if (pac_request) | 1107 if (pac_request) |
| 1106 *pac_request = req.get(); | 1108 *pac_request = req.get(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 | 1161 |
| 1160 void ProxyService::SuspendAllPendingRequests() { | 1162 void ProxyService::SuspendAllPendingRequests() { |
| 1161 for (PendingRequests::iterator it = pending_requests_.begin(); | 1163 for (PendingRequests::iterator it = pending_requests_.begin(); |
| 1162 it != pending_requests_.end(); | 1164 it != pending_requests_.end(); |
| 1163 ++it) { | 1165 ++it) { |
| 1164 PacRequest* req = it->get(); | 1166 PacRequest* req = it->get(); |
| 1165 if (req->is_started()) { | 1167 if (req->is_started()) { |
| 1166 req->CancelResolveJob(); | 1168 req->CancelResolveJob(); |
| 1167 | 1169 |
| 1168 req->net_log()->BeginEvent( | 1170 req->net_log()->BeginEvent( |
| 1169 NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); | 1171 NetLogEventType::PROXY_SERVICE_WAITING_FOR_INIT_PAC); |
| 1170 } | 1172 } |
| 1171 } | 1173 } |
| 1172 } | 1174 } |
| 1173 | 1175 |
| 1174 void ProxyService::SetReady() { | 1176 void ProxyService::SetReady() { |
| 1175 DCHECK(!init_proxy_resolver_.get()); | 1177 DCHECK(!init_proxy_resolver_.get()); |
| 1176 current_state_ = STATE_READY; | 1178 current_state_ = STATE_READY; |
| 1177 | 1179 |
| 1178 // Make a copy in case |this| is deleted during the synchronous completion | 1180 // Make a copy in case |this| is deleted during the synchronous completion |
| 1179 // of one of the requests. If |this| is deleted then all of the PacRequest | 1181 // of one of the requests. If |this| is deleted then all of the PacRequest |
| 1180 // instances will be Cancel()-ed. | 1182 // instances will be Cancel()-ed. |
| 1181 PendingRequests pending_copy = pending_requests_; | 1183 PendingRequests pending_copy = pending_requests_; |
| 1182 | 1184 |
| 1183 for (PendingRequests::iterator it = pending_copy.begin(); | 1185 for (PendingRequests::iterator it = pending_copy.begin(); |
| 1184 it != pending_copy.end(); | 1186 it != pending_copy.end(); |
| 1185 ++it) { | 1187 ++it) { |
| 1186 PacRequest* req = it->get(); | 1188 PacRequest* req = it->get(); |
| 1187 if (!req->is_started() && !req->was_cancelled()) { | 1189 if (!req->is_started() && !req->was_cancelled()) { |
| 1188 req->net_log()->EndEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); | 1190 req->net_log()->EndEvent( |
| 1191 NetLogEventType::PROXY_SERVICE_WAITING_FOR_INIT_PAC); |
| 1189 | 1192 |
| 1190 // Note that we re-check for synchronous completion, in case we are | 1193 // Note that we re-check for synchronous completion, in case we are |
| 1191 // no longer using a ProxyResolver (can happen if we fell-back to manual). | 1194 // no longer using a ProxyResolver (can happen if we fell-back to manual). |
| 1192 req->StartAndCompleteCheckingForSynchronous(); | 1195 req->StartAndCompleteCheckingForSynchronous(); |
| 1193 } | 1196 } |
| 1194 } | 1197 } |
| 1195 } | 1198 } |
| 1196 | 1199 |
| 1197 void ProxyService::ApplyProxyConfigIfAvailable() { | 1200 void ProxyService::ApplyProxyConfigIfAvailable() { |
| 1198 DCHECK_EQ(STATE_NONE, current_state_); | 1201 DCHECK_EQ(STATE_NONE, current_state_); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 ProxyServer::FromURI(iter->first, ProxyServer::SCHEME_HTTP); | 1340 ProxyServer::FromURI(iter->first, ProxyServer::SCHEME_HTTP); |
| 1338 const ProxyRetryInfo& proxy_retry_info = iter->second; | 1341 const ProxyRetryInfo& proxy_retry_info = iter->second; |
| 1339 proxy_delegate->OnFallback(bad_proxy, proxy_retry_info.net_error); | 1342 proxy_delegate->OnFallback(bad_proxy, proxy_retry_info.net_error); |
| 1340 } | 1343 } |
| 1341 } | 1344 } |
| 1342 else if (existing->second.bad_until < iter->second.bad_until) | 1345 else if (existing->second.bad_until < iter->second.bad_until) |
| 1343 existing->second.bad_until = iter->second.bad_until; | 1346 existing->second.bad_until = iter->second.bad_until; |
| 1344 } | 1347 } |
| 1345 if (net_log_) { | 1348 if (net_log_) { |
| 1346 net_log_->AddGlobalEntry( | 1349 net_log_->AddGlobalEntry( |
| 1347 NetLog::TYPE_BAD_PROXY_LIST_REPORTED, | 1350 NetLogEventType::BAD_PROXY_LIST_REPORTED, |
| 1348 base::Bind(&NetLogBadProxyListCallback, &new_retry_info)); | 1351 base::Bind(&NetLogBadProxyListCallback, &new_retry_info)); |
| 1349 } | 1352 } |
| 1350 } | 1353 } |
| 1351 | 1354 |
| 1352 void ProxyService::CancelPacRequest(PacRequest* req) { | 1355 void ProxyService::CancelPacRequest(PacRequest* req) { |
| 1353 DCHECK(CalledOnValidThread()); | 1356 DCHECK(CalledOnValidThread()); |
| 1354 DCHECK(req); | 1357 DCHECK(req); |
| 1355 req->Cancel(); | 1358 req->Cancel(); |
| 1356 RemovePendingRequest(req); | 1359 RemovePendingRequest(req); |
| 1357 } | 1360 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 base::TimeDelta::FromSeconds(20), 50); | 1406 base::TimeDelta::FromSeconds(20), 50); |
| 1404 } | 1407 } |
| 1405 | 1408 |
| 1406 // Log the result of the proxy resolution. | 1409 // Log the result of the proxy resolution. |
| 1407 if (result_code == OK) { | 1410 if (result_code == OK) { |
| 1408 // Allow the proxy delegate to interpose on the resolution decision, | 1411 // Allow the proxy delegate to interpose on the resolution decision, |
| 1409 // possibly modifying the ProxyInfo. | 1412 // possibly modifying the ProxyInfo. |
| 1410 if (proxy_delegate) | 1413 if (proxy_delegate) |
| 1411 proxy_delegate->OnResolveProxy(url, method, *this, result); | 1414 proxy_delegate->OnResolveProxy(url, method, *this, result); |
| 1412 | 1415 |
| 1413 net_log.AddEvent(NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 1416 net_log.AddEvent(NetLogEventType::PROXY_SERVICE_RESOLVED_PROXY_LIST, |
| 1414 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); | 1417 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); |
| 1415 | 1418 |
| 1416 // This check is done to only log the NetLog event when necessary, it's | 1419 // This check is done to only log the NetLog event when necessary, it's |
| 1417 // not a performance optimization. | 1420 // not a performance optimization. |
| 1418 if (!proxy_retry_info_.empty()) { | 1421 if (!proxy_retry_info_.empty()) { |
| 1419 result->DeprioritizeBadProxies(proxy_retry_info_); | 1422 result->DeprioritizeBadProxies(proxy_retry_info_); |
| 1420 net_log.AddEvent( | 1423 net_log.AddEvent( |
| 1421 NetLog::TYPE_PROXY_SERVICE_DEPRIORITIZED_BAD_PROXIES, | 1424 NetLogEventType::PROXY_SERVICE_DEPRIORITIZED_BAD_PROXIES, |
| 1422 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); | 1425 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); |
| 1423 } | 1426 } |
| 1424 } else { | 1427 } else { |
| 1425 net_log.AddEventWithNetErrorCode( | 1428 net_log.AddEventWithNetErrorCode( |
| 1426 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, result_code); | 1429 NetLogEventType::PROXY_SERVICE_RESOLVED_PROXY_LIST, result_code); |
| 1427 | 1430 |
| 1428 bool reset_config = result_code == ERR_PAC_SCRIPT_TERMINATED; | 1431 bool reset_config = result_code == ERR_PAC_SCRIPT_TERMINATED; |
| 1429 if (!config_.pac_mandatory()) { | 1432 if (!config_.pac_mandatory()) { |
| 1430 // Fall-back to direct when the proxy resolver fails. This corresponds | 1433 // Fall-back to direct when the proxy resolver fails. This corresponds |
| 1431 // with a javascript runtime error in the PAC script. | 1434 // with a javascript runtime error in the PAC script. |
| 1432 // | 1435 // |
| 1433 // This implicit fall-back to direct matches Firefox 3.5 and | 1436 // This implicit fall-back to direct matches Firefox 3.5 and |
| 1434 // Internet Explorer 8. For more information, see: | 1437 // Internet Explorer 8. For more information, see: |
| 1435 // | 1438 // |
| 1436 // http://www.chromium.org/developers/design-documents/proxy-settings-fall
back | 1439 // http://www.chromium.org/developers/design-documents/proxy-settings-fall
back |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1447 if (reset_config) { | 1450 if (reset_config) { |
| 1448 ResetProxyConfig(false); | 1451 ResetProxyConfig(false); |
| 1449 // If the ProxyResolver crashed, force it to be re-initialized for the | 1452 // If the ProxyResolver crashed, force it to be re-initialized for the |
| 1450 // next request by resetting the proxy config. If there are other pending | 1453 // next request by resetting the proxy config. If there are other pending |
| 1451 // requests, trigger the recreation immediately so those requests retry. | 1454 // requests, trigger the recreation immediately so those requests retry. |
| 1452 if (pending_requests_.size() > 1) | 1455 if (pending_requests_.size() > 1) |
| 1453 ApplyProxyConfigIfAvailable(); | 1456 ApplyProxyConfigIfAvailable(); |
| 1454 } | 1457 } |
| 1455 } | 1458 } |
| 1456 | 1459 |
| 1457 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE); | 1460 net_log.EndEvent(NetLogEventType::PROXY_SERVICE); |
| 1458 return result_code; | 1461 return result_code; |
| 1459 } | 1462 } |
| 1460 | 1463 |
| 1461 void ProxyService::SetProxyScriptFetchers( | 1464 void ProxyService::SetProxyScriptFetchers( |
| 1462 ProxyScriptFetcher* proxy_script_fetcher, | 1465 ProxyScriptFetcher* proxy_script_fetcher, |
| 1463 std::unique_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher) { | 1466 std::unique_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher) { |
| 1464 DCHECK(CalledOnValidThread()); | 1467 DCHECK(CalledOnValidThread()); |
| 1465 State previous_state = ResetProxyConfig(false); | 1468 State previous_state = ResetProxyConfig(false); |
| 1466 proxy_script_fetcher_.reset(proxy_script_fetcher); | 1469 proxy_script_fetcher_.reset(proxy_script_fetcher); |
| 1467 dhcp_proxy_script_fetcher_ = std::move(dhcp_proxy_script_fetcher); | 1470 dhcp_proxy_script_fetcher_ = std::move(dhcp_proxy_script_fetcher); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 case ProxyConfigService::CONFIG_VALID: | 1589 case ProxyConfigService::CONFIG_VALID: |
| 1587 effective_config = config; | 1590 effective_config = config; |
| 1588 break; | 1591 break; |
| 1589 case ProxyConfigService::CONFIG_UNSET: | 1592 case ProxyConfigService::CONFIG_UNSET: |
| 1590 effective_config = ProxyConfig::CreateDirect(); | 1593 effective_config = ProxyConfig::CreateDirect(); |
| 1591 break; | 1594 break; |
| 1592 } | 1595 } |
| 1593 | 1596 |
| 1594 // Emit the proxy settings change to the NetLog stream. | 1597 // Emit the proxy settings change to the NetLog stream. |
| 1595 if (net_log_) { | 1598 if (net_log_) { |
| 1596 net_log_->AddGlobalEntry(NetLog::TYPE_PROXY_CONFIG_CHANGED, | 1599 net_log_->AddGlobalEntry(NetLogEventType::PROXY_CONFIG_CHANGED, |
| 1597 base::Bind(&NetLogProxyConfigChangedCallback, | 1600 base::Bind(&NetLogProxyConfigChangedCallback, |
| 1598 &fetched_config_, &effective_config)); | 1601 &fetched_config_, &effective_config)); |
| 1599 } | 1602 } |
| 1600 | 1603 |
| 1601 // Set the new configuration as the most recently fetched one. | 1604 // Set the new configuration as the most recently fetched one. |
| 1602 fetched_config_ = effective_config; | 1605 fetched_config_ = effective_config; |
| 1603 fetched_config_.set_id(1); // Needed for a later DCHECK of is_valid(). | 1606 fetched_config_.set_id(1); // Needed for a later DCHECK of is_valid(). |
| 1604 | 1607 |
| 1605 InitializeUsingLastFetchedConfig(); | 1608 InitializeUsingLastFetchedConfig(); |
| 1606 } | 1609 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 State previous_state = ResetProxyConfig(false); | 1670 State previous_state = ResetProxyConfig(false); |
| 1668 if (previous_state != STATE_NONE) | 1671 if (previous_state != STATE_NONE) |
| 1669 ApplyProxyConfigIfAvailable(); | 1672 ApplyProxyConfigIfAvailable(); |
| 1670 } | 1673 } |
| 1671 | 1674 |
| 1672 void ProxyService::OnDNSChanged() { | 1675 void ProxyService::OnDNSChanged() { |
| 1673 OnIPAddressChanged(); | 1676 OnIPAddressChanged(); |
| 1674 } | 1677 } |
| 1675 | 1678 |
| 1676 } // namespace net | 1679 } // namespace net |
| OLD | NEW |