OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ | 5 #ifndef NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ |
bengr
2016/02/09 15:41:02
This file is too large. In a follow-up CL, please
tbansal1
2016/02/09 17:54:11
Acknowledged.
| |
6 #define NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ | 6 #define NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <deque> | 11 #include <deque> |
12 #include <map> | 12 #include <map> |
13 #include <string> | 13 #include <string> |
14 #include <tuple> | 14 #include <tuple> |
15 | 15 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 TCP, | 56 TCP, |
57 // The observation is taken at the QUIC layer. | 57 // The observation is taken at the QUIC layer. |
58 QUIC, | 58 QUIC, |
59 // The observation is a previously cached estimate of the metric. | 59 // The observation is a previously cached estimate of the metric. |
60 CACHED_ESTIMATE, | 60 CACHED_ESTIMATE, |
61 // The observation is derived from network connection information provided | 61 // The observation is derived from network connection information provided |
62 // by the platform. For example, typical RTT and throughput values are used | 62 // by the platform. For example, typical RTT and throughput values are used |
63 // for a given type of network connection. | 63 // for a given type of network connection. |
64 DEFAULT_FROM_PLATFORM, | 64 DEFAULT_FROM_PLATFORM, |
65 // The observation came from a Chromium-external source. | 65 // The observation came from a Chromium-external source. |
66 EXTERNAL_ESTIMATE | 66 EXTERNAL_ESTIMATE, |
67 // Unknown source. | |
bengr
2016/02/09 15:41:03
Why would the source ever be unknown?
tbansal1
2016/02/09 17:54:12
Fixed the function definition, and eliminated UNKN
| |
68 UNKNOWN | |
67 }; | 69 }; |
68 | 70 |
69 // Observes measurements of round trip time. | 71 // Observes measurements of round trip time. |
70 class NET_EXPORT_PRIVATE RTTObserver { | 72 class NET_EXPORT_PRIVATE RTTObserver { |
71 public: | 73 public: |
72 // Will be called when a new RTT observation is available. The round trip | 74 // Will be called when a new RTT observation is available. The round trip |
73 // time is specified in milliseconds. The time when the observation was | 75 // time is specified in milliseconds. The time when the observation was |
74 // taken and the source of the observation are provided. | 76 // taken and the source of the observation are provided. |
75 virtual void OnRTTObservation(int32_t rtt_ms, | 77 virtual void OnRTTObservation(int32_t rtt_ms, |
76 const base::TimeTicks& timestamp, | 78 const base::TimeTicks& timestamp, |
(...skipping 17 matching lines...) Expand all Loading... | |
94 ObservationSource source) = 0; | 96 ObservationSource source) = 0; |
95 | 97 |
96 protected: | 98 protected: |
97 ThroughputObserver() {} | 99 ThroughputObserver() {} |
98 virtual ~ThroughputObserver() {} | 100 virtual ~ThroughputObserver() {} |
99 | 101 |
100 private: | 102 private: |
101 DISALLOW_COPY_AND_ASSIGN(ThroughputObserver); | 103 DISALLOW_COPY_AND_ASSIGN(ThroughputObserver); |
102 }; | 104 }; |
103 | 105 |
106 // Observes measurements of packet loss. | |
107 class NET_EXPORT_PRIVATE PacketLossObserver { | |
108 public: | |
109 // Will be called when a new packet loss observation is available. | |
110 // |num_packets_lost| is the number of packets lost. | |
111 // |num_packets_received_in_order| is the number of packets received in | |
112 // order. |num_packets_received_not_in_order| is the number of packets | |
113 // received out of order. All the counts are for the duration since the last | |
114 // call to the OnPacketLossObservation to |timestamp|. | |
115 virtual void OnPacketLossObservation( | |
bengr
2016/02/09 15:41:03
Is num_packets_received_in_order the number of con
tbansal1
2016/02/09 17:54:11
Added an example in socket_performance_watcher_fac
| |
116 uint64_t num_packets_lost, | |
117 uint64_t num_packets_received_in_order, | |
118 uint64_t num_packets_received_not_in_order, | |
119 const base::TimeTicks& timestamp, | |
120 ObservationSource source) = 0; | |
121 | |
122 protected: | |
123 PacketLossObserver() {} | |
124 virtual ~PacketLossObserver() {} | |
125 | |
126 private: | |
127 DISALLOW_COPY_AND_ASSIGN(PacketLossObserver); | |
128 }; | |
129 | |
104 // Creates a new NetworkQualityEstimator. | 130 // Creates a new NetworkQualityEstimator. |
105 // |variation_params| is the map containing all field trial parameters | 131 // |variation_params| is the map containing all field trial parameters |
106 // related to NetworkQualityEstimator field trial. | 132 // related to NetworkQualityEstimator field trial. |
107 // |external_estimates_provider| may be NULL. | 133 // |external_estimates_provider| may be NULL. |
108 NetworkQualityEstimator( | 134 NetworkQualityEstimator( |
109 scoped_ptr<ExternalEstimateProvider> external_estimates_provider, | 135 scoped_ptr<ExternalEstimateProvider> external_estimates_provider, |
110 const std::map<std::string, std::string>& variation_params); | 136 const std::map<std::string, std::string>& variation_params); |
111 | 137 |
112 // Construct a NetworkQualityEstimator instance allowing for test | 138 // Construct a NetworkQualityEstimator instance allowing for test |
113 // configuration. Registers for network type change notifications so estimates | 139 // configuration. Registers for network type change notifications so estimates |
(...skipping 18 matching lines...) Expand all Loading... | |
132 | 158 |
133 // Returns true if RTT is available and sets |rtt| to estimated RTT. | 159 // Returns true if RTT is available and sets |rtt| to estimated RTT. |
134 // Virtualized for testing. |rtt| should not be null. | 160 // Virtualized for testing. |rtt| should not be null. |
135 virtual bool GetRTTEstimate(base::TimeDelta* rtt) const; | 161 virtual bool GetRTTEstimate(base::TimeDelta* rtt) const; |
136 | 162 |
137 // Returns true if downlink throughput is available and sets |kbps| to | 163 // Returns true if downlink throughput is available and sets |kbps| to |
138 // estimated downlink throughput (in kilobits per second). | 164 // estimated downlink throughput (in kilobits per second). |
139 // Virtualized for testing. |kbps| should not be null. | 165 // Virtualized for testing. |kbps| should not be null. |
140 virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const; | 166 virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const; |
141 | 167 |
168 // Returns true if the estimated packet loss rate is available and sets | |
169 // |packet_loss| to the estimated packet loss rate. Virtualized for testing. | |
170 // |packet_loss| should not be nullptr. |packet_loss| is always between 0.0 | |
bengr
2016/02/09 15:41:02
In a comment, I would say "should not be null."
tbansal1
2016/02/09 17:54:11
Done.
| |
171 // and 1.0 with a higher value indicating higher packet loss rate. | |
172 virtual bool GetPacketLossRateEstimate(float* packet_loss) const; | |
173 | |
142 // Notifies NetworkQualityEstimator that the response header of |request| has | 174 // Notifies NetworkQualityEstimator that the response header of |request| has |
143 // been received. | 175 // been received. |
144 void NotifyHeadersReceived(const URLRequest& request); | 176 void NotifyHeadersReceived(const URLRequest& request); |
145 | 177 |
146 // Notifies NetworkQualityEstimator that the response body of |request| has | 178 // Notifies NetworkQualityEstimator that the response body of |request| has |
147 // been received. | 179 // been received. |
148 void NotifyRequestCompleted(const URLRequest& request); | 180 void NotifyRequestCompleted(const URLRequest& request); |
149 | 181 |
150 // Returns true if median RTT is available and sets |rtt| to the median of | 182 // Returns true if median RTT is available and sets |rtt| to the median of |
151 // RTT observations since |begin_timestamp|. | 183 // RTT observations since |begin_timestamp|. |
152 // Virtualized for testing. |rtt| should not be null. | 184 // Virtualized for testing. |rtt| should not be null. |
153 virtual bool GetRecentMedianRTT(const base::TimeTicks& begin_timestamp, | 185 virtual bool GetRecentMedianRTT(const base::TimeTicks& begin_timestamp, |
154 base::TimeDelta* rtt) const; | 186 base::TimeDelta* rtt) const; |
155 | 187 |
156 // Returns true if median downstream throughput is available and sets |kbps| | 188 // Returns true if median downstream throughput is available and sets |kbps| |
157 // to the median of downstream throughput (in kilobits per second) | 189 // to the median of downstream throughput (in kilobits per second) |
158 // observations since |begin_timestamp|. Virtualized for testing. |kbps| | 190 // observations since |begin_timestamp|. Virtualized for testing. |kbps| |
159 // should not be null. | 191 // should not be null. |
160 virtual bool GetRecentMedianDownlinkThroughputKbps( | 192 virtual bool GetRecentMedianDownlinkThroughputKbps( |
161 const base::TimeTicks& begin_timestamp, | 193 const base::TimeTicks& begin_timestamp, |
162 int32_t* kbps) const; | 194 int32_t* kbps) const; |
163 | 195 |
164 // SocketPerformanceWatcherFactory implementation: | 196 // SocketPerformanceWatcherFactory implementation: |
165 scoped_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher( | 197 scoped_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher( |
166 const Protocol protocol) override; | 198 const Protocol protocol) override; |
167 void OnUpdatedRTTAvailable(const Protocol protocol, | 199 void OnUpdatedRTTAvailable(const Protocol protocol, |
168 const base::TimeDelta& rtt) override; | 200 const base::TimeDelta& rtt) override; |
201 void OnUpdatedPacketCountAvailable( | |
202 const Protocol protocol, | |
203 uint64_t num_packets_lost, | |
204 uint64_t num_packets_received_in_order, | |
205 uint64_t num_packets_received_not_in_order) override; | |
169 | 206 |
170 // Adds |rtt_observer| to the list of round trip time observers. Must be | 207 // Adds |rtt_observer| to the list of round trip time observers. Must be |
171 // called on the IO thread. | 208 // called on the IO thread. |
172 void AddRTTObserver(RTTObserver* rtt_observer); | 209 void AddRTTObserver(RTTObserver* rtt_observer); |
173 | 210 |
174 // Removes |rtt_observer| from the list of round trip time observers if it | 211 // Removes |rtt_observer| from the list of round trip time observers if it |
175 // is on the list of observers. Must be called on the IO thread. | 212 // is on the list of observers. Must be called on the IO thread. |
176 void RemoveRTTObserver(RTTObserver* rtt_observer); | 213 void RemoveRTTObserver(RTTObserver* rtt_observer); |
177 | 214 |
178 // Adds |throughput_observer| to the list of throughput observers. Must be | 215 // Adds |throughput_observer| to the list of throughput observers. Must be |
179 // called on the IO thread. | 216 // called on the IO thread. |
180 void AddThroughputObserver(ThroughputObserver* throughput_observer); | 217 void AddThroughputObserver(ThroughputObserver* throughput_observer); |
181 | 218 |
182 // Removes |throughput_observer| from the list of throughput observers if it | 219 // Removes |throughput_observer| from the list of throughput observers if it |
183 // is on the list of observers. Must be called on the IO thread. | 220 // is on the list of observers. Must be called on the IO thread. |
184 void RemoveThroughputObserver(ThroughputObserver* throughput_observer); | 221 void RemoveThroughputObserver(ThroughputObserver* throughput_observer); |
185 | 222 |
223 // Adds |packet_loss_observer| to the list of packet loss observers. Must be | |
224 // called on the IO thread. | |
225 void AddPacketLossObserver(PacketLossObserver* packet_loss_observer); | |
226 | |
227 // Removes |packet_loss_observer| from the list of packet loss observers if it | |
228 // is on the list of observers. Must be called on the IO thread. | |
229 void RemovePacketLossObserver(PacketLossObserver* packet_loss_observer); | |
230 | |
186 protected: | 231 protected: |
187 // NetworkID is used to uniquely identify a network. | 232 // NetworkID is used to uniquely identify a network. |
188 // For the purpose of network quality estimation and caching, a network is | 233 // For the purpose of network quality estimation and caching, a network is |
189 // uniquely identified by a combination of |type| and | 234 // uniquely identified by a combination of |type| and |
190 // |id|. This approach is unable to distinguish networks with | 235 // |id|. This approach is unable to distinguish networks with |
191 // same name (e.g., different Wi-Fi networks with same SSID). | 236 // same name (e.g., different Wi-Fi networks with same SSID). |
192 // This is a protected member to expose it to tests. | 237 // This is a protected member to expose it to tests. |
193 struct NET_EXPORT_PRIVATE NetworkID { | 238 struct NET_EXPORT_PRIVATE NetworkID { |
194 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) | 239 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) |
195 : type(type), id(id) {} | 240 : type(type), id(id) {} |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 // NetworkChangeNotifier::ConnectionTypeObserver implementation: | 272 // NetworkChangeNotifier::ConnectionTypeObserver implementation: |
228 void OnConnectionTypeChanged( | 273 void OnConnectionTypeChanged( |
229 NetworkChangeNotifier::ConnectionType type) override; | 274 NetworkChangeNotifier::ConnectionType type) override; |
230 | 275 |
231 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. | 276 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. |
232 void OnUpdatedEstimateAvailable() override; | 277 void OnUpdatedEstimateAvailable() override; |
233 | 278 |
234 private: | 279 private: |
235 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 280 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
236 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); | 281 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); |
282 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | |
283 TestPacketLossRateUpdates); | |
237 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 284 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
238 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 285 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
239 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 286 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
240 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); | 287 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); |
241 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 288 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
242 PercentileSameTimestamps); | 289 PercentileSameTimestamps); |
243 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 290 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
244 PercentileDifferentTimestamps); | 291 PercentileDifferentTimestamps); |
245 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); | 292 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); |
246 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); | 293 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 // buffer is available. Sets |result| to the computed |percentile| | 438 // buffer is available. Sets |result| to the computed |percentile| |
392 // value among all observations since |begin_timestamp|. If the value is | 439 // value among all observations since |begin_timestamp|. If the value is |
393 // unavailable, false is returned and |result| is not modified. Percentile | 440 // unavailable, false is returned and |result| is not modified. Percentile |
394 // value is unavailable if all the values in observation buffer are older | 441 // value is unavailable if all the values in observation buffer are older |
395 // than |begin_timestamp|. | 442 // than |begin_timestamp|. |
396 // |result| must not be null. | 443 // |result| must not be null. |
397 bool GetPercentile(const base::TimeTicks& begin_timestamp, | 444 bool GetPercentile(const base::TimeTicks& begin_timestamp, |
398 ValueType* result, | 445 ValueType* result, |
399 int percentile) const; | 446 int percentile) const; |
400 | 447 |
448 // Returns true iff the weighted average value of the observations in this | |
449 // buffer is available. Sets |result| to the computed average | |
450 // value among all observations since |begin_timestamp|. If the value is | |
451 // unavailable, false is returned and |result| is not modified. Average | |
452 // value is unavailable if all the values in observation buffer are older | |
453 // than |begin_timestamp|. |result| must not be nullptr. | |
454 bool GetWeightedAverage(const base::TimeTicks& begin_timestamp, | |
bengr
2016/02/09 15:41:03
If this is computed over observations then it is c
tbansal1
2016/02/09 17:54:11
I do not understand this comment. Two observations
| |
455 ValueType* result) const; | |
456 | |
401 private: | 457 private: |
402 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 458 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
403 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 459 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
404 ObtainOperatingParams); | 460 ObtainOperatingParams); |
405 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 461 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
406 | 462 |
407 // Computes the weighted observations and stores them in | 463 // Computes the weighted observations and stores them in |
408 // |weighted_observations| sorted by ascending |WeightedObservation.value|. | 464 // |weighted_observations| sorted by ascending |WeightedObservation.value|. |
409 // Only the observations with timestamp later than |begin_timestamp| are | 465 // Only the observations with timestamp later than |begin_timestamp| are |
410 // considered. Also, sets |total_weight| to the total weight of all | 466 // considered. Also, sets |total_weight| to the total weight of all |
(...skipping 23 matching lines...) Expand all Loading... | |
434 RttObservation; | 490 RttObservation; |
435 typedef net::NetworkQualityEstimator::ObservationBuffer<base::TimeDelta> | 491 typedef net::NetworkQualityEstimator::ObservationBuffer<base::TimeDelta> |
436 RttObservationBuffer; | 492 RttObservationBuffer; |
437 | 493 |
438 // Value of throughput observations is in kilobits per second. | 494 // Value of throughput observations is in kilobits per second. |
439 typedef net::NetworkQualityEstimator::Observation<int32_t> | 495 typedef net::NetworkQualityEstimator::Observation<int32_t> |
440 ThroughputObservation; | 496 ThroughputObservation; |
441 typedef net::NetworkQualityEstimator::ObservationBuffer<int32_t> | 497 typedef net::NetworkQualityEstimator::ObservationBuffer<int32_t> |
442 ThroughputObservationBuffer; | 498 ThroughputObservationBuffer; |
443 | 499 |
500 // Value of a packet loss observation. A value of 0.0 indicates one packet | |
501 // was received successfully in-order, while a value of 1.0 indicates one | |
502 // packet was lost. | |
503 typedef net::NetworkQualityEstimator::Observation<float> | |
504 PacketLossObservation; | |
505 | |
444 // This does not use a unordered_map or hash_map for code simplicity (key just | 506 // This does not use a unordered_map or hash_map for code simplicity (key just |
445 // implements operator<, rather than hash and equality) and because the map is | 507 // implements operator<, rather than hash and equality) and because the map is |
446 // tiny. | 508 // tiny. |
447 typedef std::map<NetworkID, CachedNetworkQuality> CachedNetworkQualities; | 509 typedef std::map<NetworkID, CachedNetworkQuality> CachedNetworkQualities; |
448 | 510 |
449 // Throughput is set to |kInvalidThroughput| if a valid value is | 511 // Throughput is set to |kInvalidThroughput| if a valid value is |
450 // unavailable. Readers should discard throughput value if it is set to | 512 // unavailable. Readers should discard throughput value if it is set to |
451 // |kInvalidThroughput|. | 513 // |kInvalidThroughput|. |
452 static const int32_t kInvalidThroughput; | 514 static const int32_t kInvalidThroughput; |
453 | 515 |
516 // Packet loss rate is set to |kInvalidPacketLossRate| if a valid value is | |
517 // unavailable. Readers should discard the packet loss rate value if it is | |
518 // set to |kInvalidPacketLossRate|. | |
519 static const float kInvalidPacketLossRate; | |
520 | |
454 // Tiny transfer sizes may give inaccurate throughput results. | 521 // Tiny transfer sizes may give inaccurate throughput results. |
455 // Minimum size of the transfer over which the throughput is computed. | 522 // Minimum size of the transfer over which the throughput is computed. |
456 static const int kMinTransferSizeInBytes = 10000; | 523 static const int kMinTransferSizeInBytes = 10000; |
457 | 524 |
458 // Minimum duration (in microseconds) of the transfer over which the | 525 // Minimum duration (in microseconds) of the transfer over which the |
459 // throughput is computed. | 526 // throughput is computed. |
460 static const int kMinRequestDurationMicroseconds = 1000; | 527 static const int kMinRequestDurationMicroseconds = 1000; |
461 | 528 |
462 // Minimum valid value of the variation parameter that holds RTT (in | 529 // Minimum valid value of the variation parameter that holds RTT (in |
463 // milliseconds) values. | 530 // milliseconds) values. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 // percentiles indicating less performant networks. For example, if | 569 // percentiles indicating less performant networks. For example, if |
503 // |percentile| is 90, then the network is expected to be faster than the | 570 // |percentile| is 90, then the network is expected to be faster than the |
504 // returned estimate with 0.9 probability. Similarly, network is expected to | 571 // returned estimate with 0.9 probability. Similarly, network is expected to |
505 // be slower than the returned estimate with 0.1 probability. | 572 // be slower than the returned estimate with 0.1 probability. |
506 base::TimeDelta GetRTTEstimateInternal(const base::TimeTicks& begin_timestamp, | 573 base::TimeDelta GetRTTEstimateInternal(const base::TimeTicks& begin_timestamp, |
507 int percentile) const; | 574 int percentile) const; |
508 int32_t GetDownlinkThroughputKbpsEstimateInternal( | 575 int32_t GetDownlinkThroughputKbpsEstimateInternal( |
509 const base::TimeTicks& begin_timestamp, | 576 const base::TimeTicks& begin_timestamp, |
510 int percentile) const; | 577 int percentile) const; |
511 | 578 |
579 // Returns an estimate of the packet loss rate. Only the observations later | |
580 // than |begin_timestamp| are taken into account. | |
581 float GetPacketLossRateEstimateInternal( | |
582 const base::TimeTicks& begin_timestamp) const; | |
583 | |
512 // Returns the current network ID checking by calling the platform APIs. | 584 // Returns the current network ID checking by calling the platform APIs. |
513 // Virtualized for testing. | 585 // Virtualized for testing. |
514 virtual NetworkID GetCurrentNetworkID() const; | 586 virtual NetworkID GetCurrentNetworkID() const; |
515 | 587 |
516 // Writes the estimated quality of the current network to the cache. | 588 // Writes the estimated quality of the current network to the cache. |
517 void CacheNetworkQualityEstimate(); | 589 void CacheNetworkQualityEstimate(); |
518 | 590 |
519 void NotifyObserversOfRTT(const RttObservation& observation); | 591 void NotifyObserversOfRTT(const RttObservation& observation); |
520 | 592 |
521 void NotifyObserversOfThroughput(const ThroughputObservation& observation); | 593 void NotifyObserversOfThroughput(const ThroughputObservation& observation); |
522 | 594 |
595 void NotifyObserversOfPacketLoss(uint64_t num_packets_lost, | |
596 uint64_t num_packets_received_in_order, | |
597 uint64_t num_packets_received_not_in_order, | |
598 const base::TimeTicks timestamp, | |
bengr
2016/02/09 15:41:02
Why not a const base::TimeTicks& ?
tbansal1
2016/02/09 17:54:11
Done.
| |
599 ObservationSource source); | |
600 | |
523 // Records the UMA related to RTT. | 601 // Records the UMA related to RTT. |
524 void RecordRTTUMA(int32_t estimated_value_msec, | 602 void RecordRTTUMA(int32_t estimated_value_msec, |
525 int32_t actual_value_msec) const; | 603 int32_t actual_value_msec) const; |
526 | 604 |
527 // Returns true only if |request| can be used for network quality estimation. | 605 // Returns true only if |request| can be used for network quality estimation. |
528 // Only the requests that go over network are considered to provide useful | 606 // Only the requests that go over network are considered to provide useful |
529 // observations. | 607 // observations. |
530 bool RequestProvidesUsefulObservations(const URLRequest& request) const; | 608 bool RequestProvidesUsefulObservations(const URLRequest& request) const; |
531 | 609 |
532 // Values of external estimate provider status. This enum must remain | 610 // Values of external estimate provider status. This enum must remain |
533 // synchronized with the enum of the same name in | 611 // synchronized with the enum of the same name in |
534 // metrics/histograms/histograms.xml. | 612 // metrics/histograms/histograms.xml. |
535 enum NQEExternalEstimateProviderStatus { | 613 enum NQEExternalEstimateProviderStatus { |
536 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, | 614 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, |
537 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, | 615 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, |
538 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, | 616 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, |
539 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, | 617 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, |
540 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, | 618 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, |
541 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY | 619 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY |
542 }; | 620 }; |
543 | 621 |
544 // Records the metrics related to external estimate provider. | 622 // Records the metrics related to external estimate provider. |
545 void RecordExternalEstimateProviderMetrics( | 623 void RecordExternalEstimateProviderMetrics( |
546 NQEExternalEstimateProviderStatus status) const; | 624 NQEExternalEstimateProviderStatus status) const; |
547 | 625 |
626 ObservationSource GetObservationSourceForProtocol( | |
627 const Protocol protocol) const; | |
628 | |
548 // Determines if the requests to local host can be used in estimating the | 629 // Determines if the requests to local host can be used in estimating the |
549 // network quality. Set to true only for tests. | 630 // network quality. Set to true only for tests. |
550 const bool allow_localhost_requests_; | 631 const bool allow_localhost_requests_; |
551 | 632 |
552 // Determines if the responses smaller than |kMinTransferSizeInBytes| | 633 // Determines if the responses smaller than |kMinTransferSizeInBytes| |
553 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the | 634 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the |
554 // network quality. Set to true only for tests. | 635 // network quality. Set to true only for tests. |
555 const bool allow_small_responses_; | 636 const bool allow_small_responses_; |
556 | 637 |
557 // Time when last connection change was observed. | 638 // Time when last connection change was observed. |
(...skipping 13 matching lines...) Expand all Loading... | |
571 // Cache that stores quality of previously seen networks. | 652 // Cache that stores quality of previously seen networks. |
572 CachedNetworkQualities cached_network_qualities_; | 653 CachedNetworkQualities cached_network_qualities_; |
573 | 654 |
574 // Buffer that holds throughput observations (in kilobits per second) sorted | 655 // Buffer that holds throughput observations (in kilobits per second) sorted |
575 // by timestamp. | 656 // by timestamp. |
576 ThroughputObservationBuffer downstream_throughput_kbps_observations_; | 657 ThroughputObservationBuffer downstream_throughput_kbps_observations_; |
577 | 658 |
578 // Buffer that holds RTT observations sorted by timestamp. | 659 // Buffer that holds RTT observations sorted by timestamp. |
579 RttObservationBuffer rtt_msec_observations_; | 660 RttObservationBuffer rtt_msec_observations_; |
580 | 661 |
662 // Buffer that holds packet loss observations sorted by timestamp. | |
663 ObservationBuffer<float> packet_loss_rate_observations_; | |
664 | |
581 // Default network quality observations obtained from the network quality | 665 // Default network quality observations obtained from the network quality |
582 // estimator field trial parameters. The observations are indexed by | 666 // estimator field trial parameters. The observations are indexed by |
583 // ConnectionType. | 667 // ConnectionType. |
584 NetworkQuality | 668 NetworkQuality |
585 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; | 669 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; |
586 | 670 |
587 // Estimated network quality. Updated on mainframe requests. | 671 // Estimated network quality. Updated on mainframe requests. |
588 NetworkQuality estimated_median_network_quality_; | 672 NetworkQuality estimated_median_network_quality_; |
589 | 673 |
590 // ExternalEstimateProvider that provides network quality using operating | 674 // ExternalEstimateProvider that provides network quality using operating |
591 // system APIs. May be NULL. | 675 // system APIs. May be NULL. |
592 const scoped_ptr<ExternalEstimateProvider> external_estimate_provider_; | 676 const scoped_ptr<ExternalEstimateProvider> external_estimate_provider_; |
593 | 677 |
594 // Observer lists for round trip times and throughput measurements. | 678 // Observer lists for round trip times, throughput and packet loss |
679 // measurements. | |
595 base::ObserverList<RTTObserver> rtt_observer_list_; | 680 base::ObserverList<RTTObserver> rtt_observer_list_; |
596 base::ObserverList<ThroughputObserver> throughput_observer_list_; | 681 base::ObserverList<ThroughputObserver> throughput_observer_list_; |
682 base::ObserverList<PacketLossObserver> packet_loss_observer_list_; | |
597 | 683 |
598 base::ThreadChecker thread_checker_; | 684 base::ThreadChecker thread_checker_; |
599 | 685 |
600 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 686 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
601 }; | 687 }; |
602 | 688 |
603 } // namespace net | 689 } // namespace net |
604 | 690 |
605 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ | 691 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ |
OLD | NEW |