Index: net/base/network_quality_estimator.h |
diff --git a/net/base/network_quality_estimator.h b/net/base/network_quality_estimator.h |
index ecfa08af6b8341b3a9bb06897a89baa42651c7b7..2bef37940def5063de7f8c1c70c3760374274b76 100644 |
--- a/net/base/network_quality_estimator.h |
+++ b/net/base/network_quality_estimator.h |
@@ -7,15 +7,18 @@ |
#include <stdint.h> |
+#include <deque> |
+ |
#include "base/gtest_prod_util.h" |
#include "base/macros.h" |
#include "base/threading/thread_checker.h" |
#include "base/time/time.h" |
+#include "net/base/net_export.h" |
#include "net/base/network_change_notifier.h" |
namespace net { |
-struct NetworkQuality; |
+class NetworkQuality; |
// NetworkQualityEstimator provides network quality estimates (quality of the |
// full paths to all origins that have been connected to). |
@@ -33,21 +36,68 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
~NetworkQualityEstimator() override; |
- // Returns an estimate of the current network quality. |
- NetworkQuality GetEstimate() const; |
+ // Returns the peak estimates (fastest RTT and peak throughput) of the |
+ // current network. |
+ NetworkQuality GetPeakEstimate() const; |
// Notifies NetworkQualityEstimator that a response has been received. |
- // |prefilter_bytes_read| is the count of the bytes received prior to |
- // applying filters (e.g. decompression, SDCH) from request creation time |
+ // |cumulative_prefilter_bytes_read| is the count of the bytes received prior |
+ // to applying filters (e.g. decompression, SDCH) from request creation time |
// until now. |
+ // |prefiltered_bytes_read| is the count of the bytes received prior |
+ // to applying filters in the most recent read. |
void NotifyDataReceived(const URLRequest& request, |
- int64_t prefilter_bytes_read); |
+ int64_t cumulative_prefilter_bytes_read, |
+ int64_t prefiltered_bytes_read); |
private: |
+ FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
TestPeakKbpsFastestRTTUpdates); |
+ FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); |
FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); |
+ // Observation is used to store RTT and Kbps observation in buffers. An |
bengr
2015/06/11 00:14:56
// Records the round trip time or throughput obser
tbansal1
2015/06/11 01:43:00
Done.
|
+ // observation has a value and a timestamp (when the observation was taken). |
+ struct Observation { |
+ Observation(int32_t value, base::TimeTicks timestamp); |
+ |
+ ~Observation(); |
+ |
+ // Value of the observation. |
+ const int32_t value; |
+ |
+ // Time when the observation was taken. |
+ const base::TimeTicks timestamp; |
+ }; |
+ |
+ // ObservationBuffer is used to store observations sorted by time. |
bengr
2015/06/11 00:14:56
// Stores observations sorted by time.
tbansal1
2015/06/11 01:43:00
Done.
|
+ class ObservationBuffer { |
+ public: |
+ ObservationBuffer(); |
+ |
+ ~ObservationBuffer(); |
+ |
+ // Adds an observation to the buffer. The oldest observation in the buffer |
+ // will be popped out and discarded if the buffer is already full. |
bengr
2015/06/11 00:14:56
popped out and discarded -> evicted to make room
tbansal1
2015/06/11 01:43:00
Done.
|
+ void AddObservation(int32_t value); |
+ |
+ // Returns the number of observations in this buffer. |
+ size_t size() const; |
+ |
+ private: |
+ FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); |
+ |
+ // Maximum number of observations that can be held in the ObservationBuffer. |
+ static const size_t kMaximumObservations; |
+ |
+ // Holds observations sorted by time, with the oldest observation at the |
+ // front of the queue. |
+ std::deque<Observation> observations_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ObservationBuffer); |
+ }; |
+ |
// Tiny transfer sizes may give inaccurate throughput results. |
// Minimum size of the transfer over which the throughput is computed. |
static const int kMinTransferSizeInBytes = 10000; |
@@ -81,17 +131,23 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
NetworkChangeNotifier::ConnectionType current_connection_type_; |
// Set if any network data has been received since last connectivity change. |
- bool bytes_read_since_last_connection_change_; |
+ bool have_received_bytes_since_last_connection_change_; |
// Fastest round-trip-time (RTT) since last connectivity change. RTT measured |
// from URLRequest creation until first byte received. |
- base::TimeDelta fastest_RTT_since_last_connection_change_; |
+ base::TimeDelta fastest_rtt_since_last_connection_change_; |
- // Rough measurement of downlink peak Kbps witnessed since last connectivity |
+ // Rough measurement of downstream peak Kbps witnessed since last connectivity |
// change. The accuracy is decreased by ignoring these factors: |
// 1) Multiple URLRequests can occur concurrently. |
// 2) The transfer time includes at least one RTT while no bytes are read. |
- uint64_t peak_kbps_since_last_connection_change_; |
+ int32_t peak_kbps_since_last_connection_change_; |
+ |
+ // Buffer that holds Kbps observations. |
bengr
2015/06/11 00:14:56
KB/s everywhere in comments
tbansal1
2015/06/11 01:43:00
Currently, it is Kbps (kilo bits per second). As d
|
+ ObservationBuffer kbps_observations_; |
+ |
+ // Buffer that holds RTT (in milliseconds) observations. |
+ ObservationBuffer rtt_msec_observations_; |
base::ThreadChecker thread_checker_; |