OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/nqe/network_quality_estimator.h" | 5 #include "net/nqe/network_quality_estimator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <utility> | 10 #include <utility> |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 const int estimated_observed_diff_milliseconds = | 800 const int estimated_observed_diff_milliseconds = |
801 external_estimate_provider_quality_.http_rtt().InMilliseconds() - | 801 external_estimate_provider_quality_.http_rtt().InMilliseconds() - |
802 recent_http_rtt.InMilliseconds(); | 802 recent_http_rtt.InMilliseconds(); |
803 | 803 |
804 RecordRTTAccuracy("NQE.ExternalEstimateProvider.RTT.Accuracy", | 804 RecordRTTAccuracy("NQE.ExternalEstimateProvider.RTT.Accuracy", |
805 estimated_observed_diff_milliseconds, measuring_duration, | 805 estimated_observed_diff_milliseconds, measuring_duration, |
806 recent_http_rtt); | 806 recent_http_rtt); |
807 } | 807 } |
808 } | 808 } |
809 | 809 |
810 void NetworkQualityEstimator::NotifyRequestCompleted( | 810 void NetworkQualityEstimator::NotifyRequestCompleted(const URLRequest& request, |
811 const URLRequest& request) { | 811 int net_error) { |
812 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), | 812 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), |
813 "NetworkQualityEstimator::NotifyRequestCompleted"); | 813 "NetworkQualityEstimator::NotifyRequestCompleted"); |
814 DCHECK(thread_checker_.CalledOnValidThread()); | 814 DCHECK(thread_checker_.CalledOnValidThread()); |
815 | 815 |
816 if (!RequestSchemeIsHTTPOrHTTPS(request)) | 816 if (!RequestSchemeIsHTTPOrHTTPS(request)) |
817 return; | 817 return; |
818 | 818 |
819 throughput_analyzer_->NotifyRequestCompleted(request); | 819 throughput_analyzer_->NotifyRequestCompleted(request); |
820 RecordCorrelationMetric(request); | 820 RecordCorrelationMetric(request, net_error); |
821 } | 821 } |
822 | 822 |
823 void NetworkQualityEstimator::RecordCorrelationMetric( | 823 void NetworkQualityEstimator::RecordCorrelationMetric(const URLRequest& request, |
824 const URLRequest& request) const { | 824 int net_error) const { |
825 DCHECK(thread_checker_.CalledOnValidThread()); | 825 DCHECK(thread_checker_.CalledOnValidThread()); |
826 | 826 |
827 // The histogram is recorded with probability | 827 // The histogram is recorded with probability |
828 // |correlation_uma_logging_probability_| to reduce overhead involved with | 828 // |correlation_uma_logging_probability_| to reduce overhead involved with |
829 // sparse histograms. Also, recording the correlation on each request is | 829 // sparse histograms. Also, recording the correlation on each request is |
830 // unnecessary. | 830 // unnecessary. |
831 if (RandDouble() >= correlation_uma_logging_probability_) | 831 if (RandDouble() >= correlation_uma_logging_probability_) |
832 return; | 832 return; |
833 | 833 |
834 if (request.response_info().was_cached || | 834 if (request.response_info().was_cached || |
835 !request.response_info().network_accessed) { | 835 !request.response_info().network_accessed) { |
836 return; | 836 return; |
837 } | 837 } |
838 | 838 |
839 LoadTimingInfo load_timing_info; | 839 LoadTimingInfo load_timing_info; |
840 request.GetLoadTimingInfo(&load_timing_info); | 840 request.GetLoadTimingInfo(&load_timing_info); |
841 // If the load timing info is unavailable, it probably means that the request | 841 // If the load timing info is unavailable, it probably means that the request |
842 // did not go over the network. | 842 // did not go over the network. |
843 if (load_timing_info.send_start.is_null() || | 843 if (load_timing_info.send_start.is_null() || |
844 load_timing_info.receive_headers_end.is_null()) { | 844 load_timing_info.receive_headers_end.is_null()) { |
845 return; | 845 return; |
846 } | 846 } |
847 | 847 |
848 // Record UMA only for successful requests that have completed. | 848 // Record UMA only for successful requests that have completed. |
849 if (!request.status().is_success() || request.status().is_io_pending()) | 849 if (net_error != OK) |
850 return; | 850 return; |
851 if (request.GetResponseCode() != HTTP_OK) | 851 if (request.GetResponseCode() != HTTP_OK) |
852 return; | 852 return; |
853 if (load_timing_info.receive_headers_end < last_main_frame_request_) | 853 if (load_timing_info.receive_headers_end < last_main_frame_request_) |
854 return; | 854 return; |
855 | 855 |
856 const base::TimeTicks now = tick_clock_->NowTicks(); | 856 const base::TimeTicks now = tick_clock_->NowTicks(); |
857 // Record UMA only for requests that started recently. | 857 // Record UMA only for requests that started recently. |
858 if (now - last_main_frame_request_ > base::TimeDelta::FromSeconds(15)) | 858 if (now - last_main_frame_request_ > base::TimeDelta::FromSeconds(15)) |
859 return; | 859 return; |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1711 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { | 1711 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { |
1712 network_quality_store_->Add( | 1712 network_quality_store_->Add( |
1713 current_network_id_, | 1713 current_network_id_, |
1714 nqe::internal::CachedNetworkQuality( | 1714 nqe::internal::CachedNetworkQuality( |
1715 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, | 1715 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, |
1716 effective_connection_type_)); | 1716 effective_connection_type_)); |
1717 } | 1717 } |
1718 } | 1718 } |
1719 | 1719 |
1720 } // namespace net | 1720 } // namespace net |
OLD | NEW |