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

Unified Diff: third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp

Issue 2883763002: Expose ECT to render frames, Blink and NetInfo (Closed)
Patch Set: rebased Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
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 de3cd0e844a2e8f7f8d6d2dd8d806419f00c36a7..73a679425674ac7aa8211eaaacc921a6653c72ed 100644
--- a/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp
+++ b/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp
@@ -42,6 +42,23 @@ String ConnectionTypeToString(WebConnectionType type) {
return "none";
}
+String EffectiveConnectionTypeToString(WebEffectiveConnectionType type) {
+ switch (type) {
+ case WebEffectiveConnectionType::kTypeUnknown:
+ case WebEffectiveConnectionType::kTypeOffline:
+ case WebEffectiveConnectionType::kType4G:
+ return "4g";
+ case WebEffectiveConnectionType::kTypeSlow2G:
+ return "slow-2g";
+ case WebEffectiveConnectionType::kType2G:
+ return "2g";
+ case WebEffectiveConnectionType::kType3G:
+ return "3g";
+ }
+ NOTREACHED();
+ return "4g";
+}
+
// Rounds |rtt_msec| to the nearest 25 milliseconds as per the NetInfo spec.
unsigned long RoundRtt(const Optional<TimeDelta>& rtt) {
if (!rtt.has_value()) {
@@ -82,7 +99,7 @@ NetworkInformation::~NetworkInformation() {
}
String NetworkInformation::type() const {
- // m_type is only updated when listening for events, so ask
+ // type_ is only updated when listening for events, so ask
// networkStateNotifier if not listening (crbug.com/379841).
if (!observing_)
return ConnectionTypeToString(GetNetworkStateNotifier().ConnectionType());
@@ -98,6 +115,18 @@ double NetworkInformation::downlinkMax() const {
return downlink_max_mbps_;
}
+String NetworkInformation::effectiveType() const {
+ // effective_type_ is only updated when listening for events, so ask
+ // networkStateNotifier if not listening (crbug.com/379841).
+ if (!observing_) {
+ return EffectiveConnectionTypeToString(
+ GetNetworkStateNotifier().EffectiveType());
+ }
+
+ // If observing, return m_type which changes when the event fires, per spec.
+ return EffectiveConnectionTypeToString(effective_type_);
+}
+
unsigned long NetworkInformation::rtt() const {
if (!observing_)
return RoundRtt(GetNetworkStateNotifier().TransportRtt());
@@ -115,11 +144,13 @@ double NetworkInformation::downlink() const {
void NetworkInformation::ConnectionChange(
WebConnectionType type,
double downlink_max_mbps,
+ WebEffectiveConnectionType effective_type,
const Optional<TimeDelta>& http_rtt,
const Optional<TimeDelta>& transport_rtt,
const Optional<double>& downlink_mbps) {
DCHECK(GetExecutionContext()->IsContextThread());
+ effective_type_ = effective_type;
transport_rtt_msec_ = RoundRtt(transport_rtt);
downlink_mbps_ = RoundMbps(downlink_mbps);
// TODO(tbansal): https://crbug.com/719108. Dispatch |change| event if the
@@ -204,6 +235,7 @@ NetworkInformation::NetworkInformation(ExecutionContext* context)
: ContextLifecycleObserver(context),
type_(GetNetworkStateNotifier().ConnectionType()),
downlink_max_mbps_(GetNetworkStateNotifier().MaxBandwidth()),
+ effective_type_(GetNetworkStateNotifier().EffectiveType()),
transport_rtt_msec_(RoundRtt(GetNetworkStateNotifier().TransportRtt())),
downlink_mbps_(
RoundMbps(GetNetworkStateNotifier().DownlinkThroughputMbps())),

Powered by Google App Engine
This is Rietveld 408576698