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> |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | |
17 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "net/base/external_estimate_provider.h" | 20 #include "net/base/external_estimate_provider.h" |
20 #include "net/base/net_export.h" | 21 #include "net/base/net_export.h" |
21 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 | 25 |
25 class URLRequest; | 26 class URLRequest; |
26 | 27 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 bool allow_local_host_requests_for_tests, | 134 bool allow_local_host_requests_for_tests, |
134 bool allow_smaller_responses_for_tests); | 135 bool allow_smaller_responses_for_tests); |
135 | 136 |
136 // Returns true if the cached network quality estimate was successfully read. | 137 // Returns true if the cached network quality estimate was successfully read. |
137 bool ReadCachedNetworkQualityEstimate(); | 138 bool ReadCachedNetworkQualityEstimate(); |
138 | 139 |
139 // NetworkChangeNotifier::ConnectionTypeObserver implementation. | 140 // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
140 void OnConnectionTypeChanged( | 141 void OnConnectionTypeChanged( |
141 NetworkChangeNotifier::ConnectionType type) override; | 142 NetworkChangeNotifier::ConnectionType type) override; |
142 | 143 |
144 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. | |
145 void OnUpdatedEstimateAvailable() override; | |
146 | |
143 private: | 147 private: |
144 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 148 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
145 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); | 149 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); |
146 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 150 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
147 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 151 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
148 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 152 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
149 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); | 153 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); |
150 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 154 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
151 PercentileSameTimestamps); | 155 PercentileSameTimestamps); |
152 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 156 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 static const int kMinimumThroughputVariationParameterKbps = 1; | 340 static const int kMinimumThroughputVariationParameterKbps = 1; |
337 | 341 |
338 // Maximum size of the cache that holds network quality estimates. | 342 // Maximum size of the cache that holds network quality estimates. |
339 // Smaller size may reduce the cache hit rate due to frequent evictions. | 343 // Smaller size may reduce the cache hit rate due to frequent evictions. |
340 // Larger size may affect performance. | 344 // Larger size may affect performance. |
341 static const size_t kMaximumNetworkQualityCacheSize = 10; | 345 static const size_t kMaximumNetworkQualityCacheSize = 10; |
342 | 346 |
343 // Maximum number of observations that can be held in the ObservationBuffer. | 347 // Maximum number of observations that can be held in the ObservationBuffer. |
344 static const size_t kMaximumObservationsBufferSize = 300; | 348 static const size_t kMaximumObservationsBufferSize = 300; |
345 | 349 |
350 // Minimum time duration (in milliseconds) between consecutive queries to | |
351 // external estimate provider. | |
352 static const int kExternalEstimateProviderQueryIntervalMsec = 5 * 60 * 1000; | |
353 | |
346 // Returns the RTT value to be used when the valid RTT is unavailable. Readers | 354 // 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()|. | 355 // should discard RTT if it is set to the value returned by |InvalidRTT()|. |
348 static const base::TimeDelta InvalidRTT(); | 356 static const base::TimeDelta InvalidRTT(); |
349 | 357 |
350 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. | 358 // Queries the external estimate provider for the latest network quality |
351 void OnUpdatedEstimateAvailable() override; | 359 // estimates, and adds those estimates to the current observation buffer. |
360 void QueryExternalEstimateProvider(); | |
361 | |
362 // Called when the posted task to query external estimate provider is ran. | |
363 void RunExternalEstimateProviderDelayedTask(); | |
352 | 364 |
353 // Obtains operating parameters from the field trial parameters. | 365 // Obtains operating parameters from the field trial parameters. |
354 void ObtainOperatingParams( | 366 void ObtainOperatingParams( |
355 const std::map<std::string, std::string>& variation_params); | 367 const std::map<std::string, std::string>& variation_params); |
356 | 368 |
357 // Adds the default median RTT and downstream throughput estimate for the | 369 // Adds the default median RTT and downstream throughput estimate for the |
358 // current connection type to the observation buffer. | 370 // current connection type to the observation buffer. |
359 void AddDefaultEstimates(); | 371 void AddDefaultEstimates(); |
360 | 372 |
361 // Returns an estimate of network quality at the specified |percentile|. | 373 // Returns an estimate of network quality at the specified |percentile|. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 NetworkQuality | 437 NetworkQuality |
426 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; | 438 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; |
427 | 439 |
428 // Estimated network quality. Updated on mainframe requests. | 440 // Estimated network quality. Updated on mainframe requests. |
429 NetworkQuality estimated_median_network_quality_; | 441 NetworkQuality estimated_median_network_quality_; |
430 | 442 |
431 // ExternalEstimateProvider that provides network quality using operating | 443 // ExternalEstimateProvider that provides network quality using operating |
432 // system APIs. May be NULL. | 444 // system APIs. May be NULL. |
433 const scoped_ptr<ExternalEstimateProvider> external_estimates_provider_; | 445 const scoped_ptr<ExternalEstimateProvider> external_estimates_provider_; |
434 | 446 |
447 // Time when the external estimate provider (eep) was last queried. | |
448 base::TimeTicks eep_queried_; | |
449 | |
450 // True if a delayed task querying the external estimate provider has been | |
451 // posted. | |
452 bool eep_delayed_task_posted_; | |
bengr
2015/09/02 20:27:56
How about external_estimate_pending_?
tbansal1
2015/09/03 00:22:40
Done.
| |
453 | |
454 // Values of external estimate provider status. | |
455 // This enum must remain synchronized with the enum of the same name in | |
456 // metrics/histograms/histograms.xml. | |
457 enum NQEExternalEstimateProviderStatus { | |
458 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, | |
459 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, | |
460 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, | |
461 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, | |
462 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, | |
463 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY | |
464 }; | |
465 | |
435 base::ThreadChecker thread_checker_; | 466 base::ThreadChecker thread_checker_; |
436 | 467 |
468 // Used for posting tasks. | |
469 base::WeakPtrFactory<NetworkQualityEstimator> weak_factory_; | |
470 | |
437 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 471 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
438 }; | 472 }; |
439 | 473 |
440 } // namespace net | 474 } // namespace net |
441 | 475 |
442 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ | 476 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ |
OLD | NEW |