| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/netinfo/NetworkInformation.h" | 5 #include "modules/netinfo/NetworkInformation.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
| 10 #include "core/dom/TaskRunnerHelper.h" | 10 #include "core/dom/TaskRunnerHelper.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 if (rtt.value().InMilliseconds() > std::numeric_limits<int>::max()) | 70 if (rtt.value().InMilliseconds() > std::numeric_limits<int>::max()) |
| 71 rtt_msec = std::numeric_limits<int>::max(); | 71 rtt_msec = std::numeric_limits<int>::max(); |
| 72 | 72 |
| 73 DCHECK_LE(0, rtt_msec); | 73 DCHECK_LE(0, rtt_msec); |
| 74 return std::round(static_cast<double>(rtt_msec) / 25) * 25; | 74 return std::round(static_cast<double>(rtt_msec) / 25) * 25; |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Rounds |downlink_mbps| to the nearest 25 kbps as per the NetInfo spec. The | 77 // Rounds |downlink_mbps| to the nearest 25 kbps as per the NetInfo spec. The |
| 78 // returned value is in Mbps. | 78 // returned value is in Mbps. |
| 79 double RoundMbps(const Optional<double>& downlink_mbps) { | 79 double RoundMbps(const Optional<double>& downlink_mbps) { |
| 80 double downlink_kbps = 0; |
| 80 if (!downlink_mbps.has_value()) { | 81 if (!downlink_mbps.has_value()) { |
| 81 // Throughput is unavailable. So, return the fastest value. | 82 // Throughput is unavailable. So, return the fastest value. |
| 82 return std::numeric_limits<double>::infinity(); | 83 downlink_kbps = (std::numeric_limits<double>::max()); |
| 84 } else { |
| 85 downlink_kbps = downlink_mbps.value() * 1000; |
| 83 } | 86 } |
| 84 | 87 |
| 85 DCHECK_LE(0, downlink_mbps.value()); | 88 DCHECK_LE(0, downlink_kbps); |
| 86 double downlink_kbps = downlink_mbps.value() * 1000; | |
| 87 double downlink_kbps_rounded = std::round(downlink_kbps / 25) * 25; | 89 double downlink_kbps_rounded = std::round(downlink_kbps / 25) * 25; |
| 88 return downlink_kbps_rounded / 1000; | 90 return downlink_kbps_rounded / 1000; |
| 89 } | 91 } |
| 90 | 92 |
| 91 } // namespace | 93 } // namespace |
| 92 | 94 |
| 93 NetworkInformation* NetworkInformation::Create(ExecutionContext* context) { | 95 NetworkInformation* NetworkInformation::Create(ExecutionContext* context) { |
| 94 return new NetworkInformation(context); | 96 return new NetworkInformation(context); |
| 95 } | 97 } |
| 96 | 98 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps())), | 249 RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps())), |
| 248 observing_(false), | 250 observing_(false), |
| 249 context_stopped_(false) {} | 251 context_stopped_(false) {} |
| 250 | 252 |
| 251 DEFINE_TRACE(NetworkInformation) { | 253 DEFINE_TRACE(NetworkInformation) { |
| 252 EventTargetWithInlineData::Trace(visitor); | 254 EventTargetWithInlineData::Trace(visitor); |
| 253 ContextLifecycleObserver::Trace(visitor); | 255 ContextLifecycleObserver::Trace(visitor); |
| 254 } | 256 } |
| 255 | 257 |
| 256 } // namespace blink | 258 } // namespace blink |
| OLD | NEW |