| Index: net/base/network_quality_estimator.h
|
| diff --git a/net/base/network_quality_estimator.h b/net/base/network_quality_estimator.h
|
| index 9fa0ad1817604c0472f8e5bafb9f78b619cfe477..726c3aa49e69ba055d11b8e7ee8709fa694836ca 100644
|
| --- a/net/base/network_quality_estimator.h
|
| +++ b/net/base/network_quality_estimator.h
|
| @@ -13,6 +13,7 @@
|
| #include <string>
|
| #include <tuple>
|
|
|
| +#include "base/compiler_specific.h"
|
| #include "base/gtest_prod_util.h"
|
| #include "base/macros.h"
|
| #include "base/memory/ref_counted.h"
|
| @@ -69,9 +70,9 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // Observes measurements of round trip time.
|
| class NET_EXPORT_PRIVATE RTTObserver {
|
| public:
|
| - // Will be called when a new RTT observation is available. The round trip
|
| - // time is specified in milliseconds. The time when the observation was
|
| - // taken and the source of the observation are provided.
|
| + // OnRTTObservation will be called when a new RTT observation is available.
|
| + // The round trip time is specified in milliseconds. The time when the
|
| + // observation was taken and the source of the observation are provided.
|
| virtual void OnRTTObservation(int32_t rtt_ms,
|
| const base::TimeTicks& timestamp,
|
| ObservationSource source) = 0;
|
| @@ -101,6 +102,35 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| DISALLOW_COPY_AND_ASSIGN(ThroughputObserver);
|
| };
|
|
|
| + // Observes measurements of packet loss.
|
| + class NET_EXPORT_PRIVATE PacketLossObserver {
|
| + public:
|
| + // OnPacketLossObservation will be called when a new packet loss
|
| + // observation is available. |packets_lost| is the number of packets
|
| + // lost. |packets_received_in_order| is the number of packets received
|
| + // in order. |packets_received_out_of_order| is the number of packets
|
| + // received out of order.
|
| +
|
| + // An example:
|
| + // Last observation after packet #1. Packets #5 and #6 are received:
|
| + // lost = 3, in_order = 2, out_of_order = 0.
|
| +
|
| + // Last observation after packet #6. Packet #3 received:
|
| + // lost = 0, in_order = 0, out_of_order = 1.
|
| + virtual void OnPacketLossObservation(size_t packets_lost,
|
| + size_t packets_received_in_order,
|
| + size_t packets_received_out_of_order,
|
| + const base::TimeTicks& timestamp,
|
| + ObservationSource source) = 0;
|
| +
|
| + protected:
|
| + PacketLossObserver() {}
|
| + virtual ~PacketLossObserver() {}
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(PacketLossObserver);
|
| + };
|
| +
|
| // Creates a new NetworkQualityEstimator.
|
| // |variation_params| is the map containing all field trial parameters
|
| // related to NetworkQualityEstimator field trial.
|
| @@ -131,13 +161,22 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| ~NetworkQualityEstimator() override;
|
|
|
| // Returns true if RTT is available and sets |rtt| to estimated RTT.
|
| - // Virtualized for testing. |rtt| should not be null.
|
| - virtual bool GetRTTEstimate(base::TimeDelta* rtt) const;
|
| + // Virtualized for testing. |rtt| must not be null.
|
| + virtual bool GetRTTEstimate(base::TimeDelta* rtt) const WARN_UNUSED_RESULT;
|
|
|
| // Returns true if downlink throughput is available and sets |kbps| to
|
| // estimated downlink throughput (in kilobits per second).
|
| - // Virtualized for testing. |kbps| should not be null.
|
| - virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const;
|
| + // Virtualized for testing. |kbps| must not be null.
|
| + virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const
|
| + WARN_UNUSED_RESULT;
|
| +
|
| + // Returns true if the estimated packet loss rate is available and sets
|
| + // |packet_loss_rate_estimate| to the estimated packet loss rate. Virtualized
|
| + // for testing. |packet_loss_rate_estimate| must not be NULL.
|
| + // |packet_loss_rate_estimate| is always between 0.0 and 1.0 (both inclusive)
|
| + // with a higher value indicating higher packet loss rate.
|
| + virtual bool GetPacketLossRateEstimate(float* packet_loss_rate_estimate) const
|
| + WARN_UNUSED_RESULT;
|
|
|
| // Notifies NetworkQualityEstimator that the response header of |request| has
|
| // been received.
|
| @@ -149,23 +188,29 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
|
|
| // Returns true if median RTT is available and sets |rtt| to the median of
|
| // RTT observations since |begin_timestamp|.
|
| - // Virtualized for testing. |rtt| should not be null.
|
| + // Virtualized for testing. |rtt| must not be null.
|
| virtual bool GetRecentMedianRTT(const base::TimeTicks& begin_timestamp,
|
| - base::TimeDelta* rtt) const;
|
| + base::TimeDelta* rtt) const
|
| + WARN_UNUSED_RESULT;
|
|
|
| // Returns true if median downstream throughput is available and sets |kbps|
|
| // to the median of downstream throughput (in kilobits per second)
|
| // observations since |begin_timestamp|. Virtualized for testing. |kbps|
|
| - // should not be null.
|
| + // must not be null.
|
| virtual bool GetRecentMedianDownlinkThroughputKbps(
|
| const base::TimeTicks& begin_timestamp,
|
| - int32_t* kbps) const;
|
| + int32_t* kbps) const WARN_UNUSED_RESULT;
|
|
|
| // SocketPerformanceWatcherFactory implementation:
|
| scoped_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher(
|
| const Protocol protocol) override;
|
| void OnUpdatedRTTAvailable(const Protocol protocol,
|
| const base::TimeDelta& rtt) override;
|
| + void OnUpdatedPacketCountAvailable(
|
| + Protocol protocol,
|
| + size_t packets_lost,
|
| + size_t packets_received_in_order,
|
| + size_t packets_received_out_of_order) override;
|
|
|
| // Adds |rtt_observer| to the list of round trip time observers. Must be
|
| // called on the IO thread.
|
| @@ -183,6 +228,14 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // is on the list of observers. Must be called on the IO thread.
|
| void RemoveThroughputObserver(ThroughputObserver* throughput_observer);
|
|
|
| + // Adds |packet_loss_observer| to the list of packet loss observers. Must be
|
| + // called on the IO thread.
|
| + void AddPacketLossObserver(PacketLossObserver* packet_loss_observer);
|
| +
|
| + // Removes |packet_loss_observer| from the list of packet loss observers if it
|
| + // is on the list of observers. Must be called on the IO thread.
|
| + void RemovePacketLossObserver(PacketLossObserver* packet_loss_observer);
|
| +
|
| protected:
|
| // NetworkID is used to uniquely identify a network.
|
| // For the purpose of network quality estimation and caching, a network is
|
| @@ -234,6 +287,8 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| private:
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates);
|
| + FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
|
| + TestPacketLossRateUpdates);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam);
|
| @@ -389,15 +444,23 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
|
|
| // 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.
|
| + // value among all observations since |begin_timestamp| (inclusive). 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.
|
| bool GetPercentile(const base::TimeTicks& begin_timestamp,
|
| ValueType* result,
|
| int percentile) const;
|
|
|
| + // Returns true iff the weighted average value of the observations in this
|
| + // buffer is available. Sets |result| to the computed average
|
| + // value of all observations since |begin_timestamp| (inclusive). If the
|
| + // value is unavailable, false is returned and |result| is not modified.
|
| + // The average value is unavailable if all of the values in the observation
|
| + // buffer are older than |begin_timestamp|. |result| must not be NULL.
|
| + bool GetWeightedAverage(const base::TimeTicks& begin_timestamp,
|
| + ValueType* result) const WARN_UNUSED_RESULT;
|
| +
|
| private:
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
|
| @@ -441,6 +504,15 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| typedef net::NetworkQualityEstimator::ObservationBuffer<int32_t>
|
| ThroughputObservationBuffer;
|
|
|
| + // Value of a packet loss observation. A value of 0.0 indicates all packets
|
| + // during the observation period were received successfully in-order, while a
|
| + // value of 1.0 indicates all packets during the observation period were
|
| + // lost. Currently, the observation period is set to one packet.
|
| + typedef net::NetworkQualityEstimator::Observation<float>
|
| + PacketLossRateObservation;
|
| + typedef net::NetworkQualityEstimator::ObservationBuffer<float>
|
| + PacketLossRateObservationBuffer;
|
| +
|
| // 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.
|
| @@ -451,6 +523,12 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // |kInvalidThroughput|.
|
| static const int32_t kInvalidThroughput;
|
|
|
| + // Packet loss rate is set to a value strictly lower than
|
| + // |kMinimumValidPacketLossRate| if a valid value is unavailable. Readers
|
| + // should discard the packet loss rate value if it is set to a value strictly
|
| + // lower than |kMinimumValidPacketLossRate|.
|
| + static const float kMinimumValidPacketLossRate;
|
| +
|
| // Tiny transfer sizes may give inaccurate throughput results.
|
| // Minimum size of the transfer over which the throughput is computed.
|
| static const int kMinTransferSizeInBytes = 10000;
|
| @@ -504,10 +582,16 @@ 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 base::TimeTicks& begin_timestamp,
|
| - int percentile) const;
|
| + int percentile) const
|
| + WARN_UNUSED_RESULT;
|
| int32_t GetDownlinkThroughputKbpsEstimateInternal(
|
| const base::TimeTicks& begin_timestamp,
|
| - int percentile) const;
|
| + int percentile) const WARN_UNUSED_RESULT;
|
| +
|
| + // Returns an estimate of the packet loss rate. Only the observations later
|
| + // than |begin_timestamp| are taken into account.
|
| + float GetPacketLossRateEstimateInternal(
|
| + const base::TimeTicks& begin_timestamp) const WARN_UNUSED_RESULT;
|
|
|
| // Returns the current network ID checking by calling the platform APIs.
|
| // Virtualized for testing.
|
| @@ -520,6 +604,12 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
|
|
| void NotifyObserversOfThroughput(const ThroughputObservation& observation);
|
|
|
| + void NotifyObserversOfPacketLoss(size_t packets_lost,
|
| + size_t packets_received_in_order,
|
| + size_t packets_received_out_of_order,
|
| + const base::TimeTicks& timestamp,
|
| + ObservationSource source);
|
| +
|
| // Records the UMA related to RTT.
|
| void RecordRTTUMA(int32_t estimated_value_msec,
|
| int32_t actual_value_msec) const;
|
| @@ -545,6 +635,14 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| void RecordExternalEstimateProviderMetrics(
|
| NQEExternalEstimateProviderStatus status) const;
|
|
|
| + // Gets the ObservationSource that corresponds to the given |protocol|,
|
| + // updates |observation_source| and returns true. If the corresponding
|
| + // ObservationSource is unknown, false is returned and |observation_source| is
|
| + // not modified.
|
| + bool GetObservationSourceForProtocol(
|
| + Protocol protocol,
|
| + ObservationSource* observation_source) const;
|
| +
|
| // Determines if the requests to local host can be used in estimating the
|
| // network quality. Set to true only for tests.
|
| const bool allow_localhost_requests_;
|
| @@ -578,6 +676,9 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // Buffer that holds RTT observations sorted by timestamp.
|
| RttObservationBuffer rtt_msec_observations_;
|
|
|
| + // Buffer that holds packet loss observations sorted by timestamp.
|
| + PacketLossRateObservationBuffer packet_loss_rate_observations_;
|
| +
|
| // Default network quality observations obtained from the network quality
|
| // estimator field trial parameters. The observations are indexed by
|
| // ConnectionType.
|
| @@ -591,9 +692,11 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // system APIs. May be NULL.
|
| const scoped_ptr<ExternalEstimateProvider> external_estimate_provider_;
|
|
|
| - // Observer lists for round trip times and throughput measurements.
|
| + // Observer lists for round trip times, throughput and packet loss
|
| + // measurements.
|
| base::ObserverList<RTTObserver> rtt_observer_list_;
|
| base::ObserverList<ThroughputObserver> throughput_observer_list_;
|
| + base::ObserverList<PacketLossObserver> packet_loss_observer_list_;
|
|
|
| base::ThreadChecker thread_checker_;
|
|
|
|
|