| 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 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 proxy_delegate, net_log); | 1035 proxy_delegate, net_log); |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 int ProxyService::ResolveProxyHelper(const GURL& raw_url, | 1038 int ProxyService::ResolveProxyHelper(const GURL& raw_url, |
| 1039 const std::string& method, | 1039 const std::string& method, |
| 1040 ProxyInfo* result, | 1040 ProxyInfo* result, |
| 1041 const CompletionCallback& callback, | 1041 const CompletionCallback& callback, |
| 1042 PacRequest** pac_request, | 1042 PacRequest** pac_request, |
| 1043 ProxyDelegate* proxy_delegate, | 1043 ProxyDelegate* proxy_delegate, |
| 1044 const NetLogWithSource& net_log) { | 1044 const NetLogWithSource& net_log) { |
| 1045 DCHECK(CalledOnValidThread()); | 1045 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1046 | 1046 |
| 1047 net_log.BeginEvent(NetLogEventType::PROXY_SERVICE); | 1047 net_log.BeginEvent(NetLogEventType::PROXY_SERVICE); |
| 1048 | 1048 |
| 1049 // Notify our polling-based dependencies that a resolve is taking place. | 1049 // Notify our polling-based dependencies that a resolve is taking place. |
| 1050 // This way they can schedule their polls in response to network activity. | 1050 // This way they can schedule their polls in response to network activity. |
| 1051 config_service_->OnLazyPoll(); | 1051 config_service_->OnLazyPoll(); |
| 1052 if (script_poller_.get()) | 1052 if (script_poller_.get()) |
| 1053 script_poller_->OnLazyPoll(); | 1053 script_poller_->OnLazyPoll(); |
| 1054 | 1054 |
| 1055 if (current_state_ == STATE_NONE) | 1055 if (current_state_ == STATE_NONE) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 | 1130 |
| 1131 // Use the manual proxy settings. | 1131 // Use the manual proxy settings. |
| 1132 config_.proxy_rules().Apply(url, result); | 1132 config_.proxy_rules().Apply(url, result); |
| 1133 result->config_source_ = config_.source(); | 1133 result->config_source_ = config_.source(); |
| 1134 result->config_id_ = config_.id(); | 1134 result->config_id_ = config_.id(); |
| 1135 | 1135 |
| 1136 return OK; | 1136 return OK; |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 ProxyService::~ProxyService() { | 1139 ProxyService::~ProxyService() { |
| 1140 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1140 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1141 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1141 NetworkChangeNotifier::RemoveDNSObserver(this); | 1142 NetworkChangeNotifier::RemoveDNSObserver(this); |
| 1142 config_service_->RemoveObserver(this); | 1143 config_service_->RemoveObserver(this); |
| 1143 | 1144 |
| 1144 // Cancel any inprogress requests. | 1145 // Cancel any inprogress requests. |
| 1145 for (PendingRequests::iterator it = pending_requests_.begin(); | 1146 for (PendingRequests::iterator it = pending_requests_.begin(); |
| 1146 it != pending_requests_.end(); | 1147 it != pending_requests_.end(); |
| 1147 ++it) { | 1148 ++it) { |
| 1148 (*it)->Cancel(); | 1149 (*it)->Cancel(); |
| 1149 } | 1150 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 } | 1266 } |
| 1266 | 1267 |
| 1267 int ProxyService::ReconsiderProxyAfterError(const GURL& url, | 1268 int ProxyService::ReconsiderProxyAfterError(const GURL& url, |
| 1268 const std::string& method, | 1269 const std::string& method, |
| 1269 int net_error, | 1270 int net_error, |
| 1270 ProxyInfo* result, | 1271 ProxyInfo* result, |
| 1271 const CompletionCallback& callback, | 1272 const CompletionCallback& callback, |
| 1272 PacRequest** pac_request, | 1273 PacRequest** pac_request, |
| 1273 ProxyDelegate* proxy_delegate, | 1274 ProxyDelegate* proxy_delegate, |
| 1274 const NetLogWithSource& net_log) { | 1275 const NetLogWithSource& net_log) { |
| 1275 DCHECK(CalledOnValidThread()); | 1276 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1276 | 1277 |
| 1277 // Check to see if we have a new config since ResolveProxy was called. We | 1278 // Check to see if we have a new config since ResolveProxy was called. We |
| 1278 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a | 1279 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a |
| 1279 // direct connection failed and we never tried the current config. | 1280 // direct connection failed and we never tried the current config. |
| 1280 | 1281 |
| 1281 DCHECK(result); | 1282 DCHECK(result); |
| 1282 bool re_resolve = result->config_id_ != config_.id(); | 1283 bool re_resolve = result->config_id_ != config_.id(); |
| 1283 | 1284 |
| 1284 if (re_resolve) { | 1285 if (re_resolve) { |
| 1285 // If we have a new config or the config was never tried, we delete the | 1286 // If we have a new config or the config was never tried, we delete the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1307 const std::vector<ProxyServer>& additional_bad_proxies, | 1308 const std::vector<ProxyServer>& additional_bad_proxies, |
| 1308 const NetLogWithSource& net_log) { | 1309 const NetLogWithSource& net_log) { |
| 1309 result.proxy_list_.UpdateRetryInfoOnFallback(&proxy_retry_info_, retry_delay, | 1310 result.proxy_list_.UpdateRetryInfoOnFallback(&proxy_retry_info_, retry_delay, |
| 1310 false, additional_bad_proxies, | 1311 false, additional_bad_proxies, |
| 1311 OK, net_log); | 1312 OK, net_log); |
| 1312 return result.proxy_list_.size() > (additional_bad_proxies.size() + 1); | 1313 return result.proxy_list_.size() > (additional_bad_proxies.size() + 1); |
| 1313 } | 1314 } |
| 1314 | 1315 |
| 1315 void ProxyService::ReportSuccess(const ProxyInfo& result, | 1316 void ProxyService::ReportSuccess(const ProxyInfo& result, |
| 1316 ProxyDelegate* proxy_delegate) { | 1317 ProxyDelegate* proxy_delegate) { |
| 1317 DCHECK(CalledOnValidThread()); | 1318 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1318 | 1319 |
| 1319 const ProxyRetryInfoMap& new_retry_info = result.proxy_retry_info(); | 1320 const ProxyRetryInfoMap& new_retry_info = result.proxy_retry_info(); |
| 1320 if (new_retry_info.empty()) | 1321 if (new_retry_info.empty()) |
| 1321 return; | 1322 return; |
| 1322 | 1323 |
| 1323 for (ProxyRetryInfoMap::const_iterator iter = new_retry_info.begin(); | 1324 for (ProxyRetryInfoMap::const_iterator iter = new_retry_info.begin(); |
| 1324 iter != new_retry_info.end(); ++iter) { | 1325 iter != new_retry_info.end(); ++iter) { |
| 1325 ProxyRetryInfoMap::iterator existing = proxy_retry_info_.find(iter->first); | 1326 ProxyRetryInfoMap::iterator existing = proxy_retry_info_.find(iter->first); |
| 1326 if (existing == proxy_retry_info_.end()) { | 1327 if (existing == proxy_retry_info_.end()) { |
| 1327 proxy_retry_info_[iter->first] = iter->second; | 1328 proxy_retry_info_[iter->first] = iter->second; |
| 1328 if (proxy_delegate) { | 1329 if (proxy_delegate) { |
| 1329 const ProxyServer& bad_proxy = | 1330 const ProxyServer& bad_proxy = |
| 1330 ProxyServer::FromURI(iter->first, ProxyServer::SCHEME_HTTP); | 1331 ProxyServer::FromURI(iter->first, ProxyServer::SCHEME_HTTP); |
| 1331 const ProxyRetryInfo& proxy_retry_info = iter->second; | 1332 const ProxyRetryInfo& proxy_retry_info = iter->second; |
| 1332 proxy_delegate->OnFallback(bad_proxy, proxy_retry_info.net_error); | 1333 proxy_delegate->OnFallback(bad_proxy, proxy_retry_info.net_error); |
| 1333 } | 1334 } |
| 1334 } | 1335 } |
| 1335 else if (existing->second.bad_until < iter->second.bad_until) | 1336 else if (existing->second.bad_until < iter->second.bad_until) |
| 1336 existing->second.bad_until = iter->second.bad_until; | 1337 existing->second.bad_until = iter->second.bad_until; |
| 1337 } | 1338 } |
| 1338 if (net_log_) { | 1339 if (net_log_) { |
| 1339 net_log_->AddGlobalEntry( | 1340 net_log_->AddGlobalEntry( |
| 1340 NetLogEventType::BAD_PROXY_LIST_REPORTED, | 1341 NetLogEventType::BAD_PROXY_LIST_REPORTED, |
| 1341 base::Bind(&NetLogBadProxyListCallback, &new_retry_info)); | 1342 base::Bind(&NetLogBadProxyListCallback, &new_retry_info)); |
| 1342 } | 1343 } |
| 1343 } | 1344 } |
| 1344 | 1345 |
| 1345 void ProxyService::CancelPacRequest(PacRequest* req) { | 1346 void ProxyService::CancelPacRequest(PacRequest* req) { |
| 1346 DCHECK(CalledOnValidThread()); | 1347 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1347 DCHECK(req); | 1348 DCHECK(req); |
| 1348 req->Cancel(); | 1349 req->Cancel(); |
| 1349 RemovePendingRequest(req); | 1350 RemovePendingRequest(req); |
| 1350 } | 1351 } |
| 1351 | 1352 |
| 1352 LoadState ProxyService::GetLoadState(const PacRequest* req) const { | 1353 LoadState ProxyService::GetLoadState(const PacRequest* req) const { |
| 1353 CHECK(req); | 1354 CHECK(req); |
| 1354 if (current_state_ == STATE_WAITING_FOR_INIT_PROXY_RESOLVER) | 1355 if (current_state_ == STATE_WAITING_FOR_INIT_PROXY_RESOLVER) |
| 1355 return init_proxy_resolver_->GetLoadState(); | 1356 return init_proxy_resolver_->GetLoadState(); |
| 1356 return req->GetLoadState(); | 1357 return req->GetLoadState(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1447 } | 1448 } |
| 1448 } | 1449 } |
| 1449 | 1450 |
| 1450 net_log.EndEvent(NetLogEventType::PROXY_SERVICE); | 1451 net_log.EndEvent(NetLogEventType::PROXY_SERVICE); |
| 1451 return result_code; | 1452 return result_code; |
| 1452 } | 1453 } |
| 1453 | 1454 |
| 1454 void ProxyService::SetProxyScriptFetchers( | 1455 void ProxyService::SetProxyScriptFetchers( |
| 1455 ProxyScriptFetcher* proxy_script_fetcher, | 1456 ProxyScriptFetcher* proxy_script_fetcher, |
| 1456 std::unique_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher) { | 1457 std::unique_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher) { |
| 1457 DCHECK(CalledOnValidThread()); | 1458 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1458 State previous_state = ResetProxyConfig(false); | 1459 State previous_state = ResetProxyConfig(false); |
| 1459 proxy_script_fetcher_.reset(proxy_script_fetcher); | 1460 proxy_script_fetcher_.reset(proxy_script_fetcher); |
| 1460 dhcp_proxy_script_fetcher_ = std::move(dhcp_proxy_script_fetcher); | 1461 dhcp_proxy_script_fetcher_ = std::move(dhcp_proxy_script_fetcher); |
| 1461 if (previous_state != STATE_NONE) | 1462 if (previous_state != STATE_NONE) |
| 1462 ApplyProxyConfigIfAvailable(); | 1463 ApplyProxyConfigIfAvailable(); |
| 1463 } | 1464 } |
| 1464 | 1465 |
| 1465 void ProxyService::OnShutdown() { | 1466 void ProxyService::OnShutdown() { |
| 1466 // Order here does not matter for correctness. |init_proxy_resolver_| is first | 1467 // Order here does not matter for correctness. |init_proxy_resolver_| is first |
| 1467 // because shutting it down also cancels its requests using the fetcher. | 1468 // because shutting it down also cancels its requests using the fetcher. |
| 1468 if (init_proxy_resolver_) | 1469 if (init_proxy_resolver_) |
| 1469 init_proxy_resolver_->OnShutdown(); | 1470 init_proxy_resolver_->OnShutdown(); |
| 1470 if (proxy_script_fetcher_) | 1471 if (proxy_script_fetcher_) |
| 1471 proxy_script_fetcher_->OnShutdown(); | 1472 proxy_script_fetcher_->OnShutdown(); |
| 1472 if (dhcp_proxy_script_fetcher_) | 1473 if (dhcp_proxy_script_fetcher_) |
| 1473 dhcp_proxy_script_fetcher_->OnShutdown(); | 1474 dhcp_proxy_script_fetcher_->OnShutdown(); |
| 1474 } | 1475 } |
| 1475 | 1476 |
| 1476 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const { | 1477 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const { |
| 1477 DCHECK(CalledOnValidThread()); | 1478 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1478 return proxy_script_fetcher_.get(); | 1479 return proxy_script_fetcher_.get(); |
| 1479 } | 1480 } |
| 1480 | 1481 |
| 1481 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) { | 1482 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) { |
| 1482 DCHECK(CalledOnValidThread()); | 1483 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1483 State previous_state = current_state_; | 1484 State previous_state = current_state_; |
| 1484 | 1485 |
| 1485 permanent_error_ = OK; | 1486 permanent_error_ = OK; |
| 1486 proxy_retry_info_.clear(); | 1487 proxy_retry_info_.clear(); |
| 1487 script_poller_.reset(); | 1488 script_poller_.reset(); |
| 1488 init_proxy_resolver_.reset(); | 1489 init_proxy_resolver_.reset(); |
| 1489 SuspendAllPendingRequests(); | 1490 SuspendAllPendingRequests(); |
| 1490 resolver_.reset(); | 1491 resolver_.reset(); |
| 1491 config_ = ProxyConfig(); | 1492 config_ = ProxyConfig(); |
| 1492 if (reset_fetched_config) | 1493 if (reset_fetched_config) |
| 1493 fetched_config_ = ProxyConfig(); | 1494 fetched_config_ = ProxyConfig(); |
| 1494 current_state_ = STATE_NONE; | 1495 current_state_ = STATE_NONE; |
| 1495 | 1496 |
| 1496 return previous_state; | 1497 return previous_state; |
| 1497 } | 1498 } |
| 1498 | 1499 |
| 1499 void ProxyService::ResetConfigService( | 1500 void ProxyService::ResetConfigService( |
| 1500 std::unique_ptr<ProxyConfigService> new_proxy_config_service) { | 1501 std::unique_ptr<ProxyConfigService> new_proxy_config_service) { |
| 1501 DCHECK(CalledOnValidThread()); | 1502 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1502 State previous_state = ResetProxyConfig(true); | 1503 State previous_state = ResetProxyConfig(true); |
| 1503 | 1504 |
| 1504 // Release the old configuration service. | 1505 // Release the old configuration service. |
| 1505 if (config_service_.get()) | 1506 if (config_service_.get()) |
| 1506 config_service_->RemoveObserver(this); | 1507 config_service_->RemoveObserver(this); |
| 1507 | 1508 |
| 1508 // Set the new configuration service. | 1509 // Set the new configuration service. |
| 1509 config_service_ = std::move(new_proxy_config_service); | 1510 config_service_ = std::move(new_proxy_config_service); |
| 1510 config_service_->AddObserver(this); | 1511 config_service_->AddObserver(this); |
| 1511 | 1512 |
| 1512 if (previous_state != STATE_NONE) | 1513 if (previous_state != STATE_NONE) |
| 1513 ApplyProxyConfigIfAvailable(); | 1514 ApplyProxyConfigIfAvailable(); |
| 1514 } | 1515 } |
| 1515 | 1516 |
| 1516 void ProxyService::ForceReloadProxyConfig() { | 1517 void ProxyService::ForceReloadProxyConfig() { |
| 1517 DCHECK(CalledOnValidThread()); | 1518 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1518 ResetProxyConfig(false); | 1519 ResetProxyConfig(false); |
| 1519 ApplyProxyConfigIfAvailable(); | 1520 ApplyProxyConfigIfAvailable(); |
| 1520 } | 1521 } |
| 1521 | 1522 |
| 1522 // static | 1523 // static |
| 1523 std::unique_ptr<ProxyConfigService> | 1524 std::unique_ptr<ProxyConfigService> |
| 1524 ProxyService::CreateSystemProxyConfigService( | 1525 ProxyService::CreateSystemProxyConfigService( |
| 1525 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 1526 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 1526 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { | 1527 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { |
| 1527 #if defined(OS_WIN) | 1528 #if defined(OS_WIN) |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 State previous_state = ResetProxyConfig(false); | 1672 State previous_state = ResetProxyConfig(false); |
| 1672 if (previous_state != STATE_NONE) | 1673 if (previous_state != STATE_NONE) |
| 1673 ApplyProxyConfigIfAvailable(); | 1674 ApplyProxyConfigIfAvailable(); |
| 1674 } | 1675 } |
| 1675 | 1676 |
| 1676 void ProxyService::OnDNSChanged() { | 1677 void ProxyService::OnDNSChanged() { |
| 1677 OnIPAddressChanged(); | 1678 OnIPAddressChanged(); |
| 1678 } | 1679 } |
| 1679 | 1680 |
| 1680 } // namespace net | 1681 } // namespace net |
| OLD | NEW |