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

Unified Diff: net/nqe/network_quality_estimator.cc

Issue 2491703003: NQE: Notify observer as soon as it is added (Closed)
Patch Set: ryansturm comments Created 4 years, 1 month 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
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/nqe/network_quality_estimator.cc
diff --git a/net/nqe/network_quality_estimator.cc b/net/nqe/network_quality_estimator.cc
index 926ec14904722328db9e04c9acf81c5056081a48..724b8a5f53e67f015b14a87218d1f8842dcc8619 100644
--- a/net/nqe/network_quality_estimator.cc
+++ b/net/nqe/network_quality_estimator.cc
@@ -1147,7 +1147,13 @@ NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics(
void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver(
EffectiveConnectionTypeObserver* observer) {
DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(observer);
effective_connection_type_observer_list_.AddObserver(observer);
+
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&NetworkQualityEstimator::
+ NotifyEffectiveConnectionTypeObserverIfPresent,
+ weak_ptr_factory_.GetWeakPtr(), observer));
}
void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver(
@@ -1159,7 +1165,14 @@ void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver(
void NetworkQualityEstimator::AddRTTAndThroughputEstimatesObserver(
RTTAndThroughputEstimatesObserver* observer) {
DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(observer);
rtt_and_throughput_estimates_observer_list_.AddObserver(observer);
+
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&NetworkQualityEstimator::
+ NotifyRTTAndThroughputEstimatesObserverIfPresent,
+ weak_ptr_factory_.GetWeakPtr(), observer));
}
void NetworkQualityEstimator::RemoveRTTAndThroughputEstimatesObserver(
@@ -1501,6 +1514,28 @@ void NetworkQualityEstimator::NotifyObserversOfRTTOrThroughputComputed() const {
}
}
+void NetworkQualityEstimator::NotifyEffectiveConnectionTypeObserverIfPresent(
+ EffectiveConnectionTypeObserver* observer) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ if (!effective_connection_type_observer_list_.HasObserver(observer))
RyanSturm 2016/11/10 23:07:22 Add testing for Add then Remove observer (not cras
tbansal1 2016/11/11 00:49:45 Done.
+ return;
+ if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
+ return;
+ observer->OnEffectiveConnectionTypeChanged(effective_connection_type_);
+}
+
+void NetworkQualityEstimator::NotifyRTTAndThroughputEstimatesObserverIfPresent(
+ RTTAndThroughputEstimatesObserver* observer) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ if (!rtt_and_throughput_estimates_observer_list_.HasObserver(observer))
+ return;
+ observer->OnRTTOrThroughputEstimatesComputed(
+ network_quality_.http_rtt(), network_quality_.transport_rtt(),
+ network_quality_.downstream_throughput_kbps());
+}
+
void NetworkQualityEstimator::AddNetworkQualitiesCacheObserver(
nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver*
observer) {
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698