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_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 5 #ifndef NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| 6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 virtual const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() | 315 virtual const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() |
| 316 const; | 316 const; |
| 317 | 317 |
| 318 // Overrides the tick clock used by |this| for testing. | 318 // Overrides the tick clock used by |this| for testing. |
| 319 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); | 319 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); |
| 320 | 320 |
| 321 private: | 321 private: |
| 322 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 322 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
| 323 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 323 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
| 324 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 324 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
| 325 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | |
| 326 ObtainAlgorithmToUseFromParams); | |
| 325 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 327 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
| 326 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); | 328 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); |
| 327 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); | 329 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); |
| 328 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 330 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 329 TestLRUCacheMaximumSize); | 331 TestLRUCacheMaximumSize); |
| 330 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMetricsSince); | 332 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMetricsSince); |
| 331 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 333 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 332 TestExternalEstimateProviderMergeEstimates); | 334 TestExternalEstimateProviderMergeEstimates); |
| 333 | 335 |
| 334 // Value of round trip time observations is in base::TimeDelta. | 336 // Value of round trip time observations is in base::TimeDelta. |
| 335 typedef nqe::internal::Observation<base::TimeDelta> RttObservation; | 337 typedef nqe::internal::Observation<base::TimeDelta> RttObservation; |
| 336 typedef nqe::internal::ObservationBuffer<base::TimeDelta> | 338 typedef nqe::internal::ObservationBuffer<base::TimeDelta> |
| 337 RttObservationBuffer; | 339 RttObservationBuffer; |
| 338 | 340 |
| 339 // Value of throughput observations is in kilobits per second. | 341 // Value of throughput observations is in kilobits per second. |
| 340 typedef nqe::internal::Observation<int32_t> ThroughputObservation; | 342 typedef nqe::internal::Observation<int32_t> ThroughputObservation; |
| 341 typedef nqe::internal::ObservationBuffer<int32_t> ThroughputObservationBuffer; | 343 typedef nqe::internal::ObservationBuffer<int32_t> ThroughputObservationBuffer; |
| 342 | 344 |
| 343 // This does not use a unordered_map or hash_map for code simplicity (key just | 345 // This does not use a unordered_map or hash_map for code simplicity (key just |
| 344 // implements operator<, rather than hash and equality) and because the map is | 346 // implements operator<, rather than hash and equality) and because the map is |
| 345 // tiny. | 347 // tiny. |
| 346 typedef std::map<NetworkID, nqe::internal::CachedNetworkQuality> | 348 typedef std::map<NetworkID, nqe::internal::CachedNetworkQuality> |
| 347 CachedNetworkQualities; | 349 CachedNetworkQualities; |
| 348 | 350 |
| 351 // Algorithms supported by network quality estimator for computing effective | |
| 352 // connection type. | |
| 353 enum class EffectiveConnectionTypeAlgorithm { | |
| 354 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT = 0, | |
| 355 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST | |
| 356 }; | |
| 357 | |
| 358 // Map from algorithm names to EffectiveConnectionTypeAlgorithm. | |
| 359 const std::map<std::string, EffectiveConnectionTypeAlgorithm> | |
|
bengr
2016/06/08 23:33:11
This probably shouldn't be in the .h.
tbansal1
2016/06/08 23:48:29
Done.
| |
| 360 stringToAlgorithm_ = {{"HttpRTTAndDownstreamThroughput", | |
|
bengr
2016/06/08 23:33:11
Why does this need to be a member? Also how about
tbansal1
2016/06/08 23:48:29
Done.
| |
| 361 EffectiveConnectionTypeAlgorithm:: | |
| 362 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}}; | |
| 363 | |
| 364 // The default algorithm to be used if the algorithm value is not available | |
| 365 // through field trial parameters. | |
| 366 static const EffectiveConnectionTypeAlgorithm | |
| 367 kDefaultEffectiveConnectionTypeAlgorithm = | |
| 368 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT; | |
| 369 | |
| 349 // Minimum valid value of the variation parameter that holds RTT (in | 370 // Minimum valid value of the variation parameter that holds RTT (in |
| 350 // milliseconds) values. | 371 // milliseconds) values. |
| 351 static const int kMinimumRTTVariationParameterMsec = 1; | 372 static const int kMinimumRTTVariationParameterMsec = 1; |
| 352 | 373 |
| 353 // Minimum valid value of the variation parameter that holds throughput (in | 374 // Minimum valid value of the variation parameter that holds throughput (in |
| 354 // kilobits per second) values. | 375 // kilobits per second) values. |
| 355 static const int kMinimumThroughputVariationParameterKbps = 1; | 376 static const int kMinimumThroughputVariationParameterKbps = 1; |
| 356 | 377 |
| 357 // Maximum size of the cache that holds network quality estimates. | 378 // Maximum size of the cache that holds network quality estimates. |
| 358 // Smaller size may reduce the cache hit rate due to frequent evictions. | 379 // Smaller size may reduce the cache hit rate due to frequent evictions. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 | 457 |
| 437 // Notify observers of a change in effective connection type. | 458 // Notify observers of a change in effective connection type. |
| 438 void NotifyObserversOfEffectiveConnectionTypeChanged(); | 459 void NotifyObserversOfEffectiveConnectionTypeChanged(); |
| 439 | 460 |
| 440 // Records NQE accuracy metrics. |measuring_duration| should belong to the | 461 // Records NQE accuracy metrics. |measuring_duration| should belong to the |
| 441 // vector returned by AccuracyRecordingIntervals(). | 462 // vector returned by AccuracyRecordingIntervals(). |
| 442 // RecordAccuracyAfterMainFrame should be called |measuring_duration| after a | 463 // RecordAccuracyAfterMainFrame should be called |measuring_duration| after a |
| 443 // main frame request is observed. | 464 // main frame request is observed. |
| 444 void RecordAccuracyAfterMainFrame(base::TimeDelta measuring_duration) const; | 465 void RecordAccuracyAfterMainFrame(base::TimeDelta measuring_duration) const; |
| 445 | 466 |
| 467 // Returns the effective type of the current connection based on only the | |
| 468 // samples observed after |start_time|. Uses HTTP RTT and downstream | |
| 469 // throughput to compute the effective connection type, and requires both of | |
| 470 // them to have a valid value. | |
| 471 EffectiveConnectionType | |
| 472 GetRecentEffectiveConnectionTypeHttpRTTAndDownstreamThroughput( | |
| 473 const base::TimeTicks& start_time) const; | |
| 474 | |
| 446 // Values of external estimate provider status. This enum must remain | 475 // Values of external estimate provider status. This enum must remain |
| 447 // synchronized with the enum of the same name in | 476 // synchronized with the enum of the same name in |
| 448 // metrics/histograms/histograms.xml. | 477 // metrics/histograms/histograms.xml. |
| 449 enum NQEExternalEstimateProviderStatus { | 478 enum NQEExternalEstimateProviderStatus { |
| 450 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, | 479 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, |
| 451 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, | 480 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, |
| 452 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, | 481 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, |
| 453 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, | 482 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, |
| 454 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, | 483 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, |
| 455 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE, | 484 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 466 const bool use_localhost_requests_; | 495 const bool use_localhost_requests_; |
| 467 | 496 |
| 468 // Determines if the responses smaller than |kMinTransferSizeInBytes| | 497 // Determines if the responses smaller than |kMinTransferSizeInBytes| |
| 469 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the | 498 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the |
| 470 // network quality. Set to true only for tests. | 499 // network quality. Set to true only for tests. |
| 471 const bool use_small_responses_; | 500 const bool use_small_responses_; |
| 472 | 501 |
| 473 // The factor by which the weight of an observation reduces every second. | 502 // The factor by which the weight of an observation reduces every second. |
| 474 const double weight_multiplier_per_second_; | 503 const double weight_multiplier_per_second_; |
| 475 | 504 |
| 505 // Algorithm to use for computing effective connection type. The value is | |
| 506 // obtained from field trial parameters. If the value from field trial | |
| 507 // parameters is unavailable, it is set to | |
| 508 // kDefaultEffectiveConnectionTypeAlgorithm. | |
| 509 const EffectiveConnectionTypeAlgorithm algorithm_; | |
|
bengr
2016/06/08 23:33:11
To be clear this should probably be called effecti
tbansal1
2016/06/08 23:48:29
Done.
| |
| 510 | |
| 476 // Tick clock used by the network quality estimator. | 511 // Tick clock used by the network quality estimator. |
| 477 std::unique_ptr<base::TickClock> tick_clock_; | 512 std::unique_ptr<base::TickClock> tick_clock_; |
| 478 | 513 |
| 479 // Minimum duration between two consecutive computations of effective | 514 // Minimum duration between two consecutive computations of effective |
| 480 // connection type. Set to non-zero value as a performance optimization. | 515 // connection type. Set to non-zero value as a performance optimization. |
| 481 const base::TimeDelta effective_connection_type_recomputation_interval_; | 516 const base::TimeDelta effective_connection_type_recomputation_interval_; |
| 482 | 517 |
| 483 // Time when the effective connection type was last computed. | 518 // Time when the effective connection type was last computed. |
| 484 base::TimeTicks last_effective_connection_type_computation_; | 519 base::TimeTicks last_effective_connection_type_computation_; |
| 485 | 520 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 base::ThreadChecker thread_checker_; | 595 base::ThreadChecker thread_checker_; |
| 561 | 596 |
| 562 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 597 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
| 563 | 598 |
| 564 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 599 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
| 565 }; | 600 }; |
| 566 | 601 |
| 567 } // namespace net | 602 } // namespace net |
| 568 | 603 |
| 569 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 604 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |