| 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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 if (!GetTransportRTTEstimate(&estimated_transport_rtt)) | 620 if (!GetTransportRTTEstimate(&estimated_transport_rtt)) |
| 621 estimated_transport_rtt = nqe::internal::InvalidRTT(); | 621 estimated_transport_rtt = nqe::internal::InvalidRTT(); |
| 622 | 622 |
| 623 int32_t downstream_throughput_kbps; | 623 int32_t downstream_throughput_kbps; |
| 624 if (!GetDownlinkThroughputKbpsEstimate(&downstream_throughput_kbps)) | 624 if (!GetDownlinkThroughputKbpsEstimate(&downstream_throughput_kbps)) |
| 625 downstream_throughput_kbps = nqe::internal::kInvalidThroughput; | 625 downstream_throughput_kbps = nqe::internal::kInvalidThroughput; |
| 626 | 626 |
| 627 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality( | 627 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality( |
| 628 estimated_http_rtt, estimated_transport_rtt, | 628 estimated_http_rtt, estimated_transport_rtt, |
| 629 downstream_throughput_kbps); | 629 downstream_throughput_kbps); |
| 630 |
| 631 RecomputeEffectiveConnectionType(); |
| 630 effective_connection_type_at_last_main_frame_ = | 632 effective_connection_type_at_last_main_frame_ = |
| 631 GetEffectiveConnectionType(); | 633 GetEffectiveConnectionType(); |
| 632 | 634 |
| 633 RecordMetricsOnMainFrameRequest(); | 635 RecordMetricsOnMainFrameRequest(); |
| 634 MaybeQueryExternalEstimateProvider(); | 636 MaybeQueryExternalEstimateProvider(); |
| 635 | 637 |
| 636 // Post the tasks which will run in the future and record the estimation | 638 // Post the tasks which will run in the future and record the estimation |
| 637 // accuracy based on the observations received between now and the time of | 639 // accuracy based on the observations received between now and the time of |
| 638 // task execution. Posting the task at different intervals makes it | 640 // task execution. Posting the task at different intervals makes it |
| 639 // possible to measure the accuracy by comparing the estimate with the | 641 // possible to measure the accuracy by comparing the estimate with the |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 base::Histogram::FactoryGet( | 1153 base::Histogram::FactoryGet( |
| 1152 std::string("NQE.MainFrame.EffectiveConnectionType.") + | 1154 std::string("NQE.MainFrame.EffectiveConnectionType.") + |
| 1153 GetNameForConnectionType(current_network_id_.type), | 1155 GetNameForConnectionType(current_network_id_.type), |
| 1154 0, EFFECTIVE_CONNECTION_TYPE_LAST, | 1156 0, EFFECTIVE_CONNECTION_TYPE_LAST, |
| 1155 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, | 1157 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, |
| 1156 base::HistogramBase::kUmaTargetedHistogramFlag); | 1158 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1157 | 1159 |
| 1158 effective_connection_type_histogram->Add(effective_connection_type); | 1160 effective_connection_type_histogram->Add(effective_connection_type); |
| 1159 } | 1161 } |
| 1160 | 1162 |
| 1163 void NetworkQualityEstimator::RecomputeEffectiveConnectionType() { |
| 1164 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1165 |
| 1166 const base::TimeTicks now = tick_clock_->NowTicks(); |
| 1167 |
| 1168 const EffectiveConnectionType past_type = effective_connection_type_; |
| 1169 last_effective_connection_type_computation_ = now; |
| 1170 |
| 1171 effective_connection_type_ = |
| 1172 GetRecentEffectiveConnectionType(base::TimeTicks()); |
| 1173 |
| 1174 if (past_type != effective_connection_type_) |
| 1175 NotifyObserversOfEffectiveConnectionTypeChanged(); |
| 1176 |
| 1177 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size(); |
| 1178 throughput_observations_size_at_last_ect_computation_ = |
| 1179 downstream_throughput_kbps_observations_.Size(); |
| 1180 } |
| 1181 |
| 1161 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType() | 1182 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType() |
| 1162 const { | 1183 const { |
| 1163 DCHECK(thread_checker_.CalledOnValidThread()); | 1184 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1164 return GetRecentEffectiveConnectionType(base::TimeTicks()); | 1185 return effective_connection_type_; |
| 1165 } | 1186 } |
| 1166 | 1187 |
| 1167 EffectiveConnectionType | 1188 EffectiveConnectionType |
| 1168 NetworkQualityEstimator::GetRecentEffectiveConnectionType( | 1189 NetworkQualityEstimator::GetRecentEffectiveConnectionType( |
| 1169 const base::TimeTicks& start_time) const { | 1190 const base::TimeTicks& start_time) const { |
| 1170 DCHECK(thread_checker_.CalledOnValidThread()); | 1191 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1171 | 1192 |
| 1172 if (effective_connection_type_algorithm_ == | 1193 if (effective_connection_type_algorithm_ == |
| 1173 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) { | 1194 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) { |
| 1174 return GetRecentEffectiveConnectionTypeUsingMetrics( | 1195 return GetRecentEffectiveConnectionTypeUsingMetrics( |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 // available now are more than twice in count than the number of | 1649 // available now are more than twice in count than the number of |
| 1629 // samples that were available when the effective connection type was | 1650 // samples that were available when the effective connection type was |
| 1630 // last computed. | 1651 // last computed. |
| 1631 rtt_observations_size_at_last_ect_computation_ * 2 >= | 1652 rtt_observations_size_at_last_ect_computation_ * 2 >= |
| 1632 rtt_observations_.Size() && | 1653 rtt_observations_.Size() && |
| 1633 throughput_observations_size_at_last_ect_computation_ * 2 >= | 1654 throughput_observations_size_at_last_ect_computation_ * 2 >= |
| 1634 downstream_throughput_kbps_observations_.Size()) { | 1655 downstream_throughput_kbps_observations_.Size()) { |
| 1635 return; | 1656 return; |
| 1636 } | 1657 } |
| 1637 | 1658 |
| 1638 const EffectiveConnectionType past_type = effective_connection_type_; | 1659 RecomputeEffectiveConnectionType(); |
| 1639 last_effective_connection_type_computation_ = now; | |
| 1640 effective_connection_type_ = GetEffectiveConnectionType(); | |
| 1641 | |
| 1642 if (past_type != effective_connection_type_) | |
| 1643 NotifyObserversOfEffectiveConnectionTypeChanged(); | |
| 1644 | |
| 1645 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size(); | |
| 1646 throughput_observations_size_at_last_ect_computation_ = | |
| 1647 downstream_throughput_kbps_observations_.Size(); | |
| 1648 } | 1660 } |
| 1649 | 1661 |
| 1650 void NetworkQualityEstimator:: | 1662 void NetworkQualityEstimator:: |
| 1651 NotifyObserversOfEffectiveConnectionTypeChanged() { | 1663 NotifyObserversOfEffectiveConnectionTypeChanged() { |
| 1652 DCHECK(thread_checker_.CalledOnValidThread()); | 1664 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1653 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); | 1665 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); |
| 1654 | 1666 |
| 1655 // TODO(tbansal): Add hysteresis in the notification. | 1667 // TODO(tbansal): Add hysteresis in the notification. |
| 1656 FOR_EACH_OBSERVER( | 1668 FOR_EACH_OBSERVER( |
| 1657 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, | 1669 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, |
| 1658 OnEffectiveConnectionTypeChanged(effective_connection_type_)); | 1670 OnEffectiveConnectionTypeChanged(effective_connection_type_)); |
| 1659 | 1671 |
| 1660 // Add the estimates of the current network to the cache store. | 1672 // Add the estimates of the current network to the cache store. |
| 1661 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { | 1673 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { |
| 1662 network_quality_store_.Add( | 1674 network_quality_store_.Add( |
| 1663 current_network_id_, | 1675 current_network_id_, |
| 1664 nqe::internal::CachedNetworkQuality( | 1676 nqe::internal::CachedNetworkQuality( |
| 1665 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, | 1677 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, |
| 1666 effective_connection_type_)); | 1678 effective_connection_type_)); |
| 1667 } | 1679 } |
| 1668 } | 1680 } |
| 1669 | 1681 |
| 1670 } // namespace net | 1682 } // namespace net |
| OLD | NEW |