| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 143 |
| 144 void NetworkInformation::ConnectionChange( | 144 void NetworkInformation::ConnectionChange( |
| 145 WebConnectionType type, | 145 WebConnectionType type, |
| 146 double downlink_max_mbps, | 146 double downlink_max_mbps, |
| 147 WebEffectiveConnectionType effective_type, | 147 WebEffectiveConnectionType effective_type, |
| 148 const Optional<TimeDelta>& http_rtt, | 148 const Optional<TimeDelta>& http_rtt, |
| 149 const Optional<TimeDelta>& transport_rtt, | 149 const Optional<TimeDelta>& transport_rtt, |
| 150 const Optional<double>& downlink_mbps) { | 150 const Optional<double>& downlink_mbps) { |
| 151 DCHECK(GetExecutionContext()->IsContextThread()); | 151 DCHECK(GetExecutionContext()->IsContextThread()); |
| 152 | 152 |
| 153 effective_type_ = effective_type; | 153 unsigned long new_transport_rtt_msec = RoundRtt(transport_rtt); |
| 154 transport_rtt_msec_ = RoundRtt(transport_rtt); | 154 double new_downlink_mbps = RoundMbps(downlink_mbps); |
| 155 downlink_mbps_ = RoundMbps(downlink_mbps); | |
| 156 // TODO(tbansal): https://crbug.com/719108. Dispatch |change| event if the | 155 // TODO(tbansal): https://crbug.com/719108. Dispatch |change| event if the |
| 157 // expected network quality has changed. | 156 // expected network quality has changed. |
| 158 | 157 |
| 159 // This can happen if the observer removes and then adds itself again | 158 // This can happen if the observer removes and then adds itself again |
| 160 // during notification, or if HTTP RTT was the only metric that changed. | 159 // during notification, or if |http_rtt| was the only metric that changed. |
| 161 if (type_ == type && downlink_max_mbps_ == downlink_max_mbps) | 160 if (type_ == type && downlink_max_mbps_ == downlink_max_mbps && |
| 161 effective_type_ == effective_type && |
| 162 transport_rtt_msec_ == new_transport_rtt_msec && |
| 163 downlink_mbps_ == new_downlink_mbps) { |
| 162 return; | 164 return; |
| 165 } |
| 163 | 166 |
| 164 type_ = type; | 167 type_ = type; |
| 165 downlink_max_mbps_ = downlink_max_mbps; | 168 downlink_max_mbps_ = downlink_max_mbps; |
| 169 effective_type_ = effective_type; |
| 170 transport_rtt_msec_ = new_transport_rtt_msec; |
| 171 downlink_mbps_ = new_downlink_mbps; |
| 166 DispatchEvent(Event::Create(EventTypeNames::typechange)); | 172 DispatchEvent(Event::Create(EventTypeNames::typechange)); |
| 167 | 173 |
| 168 if (RuntimeEnabledFeatures::netInfoDownlinkMaxEnabled()) | 174 if (RuntimeEnabledFeatures::netInfoDownlinkMaxEnabled()) |
| 169 DispatchEvent(Event::Create(EventTypeNames::change)); | 175 DispatchEvent(Event::Create(EventTypeNames::change)); |
| 170 } | 176 } |
| 171 | 177 |
| 172 const AtomicString& NetworkInformation::InterfaceName() const { | 178 const AtomicString& NetworkInformation::InterfaceName() const { |
| 173 return EventTargetNames::NetworkInformation; | 179 return EventTargetNames::NetworkInformation; |
| 174 } | 180 } |
| 175 | 181 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps())), | 247 RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps())), |
| 242 observing_(false), | 248 observing_(false), |
| 243 context_stopped_(false) {} | 249 context_stopped_(false) {} |
| 244 | 250 |
| 245 DEFINE_TRACE(NetworkInformation) { | 251 DEFINE_TRACE(NetworkInformation) { |
| 246 EventTargetWithInlineData::Trace(visitor); | 252 EventTargetWithInlineData::Trace(visitor); |
| 247 ContextLifecycleObserver::Trace(visitor); | 253 ContextLifecycleObserver::Trace(visitor); |
| 248 } | 254 } |
| 249 | 255 |
| 250 } // namespace blink | 256 } // namespace blink |
| OLD | NEW |