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

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: Address mmenke's feedback 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_);
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
996 scoped_refptr<PacRequest> req( 999 scoped_refptr<PacRequest> req(
997 new PacRequest(this, url, result, callback, net_log)); 1000 new PacRequest(this, url, result, callback, net_log));
998 1001
999 if (current_state_ == STATE_READY) { 1002 if (current_state_ == STATE_READY) {
1000 // Start the resolve request. 1003 // Start the resolve request.
1001 rv = req->Start(); 1004 rv = req->Start();
1002 if (rv != ERR_IO_PENDING) 1005 if (rv != ERR_IO_PENDING)
1003 return req->QueryDidComplete(rv); 1006 return req->QueryDidComplete(rv);
1004 } else { 1007 } else {
1005 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); 1008 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC);
1006 } 1009 }
1007 1010
1008 DCHECK_EQ(ERR_IO_PENDING, rv); 1011 DCHECK_EQ(ERR_IO_PENDING, rv);
1009 DCHECK(!ContainsPendingRequest(req.get())); 1012 DCHECK(!ContainsPendingRequest(req.get()));
1010 pending_requests_.push_back(req); 1013 pending_requests_.push_back(req);
1011 1014
1012 // Completion will be notified through |callback|, unless the caller cancels 1015 // Completion will be notified through |callback|, unless the caller cancels
1013 // the request using |pac_request|. 1016 // the request using |pac_request|.
1014 if (pac_request) 1017 if (pac_request)
1015 *pac_request = req.get(); 1018 *pac_request = req.get();
1016 return rv; // ERR_IO_PENDING 1019 return rv; // ERR_IO_PENDING
1017 } 1020 }
1018 1021
1019 int ProxyService::TryToCompleteSynchronously(const GURL& url, 1022 int ProxyService::TryToCompleteSynchronously(const GURL& url,
1023 int load_flags,
1024 NetworkDelegate* network_delegate,
1020 ProxyInfo* result) { 1025 ProxyInfo* result) {
1021 DCHECK_NE(STATE_NONE, current_state_); 1026 DCHECK_NE(STATE_NONE, current_state_);
1022 1027
1023 if (current_state_ != STATE_READY) 1028 if (current_state_ != STATE_READY)
1024 return ERR_IO_PENDING; // Still initializing. 1029 return ERR_IO_PENDING; // Still initializing.
1025 1030
1026 DCHECK_NE(config_.id(), ProxyConfig::kInvalidConfigID); 1031 DCHECK_NE(config_.id(), ProxyConfig::kInvalidConfigID);
1027 1032
1028 // If it was impossible to fetch or parse the PAC script, we cannot complete 1033 // If it was impossible to fetch or parse the PAC script, we cannot complete
1029 // the request here and bail out. 1034 // the request here and bail out.
1030 if (permanent_error_ != OK) 1035 if (permanent_error_ != OK)
1031 return permanent_error_; 1036 return permanent_error_;
1032 1037
1033 if (config_.HasAutomaticSettings()) 1038 if (config_.HasAutomaticSettings())
1034 return ERR_IO_PENDING; // Must submit the request to the proxy resolver. 1039 return ERR_IO_PENDING; // Must submit the request to the proxy resolver.
1035 1040
1036 // Use the manual proxy settings. 1041 // Use the manual proxy settings.
1037 config_.proxy_rules().Apply(url, result); 1042 config_.proxy_rules().Apply(url, result);
1038 result->config_source_ = config_.source(); 1043 result->config_source_ = config_.source();
1039 result->config_id_ = config_.id(); 1044 result->config_id_ = config_.id();
1045
1046 // Allow the network delegate to interpose on the resolution decision,
1047 // possibly modifying the ProxyInfo.
1048 if (network_delegate)
1049 network_delegate->NotifyResolveProxy(url, load_flags, result);
1050
1040 return OK; 1051 return OK;
1041 } 1052 }
1042 1053
1043 ProxyService::~ProxyService() { 1054 ProxyService::~ProxyService() {
1044 NetworkChangeNotifier::RemoveIPAddressObserver(this); 1055 NetworkChangeNotifier::RemoveIPAddressObserver(this);
1045 NetworkChangeNotifier::RemoveDNSObserver(this); 1056 NetworkChangeNotifier::RemoveDNSObserver(this);
1046 config_service_->RemoveObserver(this); 1057 config_service_->RemoveObserver(this);
1047 1058
1048 // Cancel any inprogress requests. 1059 // Cancel any inprogress requests.
1049 for (PendingRequests::iterator it = pending_requests_.begin(); 1060 for (PendingRequests::iterator it = pending_requests_.begin();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 // due to ProxyScriptDeciderPoller. 1170 // due to ProxyScriptDeciderPoller.
1160 config_.set_id(fetched_config_.id()); 1171 config_.set_id(fetched_config_.id());
1161 config_.set_source(fetched_config_.source()); 1172 config_.set_source(fetched_config_.source());
1162 1173
1163 // Resume any requests which we had to defer until the PAC script was 1174 // Resume any requests which we had to defer until the PAC script was
1164 // downloaded. 1175 // downloaded.
1165 SetReady(); 1176 SetReady();
1166 } 1177 }
1167 1178
1168 int ProxyService::ReconsiderProxyAfterError(const GURL& url, 1179 int ProxyService::ReconsiderProxyAfterError(const GURL& url,
1180 int load_flags,
1169 int net_error, 1181 int net_error,
1170 ProxyInfo* result, 1182 ProxyInfo* result,
1171 const CompletionCallback& callback, 1183 const CompletionCallback& callback,
1172 PacRequest** pac_request, 1184 PacRequest** pac_request,
1185 NetworkDelegate* network_delegate,
1173 const BoundNetLog& net_log) { 1186 const BoundNetLog& net_log) {
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, load_flags, result, callback, pac_request,
1200 network_delegate, net_log);
1187 } 1201 }
1188 1202
1189 #if defined(SPDY_PROXY_AUTH_ORIGIN) 1203 #if defined(SPDY_PROXY_AUTH_ORIGIN)
1190 if (result->proxy_server().isDataReductionProxy()) { 1204 if (result->proxy_server().isDataReductionProxy()) {
1191 RecordDataReductionProxyBypassInfo( 1205 RecordDataReductionProxyBypassInfo(
1192 true, result->proxy_server(), ERROR_BYPASS); 1206 true, result->proxy_server(), ERROR_BYPASS);
1193 RecordDataReductionProxyBypassOnNetworkError( 1207 RecordDataReductionProxyBypassOnNetworkError(
1194 true, result->proxy_server(), net_error); 1208 true, result->proxy_server(), net_error);
1195 } else if (result->proxy_server().isDataReductionProxyFallback()) { 1209 } else if (result->proxy_server().isDataReductionProxyFallback()) {
1196 RecordDataReductionProxyBypassInfo( 1210 RecordDataReductionProxyBypassInfo(
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 *proxy_info = proxy_info_; 1630 *proxy_info = proxy_info_;
1617 } 1631 }
1618 return result_; 1632 return result_;
1619 } 1633 }
1620 1634
1621 SyncProxyServiceHelper::~SyncProxyServiceHelper() {} 1635 SyncProxyServiceHelper::~SyncProxyServiceHelper() {}
1622 1636
1623 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url, 1637 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url,
1624 const BoundNetLog& net_log) { 1638 const BoundNetLog& net_log) {
1625 result_ = proxy_service_->ResolveProxy( 1639 result_ = proxy_service_->ResolveProxy(
1626 url, &proxy_info_, callback_, NULL, net_log); 1640 url, 0, &proxy_info_, callback_, NULL, NULL, net_log);
rcs 2014/07/02 06:08:55 Just noticed that I missed a LOAD_FLAGS -- will ch
rcs 2014/07/02 17:15:03 Done.
1627 if (result_ != net::ERR_IO_PENDING) { 1641 if (result_ != net::ERR_IO_PENDING) {
1628 OnCompletion(result_); 1642 OnCompletion(result_);
1629 } 1643 }
1630 } 1644 }
1631 1645
1632 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url, 1646 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url,
1633 int net_error, 1647 int net_error,
1634 const BoundNetLog& net_log) { 1648 const BoundNetLog& net_log) {
1635 result_ = proxy_service_->ReconsiderProxyAfterError( 1649 result_ = proxy_service_->ReconsiderProxyAfterError(
1636 url, net_error, &proxy_info_, callback_, NULL, net_log); 1650 url, 0, net_error, &proxy_info_, callback_, NULL, NULL, net_log);
1637 if (result_ != net::ERR_IO_PENDING) { 1651 if (result_ != net::ERR_IO_PENDING) {
1638 OnCompletion(result_); 1652 OnCompletion(result_);
1639 } 1653 }
1640 } 1654 }
1641 1655
1642 void SyncProxyServiceHelper::OnCompletion(int rv) { 1656 void SyncProxyServiceHelper::OnCompletion(int rv) {
1643 result_ = rv; 1657 result_ = rv;
1644 event_.Signal(); 1658 event_.Signal();
1645 } 1659 }
1646 1660
1647 } // namespace net 1661 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698