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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
16 #include "base/metrics/histogram_macros.h" | |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
19 #include "base/time/time.h" | |
18 #include "base/values.h" | 20 #include "base/values.h" |
19 #include "net/base/completion_callback.h" | 21 #include "net/base/completion_callback.h" |
20 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
21 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
22 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
23 #include "net/log/net_log.h" | 25 #include "net/log/net_log.h" |
24 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 26 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
25 #include "net/proxy/multi_threaded_proxy_resolver.h" | 27 #include "net/proxy/multi_threaded_proxy_resolver.h" |
26 #include "net/proxy/network_delegate_error_observer.h" | 28 #include "net/proxy/network_delegate_error_observer.h" |
27 #include "net/proxy/proxy_config_service_fixed.h" | 29 #include "net/proxy/proxy_config_service_fixed.h" |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 const BoundNetLog& net_log) | 791 const BoundNetLog& net_log) |
790 : service_(service), | 792 : service_(service), |
791 user_callback_(user_callback), | 793 user_callback_(user_callback), |
792 results_(results), | 794 results_(results), |
793 url_(url), | 795 url_(url), |
794 load_flags_(load_flags), | 796 load_flags_(load_flags), |
795 network_delegate_(network_delegate), | 797 network_delegate_(network_delegate), |
796 resolve_job_(NULL), | 798 resolve_job_(NULL), |
797 config_id_(ProxyConfig::kInvalidConfigID), | 799 config_id_(ProxyConfig::kInvalidConfigID), |
798 config_source_(PROXY_CONFIG_SOURCE_UNKNOWN), | 800 config_source_(PROXY_CONFIG_SOURCE_UNKNOWN), |
799 net_log_(net_log) { | 801 net_log_(net_log), |
802 request_start_time_(TimeTicks::Now()) { | |
800 DCHECK(!user_callback.is_null()); | 803 DCHECK(!user_callback.is_null()); |
801 } | 804 } |
802 | 805 |
803 // Starts the resolve proxy request. | 806 // Starts the resolve proxy request. |
804 int Start() { | 807 int Start() { |
805 DCHECK(!was_cancelled()); | 808 DCHECK(!was_cancelled()); |
806 DCHECK(!is_started()); | 809 DCHECK(!is_started()); |
807 | 810 |
808 DCHECK(service_->config_.is_valid()); | 811 DCHECK(service_->config_.is_valid()); |
809 | 812 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
877 results_->config_id_ = config_id_; | 880 results_->config_id_ = config_id_; |
878 results_->config_source_ = config_source_; | 881 results_->config_source_ = config_source_; |
879 results_->did_use_pac_script_ = true; | 882 results_->did_use_pac_script_ = true; |
880 results_->proxy_resolve_start_time_ = proxy_resolve_start_time_; | 883 results_->proxy_resolve_start_time_ = proxy_resolve_start_time_; |
881 results_->proxy_resolve_end_time_ = TimeTicks::Now(); | 884 results_->proxy_resolve_end_time_ = TimeTicks::Now(); |
882 | 885 |
883 // Reset the state associated with in-progress-resolve. | 886 // Reset the state associated with in-progress-resolve. |
884 config_id_ = ProxyConfig::kInvalidConfigID; | 887 config_id_ = ProxyConfig::kInvalidConfigID; |
885 config_source_ = PROXY_CONFIG_SOURCE_UNKNOWN; | 888 config_source_ = PROXY_CONFIG_SOURCE_UNKNOWN; |
886 | 889 |
890 UMA_HISTOGRAM_CUSTOM_TIMES( | |
891 "Net.ProxyService.ResolveTime", | |
892 results_->proxy_resolve_end_time_ - request_start_time_, | |
893 base::TimeDelta::FromMicroseconds(100), | |
894 base::TimeDelta::FromSeconds(10), 50); | |
eroman
2015/05/05 23:51:28
I don't think the upper range is high enough.
I su
Anand Mistry (off Chromium)
2015/05/06 06:52:18
Done.
| |
895 | |
887 return rv; | 896 return rv; |
888 } | 897 } |
889 | 898 |
890 BoundNetLog* net_log() { return &net_log_; } | 899 BoundNetLog* net_log() { return &net_log_; } |
891 | 900 |
892 LoadState GetLoadState() const { | 901 LoadState GetLoadState() const { |
893 if (is_started()) | 902 if (is_started()) |
894 return resolver()->GetLoadState(resolve_job_); | 903 return resolver()->GetLoadState(resolve_job_); |
895 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; | 904 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; |
896 } | 905 } |
(...skipping 27 matching lines...) Expand all Loading... | |
924 GURL url_; | 933 GURL url_; |
925 int load_flags_; | 934 int load_flags_; |
926 NetworkDelegate* network_delegate_; | 935 NetworkDelegate* network_delegate_; |
927 ProxyResolver::RequestHandle resolve_job_; | 936 ProxyResolver::RequestHandle resolve_job_; |
928 ProxyConfig::ID config_id_; // The config id when the resolve was started. | 937 ProxyConfig::ID config_id_; // The config id when the resolve was started. |
929 ProxyConfigSource config_source_; // The source of proxy settings. | 938 ProxyConfigSource config_source_; // The source of proxy settings. |
930 BoundNetLog net_log_; | 939 BoundNetLog net_log_; |
931 // Time when the PAC is started. Cached here since resetting ProxyInfo also | 940 // Time when the PAC is started. Cached here since resetting ProxyInfo also |
932 // clears the proxy times. | 941 // clears the proxy times. |
933 TimeTicks proxy_resolve_start_time_; | 942 TimeTicks proxy_resolve_start_time_; |
943 // Time when this request is created. | |
944 TimeTicks request_start_time_; | |
934 }; | 945 }; |
935 | 946 |
936 // ProxyService --------------------------------------------------------------- | 947 // ProxyService --------------------------------------------------------------- |
937 | 948 |
938 ProxyService::ProxyService(ProxyConfigService* config_service, | 949 ProxyService::ProxyService(ProxyConfigService* config_service, |
939 scoped_ptr<ProxyResolverFactory> resolver_factory, | 950 scoped_ptr<ProxyResolverFactory> resolver_factory, |
940 NetLog* net_log) | 951 NetLog* net_log) |
941 : resolver_factory_(resolver_factory.Pass()), | 952 : resolver_factory_(resolver_factory.Pass()), |
942 next_config_id_(1), | 953 next_config_id_(1), |
943 current_state_(STATE_NONE), | 954 current_state_(STATE_NONE), |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 ApplyProxyConfigIfAvailable(); | 1070 ApplyProxyConfigIfAvailable(); |
1060 | 1071 |
1061 // Strip away any reference fragments and the username/password, as they | 1072 // Strip away any reference fragments and the username/password, as they |
1062 // are not relevant to proxy resolution. | 1073 // are not relevant to proxy resolution. |
1063 GURL url = SimplifyUrlForRequest(raw_url); | 1074 GURL url = SimplifyUrlForRequest(raw_url); |
1064 | 1075 |
1065 // Check if the request can be completed right away. (This is the case when | 1076 // Check if the request can be completed right away. (This is the case when |
1066 // using a direct connection for example). | 1077 // using a direct connection for example). |
1067 int rv = TryToCompleteSynchronously(url, load_flags, | 1078 int rv = TryToCompleteSynchronously(url, load_flags, |
1068 network_delegate, result); | 1079 network_delegate, result); |
1080 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedSynchronously", | |
eroman
2015/05/05 23:51:29
This is incomplete. Requests can also be completed
Anand Mistry (off Chromium)
2015/05/06 06:52:18
I've changed these around. I hope they're better.
| |
1081 rv != ERR_IO_PENDING); | |
1069 if (rv != ERR_IO_PENDING) | 1082 if (rv != ERR_IO_PENDING) |
1070 return DidFinishResolvingProxy(url, load_flags, network_delegate, | 1083 return DidFinishResolvingProxy(url, load_flags, network_delegate, |
1071 result, rv, net_log); | 1084 result, rv, net_log); |
1072 | 1085 |
1073 if (callback.is_null()) | 1086 if (callback.is_null()) |
1074 return ERR_IO_PENDING; | 1087 return ERR_IO_PENDING; |
1075 | 1088 |
1076 scoped_refptr<PacRequest> req( | 1089 scoped_refptr<PacRequest> req( |
1077 new PacRequest(this, url, load_flags, network_delegate, | 1090 new PacRequest(this, url, load_flags, network_delegate, |
1078 result, callback, net_log)); | 1091 result, callback, net_log)); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1372 pending_requests_.begin(), pending_requests_.end(), req); | 1385 pending_requests_.begin(), pending_requests_.end(), req); |
1373 pending_requests_.erase(it); | 1386 pending_requests_.erase(it); |
1374 } | 1387 } |
1375 | 1388 |
1376 int ProxyService::DidFinishResolvingProxy(const GURL& url, | 1389 int ProxyService::DidFinishResolvingProxy(const GURL& url, |
1377 int load_flags, | 1390 int load_flags, |
1378 NetworkDelegate* network_delegate, | 1391 NetworkDelegate* network_delegate, |
1379 ProxyInfo* result, | 1392 ProxyInfo* result, |
1380 int result_code, | 1393 int result_code, |
1381 const BoundNetLog& net_log) { | 1394 const BoundNetLog& net_log) { |
1395 // This function "fixes" the result code, so make sure script terminated | |
1396 // errors are tracked. | |
1397 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ScriptTerminated", | |
1398 result_code == ERR_PAC_SCRIPT_TERMINATED); | |
1399 | |
1382 // Log the result of the proxy resolution. | 1400 // Log the result of the proxy resolution. |
1383 if (result_code == OK) { | 1401 if (result_code == OK) { |
1384 // Allow the network delegate to interpose on the resolution decision, | 1402 // Allow the network delegate to interpose on the resolution decision, |
1385 // possibly modifying the ProxyInfo. | 1403 // possibly modifying the ProxyInfo. |
1386 if (network_delegate) | 1404 if (network_delegate) |
1387 network_delegate->NotifyResolveProxy(url, load_flags, *this, result); | 1405 network_delegate->NotifyResolveProxy(url, load_flags, *this, result); |
1388 | 1406 |
1389 // When logging all events is enabled, dump the proxy list. | 1407 // When logging all events is enabled, dump the proxy list. |
1390 if (net_log.GetCaptureMode().enabled()) { | 1408 if (net_log.GetCaptureMode().enabled()) { |
1391 net_log.AddEvent( | 1409 net_log.AddEvent( |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1638 State previous_state = ResetProxyConfig(false); | 1656 State previous_state = ResetProxyConfig(false); |
1639 if (previous_state != STATE_NONE) | 1657 if (previous_state != STATE_NONE) |
1640 ApplyProxyConfigIfAvailable(); | 1658 ApplyProxyConfigIfAvailable(); |
1641 } | 1659 } |
1642 | 1660 |
1643 void ProxyService::OnDNSChanged() { | 1661 void ProxyService::OnDNSChanged() { |
1644 OnIPAddressChanged(); | 1662 OnIPAddressChanged(); |
1645 } | 1663 } |
1646 | 1664 |
1647 } // namespace net | 1665 } // namespace net |
OLD | NEW |