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. | |
|
bengr
2016/05/27 19:46:01
What is the contract? The consumer will be notifie
tbansal1
2016/05/28 01:20:42
Done.
| |
| 81 class NET_EXPORT_PRIVATE EffectiveConnectionTypeObserver { | |
| 82 public: | |
| 83 // Will be called when the effective connection type changes. | |
| 84 virtual void OnEffectiveConnectionTypeChanged( | |
| 85 EffectiveConnectionType type) = 0; | |
| 86 | |
| 87 protected: | |
| 88 EffectiveConnectionTypeObserver() {} | |
| 89 virtual ~EffectiveConnectionTypeObserver() {} | |
| 90 | |
| 91 private: | |
| 92 DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver); | |
| 93 }; | |
| 94 | |
| 79 // Observes measurements of round trip time. | 95 // Observes measurements of round trip time. |
| 80 class NET_EXPORT_PRIVATE RTTObserver { | 96 class NET_EXPORT_PRIVATE RTTObserver { |
| 81 public: | 97 public: |
| 82 // Will be called when a new RTT observation is available. The round trip | 98 // 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 | 99 // time is specified in milliseconds. The time when the observation was |
| 84 // taken and the source of the observation are provided. | 100 // taken and the source of the observation are provided. |
| 85 virtual void OnRTTObservation(int32_t rtt_ms, | 101 virtual void OnRTTObservation(int32_t rtt_ms, |
| 86 const base::TimeTicks& timestamp, | 102 const base::TimeTicks& timestamp, |
| 87 NetworkQualityObservationSource source) = 0; | 103 NetworkQualityObservationSource source) = 0; |
| 88 | 104 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 const std::map<std::string, std::string>& variation_params, | 153 const std::map<std::string, std::string>& variation_params, |
| 138 bool use_local_host_requests_for_tests, | 154 bool use_local_host_requests_for_tests, |
| 139 bool use_smaller_responses_for_tests); | 155 bool use_smaller_responses_for_tests); |
| 140 | 156 |
| 141 ~NetworkQualityEstimator() override; | 157 ~NetworkQualityEstimator() override; |
| 142 | 158 |
| 143 // Returns the effective type of the current connection. Virtualized for | 159 // Returns the effective type of the current connection. Virtualized for |
| 144 // testing. | 160 // testing. |
| 145 virtual EffectiveConnectionType GetEffectiveConnectionType() const; | 161 virtual EffectiveConnectionType GetEffectiveConnectionType() const; |
| 146 | 162 |
| 163 // Adds |observer| to the list of effective connection type observers. Must be | |
| 164 // called on the IO thread. | |
| 165 void AddEffectiveConnectionTypeObserver( | |
| 166 EffectiveConnectionTypeObserver* observer); | |
| 167 | |
| 168 // Removes |observer| from the list of effective connection type observers. | |
| 169 // Must be called on the IO thread. | |
| 170 void RemoveEffectiveConnectionTypeObserver( | |
| 171 EffectiveConnectionTypeObserver* observer); | |
| 172 | |
| 147 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at | 173 // 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 | 174 // 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 | 175 // 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 | 176 // happens after the connection is established) to the time when the response |
| 151 // headers were received. | 177 // headers were received. |
| 152 virtual bool GetURLRequestRTTEstimate(base::TimeDelta* rtt) const | 178 virtual bool GetURLRequestRTTEstimate(base::TimeDelta* rtt) const |
| 153 WARN_UNUSED_RESULT; | 179 WARN_UNUSED_RESULT; |
| 154 | 180 |
| 155 // 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 |
| 156 // the transport layer. |rtt| should not be null. | 182 // the transport layer. |rtt| should not be null. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 void OnConnectionTypeChanged( | 290 void OnConnectionTypeChanged( |
| 265 NetworkChangeNotifier::ConnectionType type) override; | 291 NetworkChangeNotifier::ConnectionType type) override; |
| 266 | 292 |
| 267 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. | 293 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. |
| 268 void OnUpdatedEstimateAvailable() override; | 294 void OnUpdatedEstimateAvailable() override; |
| 269 | 295 |
| 270 // Return a string equivalent to |type|. | 296 // Return a string equivalent to |type|. |
| 271 const char* GetNameForEffectiveConnectionType( | 297 const char* GetNameForEffectiveConnectionType( |
| 272 EffectiveConnectionType type) const; | 298 EffectiveConnectionType type) const; |
| 273 | 299 |
| 300 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); | |
|
bengr
2016/05/27 19:46:02
Add a comment.
tbansal1
2016/05/28 01:20:42
Done.
| |
| 301 | |
| 274 private: | 302 private: |
| 275 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 303 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
| 276 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 304 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
| 277 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 305 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
| 278 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 306 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
| 279 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); | 307 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); |
| 280 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); | 308 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); |
| 281 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 309 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 282 TestLRUCacheMaximumSize); | 310 TestLRUCacheMaximumSize); |
| 283 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMedianRTTSince); | 311 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMedianRTTSince); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 | 412 |
| 385 void NotifyObserversOfThroughput(const ThroughputObservation& observation); | 413 void NotifyObserversOfThroughput(const ThroughputObservation& observation); |
| 386 | 414 |
| 387 // Records the UMA related to the RTT at the URLRequest layer. | 415 // Records the UMA related to the RTT at the URLRequest layer. |
| 388 void RecordURLRequestRTTUMA(int32_t estimated_value_msec, | 416 void RecordURLRequestRTTUMA(int32_t estimated_value_msec, |
| 389 int32_t actual_value_msec) const; | 417 int32_t actual_value_msec) const; |
| 390 | 418 |
| 391 // Returns true only if the |request| can be used for RTT estimation. | 419 // Returns true only if the |request| can be used for RTT estimation. |
| 392 bool RequestProvidesRTTObservation(const URLRequest& request) const; | 420 bool RequestProvidesRTTObservation(const URLRequest& request) const; |
| 393 | 421 |
| 422 void MaybeRecomputeEffectiveConnectionType(); | |
|
bengr
2016/05/27 19:46:02
Add a comment.
tbansal1
2016/05/28 01:20:42
Done.
| |
| 423 | |
| 424 void NotifyObserversOfEffectiveConnectionTypeChanged(); | |
|
bengr
2016/05/27 19:46:02
Add a comment.
tbansal1
2016/05/28 01:20:42
Done.
| |
| 425 | |
| 394 // Values of external estimate provider status. This enum must remain | 426 // Values of external estimate provider status. This enum must remain |
| 395 // synchronized with the enum of the same name in | 427 // synchronized with the enum of the same name in |
| 396 // metrics/histograms/histograms.xml. | 428 // metrics/histograms/histograms.xml. |
| 397 enum NQEExternalEstimateProviderStatus { | 429 enum NQEExternalEstimateProviderStatus { |
| 398 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, | 430 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, |
| 399 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, | 431 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, |
| 400 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, | 432 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, |
| 401 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, | 433 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, |
| 402 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, | 434 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, |
| 403 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE, | 435 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 414 const bool use_localhost_requests_; | 446 const bool use_localhost_requests_; |
| 415 | 447 |
| 416 // Determines if the responses smaller than |kMinTransferSizeInBytes| | 448 // Determines if the responses smaller than |kMinTransferSizeInBytes| |
| 417 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the | 449 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the |
| 418 // network quality. Set to true only for tests. | 450 // network quality. Set to true only for tests. |
| 419 const bool use_small_responses_; | 451 const bool use_small_responses_; |
| 420 | 452 |
| 421 // The factor by which the weight of an observation reduces every second. | 453 // The factor by which the weight of an observation reduces every second. |
| 422 const double weight_multiplier_per_second_; | 454 const double weight_multiplier_per_second_; |
| 423 | 455 |
| 456 std::unique_ptr<base::TickClock> tick_clock_; | |
|
bengr
2016/05/27 19:46:01
Add a comment.
tbansal1
2016/05/28 01:20:42
Done, but this one seems pretty self-explanatory.
| |
| 457 | |
| 458 // Minimum duration between two consecutive computations of effective | |
| 459 // connection type. | |
| 460 const base::TimeDelta effective_connection_type_recomputation_interval_; | |
|
bengr
2016/05/27 19:46:02
Is this for hysteresis or performance or both?
tbansal1
2016/05/28 01:20:42
Performance. Hysteresis means we notify observers
| |
| 461 | |
| 424 // Time when last connection change was observed. | 462 // Time when last connection change was observed. |
| 425 base::TimeTicks last_connection_change_; | 463 base::TimeTicks last_connection_change_; |
| 426 | 464 |
| 427 // ID of the current network. | 465 // ID of the current network. |
| 428 NetworkID current_network_id_; | 466 NetworkID current_network_id_; |
| 429 | 467 |
| 430 // Peak network quality (fastest round-trip-time (RTT) and highest | 468 // Peak network quality (fastest round-trip-time (RTT) and highest |
| 431 // downstream throughput) measured since last connectivity change. RTT is | 469 // downstream throughput) measured since last connectivity change. RTT is |
| 432 // measured from time the request is sent until the first byte received. | 470 // measured from time the request is sent until the first byte received. |
| 433 // The accuracy is decreased by ignoring these factors: | 471 // The accuracy is decreased by ignoring these factors: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 458 nqe::internal::NetworkQuality | 496 nqe::internal::NetworkQuality |
| 459 connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST]; | 497 connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST]; |
| 460 | 498 |
| 461 // Estimated network quality. Updated on mainframe requests. | 499 // Estimated network quality. Updated on mainframe requests. |
| 462 nqe::internal::NetworkQuality estimated_median_network_quality_; | 500 nqe::internal::NetworkQuality estimated_median_network_quality_; |
| 463 | 501 |
| 464 // ExternalEstimateProvider that provides network quality using operating | 502 // ExternalEstimateProvider that provides network quality using operating |
| 465 // system APIs. May be NULL. | 503 // system APIs. May be NULL. |
| 466 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; | 504 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; |
| 467 | 505 |
| 506 // Observer list for changes in effective connection type. | |
| 507 base::ObserverList<EffectiveConnectionTypeObserver> | |
| 508 effective_connection_type_observer_list_; | |
| 509 | |
| 468 // Observer lists for round trip times and throughput measurements. | 510 // Observer lists for round trip times and throughput measurements. |
| 469 base::ObserverList<RTTObserver> rtt_observer_list_; | 511 base::ObserverList<RTTObserver> rtt_observer_list_; |
| 470 base::ObserverList<ThroughputObserver> throughput_observer_list_; | 512 base::ObserverList<ThroughputObserver> throughput_observer_list_; |
| 471 | 513 |
| 472 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_; | 514 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_; |
| 473 | 515 |
| 474 // Takes throughput measurements, and passes them back to |this| through the | 516 // Takes throughput measurements, and passes them back to |this| through the |
| 475 // provided callback. |this| stores the throughput observations in | 517 // provided callback. |this| stores the throughput observations in |
| 476 // |downstream_throughput_kbps_observations_|, which are later used for | 518 // |downstream_throughput_kbps_observations_|, which are later used for |
| 477 // estimating the throughput. | 519 // estimating the throughput. |
| 478 std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_; | 520 std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_; |
| 479 | 521 |
| 522 // Time when the effective connection type was last computed. | |
| 523 base::TimeTicks last_effective_connection_type_computation_; | |
|
bengr
2016/05/27 19:46:01
Should this be listed together with line 460?
tbansal1
2016/05/28 01:20:42
Done.
| |
| 524 | |
| 525 // Current effective connection type. It is updated on connection change | |
| 526 // events. It is also updated every time there is network traffic (provided | |
| 527 // the last computation was more than | |
| 528 // |effective_connection_type_recomputation_interval_| ago). | |
| 529 EffectiveConnectionType effective_connection_type_; | |
| 530 | |
| 480 base::ThreadChecker thread_checker_; | 531 base::ThreadChecker thread_checker_; |
| 481 | 532 |
| 482 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 533 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
| 483 | 534 |
| 484 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 535 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
| 485 }; | 536 }; |
| 486 | 537 |
| 487 } // namespace net | 538 } // namespace net |
| 488 | 539 |
| 489 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 540 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |