| Index: net/nqe/network_quality_estimator.h
|
| diff --git a/net/nqe/network_quality_estimator.h b/net/nqe/network_quality_estimator.h
|
| index 30428d520b3aed1f6ea9206548c39696f1efaf9b..8642062dc74a500aa8efcc68ac96756ad3a07a40 100644
|
| --- a/net/nqe/network_quality_estimator.h
|
| +++ b/net/nqe/network_quality_estimator.h
|
| @@ -8,7 +8,6 @@
|
| #include <stddef.h>
|
| #include <stdint.h>
|
|
|
| -#include <deque>
|
| #include <map>
|
| #include <memory>
|
| #include <string>
|
| @@ -24,7 +23,12 @@
|
| #include "base/time/time.h"
|
| #include "net/base/net_export.h"
|
| #include "net/base/network_change_notifier.h"
|
| +#include "net/nqe/cached_network_quality.h"
|
| #include "net/nqe/external_estimate_provider.h"
|
| +#include "net/nqe/network_quality.h"
|
| +#include "net/nqe/network_quality_observation.h"
|
| +#include "net/nqe/network_quality_observation_source.h"
|
| +#include "net/nqe/observation_buffer.h"
|
| #include "net/socket/socket_performance_watcher_factory.h"
|
|
|
| namespace base {
|
| @@ -67,29 +71,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| EFFECTIVE_CONNECTION_TYPE_LAST,
|
| };
|
|
|
| - // On Android, a Java counterpart will be generated for this enum.
|
| - // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
|
| - // GENERATED_JAVA_CLASS_NAME_OVERRIDE: NetworkQualityObservationSource
|
| - // GENERATED_JAVA_PREFIX_TO_STRIP:
|
| - enum ObservationSource {
|
| - // The observation was taken at the request layer, e.g., a round trip time
|
| - // is recorded as the time between the request being sent and the first byte
|
| - // being received.
|
| - URL_REQUEST,
|
| - // The observation is taken from TCP statistics maintained by the kernel.
|
| - TCP,
|
| - // The observation is taken at the QUIC layer.
|
| - QUIC,
|
| - // The observation is a previously cached estimate of the metric.
|
| - CACHED_ESTIMATE,
|
| - // The observation is derived from network connection information provided
|
| - // by the platform. For example, typical RTT and throughput values are used
|
| - // for a given type of network connection.
|
| - DEFAULT_FROM_PLATFORM,
|
| - // The observation came from a Chromium-external source.
|
| - EXTERNAL_ESTIMATE
|
| - };
|
| -
|
| // Observes measurements of round trip time.
|
| class NET_EXPORT_PRIVATE RTTObserver {
|
| public:
|
| @@ -98,7 +79,7 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // taken and the source of the observation are provided.
|
| virtual void OnRTTObservation(int32_t rtt_ms,
|
| const base::TimeTicks& timestamp,
|
| - ObservationSource source) = 0;
|
| + NetworkQualityObservationSource source) = 0;
|
|
|
| protected:
|
| RTTObserver() {}
|
| @@ -113,9 +94,10 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| public:
|
| // Will be called when a new throughput observation is available.
|
| // Throughput is specified in kilobits per second.
|
| - virtual void OnThroughputObservation(int32_t throughput_kbps,
|
| - const base::TimeTicks& timestamp,
|
| - ObservationSource source) = 0;
|
| + virtual void OnThroughputObservation(
|
| + int32_t throughput_kbps,
|
| + const base::TimeTicks& timestamp,
|
| + NetworkQualityObservationSource source) = 0;
|
|
|
| protected:
|
| ThroughputObserver() {}
|
| @@ -272,11 +254,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam);
|
| - FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator);
|
| - FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
|
| - PercentileSameTimestamps);
|
| - FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
|
| - PercentileDifferentTimestamps);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
|
| @@ -288,205 +265,20 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| class SocketWatcher;
|
| class SocketWatcherFactory;
|
|
|
| - // NetworkQuality is used to cache the quality of a network connection.
|
| - class NET_EXPORT_PRIVATE NetworkQuality {
|
| - public:
|
| - NetworkQuality();
|
| - // |rtt| is the estimate of the round trip time.
|
| - // |downstream_throughput_kbps| is the estimate of the downstream
|
| - // throughput in kilobits per second.
|
| - NetworkQuality(const base::TimeDelta& rtt,
|
| - int32_t downstream_throughput_kbps);
|
| - NetworkQuality(const NetworkQuality& other);
|
| - ~NetworkQuality();
|
| -
|
| - NetworkQuality& operator=(const NetworkQuality& other);
|
| -
|
| - // Returns the estimate of the round trip time.
|
| - const base::TimeDelta& rtt() const { return rtt_; }
|
| -
|
| - // Returns the estimate of the downstream throughput in Kbps (Kilobits per
|
| - // second).
|
| - int32_t downstream_throughput_kbps() const {
|
| - return downstream_throughput_kbps_;
|
| - }
|
| -
|
| - private:
|
| - // Estimated round trip time.
|
| - base::TimeDelta rtt_;
|
| -
|
| - // Estimated downstream throughput in kilobits per second.
|
| - int32_t downstream_throughput_kbps_;
|
| - };
|
| -
|
| - // CachedNetworkQuality stores the quality of a previously seen network.
|
| - class NET_EXPORT_PRIVATE CachedNetworkQuality {
|
| - public:
|
| - explicit CachedNetworkQuality(const NetworkQuality& network_quality);
|
| - CachedNetworkQuality(const CachedNetworkQuality& other);
|
| - ~CachedNetworkQuality();
|
| -
|
| - // Returns the network quality associated with this cached entry.
|
| - const NetworkQuality& network_quality() const { return network_quality_; }
|
| -
|
| - // Returns true if this cache entry was updated before
|
| - // |cached_network_quality|.
|
| - bool OlderThan(const CachedNetworkQuality& cached_network_quality) const;
|
| -
|
| - // Time when this cache entry was last updated.
|
| - const base::TimeTicks last_update_time_;
|
| -
|
| - // Quality of this cached network.
|
| - const NetworkQuality network_quality_;
|
| -
|
| - private:
|
| - DISALLOW_ASSIGN(CachedNetworkQuality);
|
| - };
|
| -
|
| - // Records observations of network quality metrics (such as round trip time
|
| - // or throughput), along with the time the observation was made. Observations
|
| - // can be made at several places in the network stack, thus the observation
|
| - // source is provided as well. ValueType must be numerical so that statistics
|
| - // such as median, average can be computed.
|
| - template <typename ValueType>
|
| - struct NET_EXPORT_PRIVATE Observation {
|
| - Observation(const ValueType& value,
|
| - base::TimeTicks timestamp,
|
| - ObservationSource source)
|
| - : value(value), timestamp(timestamp), source(source) {
|
| - DCHECK(!timestamp.is_null());
|
| - }
|
| - ~Observation() {}
|
| -
|
| - // Value of the observation.
|
| - const ValueType value;
|
| -
|
| - // Time when the observation was taken.
|
| - const base::TimeTicks timestamp;
|
| -
|
| - // The source of the observation.
|
| - const ObservationSource source;
|
| - };
|
| -
|
| - // Holds an observation and its weight.
|
| - template <typename ValueType>
|
| - struct NET_EXPORT_PRIVATE WeightedObservation {
|
| - WeightedObservation(ValueType value, double weight)
|
| - : value(value), weight(weight) {}
|
| - WeightedObservation(const WeightedObservation& other)
|
| - : WeightedObservation(other.value, other.weight) {}
|
| -
|
| - WeightedObservation& operator=(const WeightedObservation& other) {
|
| - value = other.value;
|
| - weight = other.weight;
|
| - return *this;
|
| - }
|
| -
|
| - // Required for sorting the samples in the ascending order of values.
|
| - bool operator<(const WeightedObservation& other) const {
|
| - return (value < other.value);
|
| - }
|
| -
|
| - // Value of the sample.
|
| - ValueType value;
|
| -
|
| - // Weight of the sample. This is computed based on how much time has passed
|
| - // since the sample was taken.
|
| - double weight;
|
| - };
|
| -
|
| - // Stores observations sorted by time.
|
| - template <typename ValueType>
|
| - class NET_EXPORT_PRIVATE ObservationBuffer {
|
| - public:
|
| - explicit ObservationBuffer(double weight_multiplier_per_second);
|
| - ~ObservationBuffer();
|
| -
|
| - // Adds |observation| to the buffer. The oldest observation in the buffer
|
| - // will be evicted to make room if the buffer is already full.
|
| - void AddObservation(const Observation<ValueType>& observation) {
|
| - DCHECK_LE(observations_.size(),
|
| - static_cast<size_t>(kMaximumObservationsBufferSize));
|
| - // Evict the oldest element if the buffer is already full.
|
| - if (observations_.size() == kMaximumObservationsBufferSize)
|
| - observations_.pop_front();
|
| -
|
| - observations_.push_back(observation);
|
| - DCHECK_LE(observations_.size(),
|
| - static_cast<size_t>(kMaximumObservationsBufferSize));
|
| - }
|
| -
|
| - // Clears the observations stored in this buffer.
|
| - void Clear() { observations_.clear(); }
|
| -
|
| - // Returns true iff the |percentile| value of the observations in this
|
| - // buffer is available. Sets |result| to the computed |percentile|
|
| - // value among all observations since |begin_timestamp|. If the value is
|
| - // unavailable, false is returned and |result| is not modified. Percentile
|
| - // value is unavailable if all the values in observation buffer are older
|
| - // than |begin_timestamp|. |result| must not be null.
|
| - // |disallowed_observation_sources| is the list of observation sources that
|
| - // should be excluded when computing the percentile.
|
| - bool GetPercentile(
|
| - const base::TimeTicks& begin_timestamp,
|
| - ValueType* result,
|
| - int percentile,
|
| - const std::vector<ObservationSource>& disallowed_observation_sources)
|
| - const WARN_UNUSED_RESULT;
|
| -
|
| - private:
|
| - FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam);
|
| -
|
| - // Computes the weighted observations and stores them in
|
| - // |weighted_observations| sorted by ascending |WeightedObservation.value|.
|
| - // Only the observations with timestamp later than |begin_timestamp| are
|
| - // considered. Also, sets |total_weight| to the total weight of all
|
| - // observations. Should be called only when there is at least one
|
| - // observation in the buffer. |disallowed_observation_sources| is the list
|
| - // of observation sources that should be excluded when computing the
|
| - // weighted observations.
|
| - void ComputeWeightedObservations(
|
| - const base::TimeTicks& begin_timestamp,
|
| - std::vector<WeightedObservation<ValueType>>& weighted_observations,
|
| - double* total_weight,
|
| - const std::vector<ObservationSource>& disallowed_observation_sources)
|
| - const;
|
| -
|
| - // Holds observations sorted by time, with the oldest observation at the
|
| - // front of the queue.
|
| - std::deque<Observation<ValueType>> observations_;
|
| -
|
| - // The factor by which the weight of an observation reduces every second.
|
| - // For example, if an observation is 6 seconds old, its weight would be:
|
| - // weight_multiplier_per_second_ ^ 6
|
| - // Calculated from |kHalfLifeSeconds| by solving the following equation:
|
| - // weight_multiplier_per_second_ ^ kHalfLifeSeconds = 0.5
|
| - const double weight_multiplier_per_second_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(ObservationBuffer);
|
| - };
|
| -
|
| // Value of round trip time observations is in base::TimeDelta.
|
| - typedef net::NetworkQualityEstimator::Observation<base::TimeDelta>
|
| - RttObservation;
|
| - typedef net::NetworkQualityEstimator::ObservationBuffer<base::TimeDelta>
|
| + typedef nqe::internal::Observation<base::TimeDelta> RttObservation;
|
| + typedef nqe::internal::ObservationBuffer<base::TimeDelta>
|
| RttObservationBuffer;
|
|
|
| // Value of throughput observations is in kilobits per second.
|
| - typedef net::NetworkQualityEstimator::Observation<int32_t>
|
| - ThroughputObservation;
|
| - typedef net::NetworkQualityEstimator::ObservationBuffer<int32_t>
|
| - ThroughputObservationBuffer;
|
| + typedef nqe::internal::Observation<int32_t> ThroughputObservation;
|
| + typedef nqe::internal::ObservationBuffer<int32_t> ThroughputObservationBuffer;
|
|
|
| // This does not use a unordered_map or hash_map for code simplicity (key just
|
| // implements operator<, rather than hash and equality) and because the map is
|
| // tiny.
|
| - typedef std::map<NetworkID, CachedNetworkQuality> CachedNetworkQualities;
|
| -
|
| - // Throughput is set to |kInvalidThroughput| if a valid value is
|
| - // unavailable. Readers should discard throughput value if it is set to
|
| - // |kInvalidThroughput|.
|
| - static const int32_t kInvalidThroughput;
|
| + typedef std::map<NetworkID, nqe::internal::CachedNetworkQuality>
|
| + CachedNetworkQualities;
|
|
|
| // Tiny transfer sizes may give inaccurate throughput results.
|
| // Minimum size of the transfer over which the throughput is computed.
|
| @@ -509,9 +301,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // Larger size may affect performance.
|
| static const size_t kMaximumNetworkQualityCacheSize = 10;
|
|
|
| - // Maximum number of observations that can be held in the ObservationBuffer.
|
| - static const size_t kMaximumObservationsBufferSize = 300;
|
| -
|
| // Time duration (in milliseconds) after which the estimate provided by
|
| // external estimate provider is considered stale.
|
| static const int kExternalEstimateProviderFreshnessDurationMsec =
|
| @@ -554,7 +343,8 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // returned estimate with 0.9 probability. Similarly, network is expected to
|
| // be slower than the returned estimate with 0.1 probability.
|
| base::TimeDelta GetRTTEstimateInternal(
|
| - const std::vector<ObservationSource>& disallowed_observation_sources,
|
| + const std::vector<NetworkQualityObservationSource>&
|
| + disallowed_observation_sources,
|
| const base::TimeTicks& begin_timestamp,
|
| int percentile) const;
|
| int32_t GetDownlinkThroughputKbpsEstimateInternal(
|
| @@ -623,7 +413,7 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // The accuracy is decreased by ignoring these factors:
|
| // 1) Multiple URLRequests can occur concurrently.
|
| // 2) Includes server processing time.
|
| - NetworkQuality peak_network_quality_;
|
| + nqe::internal::NetworkQuality peak_network_quality_;
|
|
|
| // Cache that stores quality of previously seen networks.
|
| CachedNetworkQualities cached_network_qualities_;
|
| @@ -638,17 +428,18 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // Default network quality observations obtained from the network quality
|
| // estimator field trial parameters. The observations are indexed by
|
| // ConnectionType.
|
| - NetworkQuality
|
| + nqe::internal::NetworkQuality
|
| default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1];
|
|
|
| // Thresholds for different effective connection types obtained from field
|
| // trial variation params. These thresholds encode how different connection
|
| // types behave in general. In future, complex encodings (e.g., curve
|
| // fitting) may be used.
|
| - NetworkQuality connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST];
|
| + nqe::internal::NetworkQuality
|
| + connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST];
|
|
|
| // Estimated network quality. Updated on mainframe requests.
|
| - NetworkQuality estimated_median_network_quality_;
|
| + nqe::internal::NetworkQuality estimated_median_network_quality_;
|
|
|
| // ExternalEstimateProvider that provides network quality using operating
|
| // system APIs. May be NULL.
|
|
|