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..796409d1b1ae8e6043ba85d6b2a95284f8bb8a54 100644 |
--- a/net/base/network_quality_estimator.h |
+++ b/net/base/network_quality_estimator.h |
@@ -101,6 +101,37 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
DISALLOW_COPY_AND_ASSIGN(ThroughputObserver); |
}; |
+ // Observes measurements of packet loss. |
+ class NET_EXPORT_PRIVATE PacketLossObserver { |
+ public: |
+ // Will be called when a new packet loss observation is available. |
bengr
2016/02/16 17:02:02
Use complete sentences. "This method will.."
tbansal1
2016/02/17 18:35:10
Done.
|
+ // |num_packets_lost| is the number of packets lost. |
+ // |num_packets_received_in_order| is the number of packets received in |
+ // order. |num_packets_received_not_in_order| is the number of packets |
+ // received out of order. See |
+ // SocketPerformanceWatcherFactory::OnUpdatedPacketCountAvailable for more |
+ // details on how these values are populated. |
+ // |
+ // Providing counts of lost, in-order and out-of-order packets provides |
+ // consumers with more information. From the perspective of network quality, |
bengr
2016/02/16 17:02:01
More information than what?
How does network quali
tbansal1
2016/02/17 18:35:10
Done.
|
+ // loss of a packet indicates worse network quality than receival of an |
bengr
2016/02/16 17:02:02
receival -> reception
tbansal1
2016/02/17 18:35:10
Removed that comment, it was confusing. Also, how
|
+ // out-of-order packet. The latter in turns indicates worse network |
bengr
2016/02/16 17:02:02
turns -> turn
tbansal1
2016/02/17 18:35:11
Done.
|
+ // quality than receival of an in-order packet. |
bengr
2016/02/16 17:02:02
receival -> reception
tbansal1
2016/02/17 18:35:10
Done.
|
+ virtual void OnPacketLossObservation( |
+ uint64_t num_packets_lost, |
+ uint64_t num_packets_received_in_order, |
+ uint64_t num_packets_received_not_in_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. |
@@ -139,6 +170,12 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
// Virtualized for testing. |kbps| should not be null. |
virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const; |
+ // Returns true if the estimated packet loss rate is available and sets |
+ // |packet_loss| to the estimated packet loss rate. Virtualized for testing. |
+ // |packet_loss| should not be NULL. |packet_loss| is always between 0.0 |
+ // and 1.0 with a higher value indicating higher packet loss rate. |
bengr
2016/02/16 17:02:02
inclusive?
tbansal1
2016/02/17 18:35:10
Done.
|
+ virtual bool GetPacketLossRateEstimate(float* packet_loss) const; |
+ |
// Notifies NetworkQualityEstimator that the response header of |request| has |
// been received. |
void NotifyHeadersReceived(const URLRequest& request); |
@@ -166,6 +203,11 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
const Protocol protocol) override; |
void OnUpdatedRTTAvailable(const Protocol protocol, |
const base::TimeDelta& rtt) override; |
+ void OnUpdatedPacketCountAvailable( |
+ const Protocol protocol, |
+ uint64_t num_packets_lost, |
+ uint64_t num_packets_received_in_order, |
+ uint64_t num_packets_received_not_in_order) override; |
// Adds |rtt_observer| to the list of round trip time observers. Must be |
// called on the IO thread. |
@@ -183,6 +225,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 +284,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); |
@@ -398,6 +450,15 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
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 among all observations since |begin_timestamp|. If the value is |
+ // unavailable, false is returned and |result| is not modified. Average |
bengr
2016/02/16 17:02:02
Average -> The average
tbansal1
2016/02/17 18:35:11
Done.
|
+ // value is unavailable if all the values in observation buffer are older |
bengr
2016/02/16 17:02:02
all the -> all of the
in observation -> in the obs
tbansal1
2016/02/17 18:35:11
Done.
|
+ // than |begin_timestamp|. |result| must not be NULL. |
+ bool GetWeightedAverage(const base::TimeTicks& begin_timestamp, |
+ ValueType* result) const; |
+ |
private: |
FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
@@ -441,6 +502,12 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
typedef net::NetworkQualityEstimator::ObservationBuffer<int32_t> |
ThroughputObservationBuffer; |
+ // Value of a packet loss observation. A value of 0.0 indicates one packet |
+ // was received successfully in-order, while a value of 1.0 indicates one |
+ // packet was lost. |
bengr
2016/02/16 17:02:02
What does a value of 0.5 mean? Why can't this be a
tbansal1
2016/02/17 18:35:11
This is packet loss rate observation from the rece
|
+ typedef net::NetworkQualityEstimator::Observation<float> |
+ PacketLossObservation; |
+ |
// 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 +518,11 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
// |kInvalidThroughput|. |
static const int32_t kInvalidThroughput; |
+ // Packet loss rate is set to |kInvalidPacketLossRate| if a valid value is |
+ // unavailable. Readers should discard the packet loss rate value if it is |
+ // set to |kInvalidPacketLossRate|. |
+ static const float kInvalidPacketLossRate; |
bengr
2016/02/16 17:02:02
It might be better to provide an is_valid() method
tbansal1
2016/02/17 18:35:11
Changed to use a min valid value.
|
+ |
// Tiny transfer sizes may give inaccurate throughput results. |
// Minimum size of the transfer over which the throughput is computed. |
static const int kMinTransferSizeInBytes = 10000; |
@@ -509,6 +581,11 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
const base::TimeTicks& begin_timestamp, |
int percentile) const; |
+ // 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; |
+ |
// Returns the current network ID checking by calling the platform APIs. |
// Virtualized for testing. |
virtual NetworkID GetCurrentNetworkID() const; |
@@ -520,6 +597,12 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
void NotifyObserversOfThroughput(const ThroughputObservation& observation); |
+ void NotifyObserversOfPacketLoss(uint64_t num_packets_lost, |
+ uint64_t num_packets_received_in_order, |
+ uint64_t num_packets_received_not_in_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 +628,13 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
void RecordExternalEstimateProviderMetrics( |
NQEExternalEstimateProviderStatus status) const; |
+ // Sets |observation_source| that corresponds to the given |protocol|, and |
bengr
2016/02/16 17:02:02
Do you mean "Gets the?" The entire comment is awkw
tbansal1
2016/02/17 18:35:11
Done.
|
+ // returns true. If the corresponding ObservationSource is unknown, false is |
+ // returned and |observation_source| is not modified. |
+ bool GetObservationSourceForProtocol( |
+ const 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 +668,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. |
+ ObservationBuffer<float> 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 +684,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_; |