| 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 weight_multiplier_per_second_( | 356 weight_multiplier_per_second_( |
| 357 GetWeightMultiplierPerSecond(variation_params)), | 357 GetWeightMultiplierPerSecond(variation_params)), |
| 358 effective_connection_type_algorithm_( | 358 effective_connection_type_algorithm_( |
| 359 algorithm_name_to_enum_.find(GetEffectiveConnectionTypeAlgorithm( | 359 algorithm_name_to_enum_.find(GetEffectiveConnectionTypeAlgorithm( |
| 360 variation_params)) == algorithm_name_to_enum_.end() | 360 variation_params)) == algorithm_name_to_enum_.end() |
| 361 ? kDefaultEffectiveConnectionTypeAlgorithm | 361 ? kDefaultEffectiveConnectionTypeAlgorithm |
| 362 : algorithm_name_to_enum_ | 362 : algorithm_name_to_enum_ |
| 363 .find(GetEffectiveConnectionTypeAlgorithm(variation_params)) | 363 .find(GetEffectiveConnectionTypeAlgorithm(variation_params)) |
| 364 ->second), | 364 ->second), |
| 365 tick_clock_(new base::DefaultTickClock()), | 365 tick_clock_(new base::DefaultTickClock()), |
| 366 effective_connection_type_recomputation_interval_( | |
| 367 base::TimeDelta::FromSeconds(15)), | |
| 368 last_connection_change_(tick_clock_->NowTicks()), | 366 last_connection_change_(tick_clock_->NowTicks()), |
| 369 current_network_id_(nqe::internal::NetworkID( | 367 current_network_id_(nqe::internal::NetworkID( |
| 370 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, | 368 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, |
| 371 std::string())), | 369 std::string())), |
| 372 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), | 370 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), |
| 373 rtt_observations_(weight_multiplier_per_second_), | 371 rtt_observations_(weight_multiplier_per_second_), |
| 374 effective_connection_type_at_last_main_frame_( | 372 effective_connection_type_at_last_main_frame_( |
| 375 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 373 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
| 376 external_estimate_provider_(std::move(external_estimates_provider)), | 374 external_estimate_provider_(std::move(external_estimates_provider)), |
| 375 effective_connection_type_recomputation_interval_( |
| 376 base::TimeDelta::FromSeconds(15)), |
| 377 rtt_observations_size_at_last_ect_computation_(0), |
| 378 throughput_observations_size_at_last_ect_computation_(0), |
| 377 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 379 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
| 378 min_signal_strength_since_connection_change_(INT32_MAX), | 380 min_signal_strength_since_connection_change_(INT32_MAX), |
| 379 max_signal_strength_since_connection_change_(INT32_MIN), | 381 max_signal_strength_since_connection_change_(INT32_MIN), |
| 380 correlation_uma_logging_probability_( | 382 correlation_uma_logging_probability_( |
| 381 GetDoubleValueForVariationParamWithDefaultValue( | 383 GetDoubleValueForVariationParamWithDefaultValue( |
| 382 variation_params, | 384 variation_params, |
| 383 "correlation_logging_probability", | 385 "correlation_logging_probability", |
| 384 0.0)), | 386 0.0)), |
| 385 weak_ptr_factory_(this) { | 387 weak_ptr_factory_(this) { |
| 386 static_assert(kDefaultHalfLifeSeconds > 0, | 388 static_assert(kDefaultHalfLifeSeconds > 0, |
| (...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 | 1610 |
| 1609 void NetworkQualityEstimator::MaybeRecomputeEffectiveConnectionType() { | 1611 void NetworkQualityEstimator::MaybeRecomputeEffectiveConnectionType() { |
| 1610 DCHECK(thread_checker_.CalledOnValidThread()); | 1612 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1611 | 1613 |
| 1612 const base::TimeTicks now = tick_clock_->NowTicks(); | 1614 const base::TimeTicks now = tick_clock_->NowTicks(); |
| 1613 // Recompute effective connection type only if | 1615 // Recompute effective connection type only if |
| 1614 // |effective_connection_type_recomputation_interval_| has passed since it was | 1616 // |effective_connection_type_recomputation_interval_| has passed since it was |
| 1615 // last computed or a connection change event was observed since the last | 1617 // last computed or a connection change event was observed since the last |
| 1616 // computation. Strict inequalities are used to ensure that effective | 1618 // computation. Strict inequalities are used to ensure that effective |
| 1617 // connection type is recomputed on connection change events even if the clock | 1619 // connection type is recomputed on connection change events even if the clock |
| 1618 // has not updated. Recompute the effective connection type if the effective | 1620 // has not updated. |
| 1619 // connection type was previously unavailable. This is because the RTT | |
| 1620 // observations are voluminous, so it may now be possible to compute the | |
| 1621 // effective connection type. | |
| 1622 if (now - last_effective_connection_type_computation_ < | 1621 if (now - last_effective_connection_type_computation_ < |
| 1623 effective_connection_type_recomputation_interval_ && | 1622 effective_connection_type_recomputation_interval_ && |
| 1624 last_connection_change_ < last_effective_connection_type_computation_ && | 1623 last_connection_change_ < last_effective_connection_type_computation_ && |
| 1625 effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { | 1624 // Recompute the effective connection type if the previously computed |
| 1625 // effective connection type was unknown. |
| 1626 effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN && |
| 1627 // Recompute the effective connection type if the number of samples |
| 1628 // available now are more than twice in count than the number of |
| 1629 // samples that were available when the effective connection type was |
| 1630 // last computed. |
| 1631 rtt_observations_size_at_last_ect_computation_ * 2 >= |
| 1632 rtt_observations_.Size() && |
| 1633 throughput_observations_size_at_last_ect_computation_ * 2 >= |
| 1634 downstream_throughput_kbps_observations_.Size()) { |
| 1626 return; | 1635 return; |
| 1627 } | 1636 } |
| 1628 | 1637 |
| 1629 const EffectiveConnectionType past_type = effective_connection_type_; | 1638 const EffectiveConnectionType past_type = effective_connection_type_; |
| 1630 last_effective_connection_type_computation_ = now; | 1639 last_effective_connection_type_computation_ = now; |
| 1631 effective_connection_type_ = GetEffectiveConnectionType(); | 1640 effective_connection_type_ = GetEffectiveConnectionType(); |
| 1632 | 1641 |
| 1633 if (past_type != effective_connection_type_) | 1642 if (past_type != effective_connection_type_) |
| 1634 NotifyObserversOfEffectiveConnectionTypeChanged(); | 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(); |
| 1635 } | 1648 } |
| 1636 | 1649 |
| 1637 void NetworkQualityEstimator:: | 1650 void NetworkQualityEstimator:: |
| 1638 NotifyObserversOfEffectiveConnectionTypeChanged() { | 1651 NotifyObserversOfEffectiveConnectionTypeChanged() { |
| 1639 DCHECK(thread_checker_.CalledOnValidThread()); | 1652 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1640 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); | 1653 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); |
| 1641 | 1654 |
| 1642 // TODO(tbansal): Add hysteresis in the notification. | 1655 // TODO(tbansal): Add hysteresis in the notification. |
| 1643 FOR_EACH_OBSERVER( | 1656 FOR_EACH_OBSERVER( |
| 1644 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, | 1657 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, |
| 1645 OnEffectiveConnectionTypeChanged(effective_connection_type_)); | 1658 OnEffectiveConnectionTypeChanged(effective_connection_type_)); |
| 1646 | 1659 |
| 1647 // Add the estimates of the current network to the cache store. | 1660 // Add the estimates of the current network to the cache store. |
| 1648 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { | 1661 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { |
| 1649 network_quality_store_.Add( | 1662 network_quality_store_.Add( |
| 1650 current_network_id_, | 1663 current_network_id_, |
| 1651 nqe::internal::CachedNetworkQuality( | 1664 nqe::internal::CachedNetworkQuality( |
| 1652 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, | 1665 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, |
| 1653 effective_connection_type_)); | 1666 effective_connection_type_)); |
| 1654 } | 1667 } |
| 1655 } | 1668 } |
| 1656 | 1669 |
| 1657 } // namespace net | 1670 } // namespace net |
| OLD | NEW |