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

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: make LOAD_NORMAL consistent 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"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/metrics/sparse_histogram.h" 17 #include "base/metrics/sparse_histogram.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "net/base/completion_callback.h" 21 #include "net/base/completion_callback.h"
22 #include "net/base/load_flags.h"
22 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
23 #include "net/base/net_log.h" 24 #include "net/base/net_log.h"
24 #include "net/base/net_util.h" 25 #include "net/base/net_util.h"
25 #include "net/proxy/dhcp_proxy_script_fetcher.h" 26 #include "net/proxy/dhcp_proxy_script_fetcher.h"
26 #include "net/proxy/multi_threaded_proxy_resolver.h" 27 #include "net/proxy/multi_threaded_proxy_resolver.h"
27 #include "net/proxy/network_delegate_error_observer.h" 28 #include "net/proxy/network_delegate_error_observer.h"
28 #include "net/proxy/proxy_config_service_fixed.h" 29 #include "net/proxy/proxy_config_service_fixed.h"
29 #include "net/proxy/proxy_resolver.h" 30 #include "net/proxy/proxy_resolver.h"
30 #include "net/proxy/proxy_script_decider.h" 31 #include "net/proxy/proxy_script_decider.h"
31 #include "net/proxy/proxy_script_fetcher.h" 32 #include "net/proxy/proxy_script_fetcher.h"
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)), 765 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)),
765 &resolve_job_, net_log_); 766 &resolve_job_, net_log_);
766 } 767 }
767 768
768 bool is_started() const { 769 bool is_started() const {
769 // Note that !! casts to bool. (VS gives a warning otherwise). 770 // Note that !! casts to bool. (VS gives a warning otherwise).
770 return !!resolve_job_; 771 return !!resolve_job_;
771 } 772 }
772 773
773 void StartAndCompleteCheckingForSynchronous() { 774 void StartAndCompleteCheckingForSynchronous() {
774 int rv = service_->TryToCompleteSynchronously(url_, results_); 775 int rv = service_->TryToCompleteSynchronously(url_, 0, NULL, results_);
775 if (rv == ERR_IO_PENDING) 776 if (rv == ERR_IO_PENDING)
776 rv = Start(); 777 rv = Start();
777 if (rv != ERR_IO_PENDING) 778 if (rv != ERR_IO_PENDING)
778 QueryComplete(rv); 779 QueryComplete(rv);
779 } 780 }
780 781
781 void CancelResolveJob() { 782 void CancelResolveJob() {
782 DCHECK(is_started()); 783 DCHECK(is_started());
783 // The request may already be running in the resolver. 784 // The request may already be running in the resolver.
784 resolver()->CancelRequest(resolve_job_); 785 resolver()->CancelRequest(resolve_job_);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 TimeTicks proxy_resolve_start_time_; 874 TimeTicks proxy_resolve_start_time_;
874 }; 875 };
875 876
876 // ProxyService --------------------------------------------------------------- 877 // ProxyService ---------------------------------------------------------------
877 878
878 ProxyService::ProxyService(ProxyConfigService* config_service, 879 ProxyService::ProxyService(ProxyConfigService* config_service,
879 ProxyResolver* resolver, 880 ProxyResolver* resolver,
880 NetLog* net_log) 881 NetLog* net_log)
881 : resolver_(resolver), 882 : resolver_(resolver),
882 next_config_id_(1), 883 next_config_id_(1),
883 current_state_(STATE_NONE) , 884 current_state_(STATE_NONE),
884 net_log_(net_log), 885 net_log_(net_log),
885 stall_proxy_auto_config_delay_(TimeDelta::FromMilliseconds( 886 stall_proxy_auto_config_delay_(TimeDelta::FromMilliseconds(
886 kDelayAfterNetworkChangesMs)), 887 kDelayAfterNetworkChangesMs)),
887 quick_check_enabled_(true) { 888 quick_check_enabled_(true) {
888 NetworkChangeNotifier::AddIPAddressObserver(this); 889 NetworkChangeNotifier::AddIPAddressObserver(this);
889 NetworkChangeNotifier::AddDNSObserver(this); 890 NetworkChangeNotifier::AddDNSObserver(this);
890 ResetConfigService(config_service); 891 ResetConfigService(config_service);
891 } 892 }
892 893
893 // static 894 // static
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 959
959 scoped_ptr<ProxyResolver> proxy_resolver( 960 scoped_ptr<ProxyResolver> proxy_resolver(
960 new ProxyResolverFromPacString(pac_string)); 961 new ProxyResolverFromPacString(pac_string));
961 962
962 return new ProxyService(proxy_config_service.release(), 963 return new ProxyService(proxy_config_service.release(),
963 proxy_resolver.release(), 964 proxy_resolver.release(),
964 NULL); 965 NULL);
965 } 966 }
966 967
967 int ProxyService::ResolveProxy(const GURL& raw_url, 968 int ProxyService::ResolveProxy(const GURL& raw_url,
969 int load_flags,
968 ProxyInfo* result, 970 ProxyInfo* result,
969 const net::CompletionCallback& callback, 971 const net::CompletionCallback& callback,
970 PacRequest** pac_request, 972 PacRequest** pac_request,
973 NetworkDelegate* network_delegate,
971 const BoundNetLog& net_log) { 974 const BoundNetLog& net_log) {
972 DCHECK(CalledOnValidThread()); 975 DCHECK(CalledOnValidThread());
973 DCHECK(!callback.is_null()); 976 DCHECK(!callback.is_null());
974 977
975 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE); 978 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE);
976 979
977 // Notify our polling-based dependencies that a resolve is taking place. 980 // Notify our polling-based dependencies that a resolve is taking place.
978 // This way they can schedule their polls in response to network activity. 981 // This way they can schedule their polls in response to network activity.
979 config_service_->OnLazyPoll(); 982 config_service_->OnLazyPoll();
980 if (script_poller_.get()) 983 if (script_poller_.get())
981 script_poller_->OnLazyPoll(); 984 script_poller_->OnLazyPoll();
982 985
983 if (current_state_ == STATE_NONE) 986 if (current_state_ == STATE_NONE)
984 ApplyProxyConfigIfAvailable(); 987 ApplyProxyConfigIfAvailable();
985 988
986 // Strip away any reference fragments and the username/password, as they 989 // Strip away any reference fragments and the username/password, as they
987 // are not relevant to proxy resolution. 990 // are not relevant to proxy resolution.
988 GURL url = SimplifyUrlForRequest(raw_url); 991 GURL url = SimplifyUrlForRequest(raw_url);
989 992
990 // Check if the request can be completed right away. (This is the case when 993 // Check if the request can be completed right away. (This is the case when
991 // using a direct connection for example). 994 // using a direct connection for example).
992 int rv = TryToCompleteSynchronously(url, result); 995 int rv = TryToCompleteSynchronously(url, load_flags,
996 network_delegate, result);
993 if (rv != ERR_IO_PENDING) 997 if (rv != ERR_IO_PENDING)
994 return DidFinishResolvingProxy(result, rv, net_log); 998 return DidFinishResolvingProxy(result, rv, net_log);
995 999
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);
bengr 2014/07/02 18:46:43 If you move this to DidFinishResolvingProxy, then
rcs 2014/07/02 22:53:13 Done.
1051
1040 return OK; 1052 return OK;
1041 } 1053 }
1042 1054
1043 ProxyService::~ProxyService() { 1055 ProxyService::~ProxyService() {
1044 NetworkChangeNotifier::RemoveIPAddressObserver(this); 1056 NetworkChangeNotifier::RemoveIPAddressObserver(this);
1045 NetworkChangeNotifier::RemoveDNSObserver(this); 1057 NetworkChangeNotifier::RemoveDNSObserver(this);
1046 config_service_->RemoveObserver(this); 1058 config_service_->RemoveObserver(this);
1047 1059
1048 // Cancel any inprogress requests. 1060 // Cancel any inprogress requests.
1049 for (PendingRequests::iterator it = pending_requests_.begin(); 1061 for (PendingRequests::iterator it = pending_requests_.begin();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 // due to ProxyScriptDeciderPoller. 1171 // due to ProxyScriptDeciderPoller.
1160 config_.set_id(fetched_config_.id()); 1172 config_.set_id(fetched_config_.id());
1161 config_.set_source(fetched_config_.source()); 1173 config_.set_source(fetched_config_.source());
1162 1174
1163 // Resume any requests which we had to defer until the PAC script was 1175 // Resume any requests which we had to defer until the PAC script was
1164 // downloaded. 1176 // downloaded.
1165 SetReady(); 1177 SetReady();
1166 } 1178 }
1167 1179
1168 int ProxyService::ReconsiderProxyAfterError(const GURL& url, 1180 int ProxyService::ReconsiderProxyAfterError(const GURL& url,
1181 int load_flags,
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,
1186 NetworkDelegate* network_delegate,
1173 const BoundNetLog& net_log) { 1187 const BoundNetLog& net_log) {
1174 DCHECK(CalledOnValidThread()); 1188 DCHECK(CalledOnValidThread());
1175 1189
1176 // Check to see if we have a new config since ResolveProxy was called. We 1190 // 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 1191 // 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. 1192 // direct connection failed and we never tried the current config.
1179 1193
1180 bool re_resolve = result->config_id_ != config_.id(); 1194 bool re_resolve = result->config_id_ != config_.id();
1181 1195
1182 if (re_resolve) { 1196 if (re_resolve) {
1183 // If we have a new config or the config was never tried, we delete the 1197 // If we have a new config or the config was never tried, we delete the
1184 // list of bad proxies and we try again. 1198 // list of bad proxies and we try again.
1185 proxy_retry_info_.clear(); 1199 proxy_retry_info_.clear();
1186 return ResolveProxy(url, result, callback, pac_request, net_log); 1200 return ResolveProxy(url, load_flags, result, callback, pac_request,
1201 network_delegate, net_log);
1187 } 1202 }
1188 1203
1189 #if defined(SPDY_PROXY_AUTH_ORIGIN) 1204 #if defined(SPDY_PROXY_AUTH_ORIGIN)
1190 if (result->proxy_server().isDataReductionProxy()) { 1205 if (result->proxy_server().isDataReductionProxy()) {
1191 RecordDataReductionProxyBypassInfo( 1206 RecordDataReductionProxyBypassInfo(
1192 true, result->proxy_server(), ERROR_BYPASS); 1207 true, result->proxy_server(), ERROR_BYPASS);
1193 RecordDataReductionProxyBypassOnNetworkError( 1208 RecordDataReductionProxyBypassOnNetworkError(
1194 true, result->proxy_server(), net_error); 1209 true, result->proxy_server(), net_error);
1195 } else if (result->proxy_server().isDataReductionProxyFallback()) { 1210 } else if (result->proxy_server().isDataReductionProxyFallback()) {
1196 RecordDataReductionProxyBypassInfo( 1211 RecordDataReductionProxyBypassInfo(
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 *proxy_info = proxy_info_; 1631 *proxy_info = proxy_info_;
1617 } 1632 }
1618 return result_; 1633 return result_;
1619 } 1634 }
1620 1635
1621 SyncProxyServiceHelper::~SyncProxyServiceHelper() {} 1636 SyncProxyServiceHelper::~SyncProxyServiceHelper() {}
1622 1637
1623 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url, 1638 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url,
1624 const BoundNetLog& net_log) { 1639 const BoundNetLog& net_log) {
1625 result_ = proxy_service_->ResolveProxy( 1640 result_ = proxy_service_->ResolveProxy(
1626 url, &proxy_info_, callback_, NULL, net_log); 1641 url, net::LOAD_NORMAL, &proxy_info_, callback_, NULL, NULL, net_log);
1627 if (result_ != net::ERR_IO_PENDING) { 1642 if (result_ != net::ERR_IO_PENDING) {
1628 OnCompletion(result_); 1643 OnCompletion(result_);
1629 } 1644 }
1630 } 1645 }
1631 1646
1632 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url, 1647 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url,
1633 int net_error, 1648 int net_error,
1634 const BoundNetLog& net_log) { 1649 const BoundNetLog& net_log) {
1635 result_ = proxy_service_->ReconsiderProxyAfterError( 1650 result_ = proxy_service_->ReconsiderProxyAfterError(
1636 url, net_error, &proxy_info_, callback_, NULL, net_log); 1651 url, net::LOAD_NORMAL, net_error, &proxy_info_, callback_, NULL, NULL,
1652 net_log);
1637 if (result_ != net::ERR_IO_PENDING) { 1653 if (result_ != net::ERR_IO_PENDING) {
1638 OnCompletion(result_); 1654 OnCompletion(result_);
1639 } 1655 }
1640 } 1656 }
1641 1657
1642 void SyncProxyServiceHelper::OnCompletion(int rv) { 1658 void SyncProxyServiceHelper::OnCompletion(int rv) {
1643 result_ = rv; 1659 result_ = rv;
1644 event_.Signal(); 1660 event_.Signal();
1645 } 1661 }
1646 1662
1647 } // namespace net 1663 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698