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 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1161 // due to ProxyScriptDeciderPoller. | 1161 // due to ProxyScriptDeciderPoller. |
1162 config_.set_id(fetched_config_.id()); | 1162 config_.set_id(fetched_config_.id()); |
1163 config_.set_source(fetched_config_.source()); | 1163 config_.set_source(fetched_config_.source()); |
1164 | 1164 |
1165 // Resume any requests which we had to defer until the PAC script was | 1165 // Resume any requests which we had to defer until the PAC script was |
1166 // downloaded. | 1166 // downloaded. |
1167 SetReady(); | 1167 SetReady(); |
1168 } | 1168 } |
1169 | 1169 |
1170 int ProxyService::ReconsiderProxyAfterError(const GURL& url, | 1170 int ProxyService::ReconsiderProxyAfterError(const GURL& url, |
1171 int net_error, | |
1171 ProxyInfo* result, | 1172 ProxyInfo* result, |
1172 const CompletionCallback& callback, | 1173 const CompletionCallback& callback, |
1173 PacRequest** pac_request, | 1174 PacRequest** pac_request, |
1174 const BoundNetLog& net_log) { | 1175 const BoundNetLog& net_log) { |
1175 DCHECK(CalledOnValidThread()); | 1176 DCHECK(CalledOnValidThread()); |
1176 | 1177 |
1177 // Check to see if we have a new config since ResolveProxy was called. We | 1178 // Check to see if we have a new config since ResolveProxy was called. We |
1178 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a | 1179 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a |
1179 // direct connection failed and we never tried the current config. | 1180 // direct connection failed and we never tried the current config. |
1180 | 1181 |
1181 bool re_resolve = result->config_id_ != config_.id(); | 1182 bool re_resolve = result->config_id_ != config_.id(); |
1182 | 1183 |
1183 if (re_resolve) { | 1184 if (re_resolve) { |
1184 // If we have a new config or the config was never tried, we delete the | 1185 // If we have a new config or the config was never tried, we delete the |
1185 // list of bad proxies and we try again. | 1186 // list of bad proxies and we try again. |
1186 proxy_retry_info_.clear(); | 1187 proxy_retry_info_.clear(); |
1187 return ResolveProxy(url, result, callback, pac_request, net_log); | 1188 return ResolveProxy(url, result, callback, pac_request, net_log); |
1188 } | 1189 } |
1189 | 1190 |
1190 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 1191 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
1191 if (result->proxy_server().isDataReductionProxy()) { | 1192 if (result->proxy_server().isDataReductionProxy()) { |
1192 RecordDataReductionProxyBypassInfo( | 1193 RecordDataReductionProxyBypassInfo( |
1193 true, result->proxy_server(), ERROR_BYPASS); | 1194 true, result->proxy_server(), ERROR_BYPASS); |
1195 RecordDataReductionProxyBypassOnNetworkError( | |
1196 true, result->proxy_server(), net_error); | |
1194 } else if (result->proxy_server().isDataReductionProxyFallback()) { | 1197 } else if (result->proxy_server().isDataReductionProxyFallback()) { |
1195 RecordDataReductionProxyBypassInfo( | 1198 RecordDataReductionProxyBypassInfo( |
1196 false, result->proxy_server(), ERROR_BYPASS); | 1199 false, result->proxy_server(), ERROR_BYPASS); |
1200 RecordDataReductionProxyBypassOnNetworkError( | |
1201 true, result->proxy_server(), net_error); | |
1197 } | 1202 } |
1198 #endif | 1203 #endif |
1199 | 1204 |
1200 // We don't have new proxy settings to try, try to fallback to the next proxy | 1205 // We don't have new proxy settings to try, try to fallback to the next proxy |
1201 // in the list. | 1206 // in the list. |
1202 bool did_fallback = result->Fallback(net_log); | 1207 bool did_fallback = result->Fallback(net_log); |
1203 | 1208 |
1204 // Return synchronous failure if there is nothing left to fall-back to. | 1209 // Return synchronous failure if there is nothing left to fall-back to. |
1205 // TODO(eroman): This is a yucky API, clean it up. | 1210 // TODO(eroman): This is a yucky API, clean it up. |
1206 return did_fallback ? OK : ERR_FAILED; | 1211 return did_fallback ? OK : ERR_FAILED; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1432 return; | 1437 return; |
1433 | 1438 |
1434 if (is_primary) { | 1439 if (is_primary) { |
1435 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.BypassInfoPrimary", | 1440 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.BypassInfoPrimary", |
1436 bypass_type, BYPASS_EVENT_TYPE_MAX); | 1441 bypass_type, BYPASS_EVENT_TYPE_MAX); |
1437 } else { | 1442 } else { |
1438 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.BypassInfoFallback", | 1443 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.BypassInfoFallback", |
1439 bypass_type, BYPASS_EVENT_TYPE_MAX); | 1444 bypass_type, BYPASS_EVENT_TYPE_MAX); |
1440 } | 1445 } |
1441 } | 1446 } |
1447 | |
1448 void ProxyService::RecordDataReductionProxyBypassOnNetworkError( | |
1449 bool is_primary, | |
1450 const ProxyServer& proxy_server, | |
1451 int net_error) { | |
1452 // Only record UMA if the proxy isn't already on the retry list. | |
1453 if (proxy_retry_info_.find(proxy_server.ToURI()) != proxy_retry_info_.end()) | |
1454 return; | |
1455 | |
1456 if (is_primary) { | |
1457 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | |
1458 "DataReductionProxy.BypassOnNetworkErrorPrimary", | |
1459 std::abs(net_error), | |
1460 GetAllErrorCodesForUma()); | |
Alexei Svitkine (slow)
2014/05/26 17:25:08
Instead, it's better to use a sparse histogram her
bengr
2014/05/27 15:59:54
Done. Do we lose any fidelity by using the sparse
Alexei Svitkine (slow)
2014/05/27 16:33:57
No, we don't. It's merely more efficient on the cl
| |
1461 return; | |
1462 } | |
1463 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | |
1464 "DataReductionProxy.BypassOnNetworkErrorFallback", | |
1465 std::abs(net_error), | |
1466 GetAllErrorCodesForUma()); | |
1467 } | |
1442 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) | 1468 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) |
1443 | 1469 |
1444 void ProxyService::OnProxyConfigChanged( | 1470 void ProxyService::OnProxyConfigChanged( |
1445 const ProxyConfig& config, | 1471 const ProxyConfig& config, |
1446 ProxyConfigService::ConfigAvailability availability) { | 1472 ProxyConfigService::ConfigAvailability availability) { |
1447 // Retrieve the current proxy configuration from the ProxyConfigService. | 1473 // Retrieve the current proxy configuration from the ProxyConfigService. |
1448 // If a configuration is not available yet, we will get called back later | 1474 // If a configuration is not available yet, we will get called back later |
1449 // by our ProxyConfigService::Observer once it changes. | 1475 // by our ProxyConfigService::Observer once it changes. |
1450 ProxyConfig effective_config; | 1476 ProxyConfig effective_config; |
1451 switch (availability) { | 1477 switch (availability) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1574 | 1600 |
1575 event_.Wait(); | 1601 event_.Wait(); |
1576 | 1602 |
1577 if (result_ == net::OK) { | 1603 if (result_ == net::OK) { |
1578 *proxy_info = proxy_info_; | 1604 *proxy_info = proxy_info_; |
1579 } | 1605 } |
1580 return result_; | 1606 return result_; |
1581 } | 1607 } |
1582 | 1608 |
1583 int SyncProxyServiceHelper::ReconsiderProxyAfterError( | 1609 int SyncProxyServiceHelper::ReconsiderProxyAfterError( |
1584 const GURL& url, ProxyInfo* proxy_info, const BoundNetLog& net_log) { | 1610 const GURL& url, int net_error, ProxyInfo* proxy_info, |
1611 const BoundNetLog& net_log) { | |
1585 DCHECK(io_message_loop_ != base::MessageLoop::current()); | 1612 DCHECK(io_message_loop_ != base::MessageLoop::current()); |
1586 | 1613 |
1587 io_message_loop_->PostTask( | 1614 io_message_loop_->PostTask( |
1588 FROM_HERE, | 1615 FROM_HERE, |
1589 base::Bind(&SyncProxyServiceHelper::StartAsyncReconsider, this, url, | 1616 base::Bind(&SyncProxyServiceHelper::StartAsyncReconsider, this, url, |
1590 net_log)); | 1617 net_error, net_log)); |
1591 | 1618 |
1592 event_.Wait(); | 1619 event_.Wait(); |
1593 | 1620 |
1594 if (result_ == net::OK) { | 1621 if (result_ == net::OK) { |
1595 *proxy_info = proxy_info_; | 1622 *proxy_info = proxy_info_; |
1596 } | 1623 } |
1597 return result_; | 1624 return result_; |
1598 } | 1625 } |
1599 | 1626 |
1600 SyncProxyServiceHelper::~SyncProxyServiceHelper() {} | 1627 SyncProxyServiceHelper::~SyncProxyServiceHelper() {} |
1601 | 1628 |
1602 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url, | 1629 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url, |
1603 const BoundNetLog& net_log) { | 1630 const BoundNetLog& net_log) { |
1604 result_ = proxy_service_->ResolveProxy( | 1631 result_ = proxy_service_->ResolveProxy( |
1605 url, &proxy_info_, callback_, NULL, net_log); | 1632 url, &proxy_info_, callback_, NULL, net_log); |
1606 if (result_ != net::ERR_IO_PENDING) { | 1633 if (result_ != net::ERR_IO_PENDING) { |
1607 OnCompletion(result_); | 1634 OnCompletion(result_); |
1608 } | 1635 } |
1609 } | 1636 } |
1610 | 1637 |
1611 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url, | 1638 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url, |
1639 int net_error, | |
1612 const BoundNetLog& net_log) { | 1640 const BoundNetLog& net_log) { |
1613 result_ = proxy_service_->ReconsiderProxyAfterError( | 1641 result_ = proxy_service_->ReconsiderProxyAfterError( |
1614 url, &proxy_info_, callback_, NULL, net_log); | 1642 url, net_error, &proxy_info_, callback_, NULL, net_log); |
1615 if (result_ != net::ERR_IO_PENDING) { | 1643 if (result_ != net::ERR_IO_PENDING) { |
1616 OnCompletion(result_); | 1644 OnCompletion(result_); |
1617 } | 1645 } |
1618 } | 1646 } |
1619 | 1647 |
1620 void SyncProxyServiceHelper::OnCompletion(int rv) { | 1648 void SyncProxyServiceHelper::OnCompletion(int rv) { |
1621 result_ = rv; | 1649 result_ = rv; |
1622 event_.Signal(); | 1650 event_.Signal(); |
1623 } | 1651 } |
1624 | 1652 |
1625 } // namespace net | 1653 } // namespace net |
OLD | NEW |