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