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

Side by Side Diff: third_party/WebKit/Source/platform/network/NetworkStateNotifier.h

Issue 2863973003: Expose RTT and downlink bandwidth using experimental Javascript API (Closed)
Patch Set: ps 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 USING_FAST_MALLOC(NetworkStateNotifier); 44 USING_FAST_MALLOC(NetworkStateNotifier);
45 45
46 public: 46 public:
47 struct NetworkState { 47 struct NetworkState {
48 static const int kInvalidMaxBandwidth = -1; 48 static const int kInvalidMaxBandwidth = -1;
49 bool on_line_initialized = false; 49 bool on_line_initialized = false;
50 bool on_line = true; 50 bool on_line = true;
51 bool connection_initialized = false; 51 bool connection_initialized = false;
52 WebConnectionType type = kWebConnectionTypeOther; 52 WebConnectionType type = kWebConnectionTypeOther;
53 double max_bandwidth_mbps = kInvalidMaxBandwidth; 53 double max_bandwidth_mbps = kInvalidMaxBandwidth;
54 int http_rtt_msec = -1;
55 int transport_rtt_msec = -1;
56 double downlink_throughput_mbps = -1;
54 }; 57 };
55 58
56 class NetworkStateObserver { 59 class NetworkStateObserver {
57 public: 60 public:
58 // Will be called on the task runner that is passed in add*Observer. 61 // Will be called on the task runner that is passed in add*Observer.
59 virtual void ConnectionChange(WebConnectionType, 62 virtual void ConnectionChange(WebConnectionType,
60 double max_bandwidth_mbps) {} 63 double max_bandwidth_mbps,
64 int http_rtt_msec,
65 int transport_rtt_msec,
66 double downlink_throughput_mbps) {}
61 virtual void OnLineStateChange(bool on_line) {} 67 virtual void OnLineStateChange(bool on_line) {}
62 }; 68 };
63 69
64 NetworkStateNotifier() : has_override_(false) {} 70 NetworkStateNotifier() : has_override_(false) {}
65 71
66 // Can be called on any thread. 72 // Can be called on any thread.
67 bool OnLine() const { 73 bool OnLine() const {
68 MutexLocker locker(mutex_); 74 MutexLocker locker(mutex_);
69 const NetworkState& state = has_override_ ? override_ : state_; 75 const NetworkState& state = has_override_ ? override_ : state_;
70 DCHECK(state.on_line_initialized); 76 DCHECK(state.on_line_initialized);
71 return state.on_line; 77 return state.on_line;
72 } 78 }
73 79
80 int HttpRttMsec() const {
81 MutexLocker locker(mutex_);
82 const NetworkState& state = has_override_ ? override_ : state_;
83 DCHECK(state.on_line_initialized);
84 return state.http_rtt_msec;
85 }
86
87 int TransportRttMsec() const {
88 MutexLocker locker(mutex_);
89 const NetworkState& state = has_override_ ? override_ : state_;
90 DCHECK(state.on_line_initialized);
91 return state.transport_rtt_msec;
92 }
93
94 double DownlinkThroughputMbps() const {
95 MutexLocker locker(mutex_);
96 const NetworkState& state = has_override_ ? override_ : state_;
97 DCHECK(state.on_line_initialized);
98 return state.downlink_throughput_mbps;
99 }
100
74 void SetOnLine(bool); 101 void SetOnLine(bool);
75 102
76 // Can be called on any thread. 103 // Can be called on any thread.
77 WebConnectionType ConnectionType() const { 104 WebConnectionType ConnectionType() const {
78 MutexLocker locker(mutex_); 105 MutexLocker locker(mutex_);
79 const NetworkState& state = has_override_ ? override_ : state_; 106 const NetworkState& state = has_override_ ? override_ : state_;
80 DCHECK(state.connection_initialized); 107 DCHECK(state.connection_initialized);
81 return state.type; 108 return state.type;
82 } 109 }
83 110
(...skipping 19 matching lines...) Expand all
103 130
104 // Can be called on any thread. 131 // Can be called on any thread.
105 double MaxBandwidth() const { 132 double MaxBandwidth() const {
106 MutexLocker locker(mutex_); 133 MutexLocker locker(mutex_);
107 const NetworkState& state = has_override_ ? override_ : state_; 134 const NetworkState& state = has_override_ ? override_ : state_;
108 DCHECK(state.connection_initialized); 135 DCHECK(state.connection_initialized);
109 return state.max_bandwidth_mbps; 136 return state.max_bandwidth_mbps;
110 } 137 }
111 138
112 void SetWebConnection(WebConnectionType, double max_bandwidth_mbps); 139 void SetWebConnection(WebConnectionType, double max_bandwidth_mbps);
140 void SetWebNetworkQuality(int http_rtt_msec,
141 int transport_rtt_msec,
142 int downlink_throughput_kbps);
113 143
114 // When called, successive setWebConnectionType/setOnLine calls are stored, 144 // When called, successive setWebConnectionType/setOnLine calls are stored,
115 // and supplied overridden values are used instead until clearOverride() is 145 // and supplied overridden values are used instead until clearOverride() is
116 // called. This is used for layout tests (see crbug.com/377736) and inspector 146 // called. This is used for layout tests (see crbug.com/377736) and inspector
117 // emulation. 147 // emulation.
118 // 148 //
119 // Since this class is a singleton, tests must clear override when completed 149 // Since this class is a singleton, tests must clear override when completed
120 // to avoid indeterminate state across the test harness. 150 // to avoid indeterminate state across the test harness.
121 void SetOverride(bool on_line, WebConnectionType, double max_bandwidth_mbps); 151 void SetOverride(bool on_line, WebConnectionType, double max_bandwidth_mbps);
122 void ClearOverride(); 152 void ClearOverride();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 223
194 ObserverListMap connection_observers_; 224 ObserverListMap connection_observers_;
195 ObserverListMap on_line_state_observers_; 225 ObserverListMap on_line_state_observers_;
196 }; 226 };
197 227
198 PLATFORM_EXPORT NetworkStateNotifier& GetNetworkStateNotifier(); 228 PLATFORM_EXPORT NetworkStateNotifier& GetNetworkStateNotifier();
199 229
200 } // namespace blink 230 } // namespace blink
201 231
202 #endif // NetworkStateNotifier_h 232 #endif // NetworkStateNotifier_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698