Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(744)

Side by Side Diff: net/nqe/network_quality_estimator.cc

Issue 2223773003: Expose effective connection type to Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased, addressed comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/nqe/effective_connection_type.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 1655
1656 void NetworkQualityEstimator::MaybeRecomputeEffectiveConnectionType() { 1656 void NetworkQualityEstimator::MaybeRecomputeEffectiveConnectionType() {
1657 DCHECK(thread_checker_.CalledOnValidThread()); 1657 DCHECK(thread_checker_.CalledOnValidThread());
1658 1658
1659 const base::TimeTicks now = tick_clock_->NowTicks(); 1659 const base::TimeTicks now = tick_clock_->NowTicks();
1660 // Recompute effective connection type only if 1660 // Recompute effective connection type only if
1661 // |effective_connection_type_recomputation_interval_| has passed since it was 1661 // |effective_connection_type_recomputation_interval_| has passed since it was
1662 // last computed or a connection change event was observed since the last 1662 // last computed or a connection change event was observed since the last
1663 // computation. Strict inequalities are used to ensure that effective 1663 // computation. Strict inequalities are used to ensure that effective
1664 // connection type is recomputed on connection change events even if the clock 1664 // connection type is recomputed on connection change events even if the clock
1665 // has not updated. Recompute the effective connection type if the effective 1665 // has not updated. Recompute the effective connection type if the effective
1666 // connection type was previously unavailable. This is because the RTT 1666 // connection type was previously unavailable. This is because the RTT
1667 // observations are voluminous, so it may now be possible to compute the 1667 // observations are voluminous, so it may now be possible to compute the
1668 // effective connection type. 1668 // effective connection type.
1669 if (now - last_effective_connection_type_computation_ < 1669 if (now - last_effective_connection_type_computation_ <
1670 effective_connection_type_recomputation_interval_ && 1670 effective_connection_type_recomputation_interval_ &&
1671 last_connection_change_ < last_effective_connection_type_computation_ && 1671 last_connection_change_ < last_effective_connection_type_computation_ &&
1672 effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1672 effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1673 return; 1673 return;
1674 } 1674 }
1675 1675
1676 const EffectiveConnectionType past_type = effective_connection_type_; 1676 const EffectiveConnectionType past_type = effective_connection_type_;
1677 last_effective_connection_type_computation_ = now; 1677 last_effective_connection_type_computation_ = now;
1678 effective_connection_type_ = GetEffectiveConnectionType(); 1678 effective_connection_type_ = GetEffectiveConnectionType();
1679 1679
1680 if (past_type != effective_connection_type_) 1680 if (past_type != effective_connection_type_)
1681 NotifyObserversOfEffectiveConnectionTypeChanged(); 1681 NotifyObserversOfEffectiveConnectionTypeChanged();
1682 } 1682 }
1683 1683
1684 void NetworkQualityEstimator:: 1684 void NetworkQualityEstimator::
1685 NotifyObserversOfEffectiveConnectionTypeChanged() { 1685 NotifyObserversOfEffectiveConnectionTypeChanged() {
1686 DCHECK(thread_checker_.CalledOnValidThread()); 1686 DCHECK(thread_checker_.CalledOnValidThread());
1687 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_);
1687 1688
1688 // TODO(tbansal): Add hysteresis in the notification. 1689 // TODO(tbansal): Add hysteresis in the notification.
1689 FOR_EACH_OBSERVER( 1690 FOR_EACH_OBSERVER(
1690 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, 1691 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_,
1691 OnEffectiveConnectionTypeChanged(effective_connection_type_)); 1692 OnEffectiveConnectionTypeChanged(effective_connection_type_));
1692 1693
1693 // Add the estimates of the current network to the cache store. 1694 // Add the estimates of the current network to the cache store.
1694 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1695 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1695 network_quality_store_.Add( 1696 network_quality_store_.Add(
1696 current_network_id_, 1697 current_network_id_,
1697 nqe::internal::CachedNetworkQuality( 1698 nqe::internal::CachedNetworkQuality(
1698 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, 1699 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_,
1699 effective_connection_type_)); 1700 effective_connection_type_));
1700 } 1701 }
1701 } 1702 }
1702 1703
1703 } // namespace net 1704 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/effective_connection_type.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698