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

Unified Diff: third_party/WebKit/Source/platform/network/NetworkStateNotifier.cpp

Issue 2863973003: Expose RTT and downlink bandwidth using experimental Javascript API (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: third_party/WebKit/Source/platform/network/NetworkStateNotifier.cpp
diff --git a/third_party/WebKit/Source/platform/network/NetworkStateNotifier.cpp b/third_party/WebKit/Source/platform/network/NetworkStateNotifier.cpp
index 800557c4944a1482b505a4102315481a86d2e06d..afecd9adba79b29c81ebb51222369eb7da1fc68f 100644
--- a/third_party/WebKit/Source/platform/network/NetworkStateNotifier.cpp
+++ b/third_party/WebKit/Source/platform/network/NetworkStateNotifier.cpp
@@ -58,7 +58,10 @@ NetworkStateNotifier::ScopedNotifier::~ScopedNotifier() {
const NetworkState& after =
notifier_.has_override_ ? notifier_.override_ : notifier_.state_;
if ((after.type != before_.type ||
- after.max_bandwidth_mbps != before_.max_bandwidth_mbps) &&
+ after.max_bandwidth_mbps != before_.max_bandwidth_mbps ||
+ after.http_rtt != before_.http_rtt ||
+ after.transport_rtt != before_.transport_rtt ||
+ after.downlink_throughput_mbps != before_.downlink_throughput_mbps) &&
before_.connection_initialized) {
notifier_.NotifyObservers(notifier_.connection_observers_,
ObserverType::CONNECTION_TYPE, after);
@@ -91,6 +94,31 @@ void NetworkStateNotifier::SetWebConnection(WebConnectionType type,
}
}
+void NetworkStateNotifier::SetNetworkQuality(TimeDelta http_rtt,
+ TimeDelta transport_rtt,
+ int downlink_throughput_kbps) {
+ DCHECK(IsMainThread());
+ ScopedNotifier notifier(*this);
+ {
+ MutexLocker locker(mutex_);
+
+ state_.http_rtt = base::nullopt;
+ state_.transport_rtt = base::nullopt;
+ state_.downlink_throughput_mbps = base::nullopt;
+
+ if (http_rtt.InMilliseconds() >= 0)
+ state_.http_rtt = http_rtt;
+
+ if (transport_rtt.InMilliseconds() >= 0)
+ state_.transport_rtt = transport_rtt;
+
+ if (downlink_throughput_kbps >= 0) {
+ state_.downlink_throughput_mbps =
+ static_cast<double>(downlink_throughput_kbps) / 1000;
+ }
+ }
+}
+
void NetworkStateNotifier::AddConnectionObserver(
NetworkStateObserver* observer,
PassRefPtr<WebTaskRunner> task_runner) {
@@ -180,8 +208,9 @@ void NetworkStateNotifier::NotifyObserversOnTaskRunner(
observer_list->observers[i]->OnLineStateChange(state.on_line);
continue;
case ObserverType::CONNECTION_TYPE:
- observer_list->observers[i]->ConnectionChange(state.type,
- state.max_bandwidth_mbps);
+ observer_list->observers[i]->ConnectionChange(
+ state.type, state.max_bandwidth_mbps, state.http_rtt,
+ state.transport_rtt, state.downlink_throughput_mbps);
continue;
}
NOTREACHED();

Powered by Google App Engine
This is Rietveld 408576698