| 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 0.0)), | 402 0.0)), |
| 403 forced_effective_connection_type_set_( | 403 forced_effective_connection_type_set_( |
| 404 !GetStringValueForVariationParamWithDefaultValue( | 404 !GetStringValueForVariationParamWithDefaultValue( |
| 405 variation_params, | 405 variation_params, |
| 406 "force_effective_connection_type", | 406 "force_effective_connection_type", |
| 407 "") | 407 "") |
| 408 .empty()), | 408 .empty()), |
| 409 weak_ptr_factory_(this) { | 409 weak_ptr_factory_(this) { |
| 410 static_assert(kDefaultHalfLifeSeconds > 0, | 410 static_assert(kDefaultHalfLifeSeconds > 0, |
| 411 "Default half life duration must be > 0"); | 411 "Default half life duration must be > 0"); |
| 412 static_assert(kMinimumRTTVariationParameterMsec > 0 && |
| 413 kMinimumRTTVariationParameterMsec > |
| 414 nqe::internal::INVALID_RTT_THROUGHPUT, |
| 415 "kMinimumRTTVariationParameterMsec is set incorrectly"); |
| 416 static_assert(kMinimumThroughputVariationParameterKbps > 0 && |
| 417 kMinimumThroughputVariationParameterKbps > |
| 418 nqe::internal::kInvalidThroughput, |
| 419 "kMinimumThroughputVariationParameterKbps is set incorrectly"); |
| 412 // None of the algorithms can have an empty name. | 420 // None of the algorithms can have an empty name. |
| 413 DCHECK(algorithm_name_to_enum_.end() == | 421 DCHECK(algorithm_name_to_enum_.end() == |
| 414 algorithm_name_to_enum_.find(std::string())); | 422 algorithm_name_to_enum_.find(std::string())); |
| 415 | 423 |
| 416 DCHECK_EQ(algorithm_name_to_enum_.size(), | 424 DCHECK_EQ(algorithm_name_to_enum_.size(), |
| 417 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: | 425 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: |
| 418 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); | 426 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); |
| 419 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: | 427 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: |
| 420 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, | 428 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, |
| 421 effective_connection_type_algorithm_); | 429 effective_connection_type_algorithm_); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 load_timing_info.receive_headers_end.is_null()) { | 715 load_timing_info.receive_headers_end.is_null()) { |
| 708 return; | 716 return; |
| 709 } | 717 } |
| 710 DCHECK(!request.response_info().was_cached); | 718 DCHECK(!request.response_info().was_cached); |
| 711 | 719 |
| 712 // Duration between when the resource was requested and when the response | 720 // Duration between when the resource was requested and when the response |
| 713 // headers were received. | 721 // headers were received. |
| 714 base::TimeDelta observed_http_rtt = | 722 base::TimeDelta observed_http_rtt = |
| 715 load_timing_info.receive_headers_end - load_timing_info.send_start; | 723 load_timing_info.receive_headers_end - load_timing_info.send_start; |
| 716 DCHECK_GE(observed_http_rtt, base::TimeDelta()); | 724 DCHECK_GE(observed_http_rtt, base::TimeDelta()); |
| 717 if (observed_http_rtt < peak_network_quality_.http_rtt()) { | 725 if (observed_http_rtt < peak_network_quality_.http_rtt() || |
| 726 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) { |
| 718 peak_network_quality_ = nqe::internal::NetworkQuality( | 727 peak_network_quality_ = nqe::internal::NetworkQuality( |
| 719 observed_http_rtt, peak_network_quality_.transport_rtt(), | 728 observed_http_rtt, peak_network_quality_.transport_rtt(), |
| 720 peak_network_quality_.downstream_throughput_kbps()); | 729 peak_network_quality_.downstream_throughput_kbps()); |
| 721 } | 730 } |
| 722 | 731 |
| 723 RttObservation http_rtt_observation( | 732 RttObservation http_rtt_observation( |
| 724 observed_http_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); | 733 observed_http_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); |
| 725 rtt_observations_.AddObservation(http_rtt_observation); | 734 rtt_observations_.AddObservation(http_rtt_observation); |
| 726 NotifyObserversOfRTT(http_rtt_observation); | 735 NotifyObserversOfRTT(http_rtt_observation); |
| 727 } | 736 } |
| (...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1696 | 1705 |
| 1697 void NetworkQualityEstimator::OnNewThroughputObservationAvailable( | 1706 void NetworkQualityEstimator::OnNewThroughputObservationAvailable( |
| 1698 int32_t downstream_kbps) { | 1707 int32_t downstream_kbps) { |
| 1699 DCHECK(thread_checker_.CalledOnValidThread()); | 1708 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1700 | 1709 |
| 1701 if (downstream_kbps == 0) | 1710 if (downstream_kbps == 0) |
| 1702 return; | 1711 return; |
| 1703 | 1712 |
| 1704 DCHECK_NE(nqe::internal::kInvalidThroughput, downstream_kbps); | 1713 DCHECK_NE(nqe::internal::kInvalidThroughput, downstream_kbps); |
| 1705 | 1714 |
| 1706 if (downstream_kbps > peak_network_quality_.downstream_throughput_kbps()) { | 1715 if (downstream_kbps > peak_network_quality_.downstream_throughput_kbps() || |
| 1716 peak_network_quality_.downstream_throughput_kbps() == |
| 1717 nqe::internal::kInvalidThroughput) { |
| 1707 peak_network_quality_ = nqe::internal::NetworkQuality( | 1718 peak_network_quality_ = nqe::internal::NetworkQuality( |
| 1708 peak_network_quality_.http_rtt(), peak_network_quality_.transport_rtt(), | 1719 peak_network_quality_.http_rtt(), peak_network_quality_.transport_rtt(), |
| 1709 downstream_kbps); | 1720 downstream_kbps); |
| 1710 } | 1721 } |
| 1711 ThroughputObservation throughput_observation( | 1722 ThroughputObservation throughput_observation( |
| 1712 downstream_kbps, tick_clock_->NowTicks(), | 1723 downstream_kbps, tick_clock_->NowTicks(), |
| 1713 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); | 1724 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); |
| 1714 downstream_throughput_kbps_observations_.AddObservation( | 1725 downstream_throughput_kbps_observations_.AddObservation( |
| 1715 throughput_observation); | 1726 throughput_observation); |
| 1716 NotifyObserversOfThroughput(throughput_observation); | 1727 NotifyObserversOfThroughput(throughput_observation); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1781 } | 1792 } |
| 1782 | 1793 |
| 1783 void NetworkQualityEstimator::RemoveNetworkQualitiesCacheObserver( | 1794 void NetworkQualityEstimator::RemoveNetworkQualitiesCacheObserver( |
| 1784 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* | 1795 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* |
| 1785 observer) { | 1796 observer) { |
| 1786 DCHECK(thread_checker_.CalledOnValidThread()); | 1797 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1787 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer); | 1798 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer); |
| 1788 } | 1799 } |
| 1789 | 1800 |
| 1790 } // namespace net | 1801 } // namespace net |
| OLD | NEW |