| 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..d73160210673cb5990c92c3a909064ddbcaf1b00 100644
|
| --- a/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp
|
| +++ b/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp
|
| @@ -40,6 +40,23 @@ String ConnectionTypeToString(WebConnectionType type) {
|
| return "none";
|
| }
|
|
|
| +// Rounds |rtt_msec| to the nearest 25 milliseconds as per the NetInfo spec.
|
| +int roundRtt(int rtt_msec) {
|
| + if (rtt_msec < 0)
|
| + return rtt_msec;
|
| + return std::round(static_cast<double>(rtt_msec) / 25) * 25;
|
| +}
|
| +
|
| +// Rounds |downlink_mbps| to the nearest 25 kbps as per the NetInfo spec. The
|
| +// returned value is in Mbps.
|
| +double roundMbps(double downlink_mbps) {
|
| + if (downlink_mbps < 0)
|
| + return downlink_mbps;
|
| + 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 +84,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_mbps_;
|
| +}
|
| +
|
| void NetworkInformation::ConnectionChange(WebConnectionType type,
|
| - double downlink_max_mbps) {
|
| + double downlink_max_mbps,
|
| + int http_rtt_msec,
|
| + int transport_rtt_msec,
|
| + double downlink_mbps) {
|
| DCHECK(GetExecutionContext()->IsContextThread());
|
|
|
| + transport_rtt_msec_ = roundRtt(transport_rtt_msec);
|
| + downlink_mbps_ = roundMbps(downlink_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())
|
|
|