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

Unified Diff: chrome/browser/net/nqe/ui_network_quality_estimator_service.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
Index: chrome/browser/net/nqe/ui_network_quality_estimator_service.cc
diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc b/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc
index 2964572feca42e65a417afc35cbd53d843adb19a..1585e06514a88fde1a2dce383b08fff9f9defb02 100644
--- a/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc
+++ b/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc
@@ -126,12 +126,6 @@ class UINetworkQualityEstimatorService::IONetworkQualityObserver
if (!network_quality_estimator_)
return;
network_quality_estimator_->AddEffectiveConnectionTypeObserver(this);
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(
- &UINetworkQualityEstimatorService::EffectiveConnectionTypeChanged,
- service_,
- network_quality_estimator_->GetEffectiveConnectionType()));
}
// net::NetworkQualityEstimator::EffectiveConnectionTypeObserver
@@ -215,6 +209,12 @@ void UINetworkQualityEstimatorService::AddEffectiveConnectionTypeObserver(
net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
effective_connection_type_observer_list_.AddObserver(observer);
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&UINetworkQualityEstimatorService::
+ NotifyEffectiveConnectionTypeObserverIfPresent,
+ weak_factory_.GetWeakPtr(), observer));
}
void UINetworkQualityEstimatorService::RemoveEffectiveConnectionTypeObserver(
@@ -242,6 +242,19 @@ void UINetworkQualityEstimatorService::ClearPrefs() {
prefs_manager_->ClearPrefs();
}
+void UINetworkQualityEstimatorService::
+ NotifyEffectiveConnectionTypeObserverIfPresent(
+ net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer)
+ const {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+ if (!effective_connection_type_observer_list_.HasObserver(observer))
+ return;
+ if (type_ == net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
+ return;
+ observer->OnEffectiveConnectionTypeChanged(type_);
+}
+
// static
void UINetworkQualityEstimatorService::RegisterProfilePrefs(
PrefRegistrySimple* registry) {

Powered by Google App Engine
This is Rietveld 408576698