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

Unified Diff: third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp

Issue 2863973003: Expose RTT and downlink bandwidth using experimental Javascript API (Closed)
Patch Set: ps 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/modules/netinfo/NetworkInformation.cpp
diff --git a/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp b/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp
index eb7ddec8cbd0d9b48fea6842d77d78c8957fbc6e..5186bbce42eb63871535e3a4984785f4fc413124 100644
--- a/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp
+++ b/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp
@@ -40,6 +40,18 @@ String ConnectionTypeToString(WebConnectionType type) {
return "none";
}
+// Rounds |rtt_msec| to the nearest 25 milliseconds.
+int roundRtt(int rtt_msec) {
jkarlin 2017/05/16 14:32:59 RoundRtt
tbansal1 2017/05/16 18:23:28 Done.
+ return std::round(static_cast<double>(rtt_msec) / 25) * 25;
+}
+
+// Rounds |downlink_mbps| to the nearest 25 kbps. The returned value is Mbps.
+double roundMbps(double downlink_mbps) {
jkarlin 2017/05/16 14:32:59 RoundMbps
tbansal1 2017/05/16 18:23:28 Done.
+ double downlink_kbps = downlink_mbps * 1000;
+ double downlink_kbps_rounded = std::round(downlink_kbps / 25) * 25;
+ return downlink_kbps_rounded / 1000;
+}
+
} // namespace
NetworkInformation* NetworkInformation::Create(ExecutionContext* context) {
@@ -67,17 +79,40 @@ double NetworkInformation::downlinkMax() const {
return downlink_max_mbps_;
}
+double NetworkInformation::rtt() const {
+ if (!observing_)
+ return roundRtt(GetNetworkStateNotifier().TransportRttMsec());
+
+ return transport_rtt_msec_;
+}
+
+double NetworkInformation::downlink() const {
+ if (!observing_)
+ return roundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps());
+
+ return downlink_throughput_mbps_;
+}
+
void NetworkInformation::ConnectionChange(WebConnectionType type,
- double downlink_max_mbps) {
+ double downlink_max_mbps,
+ int http_rtt_msec,
+ int transport_rtt_msec,
+ double downlink_throughput_mbps) {
DCHECK(GetExecutionContext()->IsContextThread());
+ transport_rtt_msec_ = roundRtt(transport_rtt_msec);
+ downlink_throughput_mbps_ = roundMbps(downlink_throughput_mbps);
+ // TODO(tbansal): https://crbug.com/719108. Dispatch |change| event if the
+ // expected network quality has changed.
+
// This can happen if the observer removes and then adds itself again
- // during notification.
+ // during notification, or if HTTP RTT was the only metric that changed.
if (type_ == type && downlink_max_mbps_ == downlink_max_mbps)
return;
type_ = type;
downlink_max_mbps_ = downlink_max_mbps;
+
DispatchEvent(Event::Create(EventTypeNames::typechange));
if (RuntimeEnabledFeatures::netInfoDownlinkMaxEnabled())

Powered by Google App Engine
This is Rietveld 408576698