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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // related to NetworkQualityEstimator field trial. | 44 // related to NetworkQualityEstimator field trial. |
45 // |external_estimates_provider| may be NULL. | 45 // |external_estimates_provider| may be NULL. |
46 NetworkQualityEstimator( | 46 NetworkQualityEstimator( |
47 scoped_ptr<ExternalEstimateProvider> external_estimates_provider, | 47 scoped_ptr<ExternalEstimateProvider> external_estimates_provider, |
48 const std::map<std::string, std::string>& variation_params); | 48 const std::map<std::string, std::string>& variation_params); |
49 | 49 |
50 ~NetworkQualityEstimator() override; | 50 ~NetworkQualityEstimator() override; |
51 | 51 |
52 // Returns true if RTT is available and sets |rtt| to estimated RTT. | 52 // Returns true if RTT is available and sets |rtt| to estimated RTT. |
53 // Virtualized for testing. |rtt| should not be null. | 53 // Virtualized for testing. |rtt| should not be null. |
54 virtual bool GetRTTEstimate(base::TimeDelta* rtt) const; | 54 virtual bool GetRTTEstimate(base::TimeDelta* rtt); |
55 | 55 |
56 // Returns true if downlink throughput is available and sets |kbps| to | 56 // Returns true if downlink throughput is available and sets |kbps| to |
57 // estimated downlink throughput (in Kilobits per second). | 57 // estimated downlink throughput (in Kilobits per second). |
58 // Virtualized for testing. |kbps| should not be null. | 58 // Virtualized for testing. |kbps| should not be null. |
59 virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const; | 59 virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps); |
60 | 60 |
61 // Notifies NetworkQualityEstimator that the response header of |request| has | 61 // Notifies NetworkQualityEstimator that the response header of |request| has |
62 // been received. | 62 // been received. |
63 void NotifyHeadersReceived(const URLRequest& request); | 63 void NotifyHeadersReceived(const URLRequest& request); |
64 | 64 |
65 // Notifies NetworkQualityEstimator that the response body of |request| has | 65 // Notifies NetworkQualityEstimator that the response body of |request| has |
66 // been received. | 66 // been received. |
67 void NotifyRequestCompleted(const URLRequest& request); | 67 void NotifyRequestCompleted(const URLRequest& request); |
68 | 68 |
69 // Returns true if median RTT is available and sets |rtt| to the median of | 69 // Returns true if median RTT is available and sets |rtt| to the median of |
70 // RTT observations since |begin_timestamp|. | 70 // RTT observations since |begin_timestamp|. |
71 // Virtualized for testing. |rtt| should not be null. | 71 // Virtualized for testing. |rtt| should not be null. |
72 virtual bool GetRecentMedianRTT(const base::TimeTicks& begin_timestamp, | 72 virtual bool GetRecentMedianRTT(const base::TimeTicks& begin_timestamp, |
73 base::TimeDelta* rtt) const; | 73 base::TimeDelta* rtt); |
74 | 74 |
75 // Returns true if median downstream throughput is available and sets |kbps| | 75 // Returns true if median downstream throughput is available and sets |kbps| |
76 // to the median of downstream Kbps observations since |begin_timestamp|. | 76 // to the median of downstream Kbps observations since |begin_timestamp|. |
77 // Virtualized for testing. |kbps| should not be null. | 77 // Virtualized for testing. |kbps| should not be null. |
78 virtual bool GetRecentMedianDownlinkThroughputKbps( | 78 virtual bool GetRecentMedianDownlinkThroughputKbps( |
79 const base::TimeTicks& begin_timestamp, | 79 const base::TimeTicks& begin_timestamp, |
80 int32_t* kbps) const; | 80 int32_t* kbps); |
81 | 81 |
82 // SocketPerformanceWatcherFactory implementation: | 82 // SocketPerformanceWatcherFactory implementation: |
83 scoped_ptr<SocketPerformanceWatcher> CreateTCPSocketPerformanceWatcher() | 83 scoped_ptr<SocketPerformanceWatcher> CreateTCPSocketPerformanceWatcher() |
84 const override; | 84 const override; |
85 scoped_ptr<SocketPerformanceWatcher> CreateUDPSocketPerformanceWatcher() | 85 scoped_ptr<SocketPerformanceWatcher> CreateUDPSocketPerformanceWatcher() |
86 const override; | 86 const override; |
87 | 87 |
88 protected: | 88 protected: |
89 // NetworkID is used to uniquely identify a network. | 89 // NetworkID is used to uniquely identify a network. |
90 // For the purpose of network quality estimation and caching, a network is | 90 // For the purpose of network quality estimation and caching, a network is |
(...skipping 51 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 |
152 private: | 155 private: |
153 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 156 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
154 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); | 157 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); |
155 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 158 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
156 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 159 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
157 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 160 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
158 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); | 161 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); |
159 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 162 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
160 PercentileSameTimestamps); | 163 PercentileSameTimestamps); |
161 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 164 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 static const int kMinimumThroughputVariationParameterKbps = 1; | 348 static const int kMinimumThroughputVariationParameterKbps = 1; |
346 | 349 |
347 // Maximum size of the cache that holds network quality estimates. | 350 // Maximum size of the cache that holds network quality estimates. |
348 // Smaller size may reduce the cache hit rate due to frequent evictions. | 351 // Smaller size may reduce the cache hit rate due to frequent evictions. |
349 // Larger size may affect performance. | 352 // Larger size may affect performance. |
350 static const size_t kMaximumNetworkQualityCacheSize = 10; | 353 static const size_t kMaximumNetworkQualityCacheSize = 10; |
351 | 354 |
352 // Maximum number of observations that can be held in the ObservationBuffer. | 355 // Maximum number of observations that can be held in the ObservationBuffer. |
353 static const size_t kMaximumObservationsBufferSize = 300; | 356 static const size_t kMaximumObservationsBufferSize = 300; |
354 | 357 |
| 358 // Minimum time duration (in milliseconds) between consecutive queries to |
| 359 // external estimate provider. |
| 360 static const int kExternalEstimateProviderQueryIntervalMsec = 5 * 60 * 1000; |
| 361 |
355 // Returns the RTT value to be used when the valid RTT is unavailable. Readers | 362 // Returns the RTT value to be used when the valid RTT is unavailable. Readers |
356 // should discard RTT if it is set to the value returned by |InvalidRTT()|. | 363 // should discard RTT if it is set to the value returned by |InvalidRTT()|. |
357 static const base::TimeDelta InvalidRTT(); | 364 static const base::TimeDelta InvalidRTT(); |
358 | 365 |
359 // ExternalEstimateProvider::UpdatedEstimateObserver implementation: | 366 // May call |QueryExternalEstimateProvider| if the most recent call to |
360 void OnUpdatedEstimateAvailable() override; | 367 // external estimate provider was more than |
| 368 // |kExternalEstimateProviderQueryIntervalMsec| back. |
| 369 void MaybeQueryExternalEstimateProvider(); |
| 370 |
| 371 // Queries the external estimate provider for the latest network quality |
| 372 // estimates, and adds those estimates to the current observation buffer. |
| 373 void QueryExternalEstimateProvider(); |
361 | 374 |
362 // Obtains operating parameters from the field trial parameters. | 375 // Obtains operating parameters from the field trial parameters. |
363 void ObtainOperatingParams( | 376 void ObtainOperatingParams( |
364 const std::map<std::string, std::string>& variation_params); | 377 const std::map<std::string, std::string>& variation_params); |
365 | 378 |
366 // Adds the default median RTT and downstream throughput estimate for the | 379 // Adds the default median RTT and downstream throughput estimate for the |
367 // current connection type to the observation buffer. | 380 // current connection type to the observation buffer. |
368 void AddDefaultEstimates(); | 381 void AddDefaultEstimates(); |
369 | 382 |
370 // Returns an estimate of network quality at the specified |percentile|. | 383 // Returns an estimate of network quality at the specified |percentile|. |
(...skipping 18 matching lines...) Expand all Loading... |
389 | 402 |
390 // Records the UMA related to RTT. | 403 // Records the UMA related to RTT. |
391 void RecordRTTUMA(int32_t estimated_value_msec, | 404 void RecordRTTUMA(int32_t estimated_value_msec, |
392 int32_t actual_value_msec) const; | 405 int32_t actual_value_msec) const; |
393 | 406 |
394 // Returns true only if |request| can be used for network quality estimation. | 407 // Returns true only if |request| can be used for network quality estimation. |
395 // Only the requests that go over network are considered to provide useful | 408 // Only the requests that go over network are considered to provide useful |
396 // observations. | 409 // observations. |
397 bool RequestProvidesUsefulObservations(const URLRequest& request) const; | 410 bool RequestProvidesUsefulObservations(const URLRequest& request) const; |
398 | 411 |
| 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 |
399 // Determines if the requests to local host can be used in estimating the | 428 // Determines if the requests to local host can be used in estimating the |
400 // network quality. Set to true only for tests. | 429 // network quality. Set to true only for tests. |
401 const bool allow_localhost_requests_; | 430 const bool allow_localhost_requests_; |
402 | 431 |
403 // Determines if the responses smaller than |kMinTransferSizeInBytes| | 432 // Determines if the responses smaller than |kMinTransferSizeInBytes| |
404 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the | 433 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the |
405 // network quality. Set to true only for tests. | 434 // network quality. Set to true only for tests. |
406 const bool allow_small_responses_; | 435 const bool allow_small_responses_; |
407 | 436 |
408 // Time when last connection change was observed. | 437 // Time when last connection change was observed. |
(...skipping 23 matching lines...) Expand all Loading... |
432 // estimator field trial parameters. The observations are indexed by | 461 // estimator field trial parameters. The observations are indexed by |
433 // ConnectionType. | 462 // ConnectionType. |
434 NetworkQuality | 463 NetworkQuality |
435 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; | 464 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; |
436 | 465 |
437 // Estimated network quality. Updated on mainframe requests. | 466 // Estimated network quality. Updated on mainframe requests. |
438 NetworkQuality estimated_median_network_quality_; | 467 NetworkQuality estimated_median_network_quality_; |
439 | 468 |
440 // ExternalEstimateProvider that provides network quality using operating | 469 // ExternalEstimateProvider that provides network quality using operating |
441 // system APIs. May be NULL. | 470 // system APIs. May be NULL. |
442 const scoped_ptr<ExternalEstimateProvider> external_estimates_provider_; | 471 const scoped_ptr<ExternalEstimateProvider> external_estimate_provider_; |
| 472 |
| 473 // Time when the external estimate provider was last queried. |
| 474 base::TimeTicks external_estimate_request_time_; |
443 | 475 |
444 base::ThreadChecker thread_checker_; | 476 base::ThreadChecker thread_checker_; |
445 | 477 |
446 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 478 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
447 }; | 479 }; |
448 | 480 |
449 } // namespace net | 481 } // namespace net |
450 | 482 |
451 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ | 483 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ |
OLD | NEW |