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

Unified Diff: content/browser/net/network_quality_observer_impl.cc

Issue 2883763002: Expose ECT to render frames, Blink and NetInfo (Closed)
Patch Set: rebased 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: content/browser/net/network_quality_observer_impl.cc
diff --git a/content/browser/net/network_quality_observer_impl.cc b/content/browser/net/network_quality_observer_impl.cc
index 27a64013d32066a6ecc9165c6bc28a338ce7f3c7..b7da9886f644ca259e3a9204ec223a0c5498c4fe 100644
--- a/content/browser/net/network_quality_observer_impl.cc
+++ b/content/browser/net/network_quality_observer_impl.cc
@@ -58,7 +58,8 @@ namespace content {
class NetworkQualityObserverImpl::UiThreadObserver
: public content::NotificationObserver {
public:
- UiThreadObserver() {}
+ UiThreadObserver()
+ : last_notified_type_(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {}
~UiThreadObserver() override {
registrar_.Remove(this, NOTIFICATION_RENDERER_PROCESS_CREATED,
@@ -71,6 +72,24 @@ class NetworkQualityObserverImpl::UiThreadObserver
NotificationService::AllSources());
}
+ void OnEffectiveConnectionTypeChanged(net::EffectiveConnectionType type) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ if (last_notified_type_ == type)
+ return;
+
+ last_notified_type_ = type;
+
+ // Notify all the existing renderers of the change in the network quality.
+ for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
+ !it.IsAtEnd(); it.Advance()) {
+ it.GetCurrentValue()->GetRendererInterface()->OnNetworkQualityChanged(
+ last_notified_type_, last_notified_network_quality_.http_rtt(),
+ last_notified_network_quality_.transport_rtt(),
+ last_notified_network_quality_.downstream_throughput_kbps());
+ }
+ }
+
void OnRTTOrThroughputEstimatesComputed(
const net::nqe::internal::NetworkQuality& network_quality) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -81,7 +100,7 @@ class NetworkQualityObserverImpl::UiThreadObserver
for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
!it.IsAtEnd(); it.Advance()) {
it.GetCurrentValue()->GetRendererInterface()->OnNetworkQualityChanged(
- last_notified_network_quality_.http_rtt(),
+ last_notified_type_, last_notified_network_quality_.http_rtt(),
last_notified_network_quality_.transport_rtt(),
last_notified_network_quality_.downstream_throughput_kbps());
}
@@ -99,7 +118,7 @@ class NetworkQualityObserverImpl::UiThreadObserver
// Notify the newly created renderer of the current network quality.
rph->GetRendererInterface()->OnNetworkQualityChanged(
- last_notified_network_quality_.http_rtt(),
+ last_notified_type_, last_notified_network_quality_.http_rtt(),
last_notified_network_quality_.transport_rtt(),
last_notified_network_quality_.downstream_throughput_kbps());
}
@@ -107,6 +126,7 @@ class NetworkQualityObserverImpl::UiThreadObserver
content::NotificationRegistrar registrar_;
// The network quality that was last sent to the renderers.
+ net::EffectiveConnectionType last_notified_type_;
net::nqe::internal::NetworkQuality last_notified_network_quality_;
DISALLOW_COPY_AND_ASSIGN(UiThreadObserver);
@@ -114,8 +134,10 @@ class NetworkQualityObserverImpl::UiThreadObserver
NetworkQualityObserverImpl::NetworkQualityObserverImpl(
net::NetworkQualityEstimator* network_quality_estimator)
- : network_quality_estimator_(network_quality_estimator) {
+ : network_quality_estimator_(network_quality_estimator),
+ last_notified_type_(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
network_quality_estimator_->AddRTTAndThroughputEstimatesObserver(this);
+ network_quality_estimator_->AddEffectiveConnectionTypeObserver(this);
ui_thread_observer_ = base::MakeUnique<UiThreadObserver>();
BrowserThread::PostTask(
@@ -127,6 +149,7 @@ NetworkQualityObserverImpl::NetworkQualityObserverImpl(
NetworkQualityObserverImpl::~NetworkQualityObserverImpl() {
DCHECK(thread_checker_.CalledOnValidThread());
network_quality_estimator_->RemoveRTTAndThroughputEstimatesObserver(this);
+ network_quality_estimator_->RemoveEffectiveConnectionTypeObserver(this);
DCHECK(ui_thread_observer_);
@@ -139,6 +162,22 @@ NetworkQualityObserverImpl::~NetworkQualityObserverImpl() {
delete ui_thread_observer_ptr;
}
+void NetworkQualityObserverImpl::OnEffectiveConnectionTypeChanged(
+ net::EffectiveConnectionType type) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ if (last_notified_type_ == type)
+ return;
+
+ last_notified_type_ = type;
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::BindOnce(&UiThreadObserver::OnEffectiveConnectionTypeChanged,
+ base::Unretained(ui_thread_observer_.get()),
+ last_notified_type_));
+}
+
void NetworkQualityObserverImpl::OnRTTOrThroughputEstimatesComputed(
base::TimeDelta http_rtt,
base::TimeDelta transport_rtt,

Powered by Google App Engine
This is Rietveld 408576698