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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 // estimator field trial parameters. The observations are indexed by | 445 // estimator field trial parameters. The observations are indexed by |
433 // ConnectionType. | 446 // ConnectionType. |
434 NetworkQuality | 447 NetworkQuality |
435 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; | 448 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; |
436 | 449 |
437 // Estimated network quality. Updated on mainframe requests. | 450 // Estimated network quality. Updated on mainframe requests. |
438 NetworkQuality estimated_median_network_quality_; | 451 NetworkQuality estimated_median_network_quality_; |
439 | 452 |
440 // ExternalEstimateProvider that provides network quality using operating | 453 // ExternalEstimateProvider that provides network quality using operating |
441 // system APIs. May be NULL. | 454 // system APIs. May be NULL. |
442 const scoped_ptr<ExternalEstimateProvider> external_estimates_provider_; | 455 const scoped_ptr<ExternalEstimateProvider> external_estimate_provider_; |
| 456 |
| 457 // Time when the external estimate provider was last queried. |
| 458 base::TimeTicks external_estimate_request_time_; |
| 459 |
| 460 // Values of external estimate provider status. This enum must remain |
| 461 // synchronized with the enum of the same name in |
| 462 // metrics/histograms/histograms.xml. |
| 463 enum NQEExternalEstimateProviderStatus { |
| 464 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, |
| 465 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, |
| 466 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, |
| 467 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, |
| 468 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, |
| 469 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY |
| 470 }; |
443 | 471 |
444 base::ThreadChecker thread_checker_; | 472 base::ThreadChecker thread_checker_; |
445 | 473 |
446 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 474 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
447 }; | 475 }; |
448 | 476 |
449 } // namespace net | 477 } // namespace net |
450 | 478 |
451 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ | 479 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ |
OLD | NEW |