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

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

Issue 1680893002: Moving proxy resolution logic out of NetworkDelegate and into ProxyDelegate for DataReductionProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "net/base/completion_callback.h" 23 #include "net/base/completion_callback.h"
24 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
25 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
26 #include "net/base/proxy_delegate.h"
26 #include "net/base/url_util.h" 27 #include "net/base/url_util.h"
27 #include "net/log/net_log.h" 28 #include "net/log/net_log.h"
28 #include "net/proxy/dhcp_proxy_script_fetcher.h" 29 #include "net/proxy/dhcp_proxy_script_fetcher.h"
29 #include "net/proxy/multi_threaded_proxy_resolver.h" 30 #include "net/proxy/multi_threaded_proxy_resolver.h"
30 #include "net/proxy/network_delegate_error_observer.h"
31 #include "net/proxy/proxy_config_service_fixed.h" 31 #include "net/proxy/proxy_config_service_fixed.h"
32 #include "net/proxy/proxy_resolver.h" 32 #include "net/proxy/proxy_resolver.h"
33 #include "net/proxy/proxy_resolver_factory.h" 33 #include "net/proxy/proxy_resolver_factory.h"
34 #include "net/proxy/proxy_script_decider.h" 34 #include "net/proxy/proxy_script_decider.h"
35 #include "net/proxy/proxy_script_fetcher.h" 35 #include "net/proxy/proxy_script_fetcher.h"
36 #include "net/url_request/url_request_context.h" 36 #include "net/url_request/url_request_context.h"
37 #include "url/gurl.h" 37 #include "url/gurl.h"
38 38
39 #if defined(OS_WIN) 39 #if defined(OS_WIN)
40 #include "net/proxy/proxy_config_service_win.h" 40 #include "net/proxy/proxy_config_service_win.h"
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 ProxyService::ProxyScriptDeciderPoller::poll_policy_ = NULL; 759 ProxyService::ProxyScriptDeciderPoller::poll_policy_ = NULL;
760 760
761 // ProxyService::PacRequest --------------------------------------------------- 761 // ProxyService::PacRequest ---------------------------------------------------
762 762
763 class ProxyService::PacRequest 763 class ProxyService::PacRequest
764 : public base::RefCounted<ProxyService::PacRequest> { 764 : public base::RefCounted<ProxyService::PacRequest> {
765 public: 765 public:
766 PacRequest(ProxyService* service, 766 PacRequest(ProxyService* service,
767 const GURL& url, 767 const GURL& url,
768 int load_flags, 768 int load_flags,
769 NetworkDelegate* network_delegate, 769 ProxyDelegate* proxy_delegate,
770 ProxyInfo* results, 770 ProxyInfo* results,
771 const CompletionCallback& user_callback, 771 const CompletionCallback& user_callback,
772 const BoundNetLog& net_log) 772 const BoundNetLog& net_log)
773 : service_(service), 773 : service_(service),
774 user_callback_(user_callback), 774 user_callback_(user_callback),
775 results_(results), 775 results_(results),
776 url_(url), 776 url_(url),
777 load_flags_(load_flags), 777 load_flags_(load_flags),
778 network_delegate_(network_delegate), 778 proxy_delegate_(proxy_delegate),
779 resolve_job_(NULL), 779 resolve_job_(NULL),
780 config_id_(ProxyConfig::kInvalidConfigID), 780 config_id_(ProxyConfig::kInvalidConfigID),
781 config_source_(PROXY_CONFIG_SOURCE_UNKNOWN), 781 config_source_(PROXY_CONFIG_SOURCE_UNKNOWN),
782 net_log_(net_log), 782 net_log_(net_log),
783 creation_time_(TimeTicks::Now()) { 783 creation_time_(TimeTicks::Now()) {
784 DCHECK(!user_callback.is_null()); 784 DCHECK(!user_callback.is_null());
785 } 785 }
786 786
787 // Starts the resolve proxy request. 787 // Starts the resolve proxy request.
788 int Start() { 788 int Start() {
(...skipping 11 matching lines...) Expand all
800 &resolve_job_, net_log_); 800 &resolve_job_, net_log_);
801 } 801 }
802 802
803 bool is_started() const { 803 bool is_started() const {
804 // Note that !! casts to bool. (VS gives a warning otherwise). 804 // Note that !! casts to bool. (VS gives a warning otherwise).
805 return !!resolve_job_; 805 return !!resolve_job_;
806 } 806 }
807 807
808 void StartAndCompleteCheckingForSynchronous() { 808 void StartAndCompleteCheckingForSynchronous() {
809 int rv = service_->TryToCompleteSynchronously(url_, load_flags_, 809 int rv = service_->TryToCompleteSynchronously(url_, load_flags_,
810 network_delegate_, results_); 810 proxy_delegate_, results_);
811 if (rv == ERR_IO_PENDING) 811 if (rv == ERR_IO_PENDING)
812 rv = Start(); 812 rv = Start();
813 if (rv != ERR_IO_PENDING) 813 if (rv != ERR_IO_PENDING)
814 QueryComplete(rv); 814 QueryComplete(rv);
815 } 815 }
816 816
817 void CancelResolveJob() { 817 void CancelResolveJob() {
818 DCHECK(is_started()); 818 DCHECK(is_started());
819 // The request may already be running in the resolver. 819 // The request may already be running in the resolver.
820 resolver()->CancelRequest(resolve_job_); 820 resolver()->CancelRequest(resolve_job_);
(...skipping 27 matching lines...) Expand all
848 848
849 // This state is cleared when resolve_job_ is set to nullptr below. 849 // This state is cleared when resolve_job_ is set to nullptr below.
850 bool script_executed = is_started(); 850 bool script_executed = is_started();
851 851
852 // Clear |resolve_job_| so is_started() returns false while 852 // Clear |resolve_job_| so is_started() returns false while
853 // DidFinishResolvingProxy() runs. 853 // DidFinishResolvingProxy() runs.
854 resolve_job_ = nullptr; 854 resolve_job_ = nullptr;
855 855
856 // Note that DidFinishResolvingProxy might modify |results_|. 856 // Note that DidFinishResolvingProxy might modify |results_|.
857 int rv = service_->DidFinishResolvingProxy( 857 int rv = service_->DidFinishResolvingProxy(
858 url_, load_flags_, network_delegate_, results_, result_code, net_log_, 858 url_, load_flags_, proxy_delegate_, results_, result_code, net_log_,
859 creation_time_, script_executed); 859 creation_time_, script_executed);
860 860
861 // Make a note in the results which configuration was in use at the 861 // Make a note in the results which configuration was in use at the
862 // time of the resolve. 862 // time of the resolve.
863 results_->config_id_ = config_id_; 863 results_->config_id_ = config_id_;
864 results_->config_source_ = config_source_; 864 results_->config_source_ = config_source_;
865 results_->did_use_pac_script_ = true; 865 results_->did_use_pac_script_ = true;
866 results_->proxy_resolve_start_time_ = creation_time_; 866 results_->proxy_resolve_start_time_ = creation_time_;
867 results_->proxy_resolve_end_time_ = TimeTicks::Now(); 867 results_->proxy_resolve_end_time_ = TimeTicks::Now();
868 868
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 ProxyResolver* resolver() const { return service_->resolver_.get(); } 902 ProxyResolver* resolver() const { return service_->resolver_.get(); }
903 903
904 // Note that we don't hold a reference to the ProxyService. Outstanding 904 // Note that we don't hold a reference to the ProxyService. Outstanding
905 // requests are cancelled during ~ProxyService, so this is guaranteed 905 // requests are cancelled during ~ProxyService, so this is guaranteed
906 // to be valid throughout our lifetime. 906 // to be valid throughout our lifetime.
907 ProxyService* service_; 907 ProxyService* service_;
908 CompletionCallback user_callback_; 908 CompletionCallback user_callback_;
909 ProxyInfo* results_; 909 ProxyInfo* results_;
910 GURL url_; 910 GURL url_;
911 int load_flags_; 911 int load_flags_;
912 NetworkDelegate* network_delegate_; 912 ProxyDelegate* proxy_delegate_;
913 ProxyResolver::RequestHandle resolve_job_; 913 ProxyResolver::RequestHandle resolve_job_;
914 ProxyConfig::ID config_id_; // The config id when the resolve was started. 914 ProxyConfig::ID config_id_; // The config id when the resolve was started.
915 ProxyConfigSource config_source_; // The source of proxy settings. 915 ProxyConfigSource config_source_; // The source of proxy settings.
916 BoundNetLog net_log_; 916 BoundNetLog net_log_;
917 // Time when the request was created. Stored here rather than in |results_| 917 // Time when the request was created. Stored here rather than in |results_|
918 // because the time in |results_| will be cleared. 918 // because the time in |results_| will be cleared.
919 TimeTicks creation_time_; 919 TimeTicks creation_time_;
920 }; 920 };
921 921
922 // ProxyService --------------------------------------------------------------- 922 // ProxyService ---------------------------------------------------------------
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 return make_scoped_ptr(new ProxyService( 1004 return make_scoped_ptr(new ProxyService(
1005 std::move(proxy_config_service), 1005 std::move(proxy_config_service),
1006 make_scoped_ptr(new ProxyResolverFactoryForPacResult(pac_string)), NULL)); 1006 make_scoped_ptr(new ProxyResolverFactoryForPacResult(pac_string)), NULL));
1007 } 1007 }
1008 1008
1009 int ProxyService::ResolveProxy(const GURL& raw_url, 1009 int ProxyService::ResolveProxy(const GURL& raw_url,
1010 int load_flags, 1010 int load_flags,
1011 ProxyInfo* result, 1011 ProxyInfo* result,
1012 const CompletionCallback& callback, 1012 const CompletionCallback& callback,
1013 PacRequest** pac_request, 1013 PacRequest** pac_request,
1014 NetworkDelegate* network_delegate, 1014 ProxyDelegate* proxy_delegate,
1015 const BoundNetLog& net_log) { 1015 const BoundNetLog& net_log) {
1016 DCHECK(!callback.is_null()); 1016 DCHECK(!callback.is_null());
1017 return ResolveProxyHelper(raw_url, 1017 return ResolveProxyHelper(raw_url, load_flags, result, callback, pac_request,
1018 load_flags, 1018 proxy_delegate, net_log);
1019 result,
1020 callback,
1021 pac_request,
1022 network_delegate,
1023 net_log);
1024 } 1019 }
1025 1020
1026 int ProxyService::ResolveProxyHelper(const GURL& raw_url, 1021 int ProxyService::ResolveProxyHelper(const GURL& raw_url,
1027 int load_flags, 1022 int load_flags,
1028 ProxyInfo* result, 1023 ProxyInfo* result,
1029 const CompletionCallback& callback, 1024 const CompletionCallback& callback,
1030 PacRequest** pac_request, 1025 PacRequest** pac_request,
1031 NetworkDelegate* network_delegate, 1026 ProxyDelegate* proxy_delegate,
1032 const BoundNetLog& net_log) { 1027 const BoundNetLog& net_log) {
1033 DCHECK(CalledOnValidThread()); 1028 DCHECK(CalledOnValidThread());
1034 1029
1035 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE); 1030 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE);
1036 1031
1037 // Notify our polling-based dependencies that a resolve is taking place. 1032 // Notify our polling-based dependencies that a resolve is taking place.
1038 // This way they can schedule their polls in response to network activity. 1033 // This way they can schedule their polls in response to network activity.
1039 config_service_->OnLazyPoll(); 1034 config_service_->OnLazyPoll();
1040 if (script_poller_.get()) 1035 if (script_poller_.get())
1041 script_poller_->OnLazyPoll(); 1036 script_poller_->OnLazyPoll();
1042 1037
1043 if (current_state_ == STATE_NONE) 1038 if (current_state_ == STATE_NONE)
1044 ApplyProxyConfigIfAvailable(); 1039 ApplyProxyConfigIfAvailable();
1045 1040
1046 // Strip away any reference fragments and the username/password, as they 1041 // Strip away any reference fragments and the username/password, as they
1047 // are not relevant to proxy resolution. 1042 // are not relevant to proxy resolution.
1048 GURL url = SimplifyUrlForRequest(raw_url); 1043 GURL url = SimplifyUrlForRequest(raw_url);
1049 1044
1050 // Check if the request can be completed right away. (This is the case when 1045 // Check if the request can be completed right away. (This is the case when
1051 // using a direct connection for example). 1046 // using a direct connection for example).
1052 int rv = TryToCompleteSynchronously(url, load_flags, 1047 int rv = TryToCompleteSynchronously(url, load_flags, proxy_delegate, result);
1053 network_delegate, result);
1054 if (rv != ERR_IO_PENDING) { 1048 if (rv != ERR_IO_PENDING) {
1055 rv = DidFinishResolvingProxy( 1049 rv = DidFinishResolvingProxy(
1056 url, load_flags, network_delegate, result, rv, net_log, 1050 url, load_flags, proxy_delegate, result, rv, net_log,
1057 callback.is_null() ? TimeTicks() : TimeTicks::Now(), false); 1051 callback.is_null() ? TimeTicks() : TimeTicks::Now(), false);
1058 return rv; 1052 return rv;
1059 } 1053 }
1060 1054
1061 if (callback.is_null()) 1055 if (callback.is_null())
1062 return ERR_IO_PENDING; 1056 return ERR_IO_PENDING;
1063 1057
1064 scoped_refptr<PacRequest> req( 1058 scoped_refptr<PacRequest> req(new PacRequest(
1065 new PacRequest(this, url, load_flags, network_delegate, 1059 this, url, load_flags, proxy_delegate, result, callback, net_log));
1066 result, callback, net_log));
1067 1060
1068 if (current_state_ == STATE_READY) { 1061 if (current_state_ == STATE_READY) {
1069 // Start the resolve request. 1062 // Start the resolve request.
1070 rv = req->Start(); 1063 rv = req->Start();
1071 if (rv != ERR_IO_PENDING) 1064 if (rv != ERR_IO_PENDING)
1072 return req->QueryDidComplete(rv); 1065 return req->QueryDidComplete(rv);
1073 } else { 1066 } else {
1074 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); 1067 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC);
1075 } 1068 }
1076 1069
1077 DCHECK_EQ(ERR_IO_PENDING, rv); 1070 DCHECK_EQ(ERR_IO_PENDING, rv);
1078 DCHECK(!ContainsPendingRequest(req.get())); 1071 DCHECK(!ContainsPendingRequest(req.get()));
1079 pending_requests_.insert(req); 1072 pending_requests_.insert(req);
1080 1073
1081 // Completion will be notified through |callback|, unless the caller cancels 1074 // Completion will be notified through |callback|, unless the caller cancels
1082 // the request using |pac_request|. 1075 // the request using |pac_request|.
1083 if (pac_request) 1076 if (pac_request)
1084 *pac_request = req.get(); 1077 *pac_request = req.get();
1085 return rv; // ERR_IO_PENDING 1078 return rv; // ERR_IO_PENDING
1086 } 1079 }
1087 1080
1088 bool ProxyService:: TryResolveProxySynchronously( 1081 bool ProxyService::TryResolveProxySynchronously(const GURL& raw_url,
1089 const GURL& raw_url, 1082 int load_flags,
1090 int load_flags, 1083 ProxyInfo* result,
1091 ProxyInfo* result, 1084 ProxyDelegate* proxy_delegate,
1092 NetworkDelegate* network_delegate, 1085 const BoundNetLog& net_log) {
1093 const BoundNetLog& net_log) {
1094 CompletionCallback null_callback; 1086 CompletionCallback null_callback;
1095 return ResolveProxyHelper(raw_url, 1087 return ResolveProxyHelper(raw_url, load_flags, result, null_callback,
1096 load_flags, 1088 NULL /* pac_request*/, proxy_delegate,
1097 result,
1098 null_callback,
1099 NULL /* pac_request*/,
1100 network_delegate,
1101 net_log) == OK; 1089 net_log) == OK;
1102 } 1090 }
1103 1091
1104 int ProxyService::TryToCompleteSynchronously(const GURL& url, 1092 int ProxyService::TryToCompleteSynchronously(const GURL& url,
1105 int load_flags, 1093 int load_flags,
1106 NetworkDelegate* network_delegate, 1094 ProxyDelegate* proxy_delegate,
1107 ProxyInfo* result) { 1095 ProxyInfo* result) {
1108 DCHECK_NE(STATE_NONE, current_state_); 1096 DCHECK_NE(STATE_NONE, current_state_);
1109 1097
1110 if (current_state_ != STATE_READY) 1098 if (current_state_ != STATE_READY)
1111 return ERR_IO_PENDING; // Still initializing. 1099 return ERR_IO_PENDING; // Still initializing.
1112 1100
1113 DCHECK_NE(config_.id(), ProxyConfig::kInvalidConfigID); 1101 DCHECK_NE(config_.id(), ProxyConfig::kInvalidConfigID);
1114 1102
1115 // If it was impossible to fetch or parse the PAC script, we cannot complete 1103 // If it was impossible to fetch or parse the PAC script, we cannot complete
1116 // the request here and bail out. 1104 // the request here and bail out.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 // downloaded. 1242 // downloaded.
1255 SetReady(); 1243 SetReady();
1256 } 1244 }
1257 1245
1258 int ProxyService::ReconsiderProxyAfterError(const GURL& url, 1246 int ProxyService::ReconsiderProxyAfterError(const GURL& url,
1259 int load_flags, 1247 int load_flags,
1260 int net_error, 1248 int net_error,
1261 ProxyInfo* result, 1249 ProxyInfo* result,
1262 const CompletionCallback& callback, 1250 const CompletionCallback& callback,
1263 PacRequest** pac_request, 1251 PacRequest** pac_request,
1264 NetworkDelegate* network_delegate, 1252 ProxyDelegate* proxy_delegate,
1265 const BoundNetLog& net_log) { 1253 const BoundNetLog& net_log) {
1266 DCHECK(CalledOnValidThread()); 1254 DCHECK(CalledOnValidThread());
1267 1255
1268 // Check to see if we have a new config since ResolveProxy was called. We 1256 // Check to see if we have a new config since ResolveProxy was called. We
1269 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a 1257 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a
1270 // direct connection failed and we never tried the current config. 1258 // direct connection failed and we never tried the current config.
1271 1259
1272 DCHECK(result); 1260 DCHECK(result);
1273 bool re_resolve = result->config_id_ != config_.id(); 1261 bool re_resolve = result->config_id_ != config_.id();
1274 1262
1275 if (re_resolve) { 1263 if (re_resolve) {
1276 // If we have a new config or the config was never tried, we delete the 1264 // If we have a new config or the config was never tried, we delete the
1277 // list of bad proxies and we try again. 1265 // list of bad proxies and we try again.
1278 proxy_retry_info_.clear(); 1266 proxy_retry_info_.clear();
1279 return ResolveProxy(url, load_flags, result, callback, pac_request, 1267 return ResolveProxy(url, load_flags, result, callback, pac_request,
1280 network_delegate, net_log); 1268 proxy_delegate, net_log);
1281 } 1269 }
1282 1270
1283 DCHECK(!result->is_empty()); 1271 DCHECK(!result->is_empty());
1284 ProxyServer bad_proxy = result->proxy_server(); 1272 ProxyServer bad_proxy = result->proxy_server();
1285 1273
1286 // We don't have new proxy settings to try, try to fallback to the next proxy 1274 // We don't have new proxy settings to try, try to fallback to the next proxy
1287 // in the list. 1275 // in the list.
1288 bool did_fallback = result->Fallback(net_error, net_log); 1276 bool did_fallback = result->Fallback(net_error, net_log);
1289 1277
1290 // Return synchronous failure if there is nothing left to fall-back to. 1278 // Return synchronous failure if there is nothing left to fall-back to.
1291 // TODO(eroman): This is a yucky API, clean it up. 1279 // TODO(eroman): This is a yucky API, clean it up.
1292 return did_fallback ? OK : ERR_FAILED; 1280 return did_fallback ? OK : ERR_FAILED;
1293 } 1281 }
1294 1282
1295 bool ProxyService::MarkProxiesAsBadUntil( 1283 bool ProxyService::MarkProxiesAsBadUntil(
1296 const ProxyInfo& result, 1284 const ProxyInfo& result,
1297 base::TimeDelta retry_delay, 1285 base::TimeDelta retry_delay,
1298 const std::vector<ProxyServer>& additional_bad_proxies, 1286 const std::vector<ProxyServer>& additional_bad_proxies,
1299 const BoundNetLog& net_log) { 1287 const BoundNetLog& net_log) {
1300 result.proxy_list_.UpdateRetryInfoOnFallback(&proxy_retry_info_, retry_delay, 1288 result.proxy_list_.UpdateRetryInfoOnFallback(&proxy_retry_info_, retry_delay,
1301 false, additional_bad_proxies, 1289 false, additional_bad_proxies,
1302 OK, net_log); 1290 OK, net_log);
1303 return result.proxy_list_.size() > (additional_bad_proxies.size() + 1); 1291 return result.proxy_list_.size() > (additional_bad_proxies.size() + 1);
1304 } 1292 }
1305 1293
1306 void ProxyService::ReportSuccess(const ProxyInfo& result, 1294 void ProxyService::ReportSuccess(const ProxyInfo& result,
1307 NetworkDelegate* network_delegate) { 1295 ProxyDelegate* proxy_delegate) {
1308 DCHECK(CalledOnValidThread()); 1296 DCHECK(CalledOnValidThread());
1309 1297
1310 const ProxyRetryInfoMap& new_retry_info = result.proxy_retry_info(); 1298 const ProxyRetryInfoMap& new_retry_info = result.proxy_retry_info();
1311 if (new_retry_info.empty()) 1299 if (new_retry_info.empty())
1312 return; 1300 return;
1313 1301
1314 for (ProxyRetryInfoMap::const_iterator iter = new_retry_info.begin(); 1302 for (ProxyRetryInfoMap::const_iterator iter = new_retry_info.begin();
1315 iter != new_retry_info.end(); ++iter) { 1303 iter != new_retry_info.end(); ++iter) {
1316 ProxyRetryInfoMap::iterator existing = proxy_retry_info_.find(iter->first); 1304 ProxyRetryInfoMap::iterator existing = proxy_retry_info_.find(iter->first);
1317 if (existing == proxy_retry_info_.end()) { 1305 if (existing == proxy_retry_info_.end()) {
1318 proxy_retry_info_[iter->first] = iter->second; 1306 proxy_retry_info_[iter->first] = iter->second;
1319 if (network_delegate) { 1307 if (proxy_delegate) {
1320 const ProxyServer& bad_proxy = 1308 const ProxyServer& bad_proxy =
1321 ProxyServer::FromURI(iter->first, ProxyServer::SCHEME_HTTP); 1309 ProxyServer::FromURI(iter->first, ProxyServer::SCHEME_HTTP);
1322 const ProxyRetryInfo& proxy_retry_info = iter->second; 1310 const ProxyRetryInfo& proxy_retry_info = iter->second;
1323 network_delegate->NotifyProxyFallback(bad_proxy, 1311 proxy_delegate->OnFallback(bad_proxy, proxy_retry_info.net_error);
1324 proxy_retry_info.net_error);
1325 } 1312 }
1326 } 1313 }
1327 else if (existing->second.bad_until < iter->second.bad_until) 1314 else if (existing->second.bad_until < iter->second.bad_until)
1328 existing->second.bad_until = iter->second.bad_until; 1315 existing->second.bad_until = iter->second.bad_until;
1329 } 1316 }
1330 if (net_log_) { 1317 if (net_log_) {
1331 net_log_->AddGlobalEntry( 1318 net_log_->AddGlobalEntry(
1332 NetLog::TYPE_BAD_PROXY_LIST_REPORTED, 1319 NetLog::TYPE_BAD_PROXY_LIST_REPORTED,
1333 base::Bind(&NetLogBadProxyListCallback, &new_retry_info)); 1320 base::Bind(&NetLogBadProxyListCallback, &new_retry_info));
1334 } 1321 }
(...skipping 17 matching lines...) Expand all
1352 return pending_requests_.count(req) == 1; 1339 return pending_requests_.count(req) == 1;
1353 } 1340 }
1354 1341
1355 void ProxyService::RemovePendingRequest(PacRequest* req) { 1342 void ProxyService::RemovePendingRequest(PacRequest* req) {
1356 DCHECK(ContainsPendingRequest(req)); 1343 DCHECK(ContainsPendingRequest(req));
1357 pending_requests_.erase(req); 1344 pending_requests_.erase(req);
1358 } 1345 }
1359 1346
1360 int ProxyService::DidFinishResolvingProxy(const GURL& url, 1347 int ProxyService::DidFinishResolvingProxy(const GURL& url,
1361 int load_flags, 1348 int load_flags,
1362 NetworkDelegate* network_delegate, 1349 ProxyDelegate* proxy_delegate,
1363 ProxyInfo* result, 1350 ProxyInfo* result,
1364 int result_code, 1351 int result_code,
1365 const BoundNetLog& net_log, 1352 const BoundNetLog& net_log,
1366 base::TimeTicks start_time, 1353 base::TimeTicks start_time,
1367 bool script_executed) { 1354 bool script_executed) {
1368 // Don't track any metrics if start_time is 0, which will happen when the user 1355 // Don't track any metrics if start_time is 0, which will happen when the user
1369 // calls |TryResolveProxySynchronously|. 1356 // calls |TryResolveProxySynchronously|.
1370 if (!start_time.is_null()) { 1357 if (!start_time.is_null()) {
1371 TimeDelta diff = TimeTicks::Now() - start_time; 1358 TimeDelta diff = TimeTicks::Now() - start_time;
1372 if (script_executed) { 1359 if (script_executed) {
1373 // This function "fixes" the result code, so make sure script terminated 1360 // This function "fixes" the result code, so make sure script terminated
1374 // errors are tracked. Only track result codes that were a result of 1361 // errors are tracked. Only track result codes that were a result of
1375 // script execution. 1362 // script execution.
1376 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ScriptTerminated", 1363 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ScriptTerminated",
1377 result_code == ERR_PAC_SCRIPT_TERMINATED); 1364 result_code == ERR_PAC_SCRIPT_TERMINATED);
1378 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.GetProxyUsingScriptTime", 1365 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.GetProxyUsingScriptTime",
1379 diff, base::TimeDelta::FromMicroseconds(100), 1366 diff, base::TimeDelta::FromMicroseconds(100),
1380 base::TimeDelta::FromSeconds(20), 50); 1367 base::TimeDelta::FromSeconds(20), 50);
1381 } 1368 }
1382 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedUsingScript", 1369 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedUsingScript",
1383 script_executed); 1370 script_executed);
1384 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.ResolveProxyTime", diff, 1371 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.ResolveProxyTime", diff,
1385 base::TimeDelta::FromMicroseconds(100), 1372 base::TimeDelta::FromMicroseconds(100),
1386 base::TimeDelta::FromSeconds(20), 50); 1373 base::TimeDelta::FromSeconds(20), 50);
1387 } 1374 }
1388
1389 // Log the result of the proxy resolution. 1375 // Log the result of the proxy resolution.
1390 if (result_code == OK) { 1376 if (result_code == OK) {
1391 // Allow the network delegate to interpose on the resolution decision, 1377 // Allow the network delegate to interpose on the resolution decision,
1392 // possibly modifying the ProxyInfo. 1378 // possibly modifying the ProxyInfo.
1393 if (network_delegate) 1379 if (proxy_delegate)
1394 network_delegate->NotifyResolveProxy(url, load_flags, *this, result); 1380 proxy_delegate->OnResolveProxy(url, load_flags, *this, result);
1395 1381
1396 net_log.AddEvent(NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, 1382 net_log.AddEvent(NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST,
1397 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); 1383 base::Bind(&NetLogFinishedResolvingProxyCallback, result));
1398 1384
1399 // This check is done to only log the NetLog event when necessary, it's 1385 // This check is done to only log the NetLog event when necessary, it's
1400 // not a performance optimization. 1386 // not a performance optimization.
1401 if (!proxy_retry_info_.empty()) { 1387 if (!proxy_retry_info_.empty()) {
1402 result->DeprioritizeBadProxies(proxy_retry_info_); 1388 result->DeprioritizeBadProxies(proxy_retry_info_);
1403 net_log.AddEvent( 1389 net_log.AddEvent(
1404 NetLog::TYPE_PROXY_SERVICE_DEPRIORITIZED_BAD_PROXIES, 1390 NetLog::TYPE_PROXY_SERVICE_DEPRIORITIZED_BAD_PROXIES,
(...skipping 10 matching lines...) Expand all
1415 // 1401 //
1416 // This implicit fall-back to direct matches Firefox 3.5 and 1402 // This implicit fall-back to direct matches Firefox 3.5 and
1417 // Internet Explorer 8. For more information, see: 1403 // Internet Explorer 8. For more information, see:
1418 // 1404 //
1419 // http://www.chromium.org/developers/design-documents/proxy-settings-fall back 1405 // http://www.chromium.org/developers/design-documents/proxy-settings-fall back
1420 result->UseDirect(); 1406 result->UseDirect();
1421 result_code = OK; 1407 result_code = OK;
1422 1408
1423 // Allow the network delegate to interpose on the resolution decision, 1409 // Allow the network delegate to interpose on the resolution decision,
1424 // possibly modifying the ProxyInfo. 1410 // possibly modifying the ProxyInfo.
1425 if (network_delegate) 1411 if (proxy_delegate)
1426 network_delegate->NotifyResolveProxy(url, load_flags, *this, result); 1412 proxy_delegate->OnResolveProxy(url, load_flags, *this, result);
1427 } else { 1413 } else {
1428 result_code = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED; 1414 result_code = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED;
1429 } 1415 }
1430 if (reset_config) { 1416 if (reset_config) {
1431 ResetProxyConfig(false); 1417 ResetProxyConfig(false);
1432 // If the ProxyResolver crashed, force it to be re-initialized for the 1418 // If the ProxyResolver crashed, force it to be re-initialized for the
1433 // next request by resetting the proxy config. If there are other pending 1419 // next request by resetting the proxy config. If there are other pending
1434 // requests, trigger the recreation immediately so those requests retry. 1420 // requests, trigger the recreation immediately so those requests retry.
1435 if (pending_requests_.size() > 1) 1421 if (pending_requests_.size() > 1)
1436 ApplyProxyConfigIfAvailable(); 1422 ApplyProxyConfigIfAvailable();
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 State previous_state = ResetProxyConfig(false); 1635 State previous_state = ResetProxyConfig(false);
1650 if (previous_state != STATE_NONE) 1636 if (previous_state != STATE_NONE)
1651 ApplyProxyConfigIfAvailable(); 1637 ApplyProxyConfigIfAvailable();
1652 } 1638 }
1653 1639
1654 void ProxyService::OnDNSChanged() { 1640 void ProxyService::OnDNSChanged() {
1655 OnIPAddressChanged(); 1641 OnIPAddressChanged();
1656 } 1642 }
1657 1643
1658 } // namespace net 1644 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698