| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 EffectiveConnectionType type) = 0; | 77 EffectiveConnectionType type) = 0; |
| 78 | 78 |
| 79 protected: | 79 protected: |
| 80 EffectiveConnectionTypeObserver() {} | 80 EffectiveConnectionTypeObserver() {} |
| 81 virtual ~EffectiveConnectionTypeObserver() {} | 81 virtual ~EffectiveConnectionTypeObserver() {} |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver); | 84 DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 // Observes changes in the network quality. |
| 88 class NET_EXPORT RTTAndThroughputEstimatesObserver { |
| 89 public: |
| 90 // Notifies the observer when estimated HTTP RTT, estimated transport RTT or |
| 91 // estimated downstream throughput is computed. NetworkQualityEstimator |
| 92 // computes the RTT and throughput estimates at regular intervals. |
| 93 // Additionally, when there is a change in the connection type of the |
| 94 // device, then the estimates are immediately computed. The observer must |
| 95 // register and unregister itself on the IO thread. All the observers would |
| 96 // be notified on the IO thread. |
| 97 // |
| 98 // |http_rtt|, |transport_rtt| and |downstream_throughput_kbps| are the |
| 99 // computed estimates of the HTTP RTT, transport RTT and downstream |
| 100 // throughput (in kilobits per second), respectively. If an estimate of the |
| 101 // HTTP or transport RTT is unavailable, it will be set to |
| 102 // nqe::internal::InvalidRTT(). If the throughput estimate is unavailable, |
| 103 // it will be set to nqe::internal::kInvalidThroughput. |
| 104 virtual void OnRTTOrThroughputEstimatesComputed( |
| 105 base::TimeDelta http_rtt, |
| 106 base::TimeDelta transport_rtt, |
| 107 int32_t downstream_throughput_kbps) = 0; |
| 108 |
| 109 protected: |
| 110 RTTAndThroughputEstimatesObserver() {} |
| 111 virtual ~RTTAndThroughputEstimatesObserver() {} |
| 112 |
| 113 private: |
| 114 DISALLOW_COPY_AND_ASSIGN(RTTAndThroughputEstimatesObserver); |
| 115 }; |
| 116 |
| 87 // Observes measurements of round trip time. | 117 // Observes measurements of round trip time. |
| 88 class NET_EXPORT_PRIVATE RTTObserver { | 118 class NET_EXPORT_PRIVATE RTTObserver { |
| 89 public: | 119 public: |
| 90 // Will be called when a new RTT observation is available. The round trip | 120 // Will be called when a new RTT observation is available. The round trip |
| 91 // time is specified in milliseconds. The time when the observation was | 121 // time is specified in milliseconds. The time when the observation was |
| 92 // taken and the source of the observation are provided. | 122 // taken and the source of the observation are provided. |
| 93 virtual void OnRTTObservation(int32_t rtt_ms, | 123 virtual void OnRTTObservation(int32_t rtt_ms, |
| 94 const base::TimeTicks& timestamp, | 124 const base::TimeTicks& timestamp, |
| 95 NetworkQualityObservationSource source) = 0; | 125 NetworkQualityObservationSource source) = 0; |
| 96 | 126 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // Adds |observer| to the list of effective connection type observers. Must be | 208 // Adds |observer| to the list of effective connection type observers. Must be |
| 179 // called on the IO thread. | 209 // called on the IO thread. |
| 180 void AddEffectiveConnectionTypeObserver( | 210 void AddEffectiveConnectionTypeObserver( |
| 181 EffectiveConnectionTypeObserver* observer); | 211 EffectiveConnectionTypeObserver* observer); |
| 182 | 212 |
| 183 // Removes |observer| from the list of effective connection type observers. | 213 // Removes |observer| from the list of effective connection type observers. |
| 184 // Must be called on the IO thread. | 214 // Must be called on the IO thread. |
| 185 void RemoveEffectiveConnectionTypeObserver( | 215 void RemoveEffectiveConnectionTypeObserver( |
| 186 EffectiveConnectionTypeObserver* observer); | 216 EffectiveConnectionTypeObserver* observer); |
| 187 | 217 |
| 218 // Adds |observer| to the list of RTT and throughput estimate observers. Must |
| 219 // be called on the IO thread. |
| 220 void AddRTTAndThroughputEstimatesObserver( |
| 221 RTTAndThroughputEstimatesObserver* observer); |
| 222 |
| 223 // Removes |observer| from the list of RTT and throughput estimate observers. |
| 224 // Must be called on the IO thread. |
| 225 void RemoveRTTAndThroughputEstimatesObserver( |
| 226 RTTAndThroughputEstimatesObserver* observer); |
| 227 |
| 188 // Notifies NetworkQualityEstimator that the response header of |request| has | 228 // Notifies NetworkQualityEstimator that the response header of |request| has |
| 189 // been received. | 229 // been received. |
| 190 void NotifyHeadersReceived(const URLRequest& request); | 230 void NotifyHeadersReceived(const URLRequest& request); |
| 191 | 231 |
| 192 // Notifies NetworkQualityEstimator that the headers of |request| are about to | 232 // Notifies NetworkQualityEstimator that the headers of |request| are about to |
| 193 // be sent. | 233 // be sent. |
| 194 void NotifyStartTransaction(const URLRequest& request); | 234 void NotifyStartTransaction(const URLRequest& request); |
| 195 | 235 |
| 196 // Notifies NetworkQualityEstimator that the response body of |request| has | 236 // Notifies NetworkQualityEstimator that the response body of |request| has |
| 197 // been received. | 237 // been received. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 // prediction should be recorded. Virtualized for testing. | 341 // prediction should be recorded. Virtualized for testing. |
| 302 virtual const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() | 342 virtual const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() |
| 303 const; | 343 const; |
| 304 | 344 |
| 305 // Overrides the tick clock used by |this| for testing. | 345 // Overrides the tick clock used by |this| for testing. |
| 306 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); | 346 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); |
| 307 | 347 |
| 308 // Returns a random double in the range [0.0, 1.0). Virtualized for testing. | 348 // Returns a random double in the range [0.0, 1.0). Virtualized for testing. |
| 309 virtual double RandDouble() const; | 349 virtual double RandDouble() const; |
| 310 | 350 |
| 351 // Returns the effective type of the current connection based on only the |
| 352 // observations received after |start_time|. |http_rtt|, |transport_rtt| and |
| 353 // |downstream_throughput_kbps| must be non-null. |http_rtt|, |transport_rtt| |
| 354 // and |downstream_throughput_kbps| are set to the expected HTTP RTT, |
| 355 // transport RTT and downstream throughput (in kilobits per second) based on |
| 356 // observations taken since |start_time|. Virtualized for testing. |
| 357 virtual EffectiveConnectionType |
| 358 GetRecentEffectiveConnectionTypeAndNetworkQuality( |
| 359 const base::TimeTicks& start_time, |
| 360 base::TimeDelta* http_rtt, |
| 361 base::TimeDelta* transport_rtt, |
| 362 int32_t* downstream_throughput_kbps) const; |
| 363 |
| 311 private: | 364 private: |
| 312 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 365 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 313 AdaptiveRecomputationEffectiveConnectionType); | 366 AdaptiveRecomputationEffectiveConnectionType); |
| 314 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 367 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
| 315 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 368 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
| 316 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 369 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
| 317 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 370 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 318 ObtainAlgorithmToUseFromParams); | 371 ObtainAlgorithmToUseFromParams); |
| 319 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 372 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
| 320 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); | 373 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 496 |
| 444 void NotifyObserversOfThroughput(const ThroughputObservation& observation); | 497 void NotifyObserversOfThroughput(const ThroughputObservation& observation); |
| 445 | 498 |
| 446 // Returns true only if the |request| can be used for RTT estimation. | 499 // Returns true only if the |request| can be used for RTT estimation. |
| 447 bool RequestProvidesRTTObservation(const URLRequest& request) const; | 500 bool RequestProvidesRTTObservation(const URLRequest& request) const; |
| 448 | 501 |
| 449 // Recomputes effective connection type, if it was computed more than the | 502 // Recomputes effective connection type, if it was computed more than the |
| 450 // specified duration ago, or if there has been a connection change recently. | 503 // specified duration ago, or if there has been a connection change recently. |
| 451 void MaybeComputeEffectiveConnectionType(); | 504 void MaybeComputeEffectiveConnectionType(); |
| 452 | 505 |
| 453 // Notify observers of a change in effective connection type. | 506 // Notifies observers of a change in effective connection type. |
| 454 void NotifyObserversOfEffectiveConnectionTypeChanged(); | 507 void NotifyObserversOfEffectiveConnectionTypeChanged(); |
| 455 | 508 |
| 509 // Notifies the observers of RTT or throughput estimates computation. |
| 510 void NotifyObserversOfRTTOrThroughputComputed() const; |
| 511 |
| 456 // Records NQE accuracy metrics. |measuring_duration| should belong to the | 512 // Records NQE accuracy metrics. |measuring_duration| should belong to the |
| 457 // vector returned by AccuracyRecordingIntervals(). | 513 // vector returned by AccuracyRecordingIntervals(). |
| 458 // RecordAccuracyAfterMainFrame should be called |measuring_duration| after a | 514 // RecordAccuracyAfterMainFrame should be called |measuring_duration| after a |
| 459 // main frame request is observed. | 515 // main frame request is observed. |
| 460 void RecordAccuracyAfterMainFrame(base::TimeDelta measuring_duration) const; | 516 void RecordAccuracyAfterMainFrame(base::TimeDelta measuring_duration) const; |
| 461 | 517 |
| 462 // Obtains the current cellular signal strength value and updates | 518 // Obtains the current cellular signal strength value and updates |
| 463 // |min_signal_strength_since_connection_change_| and | 519 // |min_signal_strength_since_connection_change_| and |
| 464 // |max_signal_strength_since_connection_change_|. | 520 // |max_signal_strength_since_connection_change_|. |
| 465 void UpdateSignalStrength(); | 521 void UpdateSignalStrength(); |
| 466 | 522 |
| 467 // Returns the effective type of the current connection based on only the | 523 // Returns the effective type of the current connection based on only the |
| 468 // samples observed after |start_time|. May use HTTP RTT, transport RTT and | 524 // samples observed after |start_time|. May use HTTP RTT, transport RTT and |
| 469 // downstream throughput to compute the effective connection type based on | 525 // downstream throughput to compute the effective connection type based on |
| 470 // |http_rtt_metric|, |transport_rtt_metric| and | 526 // |http_rtt_metric|, |transport_rtt_metric| and |
| 471 // |downstream_throughput_kbps_metric|, respectively. | 527 // |downstream_throughput_kbps_metric|, respectively. |http_rtt|, |
| 528 // |transport_rtt| and |downstream_throughput_kbps| must be non-null. |
| 529 // |http_rtt|, |transport_rtt| and |downstream_throughput_kbps| are |
| 530 // set to the expected HTTP RTT, transport RTT and downstream throughput (in |
| 531 // kilobits per second) based on observations taken since |start_time|. |
| 472 EffectiveConnectionType GetRecentEffectiveConnectionTypeUsingMetrics( | 532 EffectiveConnectionType GetRecentEffectiveConnectionTypeUsingMetrics( |
| 473 const base::TimeTicks& start_time, | 533 const base::TimeTicks& start_time, |
| 474 MetricUsage http_rtt_metric, | 534 MetricUsage http_rtt_metric, |
| 475 MetricUsage transport_rtt_metric, | 535 MetricUsage transport_rtt_metric, |
| 476 MetricUsage downstream_throughput_kbps_metric) const; | 536 MetricUsage downstream_throughput_kbps_metric, |
| 537 base::TimeDelta* http_rtt, |
| 538 base::TimeDelta* transport_rtt, |
| 539 int32_t* downstream_throughput_kbps) const; |
| 477 | 540 |
| 478 // Values of external estimate provider status. This enum must remain | 541 // Values of external estimate provider status. This enum must remain |
| 479 // synchronized with the enum of the same name in | 542 // synchronized with the enum of the same name in |
| 480 // metrics/histograms/histograms.xml. | 543 // metrics/histograms/histograms.xml. |
| 481 enum NQEExternalEstimateProviderStatus { | 544 enum NQEExternalEstimateProviderStatus { |
| 482 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, | 545 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, |
| 483 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, | 546 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, |
| 484 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, | 547 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, |
| 485 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, | 548 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, |
| 486 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, | 549 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 nqe::internal::NetworkQuality external_estimate_provider_quality_; | 650 nqe::internal::NetworkQuality external_estimate_provider_quality_; |
| 588 | 651 |
| 589 // ExternalEstimateProvider that provides network quality using operating | 652 // ExternalEstimateProvider that provides network quality using operating |
| 590 // system APIs. May be NULL. | 653 // system APIs. May be NULL. |
| 591 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; | 654 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; |
| 592 | 655 |
| 593 // Observer list for changes in effective connection type. | 656 // Observer list for changes in effective connection type. |
| 594 base::ObserverList<EffectiveConnectionTypeObserver> | 657 base::ObserverList<EffectiveConnectionTypeObserver> |
| 595 effective_connection_type_observer_list_; | 658 effective_connection_type_observer_list_; |
| 596 | 659 |
| 660 // Observer list for RTT or throughput estimates. |
| 661 base::ObserverList<RTTAndThroughputEstimatesObserver> |
| 662 rtt_and_throughput_estimates_observer_list_; |
| 663 |
| 597 // Observer lists for round trip times and throughput measurements. | 664 // Observer lists for round trip times and throughput measurements. |
| 598 base::ObserverList<RTTObserver> rtt_observer_list_; | 665 base::ObserverList<RTTObserver> rtt_observer_list_; |
| 599 base::ObserverList<ThroughputObserver> throughput_observer_list_; | 666 base::ObserverList<ThroughputObserver> throughput_observer_list_; |
| 600 | 667 |
| 601 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_; | 668 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_; |
| 602 | 669 |
| 603 // Takes throughput measurements, and passes them back to |this| through the | 670 // Takes throughput measurements, and passes them back to |this| through the |
| 604 // provided callback. |this| stores the throughput observations in | 671 // provided callback. |this| stores the throughput observations in |
| 605 // |downstream_throughput_kbps_observations_|, which are later used for | 672 // |downstream_throughput_kbps_observations_|, which are later used for |
| 606 // estimating the throughput. | 673 // estimating the throughput. |
| 607 std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_; | 674 std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_; |
| 608 | 675 |
| 609 // Minimum duration between two consecutive computations of effective | 676 // Minimum duration between two consecutive computations of effective |
| 610 // connection type. Set to non-zero value as a performance optimization. | 677 // connection type. Set to non-zero value as a performance optimization. |
| 611 const base::TimeDelta effective_connection_type_recomputation_interval_; | 678 const base::TimeDelta effective_connection_type_recomputation_interval_; |
| 612 | 679 |
| 613 // Time when the effective connection type was last computed. | 680 // Time when the effective connection type was last computed. |
| 614 base::TimeTicks last_effective_connection_type_computation_; | 681 base::TimeTicks last_effective_connection_type_computation_; |
| 615 | 682 |
| 616 // Number of RTT and bandwidth samples available when effective connection | 683 // Number of RTT and bandwidth samples available when effective connection |
| 617 // type was last recomputed. | 684 // type was last recomputed. |
| 618 size_t rtt_observations_size_at_last_ect_computation_; | 685 size_t rtt_observations_size_at_last_ect_computation_; |
| 619 size_t throughput_observations_size_at_last_ect_computation_; | 686 size_t throughput_observations_size_at_last_ect_computation_; |
| 620 | 687 |
| 688 // Current estimates of the HTTP RTT, transport RTT and downstream throughput |
| 689 // (in kilobits per second). |
| 690 base::TimeDelta http_rtt_; |
| 691 base::TimeDelta transport_rtt_; |
| 692 int32_t downstream_throughput_kbps_; |
| 693 |
| 621 // Current effective connection type. It is updated on connection change | 694 // Current effective connection type. It is updated on connection change |
| 622 // events. It is also updated every time there is network traffic (provided | 695 // events. It is also updated every time there is network traffic (provided |
| 623 // the last computation was more than | 696 // the last computation was more than |
| 624 // |effective_connection_type_recomputation_interval_| ago). | 697 // |effective_connection_type_recomputation_interval_| ago). |
| 625 EffectiveConnectionType effective_connection_type_; | 698 EffectiveConnectionType effective_connection_type_; |
| 626 | 699 |
| 627 // Minimum and Maximum signal strength (in dbM) observed since last connection | 700 // Minimum and Maximum signal strength (in dbM) observed since last connection |
| 628 // change. Updated on connection change and main frame requests. | 701 // change. Updated on connection change and main frame requests. |
| 629 int32_t min_signal_strength_since_connection_change_; | 702 int32_t min_signal_strength_since_connection_change_; |
| 630 int32_t max_signal_strength_since_connection_change_; | 703 int32_t max_signal_strength_since_connection_change_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 648 base::ThreadChecker thread_checker_; | 721 base::ThreadChecker thread_checker_; |
| 649 | 722 |
| 650 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 723 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
| 651 | 724 |
| 652 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 725 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
| 653 }; | 726 }; |
| 654 | 727 |
| 655 } // namespace net | 728 } // namespace net |
| 656 | 729 |
| 657 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 730 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |