| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <deque> | |
| 12 #include <map> | 11 #include <map> |
| 13 #include <memory> | 12 #include <memory> |
| 14 #include <string> | 13 #include <string> |
| 15 #include <tuple> | 14 #include <tuple> |
| 16 | 15 |
| 17 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 18 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 19 #include "base/macros.h" | 18 #include "base/macros.h" |
| 20 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 21 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 22 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
| 23 #include "base/threading/thread_checker.h" | 22 #include "base/threading/thread_checker.h" |
| 24 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 25 #include "net/base/net_export.h" | 24 #include "net/base/net_export.h" |
| 26 #include "net/base/network_change_notifier.h" | 25 #include "net/base/network_change_notifier.h" |
| 26 #include "net/nqe/cached_network_quality.h" |
| 27 #include "net/nqe/external_estimate_provider.h" | 27 #include "net/nqe/external_estimate_provider.h" |
| 28 #include "net/nqe/network_quality.h" |
| 29 #include "net/nqe/network_quality_observation.h" |
| 30 #include "net/nqe/network_quality_observation_source.h" |
| 31 #include "net/nqe/observation_buffer.h" |
| 28 #include "net/socket/socket_performance_watcher_factory.h" | 32 #include "net/socket/socket_performance_watcher_factory.h" |
| 29 | 33 |
| 30 namespace base { | 34 namespace base { |
| 31 class SingleThreadTaskRunner; | 35 class SingleThreadTaskRunner; |
| 32 } // namespace base | 36 } // namespace base |
| 33 | 37 |
| 34 namespace net { | 38 namespace net { |
| 35 | 39 |
| 36 class URLRequest; | 40 class URLRequest; |
| 37 | 41 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 60 EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0, | 64 EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0, |
| 61 EFFECTIVE_CONNECTION_TYPE_OFFLINE, | 65 EFFECTIVE_CONNECTION_TYPE_OFFLINE, |
| 62 EFFECTIVE_CONNECTION_TYPE_SLOW_2G, | 66 EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
| 63 EFFECTIVE_CONNECTION_TYPE_2G, | 67 EFFECTIVE_CONNECTION_TYPE_2G, |
| 64 EFFECTIVE_CONNECTION_TYPE_3G, | 68 EFFECTIVE_CONNECTION_TYPE_3G, |
| 65 EFFECTIVE_CONNECTION_TYPE_4G, | 69 EFFECTIVE_CONNECTION_TYPE_4G, |
| 66 EFFECTIVE_CONNECTION_TYPE_BROADBAND, | 70 EFFECTIVE_CONNECTION_TYPE_BROADBAND, |
| 67 EFFECTIVE_CONNECTION_TYPE_LAST, | 71 EFFECTIVE_CONNECTION_TYPE_LAST, |
| 68 }; | 72 }; |
| 69 | 73 |
| 70 // On Android, a Java counterpart will be generated for this enum. | |
| 71 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net | |
| 72 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: NetworkQualityObservationSource | |
| 73 // GENERATED_JAVA_PREFIX_TO_STRIP: | |
| 74 enum ObservationSource { | |
| 75 // The observation was taken at the request layer, e.g., a round trip time | |
| 76 // is recorded as the time between the request being sent and the first byte | |
| 77 // being received. | |
| 78 URL_REQUEST, | |
| 79 // The observation is taken from TCP statistics maintained by the kernel. | |
| 80 TCP, | |
| 81 // The observation is taken at the QUIC layer. | |
| 82 QUIC, | |
| 83 // The observation is a previously cached estimate of the metric. | |
| 84 CACHED_ESTIMATE, | |
| 85 // The observation is derived from network connection information provided | |
| 86 // by the platform. For example, typical RTT and throughput values are used | |
| 87 // for a given type of network connection. | |
| 88 DEFAULT_FROM_PLATFORM, | |
| 89 // The observation came from a Chromium-external source. | |
| 90 EXTERNAL_ESTIMATE | |
| 91 }; | |
| 92 | |
| 93 // Observes measurements of round trip time. | 74 // Observes measurements of round trip time. |
| 94 class NET_EXPORT_PRIVATE RTTObserver { | 75 class NET_EXPORT_PRIVATE RTTObserver { |
| 95 public: | 76 public: |
| 96 // Will be called when a new RTT observation is available. The round trip | 77 // Will be called when a new RTT observation is available. The round trip |
| 97 // time is specified in milliseconds. The time when the observation was | 78 // time is specified in milliseconds. The time when the observation was |
| 98 // taken and the source of the observation are provided. | 79 // taken and the source of the observation are provided. |
| 99 virtual void OnRTTObservation(int32_t rtt_ms, | 80 virtual void OnRTTObservation(int32_t rtt_ms, |
| 100 const base::TimeTicks& timestamp, | 81 const base::TimeTicks& timestamp, |
| 101 ObservationSource source) = 0; | 82 NetworkQualityObservationSource source) = 0; |
| 102 | 83 |
| 103 protected: | 84 protected: |
| 104 RTTObserver() {} | 85 RTTObserver() {} |
| 105 virtual ~RTTObserver() {} | 86 virtual ~RTTObserver() {} |
| 106 | 87 |
| 107 private: | 88 private: |
| 108 DISALLOW_COPY_AND_ASSIGN(RTTObserver); | 89 DISALLOW_COPY_AND_ASSIGN(RTTObserver); |
| 109 }; | 90 }; |
| 110 | 91 |
| 111 // Observes measurements of throughput. | 92 // Observes measurements of throughput. |
| 112 class NET_EXPORT_PRIVATE ThroughputObserver { | 93 class NET_EXPORT_PRIVATE ThroughputObserver { |
| 113 public: | 94 public: |
| 114 // Will be called when a new throughput observation is available. | 95 // Will be called when a new throughput observation is available. |
| 115 // Throughput is specified in kilobits per second. | 96 // Throughput is specified in kilobits per second. |
| 116 virtual void OnThroughputObservation(int32_t throughput_kbps, | 97 virtual void OnThroughputObservation( |
| 117 const base::TimeTicks& timestamp, | 98 int32_t throughput_kbps, |
| 118 ObservationSource source) = 0; | 99 const base::TimeTicks& timestamp, |
| 100 NetworkQualityObservationSource source) = 0; |
| 119 | 101 |
| 120 protected: | 102 protected: |
| 121 ThroughputObserver() {} | 103 ThroughputObserver() {} |
| 122 virtual ~ThroughputObserver() {} | 104 virtual ~ThroughputObserver() {} |
| 123 | 105 |
| 124 private: | 106 private: |
| 125 DISALLOW_COPY_AND_ASSIGN(ThroughputObserver); | 107 DISALLOW_COPY_AND_ASSIGN(ThroughputObserver); |
| 126 }; | 108 }; |
| 127 | 109 |
| 128 // Creates a new NetworkQualityEstimator. | 110 // Creates a new NetworkQualityEstimator. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 247 |
| 266 // Return a string equivalent to |type|. | 248 // Return a string equivalent to |type|. |
| 267 const char* GetNameForEffectiveConnectionType( | 249 const char* GetNameForEffectiveConnectionType( |
| 268 EffectiveConnectionType type) const; | 250 EffectiveConnectionType type) const; |
| 269 | 251 |
| 270 private: | 252 private: |
| 271 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); | 253 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
| 272 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); | 254 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
| 273 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); | 255 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); |
| 274 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | 256 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); |
| 275 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); | |
| 276 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | |
| 277 PercentileSameTimestamps); | |
| 278 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | |
| 279 PercentileDifferentTimestamps); | |
| 280 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); | 257 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); |
| 281 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); | 258 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); |
| 282 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 259 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 283 TestLRUCacheMaximumSize); | 260 TestLRUCacheMaximumSize); |
| 284 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMedianRTTSince); | 261 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMedianRTTSince); |
| 285 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, | 262 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| 286 TestExternalEstimateProviderMergeEstimates); | 263 TestExternalEstimateProviderMergeEstimates); |
| 287 | 264 |
| 288 class SocketWatcher; | 265 class SocketWatcher; |
| 289 class SocketWatcherFactory; | 266 class SocketWatcherFactory; |
| 290 | 267 |
| 291 // NetworkQuality is used to cache the quality of a network connection. | |
| 292 class NET_EXPORT_PRIVATE NetworkQuality { | |
| 293 public: | |
| 294 NetworkQuality(); | |
| 295 // |rtt| is the estimate of the round trip time. | |
| 296 // |downstream_throughput_kbps| is the estimate of the downstream | |
| 297 // throughput in kilobits per second. | |
| 298 NetworkQuality(const base::TimeDelta& rtt, | |
| 299 int32_t downstream_throughput_kbps); | |
| 300 NetworkQuality(const NetworkQuality& other); | |
| 301 ~NetworkQuality(); | |
| 302 | |
| 303 NetworkQuality& operator=(const NetworkQuality& other); | |
| 304 | |
| 305 // Returns the estimate of the round trip time. | |
| 306 const base::TimeDelta& rtt() const { return rtt_; } | |
| 307 | |
| 308 // Returns the estimate of the downstream throughput in Kbps (Kilobits per | |
| 309 // second). | |
| 310 int32_t downstream_throughput_kbps() const { | |
| 311 return downstream_throughput_kbps_; | |
| 312 } | |
| 313 | |
| 314 private: | |
| 315 // Estimated round trip time. | |
| 316 base::TimeDelta rtt_; | |
| 317 | |
| 318 // Estimated downstream throughput in kilobits per second. | |
| 319 int32_t downstream_throughput_kbps_; | |
| 320 }; | |
| 321 | |
| 322 // CachedNetworkQuality stores the quality of a previously seen network. | |
| 323 class NET_EXPORT_PRIVATE CachedNetworkQuality { | |
| 324 public: | |
| 325 explicit CachedNetworkQuality(const NetworkQuality& network_quality); | |
| 326 CachedNetworkQuality(const CachedNetworkQuality& other); | |
| 327 ~CachedNetworkQuality(); | |
| 328 | |
| 329 // Returns the network quality associated with this cached entry. | |
| 330 const NetworkQuality& network_quality() const { return network_quality_; } | |
| 331 | |
| 332 // Returns true if this cache entry was updated before | |
| 333 // |cached_network_quality|. | |
| 334 bool OlderThan(const CachedNetworkQuality& cached_network_quality) const; | |
| 335 | |
| 336 // Time when this cache entry was last updated. | |
| 337 const base::TimeTicks last_update_time_; | |
| 338 | |
| 339 // Quality of this cached network. | |
| 340 const NetworkQuality network_quality_; | |
| 341 | |
| 342 private: | |
| 343 DISALLOW_ASSIGN(CachedNetworkQuality); | |
| 344 }; | |
| 345 | |
| 346 // Records observations of network quality metrics (such as round trip time | |
| 347 // or throughput), along with the time the observation was made. Observations | |
| 348 // can be made at several places in the network stack, thus the observation | |
| 349 // source is provided as well. ValueType must be numerical so that statistics | |
| 350 // such as median, average can be computed. | |
| 351 template <typename ValueType> | |
| 352 struct NET_EXPORT_PRIVATE Observation { | |
| 353 Observation(const ValueType& value, | |
| 354 base::TimeTicks timestamp, | |
| 355 ObservationSource source) | |
| 356 : value(value), timestamp(timestamp), source(source) { | |
| 357 DCHECK(!timestamp.is_null()); | |
| 358 } | |
| 359 ~Observation() {} | |
| 360 | |
| 361 // Value of the observation. | |
| 362 const ValueType value; | |
| 363 | |
| 364 // Time when the observation was taken. | |
| 365 const base::TimeTicks timestamp; | |
| 366 | |
| 367 // The source of the observation. | |
| 368 const ObservationSource source; | |
| 369 }; | |
| 370 | |
| 371 // Holds an observation and its weight. | |
| 372 template <typename ValueType> | |
| 373 struct NET_EXPORT_PRIVATE WeightedObservation { | |
| 374 WeightedObservation(ValueType value, double weight) | |
| 375 : value(value), weight(weight) {} | |
| 376 WeightedObservation(const WeightedObservation& other) | |
| 377 : WeightedObservation(other.value, other.weight) {} | |
| 378 | |
| 379 WeightedObservation& operator=(const WeightedObservation& other) { | |
| 380 value = other.value; | |
| 381 weight = other.weight; | |
| 382 return *this; | |
| 383 } | |
| 384 | |
| 385 // Required for sorting the samples in the ascending order of values. | |
| 386 bool operator<(const WeightedObservation& other) const { | |
| 387 return (value < other.value); | |
| 388 } | |
| 389 | |
| 390 // Value of the sample. | |
| 391 ValueType value; | |
| 392 | |
| 393 // Weight of the sample. This is computed based on how much time has passed | |
| 394 // since the sample was taken. | |
| 395 double weight; | |
| 396 }; | |
| 397 | |
| 398 // Stores observations sorted by time. | |
| 399 template <typename ValueType> | |
| 400 class NET_EXPORT_PRIVATE ObservationBuffer { | |
| 401 public: | |
| 402 explicit ObservationBuffer(double weight_multiplier_per_second); | |
| 403 ~ObservationBuffer(); | |
| 404 | |
| 405 // Adds |observation| to the buffer. The oldest observation in the buffer | |
| 406 // will be evicted to make room if the buffer is already full. | |
| 407 void AddObservation(const Observation<ValueType>& observation) { | |
| 408 DCHECK_LE(observations_.size(), | |
| 409 static_cast<size_t>(kMaximumObservationsBufferSize)); | |
| 410 // Evict the oldest element if the buffer is already full. | |
| 411 if (observations_.size() == kMaximumObservationsBufferSize) | |
| 412 observations_.pop_front(); | |
| 413 | |
| 414 observations_.push_back(observation); | |
| 415 DCHECK_LE(observations_.size(), | |
| 416 static_cast<size_t>(kMaximumObservationsBufferSize)); | |
| 417 } | |
| 418 | |
| 419 // Clears the observations stored in this buffer. | |
| 420 void Clear() { observations_.clear(); } | |
| 421 | |
| 422 // Returns true iff the |percentile| value of the observations in this | |
| 423 // buffer is available. Sets |result| to the computed |percentile| | |
| 424 // value among all observations since |begin_timestamp|. If the value is | |
| 425 // unavailable, false is returned and |result| is not modified. Percentile | |
| 426 // value is unavailable if all the values in observation buffer are older | |
| 427 // than |begin_timestamp|. |result| must not be null. | |
| 428 // |disallowed_observation_sources| is the list of observation sources that | |
| 429 // should be excluded when computing the percentile. | |
| 430 bool GetPercentile( | |
| 431 const base::TimeTicks& begin_timestamp, | |
| 432 ValueType* result, | |
| 433 int percentile, | |
| 434 const std::vector<ObservationSource>& disallowed_observation_sources) | |
| 435 const WARN_UNUSED_RESULT; | |
| 436 | |
| 437 private: | |
| 438 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); | |
| 439 | |
| 440 // Computes the weighted observations and stores them in | |
| 441 // |weighted_observations| sorted by ascending |WeightedObservation.value|. | |
| 442 // Only the observations with timestamp later than |begin_timestamp| are | |
| 443 // considered. Also, sets |total_weight| to the total weight of all | |
| 444 // observations. Should be called only when there is at least one | |
| 445 // observation in the buffer. |disallowed_observation_sources| is the list | |
| 446 // of observation sources that should be excluded when computing the | |
| 447 // weighted observations. | |
| 448 void ComputeWeightedObservations( | |
| 449 const base::TimeTicks& begin_timestamp, | |
| 450 std::vector<WeightedObservation<ValueType>>& weighted_observations, | |
| 451 double* total_weight, | |
| 452 const std::vector<ObservationSource>& disallowed_observation_sources) | |
| 453 const; | |
| 454 | |
| 455 // Holds observations sorted by time, with the oldest observation at the | |
| 456 // front of the queue. | |
| 457 std::deque<Observation<ValueType>> observations_; | |
| 458 | |
| 459 // The factor by which the weight of an observation reduces every second. | |
| 460 // For example, if an observation is 6 seconds old, its weight would be: | |
| 461 // weight_multiplier_per_second_ ^ 6 | |
| 462 // Calculated from |kHalfLifeSeconds| by solving the following equation: | |
| 463 // weight_multiplier_per_second_ ^ kHalfLifeSeconds = 0.5 | |
| 464 const double weight_multiplier_per_second_; | |
| 465 | |
| 466 DISALLOW_COPY_AND_ASSIGN(ObservationBuffer); | |
| 467 }; | |
| 468 | |
| 469 // Value of round trip time observations is in base::TimeDelta. | 268 // Value of round trip time observations is in base::TimeDelta. |
| 470 typedef net::NetworkQualityEstimator::Observation<base::TimeDelta> | 269 typedef nqe::internal::Observation<base::TimeDelta> RttObservation; |
| 471 RttObservation; | 270 typedef nqe::internal::ObservationBuffer<base::TimeDelta> |
| 472 typedef net::NetworkQualityEstimator::ObservationBuffer<base::TimeDelta> | |
| 473 RttObservationBuffer; | 271 RttObservationBuffer; |
| 474 | 272 |
| 475 // Value of throughput observations is in kilobits per second. | 273 // Value of throughput observations is in kilobits per second. |
| 476 typedef net::NetworkQualityEstimator::Observation<int32_t> | 274 typedef nqe::internal::Observation<int32_t> ThroughputObservation; |
| 477 ThroughputObservation; | 275 typedef nqe::internal::ObservationBuffer<int32_t> ThroughputObservationBuffer; |
| 478 typedef net::NetworkQualityEstimator::ObservationBuffer<int32_t> | |
| 479 ThroughputObservationBuffer; | |
| 480 | 276 |
| 481 // This does not use a unordered_map or hash_map for code simplicity (key just | 277 // This does not use a unordered_map or hash_map for code simplicity (key just |
| 482 // implements operator<, rather than hash and equality) and because the map is | 278 // implements operator<, rather than hash and equality) and because the map is |
| 483 // tiny. | 279 // tiny. |
| 484 typedef std::map<NetworkID, CachedNetworkQuality> CachedNetworkQualities; | 280 typedef std::map<NetworkID, nqe::internal::CachedNetworkQuality> |
| 485 | 281 CachedNetworkQualities; |
| 486 // Throughput is set to |kInvalidThroughput| if a valid value is | |
| 487 // unavailable. Readers should discard throughput value if it is set to | |
| 488 // |kInvalidThroughput|. | |
| 489 static const int32_t kInvalidThroughput; | |
| 490 | 282 |
| 491 // Tiny transfer sizes may give inaccurate throughput results. | 283 // Tiny transfer sizes may give inaccurate throughput results. |
| 492 // Minimum size of the transfer over which the throughput is computed. | 284 // Minimum size of the transfer over which the throughput is computed. |
| 493 static const int kMinTransferSizeInBytes = 10000; | 285 static const int kMinTransferSizeInBytes = 10000; |
| 494 | 286 |
| 495 // Minimum duration (in microseconds) of the transfer over which the | 287 // Minimum duration (in microseconds) of the transfer over which the |
| 496 // throughput is computed. | 288 // throughput is computed. |
| 497 static const int kMinRequestDurationMicroseconds = 1000; | 289 static const int kMinRequestDurationMicroseconds = 1000; |
| 498 | 290 |
| 499 // Minimum valid value of the variation parameter that holds RTT (in | 291 // Minimum valid value of the variation parameter that holds RTT (in |
| 500 // milliseconds) values. | 292 // milliseconds) values. |
| 501 static const int kMinimumRTTVariationParameterMsec = 1; | 293 static const int kMinimumRTTVariationParameterMsec = 1; |
| 502 | 294 |
| 503 // Minimum valid value of the variation parameter that holds throughput (in | 295 // Minimum valid value of the variation parameter that holds throughput (in |
| 504 // kilobits per second) values. | 296 // kilobits per second) values. |
| 505 static const int kMinimumThroughputVariationParameterKbps = 1; | 297 static const int kMinimumThroughputVariationParameterKbps = 1; |
| 506 | 298 |
| 507 // Maximum size of the cache that holds network quality estimates. | 299 // Maximum size of the cache that holds network quality estimates. |
| 508 // Smaller size may reduce the cache hit rate due to frequent evictions. | 300 // Smaller size may reduce the cache hit rate due to frequent evictions. |
| 509 // Larger size may affect performance. | 301 // Larger size may affect performance. |
| 510 static const size_t kMaximumNetworkQualityCacheSize = 10; | 302 static const size_t kMaximumNetworkQualityCacheSize = 10; |
| 511 | 303 |
| 512 // Maximum number of observations that can be held in the ObservationBuffer. | |
| 513 static const size_t kMaximumObservationsBufferSize = 300; | |
| 514 | |
| 515 // Time duration (in milliseconds) after which the estimate provided by | 304 // Time duration (in milliseconds) after which the estimate provided by |
| 516 // external estimate provider is considered stale. | 305 // external estimate provider is considered stale. |
| 517 static const int kExternalEstimateProviderFreshnessDurationMsec = | 306 static const int kExternalEstimateProviderFreshnessDurationMsec = |
| 518 5 * 60 * 1000; | 307 5 * 60 * 1000; |
| 519 | 308 |
| 520 // Returns the RTT value to be used when the valid RTT is unavailable. Readers | 309 // Returns the RTT value to be used when the valid RTT is unavailable. Readers |
| 521 // should discard RTT if it is set to the value returned by |InvalidRTT()|. | 310 // should discard RTT if it is set to the value returned by |InvalidRTT()|. |
| 522 static const base::TimeDelta InvalidRTT(); | 311 static const base::TimeDelta InvalidRTT(); |
| 523 | 312 |
| 524 // Notifies |this| of a new transport layer RTT. | 313 // Notifies |this| of a new transport layer RTT. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 547 // Returns an estimate of network quality at the specified |percentile|. | 336 // Returns an estimate of network quality at the specified |percentile|. |
| 548 // |disallowed_observation_sources| is the list of observation sources that | 337 // |disallowed_observation_sources| is the list of observation sources that |
| 549 // should be excluded when computing the percentile. | 338 // should be excluded when computing the percentile. |
| 550 // Only the observations later than |begin_timestamp| are taken into account. | 339 // Only the observations later than |begin_timestamp| are taken into account. |
| 551 // |percentile| must be between 0 and 100 (both inclusive) with higher | 340 // |percentile| must be between 0 and 100 (both inclusive) with higher |
| 552 // percentiles indicating less performant networks. For example, if | 341 // percentiles indicating less performant networks. For example, if |
| 553 // |percentile| is 90, then the network is expected to be faster than the | 342 // |percentile| is 90, then the network is expected to be faster than the |
| 554 // returned estimate with 0.9 probability. Similarly, network is expected to | 343 // returned estimate with 0.9 probability. Similarly, network is expected to |
| 555 // be slower than the returned estimate with 0.1 probability. | 344 // be slower than the returned estimate with 0.1 probability. |
| 556 base::TimeDelta GetRTTEstimateInternal( | 345 base::TimeDelta GetRTTEstimateInternal( |
| 557 const std::vector<ObservationSource>& disallowed_observation_sources, | 346 const std::vector<NetworkQualityObservationSource>& |
| 347 disallowed_observation_sources, |
| 558 const base::TimeTicks& begin_timestamp, | 348 const base::TimeTicks& begin_timestamp, |
| 559 int percentile) const; | 349 int percentile) const; |
| 560 int32_t GetDownlinkThroughputKbpsEstimateInternal( | 350 int32_t GetDownlinkThroughputKbpsEstimateInternal( |
| 561 const base::TimeTicks& begin_timestamp, | 351 const base::TimeTicks& begin_timestamp, |
| 562 int percentile) const; | 352 int percentile) const; |
| 563 | 353 |
| 564 // Returns the current network ID checking by calling the platform APIs. | 354 // Returns the current network ID checking by calling the platform APIs. |
| 565 // Virtualized for testing. | 355 // Virtualized for testing. |
| 566 virtual NetworkID GetCurrentNetworkID() const; | 356 virtual NetworkID GetCurrentNetworkID() const; |
| 567 | 357 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 | 406 |
| 617 // ID of the current network. | 407 // ID of the current network. |
| 618 NetworkID current_network_id_; | 408 NetworkID current_network_id_; |
| 619 | 409 |
| 620 // Peak network quality (fastest round-trip-time (RTT) and highest | 410 // Peak network quality (fastest round-trip-time (RTT) and highest |
| 621 // downstream throughput) measured since last connectivity change. RTT is | 411 // downstream throughput) measured since last connectivity change. RTT is |
| 622 // measured from time the request is sent until the first byte received. | 412 // measured from time the request is sent until the first byte received. |
| 623 // The accuracy is decreased by ignoring these factors: | 413 // The accuracy is decreased by ignoring these factors: |
| 624 // 1) Multiple URLRequests can occur concurrently. | 414 // 1) Multiple URLRequests can occur concurrently. |
| 625 // 2) Includes server processing time. | 415 // 2) Includes server processing time. |
| 626 NetworkQuality peak_network_quality_; | 416 nqe::internal::NetworkQuality peak_network_quality_; |
| 627 | 417 |
| 628 // Cache that stores quality of previously seen networks. | 418 // Cache that stores quality of previously seen networks. |
| 629 CachedNetworkQualities cached_network_qualities_; | 419 CachedNetworkQualities cached_network_qualities_; |
| 630 | 420 |
| 631 // Buffer that holds throughput observations (in kilobits per second) sorted | 421 // Buffer that holds throughput observations (in kilobits per second) sorted |
| 632 // by timestamp. | 422 // by timestamp. |
| 633 ThroughputObservationBuffer downstream_throughput_kbps_observations_; | 423 ThroughputObservationBuffer downstream_throughput_kbps_observations_; |
| 634 | 424 |
| 635 // Buffer that holds RTT observations sorted by timestamp. | 425 // Buffer that holds RTT observations sorted by timestamp. |
| 636 RttObservationBuffer rtt_observations_; | 426 RttObservationBuffer rtt_observations_; |
| 637 | 427 |
| 638 // Default network quality observations obtained from the network quality | 428 // Default network quality observations obtained from the network quality |
| 639 // estimator field trial parameters. The observations are indexed by | 429 // estimator field trial parameters. The observations are indexed by |
| 640 // ConnectionType. | 430 // ConnectionType. |
| 641 NetworkQuality | 431 nqe::internal::NetworkQuality |
| 642 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; | 432 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; |
| 643 | 433 |
| 644 // Thresholds for different effective connection types obtained from field | 434 // Thresholds for different effective connection types obtained from field |
| 645 // trial variation params. These thresholds encode how different connection | 435 // trial variation params. These thresholds encode how different connection |
| 646 // types behave in general. In future, complex encodings (e.g., curve | 436 // types behave in general. In future, complex encodings (e.g., curve |
| 647 // fitting) may be used. | 437 // fitting) may be used. |
| 648 NetworkQuality connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST]; | 438 nqe::internal::NetworkQuality |
| 439 connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST]; |
| 649 | 440 |
| 650 // Estimated network quality. Updated on mainframe requests. | 441 // Estimated network quality. Updated on mainframe requests. |
| 651 NetworkQuality estimated_median_network_quality_; | 442 nqe::internal::NetworkQuality estimated_median_network_quality_; |
| 652 | 443 |
| 653 // ExternalEstimateProvider that provides network quality using operating | 444 // ExternalEstimateProvider that provides network quality using operating |
| 654 // system APIs. May be NULL. | 445 // system APIs. May be NULL. |
| 655 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; | 446 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; |
| 656 | 447 |
| 657 // Observer lists for round trip times and throughput measurements. | 448 // Observer lists for round trip times and throughput measurements. |
| 658 base::ObserverList<RTTObserver> rtt_observer_list_; | 449 base::ObserverList<RTTObserver> rtt_observer_list_; |
| 659 base::ObserverList<ThroughputObserver> throughput_observer_list_; | 450 base::ObserverList<ThroughputObserver> throughput_observer_list_; |
| 660 | 451 |
| 661 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_; | 452 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_; |
| 662 | 453 |
| 663 base::ThreadChecker thread_checker_; | 454 base::ThreadChecker thread_checker_; |
| 664 | 455 |
| 665 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 456 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
| 666 | 457 |
| 667 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 458 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
| 668 }; | 459 }; |
| 669 | 460 |
| 670 } // namespace net | 461 } // namespace net |
| 671 | 462 |
| 672 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 463 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |