| 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_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 5 #ifndef NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| 6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at | 183 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at |
| 184 // the HTTP layer. Virtualized for testing. |rtt| should not be null. The RTT | 184 // the HTTP layer. Virtualized for testing. |rtt| should not be null. The RTT |
| 185 // at the HTTP layer measures the time from when the request was sent (this | 185 // at the HTTP layer measures the time from when the request was sent (this |
| 186 // happens after the connection is established) to the time when the response | 186 // happens after the connection is established) to the time when the response |
| 187 // headers were received. | 187 // headers were received. |
| 188 virtual bool GetHttpRTTEstimate(base::TimeDelta* rtt) const | 188 virtual bool GetHttpRTTEstimate(base::TimeDelta* rtt) const |
| 189 WARN_UNUSED_RESULT; | 189 WARN_UNUSED_RESULT; |
| 190 | 190 |
| 191 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at | 191 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at |
| 192 // the transport layer. |rtt| should not be null. | 192 // the transport layer. |rtt| should not be null. Virtualized for testing. |
| 193 bool GetTransportRTTEstimate(base::TimeDelta* rtt) const WARN_UNUSED_RESULT; | 193 virtual bool GetTransportRTTEstimate(base::TimeDelta* rtt) const |
| 194 WARN_UNUSED_RESULT; |
| 194 | 195 |
| 195 // Returns true if downlink throughput is available and sets |kbps| to | 196 // Returns true if downlink throughput is available and sets |kbps| to |
| 196 // estimated downlink throughput (in kilobits per second). | 197 // estimated downlink throughput (in kilobits per second). |
| 197 // Virtualized for testing. |kbps| should not be null. | 198 // Virtualized for testing. |kbps| should not be null. |
| 198 virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const; | 199 virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const; |
| 199 | 200 |
| 200 // Notifies NetworkQualityEstimator that the response header of |request| has | 201 // Notifies NetworkQualityEstimator that the response header of |request| has |
| 201 // been received. | 202 // been received. |
| 202 void NotifyHeadersReceived(const URLRequest& request); | 203 void NotifyHeadersReceived(const URLRequest& request); |
| 203 | 204 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 217 // Virtualized for testing. |rtt| should not be null. The RTT at the HTTP | 218 // Virtualized for testing. |rtt| should not be null. The RTT at the HTTP |
| 218 // layer measures the time from when the request was sent (this happens after | 219 // layer measures the time from when the request was sent (this happens after |
| 219 // the connection is established) to the time when the response headers were | 220 // the connection is established) to the time when the response headers were |
| 220 // received. | 221 // received. |
| 221 virtual bool GetRecentHttpRTTMedian(const base::TimeTicks& start_time, | 222 virtual bool GetRecentHttpRTTMedian(const base::TimeTicks& start_time, |
| 222 base::TimeDelta* rtt) const | 223 base::TimeDelta* rtt) const |
| 223 WARN_UNUSED_RESULT; | 224 WARN_UNUSED_RESULT; |
| 224 | 225 |
| 225 // Returns true if the median RTT at the transport layer is available and sets | 226 // Returns true if the median RTT at the transport layer is available and sets |
| 226 // |rtt| to the median of transport layer RTT observations since | 227 // |rtt| to the median of transport layer RTT observations since |
| 227 // |start_time|. |rtt| should not be null. | 228 // |start_time|. |rtt| should not be null. Virtualized for testing. |
| 228 bool GetRecentTransportRTTMedian(const base::TimeTicks& start_time, | 229 virtual bool GetRecentTransportRTTMedian(const base::TimeTicks& start_time, |
| 229 base::TimeDelta* rtt) const | 230 base::TimeDelta* rtt) const |
| 230 WARN_UNUSED_RESULT; | 231 WARN_UNUSED_RESULT; |
| 231 | 232 |
| 232 // Returns true if median downstream throughput is available and sets |kbps| | 233 // Returns true if median downstream throughput is available and sets |kbps| |
| 233 // to the median of downstream throughput (in kilobits per second) | 234 // to the median of downstream throughput (in kilobits per second) |
| 234 // observations since |start_time|. Virtualized for testing. |kbps| | 235 // observations since |start_time|. Virtualized for testing. |kbps| |
| 235 // should not be null. | 236 // should not be null. Virtualized for testing. |
| 236 virtual bool GetRecentMedianDownlinkThroughputKbps( | 237 virtual bool GetRecentMedianDownlinkThroughputKbps( |
| 237 const base::TimeTicks& start_time, | 238 const base::TimeTicks& start_time, |
| 238 int32_t* kbps) const WARN_UNUSED_RESULT; | 239 int32_t* kbps) const WARN_UNUSED_RESULT; |
| 239 | 240 |
| 240 // Adds |rtt_observer| to the list of round trip time observers. Must be | 241 // Adds |rtt_observer| to the list of round trip time observers. Must be |
| 241 // called on the IO thread. | 242 // called on the IO thread. |
| 242 void AddRTTObserver(RTTObserver* rtt_observer); | 243 void AddRTTObserver(RTTObserver* rtt_observer); |
| 243 | 244 |
| 244 // Removes |rtt_observer| from the list of round trip time observers if it | 245 // Removes |rtt_observer| from the list of round trip time observers if it |
| 245 // is on the list of observers. Must be called on the IO thread. | 246 // is on the list of observers. Must be called on the IO thread. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 | 303 |
| 303 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. | 304 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. |
| 304 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt, | 305 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt, |
| 305 int32_t downstream_throughput_kbps, | 306 int32_t downstream_throughput_kbps, |
| 306 int32_t upstream_throughput_kbps) override; | 307 int32_t upstream_throughput_kbps) override; |
| 307 | 308 |
| 308 // Return a string equivalent to |type|. | 309 // Return a string equivalent to |type|. |
| 309 const char* GetNameForEffectiveConnectionType( | 310 const char* GetNameForEffectiveConnectionType( |
| 310 EffectiveConnectionType type) const; | 311 EffectiveConnectionType type) const; |
| 311 | 312 |
| 313 // Returns the list of intervals at which the accuracy of network quality |
| 314 // prediction should be recorded. Virtualized for testing. |
| 315 virtual const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() |
| 316 const; |
| 317 |
| 312 // Overrides the tick clock used by |this| for testing. | 318 // Overrides the tick clock used by |this| for testing. |
| 313 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); | 319 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); |
| 314 | 320 |
| 315 private: | 321 private: |
| 316 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 322 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
| 317 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 323 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
| 318 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 324 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
| 319 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 325 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
| 320 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); | 326 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); |
| 321 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); | 327 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 // Returns true only if the |request| can be used for RTT estimation. | 434 // Returns true only if the |request| can be used for RTT estimation. |
| 429 bool RequestProvidesRTTObservation(const URLRequest& request) const; | 435 bool RequestProvidesRTTObservation(const URLRequest& request) const; |
| 430 | 436 |
| 431 // Recomputes effective connection type, if it was computed more than the | 437 // Recomputes effective connection type, if it was computed more than the |
| 432 // specified duration ago, or if there has been a connection change recently. | 438 // specified duration ago, or if there has been a connection change recently. |
| 433 void MaybeRecomputeEffectiveConnectionType(); | 439 void MaybeRecomputeEffectiveConnectionType(); |
| 434 | 440 |
| 435 // Notify observers of a change in effective connection type. | 441 // Notify observers of a change in effective connection type. |
| 436 void NotifyObserversOfEffectiveConnectionTypeChanged(); | 442 void NotifyObserversOfEffectiveConnectionTypeChanged(); |
| 437 | 443 |
| 444 // Records NQE accuracy metrics. |measuring_duration| should belong to the |
| 445 // vector returned by AccuracyRecordingIntervals(). |
| 446 // RecordAccuracyAfterMainFrame should be called |measuring_duration| after a |
| 447 // main frame request is observed. |
| 448 void RecordAccuracyAfterMainFrame(base::TimeDelta measuring_duration) const; |
| 449 |
| 438 // Values of external estimate provider status. This enum must remain | 450 // Values of external estimate provider status. This enum must remain |
| 439 // synchronized with the enum of the same name in | 451 // synchronized with the enum of the same name in |
| 440 // metrics/histograms/histograms.xml. | 452 // metrics/histograms/histograms.xml. |
| 441 enum NQEExternalEstimateProviderStatus { | 453 enum NQEExternalEstimateProviderStatus { |
| 442 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, | 454 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, |
| 443 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, | 455 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, |
| 444 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, | 456 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, |
| 445 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, | 457 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, |
| 446 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, | 458 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, |
| 447 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE, | 459 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 468 // Tick clock used by the network quality estimator. | 480 // Tick clock used by the network quality estimator. |
| 469 std::unique_ptr<base::TickClock> tick_clock_; | 481 std::unique_ptr<base::TickClock> tick_clock_; |
| 470 | 482 |
| 471 // Minimum duration between two consecutive computations of effective | 483 // Minimum duration between two consecutive computations of effective |
| 472 // connection type. Set to non-zero value as a performance optimization. | 484 // connection type. Set to non-zero value as a performance optimization. |
| 473 const base::TimeDelta effective_connection_type_recomputation_interval_; | 485 const base::TimeDelta effective_connection_type_recomputation_interval_; |
| 474 | 486 |
| 475 // Time when the effective connection type was last computed. | 487 // Time when the effective connection type was last computed. |
| 476 base::TimeTicks last_effective_connection_type_computation_; | 488 base::TimeTicks last_effective_connection_type_computation_; |
| 477 | 489 |
| 490 // Intervals after the main frame request arrives at which accuracy of network |
| 491 // quality prediction is recorded. |
| 492 std::vector<base::TimeDelta> accuracy_recording_intervals_; |
| 493 |
| 478 // Time when last connection change was observed. | 494 // Time when last connection change was observed. |
| 479 base::TimeTicks last_connection_change_; | 495 base::TimeTicks last_connection_change_; |
| 480 | 496 |
| 481 // ID of the current network. | 497 // ID of the current network. |
| 482 NetworkID current_network_id_; | 498 NetworkID current_network_id_; |
| 483 | 499 |
| 484 // Peak network quality (fastest round-trip-time (RTT) and highest | 500 // Peak network quality (fastest round-trip-time (RTT) and highest |
| 485 // downstream throughput) measured since last connectivity change. RTT is | 501 // downstream throughput) measured since last connectivity change. RTT is |
| 486 // measured from time the request is sent until the first byte received. | 502 // measured from time the request is sent until the first byte received. |
| 487 // The accuracy is decreased by ignoring these factors: | 503 // The accuracy is decreased by ignoring these factors: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 505 nqe::internal::NetworkQuality | 521 nqe::internal::NetworkQuality |
| 506 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; | 522 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; |
| 507 | 523 |
| 508 // Thresholds for different effective connection types obtained from field | 524 // Thresholds for different effective connection types obtained from field |
| 509 // trial variation params. These thresholds encode how different connection | 525 // trial variation params. These thresholds encode how different connection |
| 510 // types behave in general. In future, complex encodings (e.g., curve | 526 // types behave in general. In future, complex encodings (e.g., curve |
| 511 // fitting) may be used. | 527 // fitting) may be used. |
| 512 nqe::internal::NetworkQuality | 528 nqe::internal::NetworkQuality |
| 513 connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST]; | 529 connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST]; |
| 514 | 530 |
| 515 // Estimated network quality. Updated on mainframe requests. | 531 // Latest time when the headers for a main frame request were received. |
| 516 nqe::internal::NetworkQuality estimated_median_network_quality_; | 532 base::TimeTicks last_main_frame_request_; |
| 533 |
| 534 // Estimated network quality when the response headers for the last mainframe |
| 535 // request were received. |
| 536 nqe::internal::NetworkQuality estimated_quality_at_last_main_frame_; |
| 517 | 537 |
| 518 // ExternalEstimateProvider that provides network quality using operating | 538 // ExternalEstimateProvider that provides network quality using operating |
| 519 // system APIs. May be NULL. | 539 // system APIs. May be NULL. |
| 520 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; | 540 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; |
| 521 | 541 |
| 522 // Observer list for changes in effective connection type. | 542 // Observer list for changes in effective connection type. |
| 523 base::ObserverList<EffectiveConnectionTypeObserver> | 543 base::ObserverList<EffectiveConnectionTypeObserver> |
| 524 effective_connection_type_observer_list_; | 544 effective_connection_type_observer_list_; |
| 525 | 545 |
| 526 // Observer lists for round trip times and throughput measurements. | 546 // Observer lists for round trip times and throughput measurements. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 544 base::ThreadChecker thread_checker_; | 564 base::ThreadChecker thread_checker_; |
| 545 | 565 |
| 546 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 566 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
| 547 | 567 |
| 548 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 568 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
| 549 }; | 569 }; |
| 550 | 570 |
| 551 } // namespace net | 571 } // namespace net |
| 552 | 572 |
| 553 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 573 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |