Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: net/proxy/proxy_service.cc

Issue 332313003: Add Finch experiment for selectively bypassing proxies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2-line change: Add missing ifdef(SPDY_PROXY_AUTH_ORIGIN); previously only compiled on android, but … Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)), 764 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)),
765 &resolve_job_, net_log_); 765 &resolve_job_, net_log_);
766 } 766 }
767 767
768 bool is_started() const { 768 bool is_started() const {
769 // Note that !! casts to bool. (VS gives a warning otherwise). 769 // Note that !! casts to bool. (VS gives a warning otherwise).
770 return !!resolve_job_; 770 return !!resolve_job_;
771 } 771 }
772 772
773 void StartAndCompleteCheckingForSynchronous() { 773 void StartAndCompleteCheckingForSynchronous() {
774 int rv = service_->TryToCompleteSynchronously(url_, results_); 774 int rv = service_->TryToCompleteSynchronously(url_, 0, NULL, results_);
mmenke 2014/07/01 19:45:12 Rather than using 0 for load flags, should use LOA
rcs 2014/07/02 00:56:20 Done.
775 if (rv == ERR_IO_PENDING) 775 if (rv == ERR_IO_PENDING)
776 rv = Start(); 776 rv = Start();
777 if (rv != ERR_IO_PENDING) 777 if (rv != ERR_IO_PENDING)
778 QueryComplete(rv); 778 QueryComplete(rv);
779 } 779 }
780 780
781 void CancelResolveJob() { 781 void CancelResolveJob() {
782 DCHECK(is_started()); 782 DCHECK(is_started());
783 // The request may already be running in the resolver. 783 // The request may already be running in the resolver.
784 resolver()->CancelRequest(resolve_job_); 784 resolver()->CancelRequest(resolve_job_);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 TimeTicks proxy_resolve_start_time_; 873 TimeTicks proxy_resolve_start_time_;
874 }; 874 };
875 875
876 // ProxyService --------------------------------------------------------------- 876 // ProxyService ---------------------------------------------------------------
877 877
878 ProxyService::ProxyService(ProxyConfigService* config_service, 878 ProxyService::ProxyService(ProxyConfigService* config_service,
879 ProxyResolver* resolver, 879 ProxyResolver* resolver,
880 NetLog* net_log) 880 NetLog* net_log)
881 : resolver_(resolver), 881 : resolver_(resolver),
882 next_config_id_(1), 882 next_config_id_(1),
883 current_state_(STATE_NONE) , 883 current_state_(STATE_NONE),
884 net_log_(net_log), 884 net_log_(net_log),
885 stall_proxy_auto_config_delay_(TimeDelta::FromMilliseconds( 885 stall_proxy_auto_config_delay_(TimeDelta::FromMilliseconds(
886 kDelayAfterNetworkChangesMs)), 886 kDelayAfterNetworkChangesMs)),
887 quick_check_enabled_(true) { 887 quick_check_enabled_(true) {
888 NetworkChangeNotifier::AddIPAddressObserver(this); 888 NetworkChangeNotifier::AddIPAddressObserver(this);
889 NetworkChangeNotifier::AddDNSObserver(this); 889 NetworkChangeNotifier::AddDNSObserver(this);
890 ResetConfigService(config_service); 890 ResetConfigService(config_service);
891 } 891 }
892 892
893 // static 893 // static
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 958
959 scoped_ptr<ProxyResolver> proxy_resolver( 959 scoped_ptr<ProxyResolver> proxy_resolver(
960 new ProxyResolverFromPacString(pac_string)); 960 new ProxyResolverFromPacString(pac_string));
961 961
962 return new ProxyService(proxy_config_service.release(), 962 return new ProxyService(proxy_config_service.release(),
963 proxy_resolver.release(), 963 proxy_resolver.release(),
964 NULL); 964 NULL);
965 } 965 }
966 966
967 int ProxyService::ResolveProxy(const GURL& raw_url, 967 int ProxyService::ResolveProxy(const GURL& raw_url,
968 int load_flags,
968 ProxyInfo* result, 969 ProxyInfo* result,
969 const net::CompletionCallback& callback, 970 const net::CompletionCallback& callback,
970 PacRequest** pac_request, 971 PacRequest** pac_request,
972 NetworkDelegate* network_delegate,
971 const BoundNetLog& net_log) { 973 const BoundNetLog& net_log) {
972 DCHECK(CalledOnValidThread()); 974 DCHECK(CalledOnValidThread());
973 DCHECK(!callback.is_null()); 975 DCHECK(!callback.is_null());
974 976
975 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE); 977 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE);
976 978
977 // Notify our polling-based dependencies that a resolve is taking place. 979 // Notify our polling-based dependencies that a resolve is taking place.
978 // This way they can schedule their polls in response to network activity. 980 // This way they can schedule their polls in response to network activity.
979 config_service_->OnLazyPoll(); 981 config_service_->OnLazyPoll();
980 if (script_poller_.get()) 982 if (script_poller_.get())
981 script_poller_->OnLazyPoll(); 983 script_poller_->OnLazyPoll();
982 984
983 if (current_state_ == STATE_NONE) 985 if (current_state_ == STATE_NONE)
984 ApplyProxyConfigIfAvailable(); 986 ApplyProxyConfigIfAvailable();
985 987
986 // Strip away any reference fragments and the username/password, as they 988 // Strip away any reference fragments and the username/password, as they
987 // are not relevant to proxy resolution. 989 // are not relevant to proxy resolution.
988 GURL url = SimplifyUrlForRequest(raw_url); 990 GURL url = SimplifyUrlForRequest(raw_url);
989 991
990 // Check if the request can be completed right away. (This is the case when 992 // Check if the request can be completed right away. (This is the case when
991 // using a direct connection for example). 993 // using a direct connection for example).
992 int rv = TryToCompleteSynchronously(url, result); 994 int rv = TryToCompleteSynchronously(url, load_flags,
995 network_delegate, result);
993 if (rv != ERR_IO_PENDING) 996 if (rv != ERR_IO_PENDING)
994 return DidFinishResolvingProxy(result, rv, net_log); 997 return DidFinishResolvingProxy(result, rv, net_log);
995 998
999 // TODO(rcs): add load_flags and network_delegate to PacRequest.
mmenke 2014/07/01 19:45:12 Since we aren't using flywheel with PACs, and are
rcs 2014/07/02 00:56:20 Done.
996 scoped_refptr<PacRequest> req( 1000 scoped_refptr<PacRequest> req(
997 new PacRequest(this, url, result, callback, net_log)); 1001 new PacRequest(this, url, result, callback, net_log));
998 1002
999 if (current_state_ == STATE_READY) { 1003 if (current_state_ == STATE_READY) {
1000 // Start the resolve request. 1004 // Start the resolve request.
1001 rv = req->Start(); 1005 rv = req->Start();
1002 if (rv != ERR_IO_PENDING) 1006 if (rv != ERR_IO_PENDING)
1003 return req->QueryDidComplete(rv); 1007 return req->QueryDidComplete(rv);
1004 } else { 1008 } else {
1005 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); 1009 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC);
1006 } 1010 }
1007 1011
1008 DCHECK_EQ(ERR_IO_PENDING, rv); 1012 DCHECK_EQ(ERR_IO_PENDING, rv);
1009 DCHECK(!ContainsPendingRequest(req.get())); 1013 DCHECK(!ContainsPendingRequest(req.get()));
1010 pending_requests_.push_back(req); 1014 pending_requests_.push_back(req);
1011 1015
1012 // Completion will be notified through |callback|, unless the caller cancels 1016 // Completion will be notified through |callback|, unless the caller cancels
1013 // the request using |pac_request|. 1017 // the request using |pac_request|.
1014 if (pac_request) 1018 if (pac_request)
1015 *pac_request = req.get(); 1019 *pac_request = req.get();
1016 return rv; // ERR_IO_PENDING 1020 return rv; // ERR_IO_PENDING
1017 } 1021 }
1018 1022
1019 int ProxyService::TryToCompleteSynchronously(const GURL& url, 1023 int ProxyService::TryToCompleteSynchronously(const GURL& url,
1024 int load_flags,
1025 NetworkDelegate* network_delegate,
1020 ProxyInfo* result) { 1026 ProxyInfo* result) {
1021 DCHECK_NE(STATE_NONE, current_state_); 1027 DCHECK_NE(STATE_NONE, current_state_);
1022 1028
1023 if (current_state_ != STATE_READY) 1029 if (current_state_ != STATE_READY)
1024 return ERR_IO_PENDING; // Still initializing. 1030 return ERR_IO_PENDING; // Still initializing.
1025 1031
1026 DCHECK_NE(config_.id(), ProxyConfig::kInvalidConfigID); 1032 DCHECK_NE(config_.id(), ProxyConfig::kInvalidConfigID);
1027 1033
1028 // If it was impossible to fetch or parse the PAC script, we cannot complete 1034 // If it was impossible to fetch or parse the PAC script, we cannot complete
1029 // the request here and bail out. 1035 // the request here and bail out.
1030 if (permanent_error_ != OK) 1036 if (permanent_error_ != OK)
1031 return permanent_error_; 1037 return permanent_error_;
1032 1038
1033 if (config_.HasAutomaticSettings()) 1039 if (config_.HasAutomaticSettings())
1034 return ERR_IO_PENDING; // Must submit the request to the proxy resolver. 1040 return ERR_IO_PENDING; // Must submit the request to the proxy resolver.
1035 1041
1036 // Use the manual proxy settings. 1042 // Use the manual proxy settings.
1037 config_.proxy_rules().Apply(url, result); 1043 config_.proxy_rules().Apply(url, result);
1038 result->config_source_ = config_.source(); 1044 result->config_source_ = config_.source();
1039 result->config_id_ = config_.id(); 1045 result->config_id_ = config_.id();
1046
1047 // Allow the network delegate to interpose on the resolution decision,
1048 // possibly modifying the ProxyInfo.
1049 if (network_delegate) {
1050 network_delegate->NotifyResolveProxy(url, load_flags, result);
1051 }
mmenke 2014/07/01 19:45:12 nit: To be consistent with the rest of the code i
rcs 2014/07/02 00:56:20 Done.
1052
1040 return OK; 1053 return OK;
1041 } 1054 }
1042 1055
1043 ProxyService::~ProxyService() { 1056 ProxyService::~ProxyService() {
1044 NetworkChangeNotifier::RemoveIPAddressObserver(this); 1057 NetworkChangeNotifier::RemoveIPAddressObserver(this);
1045 NetworkChangeNotifier::RemoveDNSObserver(this); 1058 NetworkChangeNotifier::RemoveDNSObserver(this);
1046 config_service_->RemoveObserver(this); 1059 config_service_->RemoveObserver(this);
1047 1060
1048 // Cancel any inprogress requests. 1061 // Cancel any inprogress requests.
1049 for (PendingRequests::iterator it = pending_requests_.begin(); 1062 for (PendingRequests::iterator it = pending_requests_.begin();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 // Resume any requests which we had to defer until the PAC script was 1176 // Resume any requests which we had to defer until the PAC script was
1164 // downloaded. 1177 // downloaded.
1165 SetReady(); 1178 SetReady();
1166 } 1179 }
1167 1180
1168 int ProxyService::ReconsiderProxyAfterError(const GURL& url, 1181 int ProxyService::ReconsiderProxyAfterError(const GURL& url,
1169 int net_error, 1182 int net_error,
1170 ProxyInfo* result, 1183 ProxyInfo* result,
1171 const CompletionCallback& callback, 1184 const CompletionCallback& callback,
1172 PacRequest** pac_request, 1185 PacRequest** pac_request,
1173 const BoundNetLog& net_log) { 1186 const BoundNetLog& net_log) {
mmenke 2014/07/01 19:45:12 When this is called from http_stream_factory_impl_
rcs 2014/07/02 00:56:20 Done.
1174 DCHECK(CalledOnValidThread()); 1187 DCHECK(CalledOnValidThread());
1175 1188
1176 // Check to see if we have a new config since ResolveProxy was called. We 1189 // Check to see if we have a new config since ResolveProxy was called. We
1177 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a 1190 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a
1178 // direct connection failed and we never tried the current config. 1191 // direct connection failed and we never tried the current config.
1179 1192
1180 bool re_resolve = result->config_id_ != config_.id(); 1193 bool re_resolve = result->config_id_ != config_.id();
1181 1194
1182 if (re_resolve) { 1195 if (re_resolve) {
1183 // If we have a new config or the config was never tried, we delete the 1196 // If we have a new config or the config was never tried, we delete the
1184 // list of bad proxies and we try again. 1197 // list of bad proxies and we try again.
1185 proxy_retry_info_.clear(); 1198 proxy_retry_info_.clear();
1186 return ResolveProxy(url, result, callback, pac_request, net_log); 1199 return ResolveProxy(url, 0, result, callback, pac_request, NULL, net_log);
1187 } 1200 }
1188 1201
1189 #if defined(SPDY_PROXY_AUTH_ORIGIN) 1202 #if defined(SPDY_PROXY_AUTH_ORIGIN)
1190 if (result->proxy_server().isDataReductionProxy()) { 1203 if (result->proxy_server().isDataReductionProxy()) {
1191 RecordDataReductionProxyBypassInfo( 1204 RecordDataReductionProxyBypassInfo(
1192 true, result->proxy_server(), ERROR_BYPASS); 1205 true, result->proxy_server(), ERROR_BYPASS);
1193 RecordDataReductionProxyBypassOnNetworkError( 1206 RecordDataReductionProxyBypassOnNetworkError(
1194 true, result->proxy_server(), net_error); 1207 true, result->proxy_server(), net_error);
1195 } else if (result->proxy_server().isDataReductionProxyFallback()) { 1208 } else if (result->proxy_server().isDataReductionProxyFallback()) {
1196 RecordDataReductionProxyBypassInfo( 1209 RecordDataReductionProxyBypassInfo(
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 *proxy_info = proxy_info_; 1629 *proxy_info = proxy_info_;
1617 } 1630 }
1618 return result_; 1631 return result_;
1619 } 1632 }
1620 1633
1621 SyncProxyServiceHelper::~SyncProxyServiceHelper() {} 1634 SyncProxyServiceHelper::~SyncProxyServiceHelper() {}
1622 1635
1623 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url, 1636 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url,
1624 const BoundNetLog& net_log) { 1637 const BoundNetLog& net_log) {
1625 result_ = proxy_service_->ResolveProxy( 1638 result_ = proxy_service_->ResolveProxy(
1626 url, &proxy_info_, callback_, NULL, net_log); 1639 url, 0, &proxy_info_, callback_, NULL, NULL, net_log);
1627 if (result_ != net::ERR_IO_PENDING) { 1640 if (result_ != net::ERR_IO_PENDING) {
1628 OnCompletion(result_); 1641 OnCompletion(result_);
1629 } 1642 }
1630 } 1643 }
1631 1644
1632 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url, 1645 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url,
1633 int net_error, 1646 int net_error,
1634 const BoundNetLog& net_log) { 1647 const BoundNetLog& net_log) {
1635 result_ = proxy_service_->ReconsiderProxyAfterError( 1648 result_ = proxy_service_->ReconsiderProxyAfterError(
1636 url, net_error, &proxy_info_, callback_, NULL, net_log); 1649 url, net_error, &proxy_info_, callback_, NULL, net_log);
1637 if (result_ != net::ERR_IO_PENDING) { 1650 if (result_ != net::ERR_IO_PENDING) {
1638 OnCompletion(result_); 1651 OnCompletion(result_);
1639 } 1652 }
1640 } 1653 }
1641 1654
1642 void SyncProxyServiceHelper::OnCompletion(int rv) { 1655 void SyncProxyServiceHelper::OnCompletion(int rv) {
1643 result_ = rv; 1656 result_ = rv;
1644 event_.Signal(); 1657 event_.Signal();
1645 } 1658 }
1646 1659
1647 } // namespace net 1660 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698