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_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 30 matching lines...) Expand all Loading... | |
| 41 // related to NetworkQualityEstimator field trial. | 41 // related to NetworkQualityEstimator field trial. |
| 42 // |external_estimates_provider| may be NULL. | 42 // |external_estimates_provider| may be NULL. |
| 43 NetworkQualityEstimator( | 43 NetworkQualityEstimator( |
| 44 scoped_ptr<ExternalEstimateProvider> external_estimates_provider, | 44 scoped_ptr<ExternalEstimateProvider> external_estimates_provider, |
| 45 const std::map<std::string, std::string>& variation_params); | 45 const std::map<std::string, std::string>& variation_params); |
| 46 | 46 |
| 47 ~NetworkQualityEstimator() override; | 47 ~NetworkQualityEstimator() override; |
| 48 | 48 |
| 49 // Returns true if RTT is available and sets |rtt| to estimated RTT. | 49 // Returns true if RTT is available and sets |rtt| to estimated RTT. |
| 50 // Virtualized for testing. |rtt| should not be null. | 50 // Virtualized for testing. |rtt| should not be null. |
| 51 virtual bool GetRTTEstimate(base::TimeDelta* rtt) const; | 51 virtual bool GetRTTEstimate(base::TimeDelta* rtt); |
| 52 | 52 |
| 53 // Returns true if downlink throughput is available and sets |kbps| to | 53 // Returns true if downlink throughput is available and sets |kbps| to |
| 54 // estimated downlink throughput (in Kilobits per second). | 54 // estimated downlink throughput (in Kilobits per second). |
| 55 // Virtualized for testing. |kbps| should not be null. | 55 // Virtualized for testing. |kbps| should not be null. |
| 56 virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const; | 56 virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps); |
| 57 | 57 |
| 58 // Notifies NetworkQualityEstimator that the response header of |request| has | 58 // Notifies NetworkQualityEstimator that the response header of |request| has |
| 59 // been received. | 59 // been received. |
| 60 void NotifyHeadersReceived(const URLRequest& request); | 60 void NotifyHeadersReceived(const URLRequest& request); |
| 61 | 61 |
| 62 // Notifies NetworkQualityEstimator that the response body of |request| has | 62 // Notifies NetworkQualityEstimator that the response body of |request| has |
| 63 // been received. | 63 // been received. |
| 64 void NotifyRequestCompleted(const URLRequest& request); | 64 void NotifyRequestCompleted(const URLRequest& request); |
| 65 | 65 |
| 66 // Returns true if median RTT is available and sets |rtt| to the median of | 66 // Returns true if median RTT is available and sets |rtt| to the median of |
| 67 // RTT observations since |begin_timestamp|. | 67 // RTT observations since |begin_timestamp|. |
| 68 // Virtualized for testing. |rtt| should not be null. | 68 // Virtualized for testing. |rtt| should not be null. |
| 69 virtual bool GetRecentMedianRTT(const base::TimeTicks& begin_timestamp, | 69 virtual bool GetRecentMedianRTT(const base::TimeTicks& begin_timestamp, |
| 70 base::TimeDelta* rtt) const; | 70 base::TimeDelta* rtt); |
| 71 | 71 |
| 72 // Returns true if median downstream throughput is available and sets |kbps| | 72 // Returns true if median downstream throughput is available and sets |kbps| |
| 73 // to the median of downstream Kbps observations since |begin_timestamp|. | 73 // to the median of downstream Kbps observations since |begin_timestamp|. |
| 74 // Virtualized for testing. |kbps| should not be null. | 74 // Virtualized for testing. |kbps| should not be null. |
| 75 virtual bool GetRecentMedianDownlinkThroughputKbps( | 75 virtual bool GetRecentMedianDownlinkThroughputKbps( |
| 76 const base::TimeTicks& begin_timestamp, | 76 const base::TimeTicks& begin_timestamp, |
| 77 int32_t* kbps) const; | 77 int32_t* kbps); |
| 78 | 78 |
| 79 protected: | 79 protected: |
| 80 // NetworkID is used to uniquely identify a network. | 80 // NetworkID is used to uniquely identify a network. |
| 81 // For the purpose of network quality estimation and caching, a network is | 81 // For the purpose of network quality estimation and caching, a network is |
| 82 // uniquely identified by a combination of |type| and | 82 // uniquely identified by a combination of |type| and |
| 83 // |id|. This approach is unable to distinguish networks with | 83 // |id|. This approach is unable to distinguish networks with |
| 84 // same name (e.g., different Wi-Fi networks with same SSID). | 84 // same name (e.g., different Wi-Fi networks with same SSID). |
| 85 // This is a protected member to expose it to tests. | 85 // This is a protected member to expose it to tests. |
| 86 struct NET_EXPORT_PRIVATE NetworkID { | 86 struct NET_EXPORT_PRIVATE NetworkID { |
| 87 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) | 87 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 bool allow_local_host_requests_for_tests, | 133 bool allow_local_host_requests_for_tests, |
| 134 bool allow_smaller_responses_for_tests); | 134 bool allow_smaller_responses_for_tests); |
| 135 | 135 |
| 136 // Returns true if the cached network quality estimate was successfully read. | 136 // Returns true if the cached network quality estimate was successfully read. |
| 137 bool ReadCachedNetworkQualityEstimate(); | 137 bool ReadCachedNetworkQualityEstimate(); |
| 138 | 138 |
| 139 // NetworkChangeNotifier::ConnectionTypeObserver implementation. | 139 // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| 140 void OnConnectionTypeChanged( | 140 void OnConnectionTypeChanged( |
| 141 NetworkChangeNotifier::ConnectionType type) override; | 141 NetworkChangeNotifier::ConnectionType type) override; |
| 142 | 142 |
| 143 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. | |
| 144 void OnUpdatedEstimateAvailable() override; | |
| 145 | |
| 143 private: | 146 private: |
| 144 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 147 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
| 145 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); | 148 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); |
| 146 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 149 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
| 147 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 150 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
| 148 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 151 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
| 149 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); | 152 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); |
| 150 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 153 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 151 PercentileSameTimestamps); | 154 PercentileSameTimestamps); |
| 152 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 155 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 static const int kMinimumThroughputVariationParameterKbps = 1; | 339 static const int kMinimumThroughputVariationParameterKbps = 1; |
| 337 | 340 |
| 338 // Maximum size of the cache that holds network quality estimates. | 341 // Maximum size of the cache that holds network quality estimates. |
| 339 // Smaller size may reduce the cache hit rate due to frequent evictions. | 342 // Smaller size may reduce the cache hit rate due to frequent evictions. |
| 340 // Larger size may affect performance. | 343 // Larger size may affect performance. |
| 341 static const size_t kMaximumNetworkQualityCacheSize = 10; | 344 static const size_t kMaximumNetworkQualityCacheSize = 10; |
| 342 | 345 |
| 343 // Maximum number of observations that can be held in the ObservationBuffer. | 346 // Maximum number of observations that can be held in the ObservationBuffer. |
| 344 static const size_t kMaximumObservationsBufferSize = 300; | 347 static const size_t kMaximumObservationsBufferSize = 300; |
| 345 | 348 |
| 349 // Minimum time duration (in milliseconds) between consecutive queries to | |
| 350 // external estimate provider. | |
| 351 static const int kExternalEstimateProviderQueryIntervalMsec = 5 * 60 * 1000; | |
| 352 | |
| 346 // Returns the RTT value to be used when the valid RTT is unavailable. Readers | 353 // Returns the RTT value to be used when the valid RTT is unavailable. Readers |
| 347 // should discard RTT if it is set to the value returned by |InvalidRTT()|. | 354 // should discard RTT if it is set to the value returned by |InvalidRTT()|. |
| 348 static const base::TimeDelta InvalidRTT(); | 355 static const base::TimeDelta InvalidRTT(); |
| 349 | 356 |
| 350 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. | 357 // May call |QueryExternalEstimateProvider| if the most recent call to |
| 351 void OnUpdatedEstimateAvailable() override; | 358 // external estimate provider was more than |
| 359 // |kExternalEstimateProviderQueryIntervalMsec| back. | |
| 360 void MaybeQueryExternalEstimateProvider(); | |
| 361 | |
| 362 // Queries the external estimate provider for the latest network quality | |
| 363 // estimates, and adds those estimates to the current observation buffer. | |
| 364 void QueryExternalEstimateProvider(); | |
| 352 | 365 |
| 353 // Obtains operating parameters from the field trial parameters. | 366 // Obtains operating parameters from the field trial parameters. |
| 354 void ObtainOperatingParams( | 367 void ObtainOperatingParams( |
| 355 const std::map<std::string, std::string>& variation_params); | 368 const std::map<std::string, std::string>& variation_params); |
| 356 | 369 |
| 357 // Adds the default median RTT and downstream throughput estimate for the | 370 // Adds the default median RTT and downstream throughput estimate for the |
| 358 // current connection type to the observation buffer. | 371 // current connection type to the observation buffer. |
| 359 void AddDefaultEstimates(); | 372 void AddDefaultEstimates(); |
| 360 | 373 |
| 361 // Returns an estimate of network quality at the specified |percentile|. | 374 // Returns an estimate of network quality at the specified |percentile|. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 // estimator field trial parameters. The observations are indexed by | 436 // estimator field trial parameters. The observations are indexed by |
| 424 // ConnectionType. | 437 // ConnectionType. |
| 425 NetworkQuality | 438 NetworkQuality |
| 426 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; | 439 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; |
| 427 | 440 |
| 428 // Estimated network quality. Updated on mainframe requests. | 441 // Estimated network quality. Updated on mainframe requests. |
| 429 NetworkQuality estimated_median_network_quality_; | 442 NetworkQuality estimated_median_network_quality_; |
| 430 | 443 |
| 431 // ExternalEstimateProvider that provides network quality using operating | 444 // ExternalEstimateProvider that provides network quality using operating |
| 432 // system APIs. May be NULL. | 445 // system APIs. May be NULL. |
| 433 const scoped_ptr<ExternalEstimateProvider> external_estimates_provider_; | 446 const scoped_ptr<ExternalEstimateProvider> external_estimate_provider_; |
| 447 | |
| 448 // Time when the external estimate provider was last queried. | |
| 449 base::TimeTicks external_estimate_request_time_; | |
| 450 | |
| 451 // Values of external estimate provider status. | |
|
bengr
2015/09/08 18:14:23
Move the next line up and fill out to 80 character
tbansal1
2015/09/08 21:25:55
Done.
| |
| 452 // This enum must remain synchronized with the enum of the same name in | |
| 453 // metrics/histograms/histograms.xml. | |
| 454 enum NQEExternalEstimateProviderStatus { | |
| 455 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, | |
| 456 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, | |
| 457 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, | |
| 458 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, | |
| 459 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, | |
| 460 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY | |
| 461 }; | |
| 434 | 462 |
| 435 base::ThreadChecker thread_checker_; | 463 base::ThreadChecker thread_checker_; |
| 436 | 464 |
| 437 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 465 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
| 438 }; | 466 }; |
| 439 | 467 |
| 440 } // namespace net | 468 } // namespace net |
| 441 | 469 |
| 442 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ | 470 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |