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

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

Powered by Google App Engine
This is Rietveld 408576698