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

Unified Diff: net/nqe/network_quality_estimator.cc

Issue 2863973003: Expose RTT and downlink bandwidth using experimental Javascript API (Closed)
Patch Set: ps Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: net/nqe/network_quality_estimator.cc
diff --git a/net/nqe/network_quality_estimator.cc b/net/nqe/network_quality_estimator.cc
index e52cf68ce97795503dfaa9d24ba8f9f993e3f5c3..f495e3f4c0a7e08aab796a1eb8bdb9188ecc438e 100644
--- a/net/nqe/network_quality_estimator.cc
+++ b/net/nqe/network_quality_estimator.cc
@@ -293,6 +293,7 @@ NetworkQualityEstimator::NetworkQualityEstimator(
NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE,
NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE,
NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM}),
+ suppress_notifications_for_testing_(false),
weak_ptr_factory_(this) {
// None of the algorithms can have an empty name.
DCHECK(algorithm_name_to_enum_.end() ==
@@ -1587,6 +1588,10 @@ void NetworkQualityEstimator::NotifyObserversOfRTT(
// Maybe recompute the effective connection type since a new RTT observation
// is available.
MaybeComputeEffectiveConnectionType();
+
+ if (suppress_notifications_for_testing_)
+ return;
+
for (auto& observer : rtt_observer_list_) {
observer.OnRTTObservation(observation.value.InMilliseconds(),
observation.timestamp, observation.source);
@@ -1605,6 +1610,10 @@ void NetworkQualityEstimator::NotifyObserversOfThroughput(
// Maybe recompute the effective connection type since a new throughput
// observation is available.
MaybeComputeEffectiveConnectionType();
+
+ if (suppress_notifications_for_testing_)
+ return;
+
for (auto& observer : throughput_observer_list_) {
bengr 2017/05/12 19:09:54 I'd prefer that you didn't add test support into n
tbansal1 2017/05/12 22:18:17 Done.
observer.OnThroughputObservation(observation.value, observation.timestamp,
observation.source);
@@ -1668,10 +1677,6 @@ void NetworkQualityEstimator::
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_);
- // TODO(tbansal): Add hysteresis in the notification.
- for (auto& observer : effective_connection_type_observer_list_)
- observer.OnEffectiveConnectionTypeChanged(effective_connection_type_);
-
// Add the estimates of the current network to the cache store.
if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
network_quality_store_->Add(current_network_id_,
@@ -1679,11 +1684,21 @@ void NetworkQualityEstimator::
tick_clock_->NowTicks(), network_quality_,
effective_connection_type_));
}
+
+ if (suppress_notifications_for_testing_)
+ return;
+
+ // TODO(tbansal): Add hysteresis in the notification.
bengr 2017/05/12 19:09:55 What kind of hysteresis? Consider making the hyste
tbansal1 2017/05/12 22:18:17 Removed this. We can consider adding hysteresis in
+ for (auto& observer : effective_connection_type_observer_list_)
+ observer.OnEffectiveConnectionTypeChanged(effective_connection_type_);
}
void NetworkQualityEstimator::NotifyObserversOfRTTOrThroughputComputed() const {
DCHECK(thread_checker_.CalledOnValidThread());
+ if (suppress_notifications_for_testing_)
bengr 2017/05/12 19:09:55 Yeah, this is gross. Virtualize.
tbansal1 2017/05/12 22:18:17 Done.
+ return;
+
// TODO(tbansal): Add hysteresis in the notification.
for (auto& observer : rtt_and_throughput_estimates_observer_list_) {
observer.OnRTTOrThroughputEstimatesComputed(
@@ -1696,6 +1711,8 @@ void NetworkQualityEstimator::NotifyEffectiveConnectionTypeObserverIfPresent(
EffectiveConnectionTypeObserver* observer) const {
DCHECK(thread_checker_.CalledOnValidThread());
+ if (suppress_notifications_for_testing_)
+ return;
if (!effective_connection_type_observer_list_.HasObserver(observer))
return;
if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
@@ -1707,6 +1724,8 @@ void NetworkQualityEstimator::NotifyRTTAndThroughputEstimatesObserverIfPresent(
RTTAndThroughputEstimatesObserver* observer) const {
DCHECK(thread_checker_.CalledOnValidThread());
+ if (suppress_notifications_for_testing_)
+ return;
if (!rtt_and_throughput_estimates_observer_list_.HasObserver(observer))
return;
observer->OnRTTOrThroughputEstimatesComputed(
@@ -1820,6 +1839,11 @@ const char* NetworkQualityEstimator::GetNameForStatistic(int i) const {
return "";
}
+void NetworkQualityEstimator::SuppressNotificationsForTesting() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ suppress_notifications_for_testing_ = true;
+}
+
base::Optional<base::TimeDelta>
NetworkQualityEstimator::NetworkQualityProvider::GetHttpRTT() const {
return base::Optional<base::TimeDelta>();

Powered by Google App Engine
This is Rietveld 408576698