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_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 14 matching lines...) Expand all Loading... | |
| 25 #include "net/nqe/cached_network_quality.h" | 25 #include "net/nqe/cached_network_quality.h" |
| 26 #include "net/nqe/external_estimate_provider.h" | 26 #include "net/nqe/external_estimate_provider.h" |
| 27 #include "net/nqe/network_quality.h" | 27 #include "net/nqe/network_quality.h" |
| 28 #include "net/nqe/network_quality_observation.h" | 28 #include "net/nqe/network_quality_observation.h" |
| 29 #include "net/nqe/network_quality_observation_source.h" | 29 #include "net/nqe/network_quality_observation_source.h" |
| 30 #include "net/nqe/observation_buffer.h" | 30 #include "net/nqe/observation_buffer.h" |
| 31 #include "net/socket/socket_performance_watcher_factory.h" | 31 #include "net/socket/socket_performance_watcher_factory.h" |
| 32 | 32 |
| 33 namespace base { | 33 namespace base { |
| 34 class SingleThreadTaskRunner; | 34 class SingleThreadTaskRunner; |
| 35 class TickClock; | |
| 35 } // namespace base | 36 } // namespace base |
| 36 | 37 |
| 37 namespace net { | 38 namespace net { |
| 38 | 39 |
| 39 namespace nqe { | 40 namespace nqe { |
| 40 namespace internal { | 41 namespace internal { |
| 41 class ThroughputAnalyzer; | 42 class ThroughputAnalyzer; |
| 42 } | 43 } |
| 43 } | 44 } |
| 44 | 45 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 69 EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0, | 70 EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0, |
| 70 EFFECTIVE_CONNECTION_TYPE_OFFLINE, | 71 EFFECTIVE_CONNECTION_TYPE_OFFLINE, |
| 71 EFFECTIVE_CONNECTION_TYPE_SLOW_2G, | 72 EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
| 72 EFFECTIVE_CONNECTION_TYPE_2G, | 73 EFFECTIVE_CONNECTION_TYPE_2G, |
| 73 EFFECTIVE_CONNECTION_TYPE_3G, | 74 EFFECTIVE_CONNECTION_TYPE_3G, |
| 74 EFFECTIVE_CONNECTION_TYPE_4G, | 75 EFFECTIVE_CONNECTION_TYPE_4G, |
| 75 EFFECTIVE_CONNECTION_TYPE_BROADBAND, | 76 EFFECTIVE_CONNECTION_TYPE_BROADBAND, |
| 76 EFFECTIVE_CONNECTION_TYPE_LAST, | 77 EFFECTIVE_CONNECTION_TYPE_LAST, |
| 77 }; | 78 }; |
| 78 | 79 |
| 80 // Observes changes in effective connection type. | |
| 81 class NET_EXPORT_PRIVATE EffectiveConnectionTypeObserver { | |
| 82 public: | |
| 83 // Notifies the observer of change in the effective connection type. | |
|
bengr
2016/05/31 17:39:25
of -> of a
tbansal1
2016/05/31 21:40:25
Done.
| |
| 84 // NetworkQualityEstimator computes effective connection type once in every | |
|
bengr
2016/05/31 17:39:25
computes -> computes the
tbansal1
2016/05/31 21:40:25
Done.
| |
| 85 // interval of duration |effective_connection_type_recomputation_interval_|. | |
| 86 // Additionally, when there is a change in the connection type of the | |
| 87 // device, then the effective connection type is immediately recomputed. | |
| 88 // | |
| 89 // If the computed effective connection type is different from the | |
| 90 // previously notified effective connection type, then all the registered | |
| 91 // observers are notified of the new effective connection type. | |
| 92 virtual void OnEffectiveConnectionTypeChanged( | |
|
bengr
2016/05/31 17:39:25
This is not threadsafe, right? Say so.
tbansal1
2016/05/31 21:40:26
Done.
| |
| 93 EffectiveConnectionType type) = 0; | |
| 94 | |
| 95 protected: | |
| 96 EffectiveConnectionTypeObserver() {} | |
| 97 virtual ~EffectiveConnectionTypeObserver() {} | |
| 98 | |
| 99 private: | |
| 100 DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver); | |
| 101 }; | |
| 102 | |
| 79 // Observes measurements of round trip time. | 103 // Observes measurements of round trip time. |
| 80 class NET_EXPORT_PRIVATE RTTObserver { | 104 class NET_EXPORT_PRIVATE RTTObserver { |
| 81 public: | 105 public: |
| 82 // Will be called when a new RTT observation is available. The round trip | 106 // Will be called when a new RTT observation is available. The round trip |
| 83 // time is specified in milliseconds. The time when the observation was | 107 // time is specified in milliseconds. The time when the observation was |
| 84 // taken and the source of the observation are provided. | 108 // taken and the source of the observation are provided. |
| 85 virtual void OnRTTObservation(int32_t rtt_ms, | 109 virtual void OnRTTObservation(int32_t rtt_ms, |
| 86 const base::TimeTicks& timestamp, | 110 const base::TimeTicks& timestamp, |
| 87 NetworkQualityObservationSource source) = 0; | 111 NetworkQualityObservationSource source) = 0; |
| 88 | 112 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 const std::map<std::string, std::string>& variation_params, | 161 const std::map<std::string, std::string>& variation_params, |
| 138 bool use_local_host_requests_for_tests, | 162 bool use_local_host_requests_for_tests, |
| 139 bool use_smaller_responses_for_tests); | 163 bool use_smaller_responses_for_tests); |
| 140 | 164 |
| 141 ~NetworkQualityEstimator() override; | 165 ~NetworkQualityEstimator() override; |
| 142 | 166 |
| 143 // Returns the effective type of the current connection. Virtualized for | 167 // Returns the effective type of the current connection. Virtualized for |
| 144 // testing. | 168 // testing. |
| 145 virtual EffectiveConnectionType GetEffectiveConnectionType() const; | 169 virtual EffectiveConnectionType GetEffectiveConnectionType() const; |
| 146 | 170 |
| 171 // Adds |observer| to the list of effective connection type observers. Must be | |
| 172 // called on the IO thread. | |
| 173 void AddEffectiveConnectionTypeObserver( | |
| 174 EffectiveConnectionTypeObserver* observer); | |
| 175 | |
| 176 // Removes |observer| from the list of effective connection type observers. | |
| 177 // Must be called on the IO thread. | |
| 178 void RemoveEffectiveConnectionTypeObserver( | |
| 179 EffectiveConnectionTypeObserver* observer); | |
| 180 | |
| 147 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at | 181 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at |
| 148 // the HTTP layer. Virtualized for testing. |rtt| should not be null. The RTT | 182 // the HTTP layer. Virtualized for testing. |rtt| should not be null. The RTT |
| 149 // at the HTTP layer measures the time from when the request was sent (this | 183 // at the HTTP layer measures the time from when the request was sent (this |
| 150 // happens after the connection is established) to the time when the response | 184 // happens after the connection is established) to the time when the response |
| 151 // headers were received. | 185 // headers were received. |
| 152 virtual bool GetHttpRTTEstimate(base::TimeDelta* rtt) const | 186 virtual bool GetHttpRTTEstimate(base::TimeDelta* rtt) const |
| 153 WARN_UNUSED_RESULT; | 187 WARN_UNUSED_RESULT; |
| 154 | 188 |
| 155 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at | 189 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at |
| 156 // the transport layer. |rtt| should not be null. | 190 // the transport layer. |rtt| should not be null. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 void OnConnectionTypeChanged( | 298 void OnConnectionTypeChanged( |
| 265 NetworkChangeNotifier::ConnectionType type) override; | 299 NetworkChangeNotifier::ConnectionType type) override; |
| 266 | 300 |
| 267 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. | 301 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. |
| 268 void OnUpdatedEstimateAvailable() override; | 302 void OnUpdatedEstimateAvailable() override; |
| 269 | 303 |
| 270 // Return a string equivalent to |type|. | 304 // Return a string equivalent to |type|. |
| 271 const char* GetNameForEffectiveConnectionType( | 305 const char* GetNameForEffectiveConnectionType( |
| 272 EffectiveConnectionType type) const; | 306 EffectiveConnectionType type) const; |
| 273 | 307 |
| 308 // Overrides the tick clock used by |this| for testing. | |
| 309 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); | |
| 310 | |
| 274 private: | 311 private: |
| 275 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 312 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
| 276 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 313 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
| 277 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 314 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
| 278 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 315 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
| 279 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); | 316 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); |
| 280 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); | 317 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); |
| 281 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 318 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 282 TestLRUCacheMaximumSize); | 319 TestLRUCacheMaximumSize); |
| 283 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMedianRTTSince); | 320 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMedianRTTSince); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 | 421 |
| 385 void NotifyObserversOfThroughput(const ThroughputObservation& observation); | 422 void NotifyObserversOfThroughput(const ThroughputObservation& observation); |
| 386 | 423 |
| 387 // Records the UMA related to the RTT at the HTTP layer. | 424 // Records the UMA related to the RTT at the HTTP layer. |
| 388 void RecordHttpRTTUMA(int32_t estimated_value_msec, | 425 void RecordHttpRTTUMA(int32_t estimated_value_msec, |
| 389 int32_t actual_value_msec) const; | 426 int32_t actual_value_msec) const; |
| 390 | 427 |
| 391 // Returns true only if the |request| can be used for RTT estimation. | 428 // Returns true only if the |request| can be used for RTT estimation. |
| 392 bool RequestProvidesRTTObservation(const URLRequest& request) const; | 429 bool RequestProvidesRTTObservation(const URLRequest& request) const; |
| 393 | 430 |
| 431 // Recomputes effective connection type, if it was computed more than the | |
| 432 // specified duration ago, or if there has been a connection change recently. | |
| 433 void MaybeRecomputeEffectiveConnectionType(); | |
| 434 | |
| 435 // Notify observers of change in effective connection type. | |
|
bengr
2016/05/31 17:39:24
of -> of a
tbansal1
2016/05/31 21:40:25
Done.
| |
| 436 void NotifyObserversOfEffectiveConnectionTypeChanged(); | |
| 437 | |
| 394 // Values of external estimate provider status. This enum must remain | 438 // Values of external estimate provider status. This enum must remain |
| 395 // synchronized with the enum of the same name in | 439 // synchronized with the enum of the same name in |
| 396 // metrics/histograms/histograms.xml. | 440 // metrics/histograms/histograms.xml. |
| 397 enum NQEExternalEstimateProviderStatus { | 441 enum NQEExternalEstimateProviderStatus { |
| 398 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, | 442 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, |
| 399 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, | 443 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, |
| 400 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, | 444 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, |
| 401 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, | 445 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, |
| 402 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, | 446 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, |
| 403 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE, | 447 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 414 const bool use_localhost_requests_; | 458 const bool use_localhost_requests_; |
| 415 | 459 |
| 416 // Determines if the responses smaller than |kMinTransferSizeInBytes| | 460 // Determines if the responses smaller than |kMinTransferSizeInBytes| |
| 417 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the | 461 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the |
| 418 // network quality. Set to true only for tests. | 462 // network quality. Set to true only for tests. |
| 419 const bool use_small_responses_; | 463 const bool use_small_responses_; |
| 420 | 464 |
| 421 // The factor by which the weight of an observation reduces every second. | 465 // The factor by which the weight of an observation reduces every second. |
| 422 const double weight_multiplier_per_second_; | 466 const double weight_multiplier_per_second_; |
| 423 | 467 |
| 468 // Tick clock used by network quality estimator. | |
|
bengr
2016/05/31 17:39:24
by -> by the
tbansal1
2016/05/31 21:40:25
Done.
| |
| 469 std::unique_ptr<base::TickClock> tick_clock_; | |
| 470 | |
| 471 // Minimum duration between two consecutive computations of effective | |
| 472 // connection type. | |
|
bengr
2016/05/31 17:39:25
Add "Non-zero as a performance optimization."
tbansal1
2016/05/31 21:40:25
Done.
| |
| 473 const base::TimeDelta effective_connection_type_recomputation_interval_; | |
| 474 | |
| 475 // Time when the effective connection type was last computed. | |
| 476 base::TimeTicks last_effective_connection_type_computation_; | |
| 477 | |
| 424 // Time when last connection change was observed. | 478 // Time when last connection change was observed. |
| 425 base::TimeTicks last_connection_change_; | 479 base::TimeTicks last_connection_change_; |
| 426 | 480 |
| 427 // ID of the current network. | 481 // ID of the current network. |
| 428 NetworkID current_network_id_; | 482 NetworkID current_network_id_; |
| 429 | 483 |
| 430 // Peak network quality (fastest round-trip-time (RTT) and highest | 484 // Peak network quality (fastest round-trip-time (RTT) and highest |
| 431 // downstream throughput) measured since last connectivity change. RTT is | 485 // downstream throughput) measured since last connectivity change. RTT is |
| 432 // measured from time the request is sent until the first byte received. | 486 // measured from time the request is sent until the first byte received. |
| 433 // The accuracy is decreased by ignoring these factors: | 487 // The accuracy is decreased by ignoring these factors: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 458 nqe::internal::NetworkQuality | 512 nqe::internal::NetworkQuality |
| 459 connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST]; | 513 connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST]; |
| 460 | 514 |
| 461 // Estimated network quality. Updated on mainframe requests. | 515 // Estimated network quality. Updated on mainframe requests. |
| 462 nqe::internal::NetworkQuality estimated_median_network_quality_; | 516 nqe::internal::NetworkQuality estimated_median_network_quality_; |
| 463 | 517 |
| 464 // ExternalEstimateProvider that provides network quality using operating | 518 // ExternalEstimateProvider that provides network quality using operating |
| 465 // system APIs. May be NULL. | 519 // system APIs. May be NULL. |
| 466 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; | 520 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; |
| 467 | 521 |
| 522 // Observer list for changes in effective connection type. | |
| 523 base::ObserverList<EffectiveConnectionTypeObserver> | |
| 524 effective_connection_type_observer_list_; | |
| 525 | |
| 468 // Observer lists for round trip times and throughput measurements. | 526 // Observer lists for round trip times and throughput measurements. |
| 469 base::ObserverList<RTTObserver> rtt_observer_list_; | 527 base::ObserverList<RTTObserver> rtt_observer_list_; |
| 470 base::ObserverList<ThroughputObserver> throughput_observer_list_; | 528 base::ObserverList<ThroughputObserver> throughput_observer_list_; |
| 471 | 529 |
| 472 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_; | 530 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_; |
| 473 | 531 |
| 474 // Takes throughput measurements, and passes them back to |this| through the | 532 // Takes throughput measurements, and passes them back to |this| through the |
| 475 // provided callback. |this| stores the throughput observations in | 533 // provided callback. |this| stores the throughput observations in |
| 476 // |downstream_throughput_kbps_observations_|, which are later used for | 534 // |downstream_throughput_kbps_observations_|, which are later used for |
| 477 // estimating the throughput. | 535 // estimating the throughput. |
| 478 std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_; | 536 std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_; |
| 479 | 537 |
| 538 // Current effective connection type. It is updated on connection change | |
| 539 // events. It is also updated every time there is network traffic (provided | |
| 540 // the last computation was more than | |
| 541 // |effective_connection_type_recomputation_interval_| ago). | |
| 542 EffectiveConnectionType effective_connection_type_; | |
| 543 | |
| 480 base::ThreadChecker thread_checker_; | 544 base::ThreadChecker thread_checker_; |
| 481 | 545 |
| 482 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 546 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
| 483 | 547 |
| 484 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 548 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
| 485 }; | 549 }; |
| 486 | 550 |
| 487 } // namespace net | 551 } // namespace net |
| 488 | 552 |
| 489 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 553 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |