| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 bool allow_local_host_requests_for_tests, | 142 bool allow_local_host_requests_for_tests, |
| 143 bool allow_smaller_responses_for_tests); | 143 bool allow_smaller_responses_for_tests); |
| 144 | 144 |
| 145 // Returns true if the cached network quality estimate was successfully read. | 145 // Returns true if the cached network quality estimate was successfully read. |
| 146 bool ReadCachedNetworkQualityEstimate(); | 146 bool ReadCachedNetworkQualityEstimate(); |
| 147 | 147 |
| 148 // NetworkChangeNotifier::ConnectionTypeObserver implementation: | 148 // NetworkChangeNotifier::ConnectionTypeObserver implementation: |
| 149 void OnConnectionTypeChanged( | 149 void OnConnectionTypeChanged( |
| 150 NetworkChangeNotifier::ConnectionType type) override; | 150 NetworkChangeNotifier::ConnectionType type) override; |
| 151 | 151 |
| 152 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. | |
| 153 void OnUpdatedEstimateAvailable() override; | |
| 154 | |
| 155 private: | 152 private: |
| 156 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 153 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
| 157 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); | 154 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); |
| 158 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 155 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
| 159 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 156 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
| 160 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 157 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
| 161 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); | 158 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); |
| 162 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 159 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 163 PercentileSameTimestamps); | 160 PercentileSameTimestamps); |
| 164 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 161 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 165 PercentileDifferentTimestamps); | 162 PercentileDifferentTimestamps); |
| 166 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); | 163 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); |
| 167 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); | 164 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); |
| 168 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 165 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 169 TestLRUCacheMaximumSize); | 166 TestLRUCacheMaximumSize); |
| 170 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMedianRTTSince); | 167 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMedianRTTSince); |
| 171 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | |
| 172 TestExternalEstimateProvider); | |
| 173 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | |
| 174 TestExternalEstimateProviderMergeEstimates); | |
| 175 | 168 |
| 176 // NetworkQuality is used to cache the quality of a network connection. | 169 // NetworkQuality is used to cache the quality of a network connection. |
| 177 class NET_EXPORT_PRIVATE NetworkQuality { | 170 class NET_EXPORT_PRIVATE NetworkQuality { |
| 178 public: | 171 public: |
| 179 NetworkQuality(); | 172 NetworkQuality(); |
| 180 // |rtt| is the estimate of the round trip time. | 173 // |rtt| is the estimate of the round trip time. |
| 181 // |downstream_throughput_kbps| is the estimate of the downstream | 174 // |downstream_throughput_kbps| is the estimate of the downstream |
| 182 // throughput. | 175 // throughput. |
| 183 NetworkQuality(const base::TimeDelta& rtt, | 176 NetworkQuality(const base::TimeDelta& rtt, |
| 184 int32_t downstream_throughput_kbps); | 177 int32_t downstream_throughput_kbps); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 static const int kMinimumThroughputVariationParameterKbps = 1; | 345 static const int kMinimumThroughputVariationParameterKbps = 1; |
| 353 | 346 |
| 354 // Maximum size of the cache that holds network quality estimates. | 347 // Maximum size of the cache that holds network quality estimates. |
| 355 // Smaller size may reduce the cache hit rate due to frequent evictions. | 348 // Smaller size may reduce the cache hit rate due to frequent evictions. |
| 356 // Larger size may affect performance. | 349 // Larger size may affect performance. |
| 357 static const size_t kMaximumNetworkQualityCacheSize = 10; | 350 static const size_t kMaximumNetworkQualityCacheSize = 10; |
| 358 | 351 |
| 359 // Maximum number of observations that can be held in the ObservationBuffer. | 352 // Maximum number of observations that can be held in the ObservationBuffer. |
| 360 static const size_t kMaximumObservationsBufferSize = 300; | 353 static const size_t kMaximumObservationsBufferSize = 300; |
| 361 | 354 |
| 362 // Time duration (in milliseconds) after which the estimate provided by | |
| 363 // external estimate provider is considered stale. | |
| 364 static const int kExternalEstimateProviderFreshnessDurationMsec = | |
| 365 5 * 60 * 1000; | |
| 366 | |
| 367 // Returns the RTT value to be used when the valid RTT is unavailable. Readers | 355 // Returns the RTT value to be used when the valid RTT is unavailable. Readers |
| 368 // should discard RTT if it is set to the value returned by |InvalidRTT()|. | 356 // should discard RTT if it is set to the value returned by |InvalidRTT()|. |
| 369 static const base::TimeDelta InvalidRTT(); | 357 static const base::TimeDelta InvalidRTT(); |
| 370 | 358 |
| 371 // Queries the external estimate provider for the latest network quality | 359 // ExternalEstimateProvider::UpdatedEstimateObserver implementation: |
| 372 // estimates, and adds those estimates to the current observation buffer. | 360 void OnUpdatedEstimateAvailable() override; |
| 373 void QueryExternalEstimateProvider(); | |
| 374 | 361 |
| 375 // Obtains operating parameters from the field trial parameters. | 362 // Obtains operating parameters from the field trial parameters. |
| 376 void ObtainOperatingParams( | 363 void ObtainOperatingParams( |
| 377 const std::map<std::string, std::string>& variation_params); | 364 const std::map<std::string, std::string>& variation_params); |
| 378 | 365 |
| 379 // Adds the default median RTT and downstream throughput estimate for the | 366 // Adds the default median RTT and downstream throughput estimate for the |
| 380 // current connection type to the observation buffer. | 367 // current connection type to the observation buffer. |
| 381 void AddDefaultEstimates(); | 368 void AddDefaultEstimates(); |
| 382 | 369 |
| 383 // Returns an estimate of network quality at the specified |percentile|. | 370 // Returns an estimate of network quality at the specified |percentile|. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 402 | 389 |
| 403 // Records the UMA related to RTT. | 390 // Records the UMA related to RTT. |
| 404 void RecordRTTUMA(int32_t estimated_value_msec, | 391 void RecordRTTUMA(int32_t estimated_value_msec, |
| 405 int32_t actual_value_msec) const; | 392 int32_t actual_value_msec) const; |
| 406 | 393 |
| 407 // Returns true only if |request| can be used for network quality estimation. | 394 // Returns true only if |request| can be used for network quality estimation. |
| 408 // Only the requests that go over network are considered to provide useful | 395 // Only the requests that go over network are considered to provide useful |
| 409 // observations. | 396 // observations. |
| 410 bool RequestProvidesUsefulObservations(const URLRequest& request) const; | 397 bool RequestProvidesUsefulObservations(const URLRequest& request) const; |
| 411 | 398 |
| 412 // Values of external estimate provider status. This enum must remain | |
| 413 // synchronized with the enum of the same name in | |
| 414 // metrics/histograms/histograms.xml. | |
| 415 enum NQEExternalEstimateProviderStatus { | |
| 416 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, | |
| 417 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, | |
| 418 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, | |
| 419 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, | |
| 420 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, | |
| 421 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY | |
| 422 }; | |
| 423 | |
| 424 // Records the metrics related to external estimate provider. | |
| 425 void RecordExternalEstimateProviderMetrics( | |
| 426 NQEExternalEstimateProviderStatus status) const; | |
| 427 | |
| 428 // Determines if the requests to local host can be used in estimating the | 399 // Determines if the requests to local host can be used in estimating the |
| 429 // network quality. Set to true only for tests. | 400 // network quality. Set to true only for tests. |
| 430 const bool allow_localhost_requests_; | 401 const bool allow_localhost_requests_; |
| 431 | 402 |
| 432 // Determines if the responses smaller than |kMinTransferSizeInBytes| | 403 // Determines if the responses smaller than |kMinTransferSizeInBytes| |
| 433 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the | 404 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the |
| 434 // network quality. Set to true only for tests. | 405 // network quality. Set to true only for tests. |
| 435 const bool allow_small_responses_; | 406 const bool allow_small_responses_; |
| 436 | 407 |
| 437 // Time when last connection change was observed. | 408 // Time when last connection change was observed. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 461 // estimator field trial parameters. The observations are indexed by | 432 // estimator field trial parameters. The observations are indexed by |
| 462 // ConnectionType. | 433 // ConnectionType. |
| 463 NetworkQuality | 434 NetworkQuality |
| 464 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; | 435 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; |
| 465 | 436 |
| 466 // Estimated network quality. Updated on mainframe requests. | 437 // Estimated network quality. Updated on mainframe requests. |
| 467 NetworkQuality estimated_median_network_quality_; | 438 NetworkQuality estimated_median_network_quality_; |
| 468 | 439 |
| 469 // ExternalEstimateProvider that provides network quality using operating | 440 // ExternalEstimateProvider that provides network quality using operating |
| 470 // system APIs. May be NULL. | 441 // system APIs. May be NULL. |
| 471 const scoped_ptr<ExternalEstimateProvider> external_estimate_provider_; | 442 const scoped_ptr<ExternalEstimateProvider> external_estimates_provider_; |
| 472 | 443 |
| 473 base::ThreadChecker thread_checker_; | 444 base::ThreadChecker thread_checker_; |
| 474 | 445 |
| 475 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 446 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
| 476 }; | 447 }; |
| 477 | 448 |
| 478 } // namespace net | 449 } // namespace net |
| 479 | 450 |
| 480 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ | 451 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |