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

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

Issue 1735203002: Revert of Moving proxy resolution logic out of NetworkDelegate and into ProxyDelegate (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
« no previous file with comments | « net/proxy/proxy_service.h ('k') | net/proxy/proxy_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
29 #include "net/base/url_util.h" 28 #include "net/base/url_util.h"
30 #include "net/log/net_log.h" 29 #include "net/log/net_log.h"
31 #include "net/proxy/dhcp_proxy_script_fetcher.h" 30 #include "net/proxy/dhcp_proxy_script_fetcher.h"
32 #include "net/proxy/multi_threaded_proxy_resolver.h" 31 #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 ProxyDelegate* proxy_delegate, 771 NetworkDelegate* network_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 proxy_delegate_(proxy_delegate), 780 network_delegate_(network_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 proxy_delegate_, results_); 812 network_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_, proxy_delegate_, results_, result_code, net_log_, 860 url_, load_flags_, network_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 ProxyDelegate* proxy_delegate_; 914 NetworkDelegate* network_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 ProxyDelegate* proxy_delegate, 1016 NetworkDelegate* network_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, load_flags, result, callback, pac_request, 1019 return ResolveProxyHelper(raw_url,
1020 proxy_delegate, net_log); 1020 load_flags,
1021 result,
1022 callback,
1023 pac_request,
1024 network_delegate,
1025 net_log);
1021 } 1026 }
1022 1027
1023 int ProxyService::ResolveProxyHelper(const GURL& raw_url, 1028 int ProxyService::ResolveProxyHelper(const GURL& raw_url,
1024 int load_flags, 1029 int load_flags,
1025 ProxyInfo* result, 1030 ProxyInfo* result,
1026 const CompletionCallback& callback, 1031 const CompletionCallback& callback,
1027 PacRequest** pac_request, 1032 PacRequest** pac_request,
1028 ProxyDelegate* proxy_delegate, 1033 NetworkDelegate* network_delegate,
1029 const BoundNetLog& net_log) { 1034 const BoundNetLog& net_log) {
1030 DCHECK(CalledOnValidThread()); 1035 DCHECK(CalledOnValidThread());
1031 1036
1032 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE); 1037 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE);
1033 1038
1034 // Notify our polling-based dependencies that a resolve is taking place. 1039 // Notify our polling-based dependencies that a resolve is taking place.
1035 // This way they can schedule their polls in response to network activity. 1040 // This way they can schedule their polls in response to network activity.
1036 config_service_->OnLazyPoll(); 1041 config_service_->OnLazyPoll();
1037 if (script_poller_.get()) 1042 if (script_poller_.get())
1038 script_poller_->OnLazyPoll(); 1043 script_poller_->OnLazyPoll();
1039 1044
1040 if (current_state_ == STATE_NONE) 1045 if (current_state_ == STATE_NONE)
1041 ApplyProxyConfigIfAvailable(); 1046 ApplyProxyConfigIfAvailable();
1042 1047
1043 // Strip away any reference fragments and the username/password, as they 1048 // Strip away any reference fragments and the username/password, as they
1044 // are not relevant to proxy resolution. 1049 // are not relevant to proxy resolution.
1045 GURL url = SimplifyUrlForRequest(raw_url); 1050 GURL url = SimplifyUrlForRequest(raw_url);
1046 1051
1047 // Check if the request can be completed right away. (This is the case when 1052 // Check if the request can be completed right away. (This is the case when
1048 // using a direct connection for example). 1053 // using a direct connection for example).
1049 int rv = TryToCompleteSynchronously(url, load_flags, proxy_delegate, result); 1054 int rv = TryToCompleteSynchronously(url, load_flags,
1055 network_delegate, result);
1050 if (rv != ERR_IO_PENDING) { 1056 if (rv != ERR_IO_PENDING) {
1051 rv = DidFinishResolvingProxy( 1057 rv = DidFinishResolvingProxy(
1052 url, load_flags, proxy_delegate, result, rv, net_log, 1058 url, load_flags, network_delegate, result, rv, net_log,
1053 callback.is_null() ? TimeTicks() : TimeTicks::Now(), false); 1059 callback.is_null() ? TimeTicks() : TimeTicks::Now(), false);
1054 return rv; 1060 return rv;
1055 } 1061 }
1056 1062
1057 if (callback.is_null()) 1063 if (callback.is_null())
1058 return ERR_IO_PENDING; 1064 return ERR_IO_PENDING;
1059 1065
1060 scoped_refptr<PacRequest> req(new PacRequest( 1066 scoped_refptr<PacRequest> req(
1061 this, url, load_flags, proxy_delegate, result, callback, net_log)); 1067 new PacRequest(this, url, load_flags, network_delegate,
1068 result, callback, net_log));
1062 1069
1063 if (current_state_ == STATE_READY) { 1070 if (current_state_ == STATE_READY) {
1064 // Start the resolve request. 1071 // Start the resolve request.
1065 rv = req->Start(); 1072 rv = req->Start();
1066 if (rv != ERR_IO_PENDING) 1073 if (rv != ERR_IO_PENDING)
1067 return req->QueryDidComplete(rv); 1074 return req->QueryDidComplete(rv);
1068 } else { 1075 } else {
1069 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); 1076 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC);
1070 } 1077 }
1071 1078
1072 DCHECK_EQ(ERR_IO_PENDING, rv); 1079 DCHECK_EQ(ERR_IO_PENDING, rv);
1073 DCHECK(!ContainsPendingRequest(req.get())); 1080 DCHECK(!ContainsPendingRequest(req.get()));
1074 pending_requests_.insert(req); 1081 pending_requests_.insert(req);
1075 1082
1076 // Completion will be notified through |callback|, unless the caller cancels 1083 // Completion will be notified through |callback|, unless the caller cancels
1077 // the request using |pac_request|. 1084 // the request using |pac_request|.
1078 if (pac_request) 1085 if (pac_request)
1079 *pac_request = req.get(); 1086 *pac_request = req.get();
1080 return rv; // ERR_IO_PENDING 1087 return rv; // ERR_IO_PENDING
1081 } 1088 }
1082 1089
1083 bool ProxyService::TryResolveProxySynchronously(const GURL& raw_url, 1090 bool ProxyService:: TryResolveProxySynchronously(
1084 int load_flags, 1091 const GURL& raw_url,
1085 ProxyInfo* result, 1092 int load_flags,
1086 ProxyDelegate* proxy_delegate, 1093 ProxyInfo* result,
1087 const BoundNetLog& net_log) { 1094 NetworkDelegate* network_delegate,
1095 const BoundNetLog& net_log) {
1088 CompletionCallback null_callback; 1096 CompletionCallback null_callback;
1089 return ResolveProxyHelper(raw_url, load_flags, result, null_callback, 1097 return ResolveProxyHelper(raw_url,
1090 nullptr /* pac_request*/, proxy_delegate, 1098 load_flags,
1099 result,
1100 null_callback,
1101 NULL /* pac_request*/,
1102 network_delegate,
1091 net_log) == OK; 1103 net_log) == OK;
1092 } 1104 }
1093 1105
1094 int ProxyService::TryToCompleteSynchronously(const GURL& url, 1106 int ProxyService::TryToCompleteSynchronously(const GURL& url,
1095 int load_flags, 1107 int load_flags,
1096 ProxyDelegate* proxy_delegate, 1108 NetworkDelegate* network_delegate,
1097 ProxyInfo* result) { 1109 ProxyInfo* result) {
1098 DCHECK_NE(STATE_NONE, current_state_); 1110 DCHECK_NE(STATE_NONE, current_state_);
1099 1111
1100 if (current_state_ != STATE_READY) 1112 if (current_state_ != STATE_READY)
1101 return ERR_IO_PENDING; // Still initializing. 1113 return ERR_IO_PENDING; // Still initializing.
1102 1114
1103 DCHECK_NE(config_.id(), ProxyConfig::kInvalidConfigID); 1115 DCHECK_NE(config_.id(), ProxyConfig::kInvalidConfigID);
1104 1116
1105 // If it was impossible to fetch or parse the PAC script, we cannot complete 1117 // If it was impossible to fetch or parse the PAC script, we cannot complete
1106 // the request here and bail out. 1118 // the request here and bail out.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 // downloaded. 1256 // downloaded.
1245 SetReady(); 1257 SetReady();
1246 } 1258 }
1247 1259
1248 int ProxyService::ReconsiderProxyAfterError(const GURL& url, 1260 int ProxyService::ReconsiderProxyAfterError(const GURL& url,
1249 int load_flags, 1261 int load_flags,
1250 int net_error, 1262 int net_error,
1251 ProxyInfo* result, 1263 ProxyInfo* result,
1252 const CompletionCallback& callback, 1264 const CompletionCallback& callback,
1253 PacRequest** pac_request, 1265 PacRequest** pac_request,
1254 ProxyDelegate* proxy_delegate, 1266 NetworkDelegate* network_delegate,
1255 const BoundNetLog& net_log) { 1267 const BoundNetLog& net_log) {
1256 DCHECK(CalledOnValidThread()); 1268 DCHECK(CalledOnValidThread());
1257 1269
1258 // Check to see if we have a new config since ResolveProxy was called. We 1270 // Check to see if we have a new config since ResolveProxy was called. We
1259 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a 1271 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a
1260 // direct connection failed and we never tried the current config. 1272 // direct connection failed and we never tried the current config.
1261 1273
1262 DCHECK(result); 1274 DCHECK(result);
1263 bool re_resolve = result->config_id_ != config_.id(); 1275 bool re_resolve = result->config_id_ != config_.id();
1264 1276
1265 if (re_resolve) { 1277 if (re_resolve) {
1266 // If we have a new config or the config was never tried, we delete the 1278 // If we have a new config or the config was never tried, we delete the
1267 // list of bad proxies and we try again. 1279 // list of bad proxies and we try again.
1268 proxy_retry_info_.clear(); 1280 proxy_retry_info_.clear();
1269 return ResolveProxy(url, load_flags, result, callback, pac_request, 1281 return ResolveProxy(url, load_flags, result, callback, pac_request,
1270 proxy_delegate, net_log); 1282 network_delegate, net_log);
1271 } 1283 }
1272 1284
1273 DCHECK(!result->is_empty()); 1285 DCHECK(!result->is_empty());
1274 ProxyServer bad_proxy = result->proxy_server(); 1286 ProxyServer bad_proxy = result->proxy_server();
1275 1287
1276 // We don't have new proxy settings to try, try to fallback to the next proxy 1288 // We don't have new proxy settings to try, try to fallback to the next proxy
1277 // in the list. 1289 // in the list.
1278 bool did_fallback = result->Fallback(net_error, net_log); 1290 bool did_fallback = result->Fallback(net_error, net_log);
1279 1291
1280 // Return synchronous failure if there is nothing left to fall-back to. 1292 // Return synchronous failure if there is nothing left to fall-back to.
1281 // TODO(eroman): This is a yucky API, clean it up. 1293 // TODO(eroman): This is a yucky API, clean it up.
1282 return did_fallback ? OK : ERR_FAILED; 1294 return did_fallback ? OK : ERR_FAILED;
1283 } 1295 }
1284 1296
1285 bool ProxyService::MarkProxiesAsBadUntil( 1297 bool ProxyService::MarkProxiesAsBadUntil(
1286 const ProxyInfo& result, 1298 const ProxyInfo& result,
1287 base::TimeDelta retry_delay, 1299 base::TimeDelta retry_delay,
1288 const std::vector<ProxyServer>& additional_bad_proxies, 1300 const std::vector<ProxyServer>& additional_bad_proxies,
1289 const BoundNetLog& net_log) { 1301 const BoundNetLog& net_log) {
1290 result.proxy_list_.UpdateRetryInfoOnFallback(&proxy_retry_info_, retry_delay, 1302 result.proxy_list_.UpdateRetryInfoOnFallback(&proxy_retry_info_, retry_delay,
1291 false, additional_bad_proxies, 1303 false, additional_bad_proxies,
1292 OK, net_log); 1304 OK, net_log);
1293 return result.proxy_list_.size() > (additional_bad_proxies.size() + 1); 1305 return result.proxy_list_.size() > (additional_bad_proxies.size() + 1);
1294 } 1306 }
1295 1307
1296 void ProxyService::ReportSuccess(const ProxyInfo& result, 1308 void ProxyService::ReportSuccess(const ProxyInfo& result,
1297 ProxyDelegate* proxy_delegate) { 1309 NetworkDelegate* network_delegate) {
1298 DCHECK(CalledOnValidThread()); 1310 DCHECK(CalledOnValidThread());
1299 1311
1300 const ProxyRetryInfoMap& new_retry_info = result.proxy_retry_info(); 1312 const ProxyRetryInfoMap& new_retry_info = result.proxy_retry_info();
1301 if (new_retry_info.empty()) 1313 if (new_retry_info.empty())
1302 return; 1314 return;
1303 1315
1304 for (ProxyRetryInfoMap::const_iterator iter = new_retry_info.begin(); 1316 for (ProxyRetryInfoMap::const_iterator iter = new_retry_info.begin();
1305 iter != new_retry_info.end(); ++iter) { 1317 iter != new_retry_info.end(); ++iter) {
1306 ProxyRetryInfoMap::iterator existing = proxy_retry_info_.find(iter->first); 1318 ProxyRetryInfoMap::iterator existing = proxy_retry_info_.find(iter->first);
1307 if (existing == proxy_retry_info_.end()) { 1319 if (existing == proxy_retry_info_.end()) {
1308 proxy_retry_info_[iter->first] = iter->second; 1320 proxy_retry_info_[iter->first] = iter->second;
1309 if (proxy_delegate) { 1321 if (network_delegate) {
1310 const ProxyServer& bad_proxy = 1322 const ProxyServer& bad_proxy =
1311 ProxyServer::FromURI(iter->first, ProxyServer::SCHEME_HTTP); 1323 ProxyServer::FromURI(iter->first, ProxyServer::SCHEME_HTTP);
1312 const ProxyRetryInfo& proxy_retry_info = iter->second; 1324 const ProxyRetryInfo& proxy_retry_info = iter->second;
1313 proxy_delegate->OnFallback(bad_proxy, proxy_retry_info.net_error); 1325 network_delegate->NotifyProxyFallback(bad_proxy,
1326 proxy_retry_info.net_error);
1314 } 1327 }
1315 } 1328 }
1316 else if (existing->second.bad_until < iter->second.bad_until) 1329 else if (existing->second.bad_until < iter->second.bad_until)
1317 existing->second.bad_until = iter->second.bad_until; 1330 existing->second.bad_until = iter->second.bad_until;
1318 } 1331 }
1319 if (net_log_) { 1332 if (net_log_) {
1320 net_log_->AddGlobalEntry( 1333 net_log_->AddGlobalEntry(
1321 NetLog::TYPE_BAD_PROXY_LIST_REPORTED, 1334 NetLog::TYPE_BAD_PROXY_LIST_REPORTED,
1322 base::Bind(&NetLogBadProxyListCallback, &new_retry_info)); 1335 base::Bind(&NetLogBadProxyListCallback, &new_retry_info));
1323 } 1336 }
(...skipping 17 matching lines...) Expand all
1341 return pending_requests_.count(req) == 1; 1354 return pending_requests_.count(req) == 1;
1342 } 1355 }
1343 1356
1344 void ProxyService::RemovePendingRequest(PacRequest* req) { 1357 void ProxyService::RemovePendingRequest(PacRequest* req) {
1345 DCHECK(ContainsPendingRequest(req)); 1358 DCHECK(ContainsPendingRequest(req));
1346 pending_requests_.erase(req); 1359 pending_requests_.erase(req);
1347 } 1360 }
1348 1361
1349 int ProxyService::DidFinishResolvingProxy(const GURL& url, 1362 int ProxyService::DidFinishResolvingProxy(const GURL& url,
1350 int load_flags, 1363 int load_flags,
1351 ProxyDelegate* proxy_delegate, 1364 NetworkDelegate* network_delegate,
1352 ProxyInfo* result, 1365 ProxyInfo* result,
1353 int result_code, 1366 int result_code,
1354 const BoundNetLog& net_log, 1367 const BoundNetLog& net_log,
1355 base::TimeTicks start_time, 1368 base::TimeTicks start_time,
1356 bool script_executed) { 1369 bool script_executed) {
1357 // Don't track any metrics if start_time is 0, which will happen when the user 1370 // Don't track any metrics if start_time is 0, which will happen when the user
1358 // calls |TryResolveProxySynchronously|. 1371 // calls |TryResolveProxySynchronously|.
1359 if (!start_time.is_null()) { 1372 if (!start_time.is_null()) {
1360 TimeDelta diff = TimeTicks::Now() - start_time; 1373 TimeDelta diff = TimeTicks::Now() - start_time;
1361 if (script_executed) { 1374 if (script_executed) {
1362 // This function "fixes" the result code, so make sure script terminated 1375 // This function "fixes" the result code, so make sure script terminated
1363 // errors are tracked. Only track result codes that were a result of 1376 // errors are tracked. Only track result codes that were a result of
1364 // script execution. 1377 // script execution.
1365 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ScriptTerminated", 1378 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ScriptTerminated",
1366 result_code == ERR_PAC_SCRIPT_TERMINATED); 1379 result_code == ERR_PAC_SCRIPT_TERMINATED);
1367 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.GetProxyUsingScriptTime", 1380 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.GetProxyUsingScriptTime",
1368 diff, base::TimeDelta::FromMicroseconds(100), 1381 diff, base::TimeDelta::FromMicroseconds(100),
1369 base::TimeDelta::FromSeconds(20), 50); 1382 base::TimeDelta::FromSeconds(20), 50);
1370 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.ProxyService.GetProxyUsingScriptResult", 1383 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.ProxyService.GetProxyUsingScriptResult",
1371 std::abs(result_code)); 1384 std::abs(result_code));
1372 } 1385 }
1373 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedUsingScript", 1386 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedUsingScript",
1374 script_executed); 1387 script_executed);
1375 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.ResolveProxyTime", diff, 1388 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.ResolveProxyTime", diff,
1376 base::TimeDelta::FromMicroseconds(100), 1389 base::TimeDelta::FromMicroseconds(100),
1377 base::TimeDelta::FromSeconds(20), 50); 1390 base::TimeDelta::FromSeconds(20), 50);
1378 } 1391 }
1392
1379 // Log the result of the proxy resolution. 1393 // Log the result of the proxy resolution.
1380 if (result_code == OK) { 1394 if (result_code == OK) {
1381 // Allow the proxy delegate to interpose on the resolution decision, 1395 // Allow the network delegate to interpose on the resolution decision,
1382 // possibly modifying the ProxyInfo. 1396 // possibly modifying the ProxyInfo.
1383 if (proxy_delegate) 1397 if (network_delegate)
1384 proxy_delegate->OnResolveProxy(url, load_flags, *this, result); 1398 network_delegate->NotifyResolveProxy(url, load_flags, *this, result);
1385 1399
1386 net_log.AddEvent(NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, 1400 net_log.AddEvent(NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST,
1387 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); 1401 base::Bind(&NetLogFinishedResolvingProxyCallback, result));
1388 1402
1389 // This check is done to only log the NetLog event when necessary, it's 1403 // This check is done to only log the NetLog event when necessary, it's
1390 // not a performance optimization. 1404 // not a performance optimization.
1391 if (!proxy_retry_info_.empty()) { 1405 if (!proxy_retry_info_.empty()) {
1392 result->DeprioritizeBadProxies(proxy_retry_info_); 1406 result->DeprioritizeBadProxies(proxy_retry_info_);
1393 net_log.AddEvent( 1407 net_log.AddEvent(
1394 NetLog::TYPE_PROXY_SERVICE_DEPRIORITIZED_BAD_PROXIES, 1408 NetLog::TYPE_PROXY_SERVICE_DEPRIORITIZED_BAD_PROXIES,
1395 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); 1409 base::Bind(&NetLogFinishedResolvingProxyCallback, result));
1396 } 1410 }
1397 } else { 1411 } else {
1398 net_log.AddEventWithNetErrorCode( 1412 net_log.AddEventWithNetErrorCode(
1399 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, result_code); 1413 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, result_code);
1400 1414
1401 bool reset_config = result_code == ERR_PAC_SCRIPT_TERMINATED; 1415 bool reset_config = result_code == ERR_PAC_SCRIPT_TERMINATED;
1402 if (!config_.pac_mandatory()) { 1416 if (!config_.pac_mandatory()) {
1403 // Fall-back to direct when the proxy resolver fails. This corresponds 1417 // Fall-back to direct when the proxy resolver fails. This corresponds
1404 // with a javascript runtime error in the PAC script. 1418 // with a javascript runtime error in the PAC script.
1405 // 1419 //
1406 // This implicit fall-back to direct matches Firefox 3.5 and 1420 // This implicit fall-back to direct matches Firefox 3.5 and
1407 // Internet Explorer 8. For more information, see: 1421 // Internet Explorer 8. For more information, see:
1408 // 1422 //
1409 // http://www.chromium.org/developers/design-documents/proxy-settings-fall back 1423 // http://www.chromium.org/developers/design-documents/proxy-settings-fall back
1410 result->UseDirect(); 1424 result->UseDirect();
1411 result_code = OK; 1425 result_code = OK;
1412 1426
1413 // Allow the proxy delegate to interpose on the resolution decision, 1427 // Allow the network delegate to interpose on the resolution decision,
1414 // possibly modifying the ProxyInfo. 1428 // possibly modifying the ProxyInfo.
1415 if (proxy_delegate) 1429 if (network_delegate)
1416 proxy_delegate->OnResolveProxy(url, load_flags, *this, result); 1430 network_delegate->NotifyResolveProxy(url, load_flags, *this, result);
1417 } else { 1431 } else {
1418 result_code = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED; 1432 result_code = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED;
1419 } 1433 }
1420 if (reset_config) { 1434 if (reset_config) {
1421 ResetProxyConfig(false); 1435 ResetProxyConfig(false);
1422 // If the ProxyResolver crashed, force it to be re-initialized for the 1436 // If the ProxyResolver crashed, force it to be re-initialized for the
1423 // next request by resetting the proxy config. If there are other pending 1437 // next request by resetting the proxy config. If there are other pending
1424 // requests, trigger the recreation immediately so those requests retry. 1438 // requests, trigger the recreation immediately so those requests retry.
1425 if (pending_requests_.size() > 1) 1439 if (pending_requests_.size() > 1)
1426 ApplyProxyConfigIfAvailable(); 1440 ApplyProxyConfigIfAvailable();
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 State previous_state = ResetProxyConfig(false); 1653 State previous_state = ResetProxyConfig(false);
1640 if (previous_state != STATE_NONE) 1654 if (previous_state != STATE_NONE)
1641 ApplyProxyConfigIfAvailable(); 1655 ApplyProxyConfigIfAvailable();
1642 } 1656 }
1643 1657
1644 void ProxyService::OnDNSChanged() { 1658 void ProxyService::OnDNSChanged() {
1645 OnIPAddressChanged(); 1659 OnIPAddressChanged();
1646 } 1660 }
1647 1661
1648 } // namespace net 1662 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.h ('k') | net/proxy/proxy_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698