| 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 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1636 | 1636 |
| 1637 void NetworkQualityEstimator::MaybeRecomputeEffectiveConnectionType() { | 1637 void NetworkQualityEstimator::MaybeRecomputeEffectiveConnectionType() { |
| 1638 DCHECK(thread_checker_.CalledOnValidThread()); | 1638 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1639 | 1639 |
| 1640 const base::TimeTicks now = tick_clock_->NowTicks(); | 1640 const base::TimeTicks now = tick_clock_->NowTicks(); |
| 1641 // Recompute effective connection type only if | 1641 // Recompute effective connection type only if |
| 1642 // |effective_connection_type_recomputation_interval_| has passed since it was | 1642 // |effective_connection_type_recomputation_interval_| has passed since it was |
| 1643 // last computed or a connection change event was observed since the last | 1643 // last computed or a connection change event was observed since the last |
| 1644 // computation. Strict inequalities are used to ensure that effective | 1644 // computation. Strict inequalities are used to ensure that effective |
| 1645 // connection type is recomputed on connection change events even if the clock | 1645 // connection type is recomputed on connection change events even if the clock |
| 1646 // has not updated. | 1646 // has not updated. Recompute the effective connection type if the effective |
| 1647 // connection type was previously unavailable. This is because the RTT |
| 1648 // observations are voluminous, so it may now be possible to compute the |
| 1649 // effective connection type. |
| 1647 if (now - last_effective_connection_type_computation_ < | 1650 if (now - last_effective_connection_type_computation_ < |
| 1648 effective_connection_type_recomputation_interval_ && | 1651 effective_connection_type_recomputation_interval_ && |
| 1649 last_connection_change_ < last_effective_connection_type_computation_) { | 1652 last_connection_change_ < last_effective_connection_type_computation_ && |
| 1653 effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { |
| 1650 return; | 1654 return; |
| 1651 } | 1655 } |
| 1652 | 1656 |
| 1653 const EffectiveConnectionType past_type = effective_connection_type_; | 1657 const EffectiveConnectionType past_type = effective_connection_type_; |
| 1654 last_effective_connection_type_computation_ = now; | 1658 last_effective_connection_type_computation_ = now; |
| 1655 effective_connection_type_ = GetEffectiveConnectionType(); | 1659 effective_connection_type_ = GetEffectiveConnectionType(); |
| 1656 | 1660 |
| 1657 if (past_type != effective_connection_type_) | 1661 if (past_type != effective_connection_type_) |
| 1658 NotifyObserversOfEffectiveConnectionTypeChanged(); | 1662 NotifyObserversOfEffectiveConnectionTypeChanged(); |
| 1659 } | 1663 } |
| 1660 | 1664 |
| 1661 void NetworkQualityEstimator:: | 1665 void NetworkQualityEstimator:: |
| 1662 NotifyObserversOfEffectiveConnectionTypeChanged() { | 1666 NotifyObserversOfEffectiveConnectionTypeChanged() { |
| 1663 DCHECK(thread_checker_.CalledOnValidThread()); | 1667 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1668 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); |
| 1664 | 1669 |
| 1665 // TODO(tbansal): Add hysteresis in the notification. | 1670 // TODO(tbansal): Add hysteresis in the notification. |
| 1666 FOR_EACH_OBSERVER( | 1671 FOR_EACH_OBSERVER( |
| 1667 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, | 1672 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, |
| 1668 OnEffectiveConnectionTypeChanged(effective_connection_type_)); | 1673 OnEffectiveConnectionTypeChanged(effective_connection_type_)); |
| 1669 } | 1674 } |
| 1670 | 1675 |
| 1671 } // namespace net | 1676 } // namespace net |
| OLD | NEW |