| 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 73a679425674ac7aa8211eaaacc921a6653c72ed..bd5bd0f832a82b81c3c856c29e1db0f162493897 100644
|
| --- a/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp
|
| +++ b/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp
|
| @@ -60,30 +60,39 @@ String EffectiveConnectionTypeToString(WebEffectiveConnectionType type) {
|
| }
|
|
|
| // Rounds |rtt_msec| to the nearest 25 milliseconds as per the NetInfo spec.
|
| -unsigned long RoundRtt(const Optional<TimeDelta>& rtt) {
|
| +// If |rtt| has no value, |type| is used to determine a default value.
|
| +unsigned long RoundTransportRtt(WebConnectionType type,
|
| + const Optional<TimeDelta>& rtt) {
|
| + int rtt_msec = 0;
|
| if (!rtt.has_value()) {
|
| - // RTT is unavailable. So, return the fastest value.
|
| - return 0;
|
| + DCHECK(kWebConnectionTypeUnknown == type ||
|
| + kWebConnectionTypeNone == type || kWebConnectionTypeOther == type);
|
| + rtt_msec = 55;
|
| + } else {
|
| + rtt_msec = rtt.value().InMilliseconds();
|
| + if (rtt.value().InMilliseconds() > std::numeric_limits<int>::max())
|
| + rtt_msec = std::numeric_limits<int>::max();
|
| }
|
|
|
| - int rtt_msec = rtt.value().InMilliseconds();
|
| - if (rtt.value().InMilliseconds() > std::numeric_limits<int>::max())
|
| - rtt_msec = std::numeric_limits<int>::max();
|
| -
|
| DCHECK_LE(0, 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(const Optional<double>& downlink_mbps) {
|
| +// returned value is in Mbps. If |downlink_mbps| has no value, |type| is used to
|
| +// determine a default value.
|
| +double RoundMbps(WebConnectionType type,
|
| + const Optional<double>& downlink_mbps) {
|
| + double downlink_kbps = std::numeric_limits<double>::infinity();
|
| if (!downlink_mbps.has_value()) {
|
| - // Throughput is unavailable. So, return the fastest value.
|
| - return std::numeric_limits<double>::infinity();
|
| + DCHECK(kWebConnectionTypeUnknown == type ||
|
| + kWebConnectionTypeNone == type || kWebConnectionTypeOther == type);
|
| + downlink_kbps = 1961;
|
| + } else {
|
| + downlink_kbps = downlink_mbps.value() * 1000;
|
| }
|
|
|
| - DCHECK_LE(0, downlink_mbps.value());
|
| - double downlink_kbps = downlink_mbps.value() * 1000;
|
| + DCHECK_LE(0, downlink_kbps);
|
| double downlink_kbps_rounded = std::round(downlink_kbps / 25) * 25;
|
| return downlink_kbps_rounded / 1000;
|
| }
|
| @@ -128,16 +137,18 @@ String NetworkInformation::effectiveType() const {
|
| }
|
|
|
| unsigned long NetworkInformation::rtt() const {
|
| - if (!observing_)
|
| - return RoundRtt(GetNetworkStateNotifier().TransportRtt());
|
| -
|
| + if (!observing_) {
|
| + return RoundTransportRtt(GetNetworkStateNotifier().ConnectionType(),
|
| + GetNetworkStateNotifier().TransportRtt());
|
| + }
|
| return transport_rtt_msec_;
|
| }
|
|
|
| double NetworkInformation::downlink() const {
|
| - if (!observing_)
|
| - return RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps());
|
| -
|
| + if (!observing_) {
|
| + return RoundMbps(GetNetworkStateNotifier().ConnectionType(),
|
| + GetNetworkStateNotifier().DownlinkThroughputMbps());
|
| + }
|
| return downlink_mbps_;
|
| }
|
|
|
| @@ -151,8 +162,8 @@ void NetworkInformation::ConnectionChange(
|
| DCHECK(GetExecutionContext()->IsContextThread());
|
|
|
| effective_type_ = effective_type;
|
| - transport_rtt_msec_ = RoundRtt(transport_rtt);
|
| - downlink_mbps_ = RoundMbps(downlink_mbps);
|
| + transport_rtt_msec_ = RoundTransportRtt(type, transport_rtt);
|
| + downlink_mbps_ = RoundMbps(type, downlink_mbps);
|
| // TODO(tbansal): https://crbug.com/719108. Dispatch |change| event if the
|
| // expected network quality has changed.
|
|
|
| @@ -236,9 +247,10 @@ NetworkInformation::NetworkInformation(ExecutionContext* context)
|
| type_(GetNetworkStateNotifier().ConnectionType()),
|
| downlink_max_mbps_(GetNetworkStateNotifier().MaxBandwidth()),
|
| effective_type_(GetNetworkStateNotifier().EffectiveType()),
|
| - transport_rtt_msec_(RoundRtt(GetNetworkStateNotifier().TransportRtt())),
|
| + transport_rtt_msec_(
|
| + RoundTransportRtt(type_, GetNetworkStateNotifier().TransportRtt())),
|
| downlink_mbps_(
|
| - RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps())),
|
| + RoundMbps(type_, GetNetworkStateNotifier().DownlinkThroughputMbps())),
|
| observing_(false),
|
| context_stopped_(false) {}
|
|
|
|
|