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..55da1c78532cb6463996cd4a23a0e7303ccdbaeb 100644 |
--- a/net/nqe/network_quality_estimator.cc |
+++ b/net/nqe/network_quality_estimator.cc |
@@ -1147,7 +1147,15 @@ NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics( |
void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver( |
EffectiveConnectionTypeObserver* observer) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
+ DCHECK(observer); |
effective_connection_type_observer_list_.AddObserver(observer); |
+ |
+ // Notify the |observer| on the next message pump since |observer| may not |
+ // be completely set up for receiving the callbacks. |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, base::Bind(&NetworkQualityEstimator:: |
+ NotifyEffectiveConnectionTypeObserverIfPresent, |
+ weak_ptr_factory_.GetWeakPtr(), observer)); |
} |
void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver( |
@@ -1159,7 +1167,16 @@ void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver( |
void NetworkQualityEstimator::AddRTTAndThroughputEstimatesObserver( |
RTTAndThroughputEstimatesObserver* observer) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
+ DCHECK(observer); |
rtt_and_throughput_estimates_observer_list_.AddObserver(observer); |
+ |
+ // Notify the |observer| on the next message pump since |observer| may not |
+ // be completely set up for receiving the callbacks. |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&NetworkQualityEstimator:: |
+ NotifyRTTAndThroughputEstimatesObserverIfPresent, |
+ weak_ptr_factory_.GetWeakPtr(), observer)); |
} |
void NetworkQualityEstimator::RemoveRTTAndThroughputEstimatesObserver( |
@@ -1501,6 +1518,28 @@ void NetworkQualityEstimator::NotifyObserversOfRTTOrThroughputComputed() const { |
} |
} |
+void NetworkQualityEstimator::NotifyEffectiveConnectionTypeObserverIfPresent( |
+ EffectiveConnectionTypeObserver* observer) const { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
+ if (!effective_connection_type_observer_list_.HasObserver(observer)) |
+ 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) { |