Chromium Code Reviews

Side by Side Diff: net/base/network_quality_estimator.h

Issue 1316863006: Populate EEP estimate in NQE (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests and mmenke comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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...)
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...)
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,
162 PercentileDifferentTimestamps); 165 PercentileDifferentTimestamps);
163 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); 166 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles);
164 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); 167 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching);
165 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 168 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
166 TestLRUCacheMaximumSize); 169 TestLRUCacheMaximumSize);
167 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMedianRTTSince); 170 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMedianRTTSince);
171 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
172 TestExternalEstimateProvider);
168 173
169 // NetworkQuality is used to cache the quality of a network connection. 174 // NetworkQuality is used to cache the quality of a network connection.
170 class NET_EXPORT_PRIVATE NetworkQuality { 175 class NET_EXPORT_PRIVATE NetworkQuality {
171 public: 176 public:
172 NetworkQuality(); 177 NetworkQuality();
173 // |rtt| is the estimate of the round trip time. 178 // |rtt| is the estimate of the round trip time.
174 // |downstream_throughput_kbps| is the estimate of the downstream 179 // |downstream_throughput_kbps| is the estimate of the downstream
175 // throughput. 180 // throughput.
176 NetworkQuality(const base::TimeDelta& rtt, 181 NetworkQuality(const base::TimeDelta& rtt,
177 int32_t downstream_throughput_kbps); 182 int32_t downstream_throughput_kbps);
(...skipping 167 matching lines...)
345 static const int kMinimumThroughputVariationParameterKbps = 1; 350 static const int kMinimumThroughputVariationParameterKbps = 1;
346 351
347 // Maximum size of the cache that holds network quality estimates. 352 // Maximum size of the cache that holds network quality estimates.
348 // Smaller size may reduce the cache hit rate due to frequent evictions. 353 // Smaller size may reduce the cache hit rate due to frequent evictions.
349 // Larger size may affect performance. 354 // Larger size may affect performance.
350 static const size_t kMaximumNetworkQualityCacheSize = 10; 355 static const size_t kMaximumNetworkQualityCacheSize = 10;
351 356
352 // Maximum number of observations that can be held in the ObservationBuffer. 357 // Maximum number of observations that can be held in the ObservationBuffer.
353 static const size_t kMaximumObservationsBufferSize = 300; 358 static const size_t kMaximumObservationsBufferSize = 300;
354 359
360 // Minimum time duration (in milliseconds) between consecutive queries to
361 // external estimate provider.
362 static const int kExternalEstimateProviderQueryIntervalMsec = 5 * 60 * 1000;
363
364 // Time duration (in milliseconds) after which the estimate provided by
365 // external estimate provider is considered stale.
366 static const int kExternalEstimateProviderFreshnessDurationMsec =
367 5 * 60 * 1000;
368
355 // Returns the RTT value to be used when the valid RTT is unavailable. Readers 369 // 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()|. 370 // should discard RTT if it is set to the value returned by |InvalidRTT()|.
357 static const base::TimeDelta InvalidRTT(); 371 static const base::TimeDelta InvalidRTT();
358 372
359 // ExternalEstimateProvider::UpdatedEstimateObserver implementation: 373 // May call |QueryExternalEstimateProvider| if the most recent call to
360 void OnUpdatedEstimateAvailable() override; 374 // external estimate provider was more than
375 // |kExternalEstimateProviderQueryIntervalMsec| back.
376 void MaybeQueryExternalEstimateProvider();
377
378 // Queries the external estimate provider for the latest network quality
379 // estimates, and adds those estimates to the current observation buffer.
380 void QueryExternalEstimateProvider();
361 381
362 // Obtains operating parameters from the field trial parameters. 382 // Obtains operating parameters from the field trial parameters.
363 void ObtainOperatingParams( 383 void ObtainOperatingParams(
364 const std::map<std::string, std::string>& variation_params); 384 const std::map<std::string, std::string>& variation_params);
365 385
366 // Adds the default median RTT and downstream throughput estimate for the 386 // Adds the default median RTT and downstream throughput estimate for the
367 // current connection type to the observation buffer. 387 // current connection type to the observation buffer.
368 void AddDefaultEstimates(); 388 void AddDefaultEstimates();
369 389
370 // Returns an estimate of network quality at the specified |percentile|. 390 // Returns an estimate of network quality at the specified |percentile|.
(...skipping 18 matching lines...)
389 409
390 // Records the UMA related to RTT. 410 // Records the UMA related to RTT.
391 void RecordRTTUMA(int32_t estimated_value_msec, 411 void RecordRTTUMA(int32_t estimated_value_msec,
392 int32_t actual_value_msec) const; 412 int32_t actual_value_msec) const;
393 413
394 // Returns true only if |request| can be used for network quality estimation. 414 // 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 415 // Only the requests that go over network are considered to provide useful
396 // observations. 416 // observations.
397 bool RequestProvidesUsefulObservations(const URLRequest& request) const; 417 bool RequestProvidesUsefulObservations(const URLRequest& request) const;
398 418
419 // Values of external estimate provider status. This enum must remain
420 // synchronized with the enum of the same name in
421 // metrics/histograms/histograms.xml.
422 enum NQEExternalEstimateProviderStatus {
423 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE,
424 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE,
425 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED,
426 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL,
427 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK,
428 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY
429 };
430
431 // Records the metrics related to external estimate provider.
432 void RecordExternalEstimateProviderMetrics(
433 NQEExternalEstimateProviderStatus status) const;
434
399 // Determines if the requests to local host can be used in estimating the 435 // Determines if the requests to local host can be used in estimating the
400 // network quality. Set to true only for tests. 436 // network quality. Set to true only for tests.
401 const bool allow_localhost_requests_; 437 const bool allow_localhost_requests_;
402 438
403 // Determines if the responses smaller than |kMinTransferSizeInBytes| 439 // Determines if the responses smaller than |kMinTransferSizeInBytes|
404 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the 440 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the
405 // network quality. Set to true only for tests. 441 // network quality. Set to true only for tests.
406 const bool allow_small_responses_; 442 const bool allow_small_responses_;
407 443
408 // Time when last connection change was observed. 444 // Time when last connection change was observed.
(...skipping 23 matching lines...)
432 // estimator field trial parameters. The observations are indexed by 468 // estimator field trial parameters. The observations are indexed by
433 // ConnectionType. 469 // ConnectionType.
434 NetworkQuality 470 NetworkQuality
435 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; 471 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1];
436 472
437 // Estimated network quality. Updated on mainframe requests. 473 // Estimated network quality. Updated on mainframe requests.
438 NetworkQuality estimated_median_network_quality_; 474 NetworkQuality estimated_median_network_quality_;
439 475
440 // ExternalEstimateProvider that provides network quality using operating 476 // ExternalEstimateProvider that provides network quality using operating
441 // system APIs. May be NULL. 477 // system APIs. May be NULL.
442 const scoped_ptr<ExternalEstimateProvider> external_estimates_provider_; 478 const scoped_ptr<ExternalEstimateProvider> external_estimate_provider_;
479
480 // Time when the external estimate provider was last queried.
481 base::TimeTicks external_estimate_request_time_;
443 482
444 base::ThreadChecker thread_checker_; 483 base::ThreadChecker thread_checker_;
445 484
446 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); 485 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator);
447 }; 486 };
448 487
449 } // namespace net 488 } // namespace net
450 489
451 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ 490 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_
OLDNEW

Powered by Google App Engine