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

Side by Side Diff: third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp

Issue 2941713002: NetInfo: Return HTTP layer metrics instead of transport layer (Closed)
Patch Set: ps Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return EffectiveConnectionTypeToString( 124 return EffectiveConnectionTypeToString(
125 GetNetworkStateNotifier().EffectiveType()); 125 GetNetworkStateNotifier().EffectiveType());
126 } 126 }
127 127
128 // If observing, return m_type which changes when the event fires, per spec. 128 // If observing, return m_type which changes when the event fires, per spec.
129 return EffectiveConnectionTypeToString(effective_type_); 129 return EffectiveConnectionTypeToString(effective_type_);
130 } 130 }
131 131
132 unsigned long NetworkInformation::rtt() const { 132 unsigned long NetworkInformation::rtt() const {
133 if (!observing_) 133 if (!observing_)
134 return RoundRtt(GetNetworkStateNotifier().TransportRtt()); 134 return RoundRtt(GetNetworkStateNotifier().HttpRtt());
135 135
136 return transport_rtt_msec_; 136 return http_rtt_msec_;
137 } 137 }
138 138
139 double NetworkInformation::downlink() const { 139 double NetworkInformation::downlink() const {
140 if (!observing_) 140 if (!observing_)
141 return RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps()); 141 return RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps());
142 142
143 return downlink_mbps_; 143 return downlink_mbps_;
144 } 144 }
145 145
146 void NetworkInformation::ConnectionChange( 146 void NetworkInformation::ConnectionChange(
147 WebConnectionType type, 147 WebConnectionType type,
148 double downlink_max_mbps, 148 double downlink_max_mbps,
149 WebEffectiveConnectionType effective_type, 149 WebEffectiveConnectionType effective_type,
150 const Optional<TimeDelta>& http_rtt, 150 const Optional<TimeDelta>& http_rtt,
151 const Optional<TimeDelta>& transport_rtt, 151 const Optional<TimeDelta>& transport_rtt,
152 const Optional<double>& downlink_mbps) { 152 const Optional<double>& downlink_mbps) {
153 DCHECK(GetExecutionContext()->IsContextThread()); 153 DCHECK(GetExecutionContext()->IsContextThread());
154 154
155 unsigned long new_transport_rtt_msec = RoundRtt(transport_rtt); 155 unsigned long new_http_rtt_msec = RoundRtt(http_rtt);
156 double new_downlink_mbps = RoundMbps(downlink_mbps); 156 double new_downlink_mbps = RoundMbps(downlink_mbps);
157 // TODO(tbansal): https://crbug.com/719108. Dispatch |change| event if the
158 // expected network quality has changed.
159 157
160 // 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
161 // during notification, or if |http_rtt| was the only metric that changed. 159 // during notification, or if |transport_rtt| was the only metric that
160 // changed.
162 if (type_ == type && downlink_max_mbps_ == downlink_max_mbps && 161 if (type_ == type && downlink_max_mbps_ == downlink_max_mbps &&
163 effective_type_ == effective_type && 162 effective_type_ == effective_type &&
164 transport_rtt_msec_ == new_transport_rtt_msec && 163 http_rtt_msec_ == new_http_rtt_msec &&
165 downlink_mbps_ == new_downlink_mbps) { 164 downlink_mbps_ == new_downlink_mbps) {
166 return; 165 return;
167 } 166 }
168 167
169 type_ = type; 168 type_ = type;
170 downlink_max_mbps_ = downlink_max_mbps; 169 downlink_max_mbps_ = downlink_max_mbps;
171 effective_type_ = effective_type; 170 effective_type_ = effective_type;
172 transport_rtt_msec_ = new_transport_rtt_msec; 171 http_rtt_msec_ = new_http_rtt_msec;
173 downlink_mbps_ = new_downlink_mbps; 172 downlink_mbps_ = new_downlink_mbps;
174 DispatchEvent(Event::Create(EventTypeNames::typechange)); 173 DispatchEvent(Event::Create(EventTypeNames::typechange));
175 174
176 if (RuntimeEnabledFeatures::NetInfoDownlinkMaxEnabled()) 175 if (RuntimeEnabledFeatures::NetInfoDownlinkMaxEnabled())
177 DispatchEvent(Event::Create(EventTypeNames::change)); 176 DispatchEvent(Event::Create(EventTypeNames::change));
178 } 177 }
179 178
180 const AtomicString& NetworkInformation::InterfaceName() const { 179 const AtomicString& NetworkInformation::InterfaceName() const {
181 return EventTargetNames::NetworkInformation; 180 return EventTargetNames::NetworkInformation;
182 } 181 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 TaskRunnerHelper::Get(TaskType::kNetworking, GetExecutionContext())); 236 TaskRunnerHelper::Get(TaskType::kNetworking, GetExecutionContext()));
238 observing_ = false; 237 observing_ = false;
239 } 238 }
240 } 239 }
241 240
242 NetworkInformation::NetworkInformation(ExecutionContext* context) 241 NetworkInformation::NetworkInformation(ExecutionContext* context)
243 : ContextLifecycleObserver(context), 242 : ContextLifecycleObserver(context),
244 type_(GetNetworkStateNotifier().ConnectionType()), 243 type_(GetNetworkStateNotifier().ConnectionType()),
245 downlink_max_mbps_(GetNetworkStateNotifier().MaxBandwidth()), 244 downlink_max_mbps_(GetNetworkStateNotifier().MaxBandwidth()),
246 effective_type_(GetNetworkStateNotifier().EffectiveType()), 245 effective_type_(GetNetworkStateNotifier().EffectiveType()),
247 transport_rtt_msec_(RoundRtt(GetNetworkStateNotifier().TransportRtt())), 246 http_rtt_msec_(RoundRtt(GetNetworkStateNotifier().HttpRtt())),
248 downlink_mbps_( 247 downlink_mbps_(
249 RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps())), 248 RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps())),
250 observing_(false), 249 observing_(false),
251 context_stopped_(false) {} 250 context_stopped_(false) {}
252 251
253 DEFINE_TRACE(NetworkInformation) { 252 DEFINE_TRACE(NetworkInformation) {
254 EventTargetWithInlineData::Trace(visitor); 253 EventTargetWithInlineData::Trace(visitor);
255 ContextLifecycleObserver::Trace(visitor); 254 ContextLifecycleObserver::Trace(visitor);
256 } 255 }
257 256
258 } // namespace blink 257 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698