OLD | NEW |
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/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/metrics/histogram_macros.h" | |
20 #include "base/metrics/sparse_histogram.h" | |
21 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
22 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
23 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
24 #include "base/time/time.h" | 22 #include "base/time/time.h" |
25 #include "base/values.h" | 23 #include "base/values.h" |
26 #include "net/base/completion_callback.h" | 24 #include "net/base/completion_callback.h" |
27 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
28 #include "net/base/proxy_delegate.h" | 26 #include "net/base/proxy_delegate.h" |
29 #include "net/base/url_util.h" | 27 #include "net/base/url_util.h" |
30 #include "net/log/net_log_capture_mode.h" | 28 #include "net/log/net_log_capture_mode.h" |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 // Returns true if Cancel() has been called. | 854 // Returns true if Cancel() has been called. |
857 bool was_cancelled() const { | 855 bool was_cancelled() const { |
858 return user_callback_.is_null(); | 856 return user_callback_.is_null(); |
859 } | 857 } |
860 | 858 |
861 // Helper to call after ProxyResolver completion (both synchronous and | 859 // Helper to call after ProxyResolver completion (both synchronous and |
862 // asynchronous). Fixes up the result that is to be returned to user. | 860 // asynchronous). Fixes up the result that is to be returned to user. |
863 int QueryDidComplete(int result_code) { | 861 int QueryDidComplete(int result_code) { |
864 DCHECK(!was_cancelled()); | 862 DCHECK(!was_cancelled()); |
865 | 863 |
866 // This state is cleared when resolve_job_ is reset below. | |
867 bool script_executed = is_started(); | |
868 | |
869 // Clear |resolve_job_| so is_started() returns false while | 864 // Clear |resolve_job_| so is_started() returns false while |
870 // DidFinishResolvingProxy() runs. | 865 // DidFinishResolvingProxy() runs. |
871 resolve_job_.reset(); | 866 resolve_job_.reset(); |
872 | 867 |
873 // Note that DidFinishResolvingProxy might modify |results_|. | 868 // Note that DidFinishResolvingProxy might modify |results_|. |
874 int rv = service_->DidFinishResolvingProxy(url_, method_, proxy_delegate_, | 869 int rv = service_->DidFinishResolvingProxy(url_, method_, proxy_delegate_, |
875 results_, result_code, net_log_, | 870 results_, result_code, net_log_); |
876 creation_time_, script_executed); | |
877 | 871 |
878 // Make a note in the results which configuration was in use at the | 872 // Make a note in the results which configuration was in use at the |
879 // time of the resolve. | 873 // time of the resolve. |
880 results_->config_id_ = config_id_; | 874 results_->config_id_ = config_id_; |
881 results_->config_source_ = config_source_; | 875 results_->config_source_ = config_source_; |
882 results_->did_use_pac_script_ = true; | 876 results_->did_use_pac_script_ = true; |
883 results_->proxy_resolve_start_time_ = creation_time_; | 877 results_->proxy_resolve_start_time_ = creation_time_; |
884 results_->proxy_resolve_end_time_ = TimeTicks::Now(); | 878 results_->proxy_resolve_end_time_ = TimeTicks::Now(); |
885 | 879 |
886 // Reset the state associated with in-progress-resolve. | 880 // Reset the state associated with in-progress-resolve. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 // Sanitize the URL before passing it on to the proxy resolver (i.e. PAC | 1052 // Sanitize the URL before passing it on to the proxy resolver (i.e. PAC |
1059 // script). The goal is to remove sensitive data (like embedded user names | 1053 // script). The goal is to remove sensitive data (like embedded user names |
1060 // and password), and local data (i.e. reference fragment) which does not need | 1054 // and password), and local data (i.e. reference fragment) which does not need |
1061 // to be disclosed to the resolver. | 1055 // to be disclosed to the resolver. |
1062 GURL url = SanitizeUrl(raw_url, sanitize_url_policy_); | 1056 GURL url = SanitizeUrl(raw_url, sanitize_url_policy_); |
1063 | 1057 |
1064 // Check if the request can be completed right away. (This is the case when | 1058 // Check if the request can be completed right away. (This is the case when |
1065 // using a direct connection for example). | 1059 // using a direct connection for example). |
1066 int rv = TryToCompleteSynchronously(url, proxy_delegate, result); | 1060 int rv = TryToCompleteSynchronously(url, proxy_delegate, result); |
1067 if (rv != ERR_IO_PENDING) { | 1061 if (rv != ERR_IO_PENDING) { |
1068 rv = DidFinishResolvingProxy( | 1062 rv = DidFinishResolvingProxy(url, method, proxy_delegate, result, rv, |
1069 url, method, proxy_delegate, result, rv, net_log, | 1063 net_log); |
1070 callback.is_null() ? TimeTicks() : TimeTicks::Now(), false); | |
1071 return rv; | 1064 return rv; |
1072 } | 1065 } |
1073 | 1066 |
1074 if (callback.is_null()) | 1067 if (callback.is_null()) |
1075 return ERR_IO_PENDING; | 1068 return ERR_IO_PENDING; |
1076 | 1069 |
1077 scoped_refptr<PacRequest> req(new PacRequest( | 1070 scoped_refptr<PacRequest> req(new PacRequest( |
1078 this, url, method, proxy_delegate, result, callback, net_log)); | 1071 this, url, method, proxy_delegate, result, callback, net_log)); |
1079 | 1072 |
1080 if (current_state_ == STATE_READY) { | 1073 if (current_state_ == STATE_READY) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 script_poller_.reset(new ProxyScriptDeciderPoller( | 1219 script_poller_.reset(new ProxyScriptDeciderPoller( |
1227 base::Bind(&ProxyService::InitializeUsingDecidedConfig, | 1220 base::Bind(&ProxyService::InitializeUsingDecidedConfig, |
1228 base::Unretained(this)), | 1221 base::Unretained(this)), |
1229 fetched_config_, resolver_factory_->expects_pac_bytes(), | 1222 fetched_config_, resolver_factory_->expects_pac_bytes(), |
1230 proxy_script_fetcher_.get(), dhcp_proxy_script_fetcher_.get(), result, | 1223 proxy_script_fetcher_.get(), dhcp_proxy_script_fetcher_.get(), result, |
1231 init_proxy_resolver_->script_data(), NULL)); | 1224 init_proxy_resolver_->script_data(), NULL)); |
1232 script_poller_->set_quick_check_enabled(quick_check_enabled_); | 1225 script_poller_->set_quick_check_enabled(quick_check_enabled_); |
1233 | 1226 |
1234 init_proxy_resolver_.reset(); | 1227 init_proxy_resolver_.reset(); |
1235 | 1228 |
1236 // When using the out-of-process resolver, creating the resolver can complete | |
1237 // with the ERR_PAC_SCRIPT_TERMINATED result code, which indicates the | |
1238 // resolver process crashed. | |
1239 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ScriptTerminatedOnInit", | |
1240 result == ERR_PAC_SCRIPT_TERMINATED); | |
1241 | |
1242 if (result != OK) { | 1229 if (result != OK) { |
1243 if (fetched_config_.pac_mandatory()) { | 1230 if (fetched_config_.pac_mandatory()) { |
1244 VLOG(1) << "Failed configuring with mandatory PAC script, blocking all " | 1231 VLOG(1) << "Failed configuring with mandatory PAC script, blocking all " |
1245 "traffic."; | 1232 "traffic."; |
1246 config_ = fetched_config_; | 1233 config_ = fetched_config_; |
1247 result = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED; | 1234 result = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED; |
1248 } else { | 1235 } else { |
1249 VLOG(1) << "Failed configuring with PAC script, falling-back to manual " | 1236 VLOG(1) << "Failed configuring with PAC script, falling-back to manual " |
1250 "proxy servers."; | 1237 "proxy servers."; |
1251 config_ = fetched_config_; | 1238 config_ = fetched_config_; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 void ProxyService::RemovePendingRequest(PacRequest* req) { | 1351 void ProxyService::RemovePendingRequest(PacRequest* req) { |
1365 DCHECK(ContainsPendingRequest(req)); | 1352 DCHECK(ContainsPendingRequest(req)); |
1366 pending_requests_.erase(req); | 1353 pending_requests_.erase(req); |
1367 } | 1354 } |
1368 | 1355 |
1369 int ProxyService::DidFinishResolvingProxy(const GURL& url, | 1356 int ProxyService::DidFinishResolvingProxy(const GURL& url, |
1370 const std::string& method, | 1357 const std::string& method, |
1371 ProxyDelegate* proxy_delegate, | 1358 ProxyDelegate* proxy_delegate, |
1372 ProxyInfo* result, | 1359 ProxyInfo* result, |
1373 int result_code, | 1360 int result_code, |
1374 const NetLogWithSource& net_log, | 1361 const NetLogWithSource& net_log) { |
1375 base::TimeTicks start_time, | |
1376 bool script_executed) { | |
1377 // Don't track any metrics if start_time is 0, which will happen when the user | |
1378 // calls |TryResolveProxySynchronously|. | |
1379 if (!start_time.is_null()) { | |
1380 TimeDelta diff = TimeTicks::Now() - start_time; | |
1381 if (script_executed) { | |
1382 // This function "fixes" the result code, so make sure script terminated | |
1383 // errors are tracked. Only track result codes that were a result of | |
1384 // script execution. | |
1385 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ScriptTerminated", | |
1386 result_code == ERR_PAC_SCRIPT_TERMINATED); | |
1387 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.GetProxyUsingScriptTime", | |
1388 diff, base::TimeDelta::FromMicroseconds(100), | |
1389 base::TimeDelta::FromSeconds(20), 50); | |
1390 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.ProxyService.GetProxyUsingScriptResult", | |
1391 std::abs(result_code)); | |
1392 } | |
1393 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedUsingScript", | |
1394 script_executed); | |
1395 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.ResolveProxyTime", diff, | |
1396 base::TimeDelta::FromMicroseconds(100), | |
1397 base::TimeDelta::FromSeconds(20), 50); | |
1398 } | |
1399 | |
1400 // Log the result of the proxy resolution. | 1362 // Log the result of the proxy resolution. |
1401 if (result_code == OK) { | 1363 if (result_code == OK) { |
1402 // Allow the proxy delegate to interpose on the resolution decision, | 1364 // Allow the proxy delegate to interpose on the resolution decision, |
1403 // possibly modifying the ProxyInfo. | 1365 // possibly modifying the ProxyInfo. |
1404 if (proxy_delegate) | 1366 if (proxy_delegate) |
1405 proxy_delegate->OnResolveProxy(url, method, *this, result); | 1367 proxy_delegate->OnResolveProxy(url, method, *this, result); |
1406 | 1368 |
1407 net_log.AddEvent(NetLogEventType::PROXY_SERVICE_RESOLVED_PROXY_LIST, | 1369 net_log.AddEvent(NetLogEventType::PROXY_SERVICE_RESOLVED_PROXY_LIST, |
1408 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); | 1370 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); |
1409 | 1371 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 State previous_state = ResetProxyConfig(false); | 1633 State previous_state = ResetProxyConfig(false); |
1672 if (previous_state != STATE_NONE) | 1634 if (previous_state != STATE_NONE) |
1673 ApplyProxyConfigIfAvailable(); | 1635 ApplyProxyConfigIfAvailable(); |
1674 } | 1636 } |
1675 | 1637 |
1676 void ProxyService::OnDNSChanged() { | 1638 void ProxyService::OnDNSChanged() { |
1677 OnIPAddressChanged(); | 1639 OnIPAddressChanged(); |
1678 } | 1640 } |
1679 | 1641 |
1680 } // namespace net | 1642 } // namespace net |
OLD | NEW |