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..d95e690e24183e88ff3f6f6787e62d485811fc6f 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,61 @@ 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 |
+ // |cummulative_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 cummulative_prefilter_bytes_read, |
+ int64_t prefiltered_bytes_read); |
private: |
FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
TestPeakKbpsFastestRTTUpdates); |
FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); |
+ // Sample is used to store RTT and Kbps samples in buffers. A sample has a |
+ // value and a timestamp (when the sample was taken). |
+ struct Sample { |
+ Sample(int value, base::TimeTicks timestamp); |
+ |
+ ~Sample(); |
+ |
+ // Value of the sample. |
+ const int value; |
+ |
+ // Time when the sample was taken. |
+ const base::TimeTicks timestamp; |
+ }; |
+ |
+ // SampleRingBuffer is used to store samples sorted by time. |
+ class SampleRingBuffer { |
+ public: |
+ SampleRingBuffer(); |
+ |
+ ~SampleRingBuffer(); |
+ |
+ // Adds a sample to the buffer. The oldest sample in the buffer will be |
+ // popped out and discarded if the buffer is already full. |
+ void AddSample(int value); |
+ |
+ private: |
+ // Maximum number of samples to hold in the SampleRingBuffer. |
+ static const size_t kMaximumSamples; |
+ |
+ // Buffer that holds samples sorted by time. |
+ // Oldest sample is at the front of the queue. |
+ std::deque<Sample> samples_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SampleRingBuffer); |
+ }; |
+ |
// Tiny transfer sizes may give inaccurate throughput results. |
// Minimum size of the transfer over which the throughput is computed. |
static const int kMinTransferSizeInBytes = 10000; |
@@ -93,6 +136,12 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
// 2) The transfer time includes at least one RTT while no bytes are read. |
uint64_t peak_kbps_since_last_connection_change_; |
+ // Buffer that holds Kbps samples. |
+ SampleRingBuffer kbps_samples_; |
+ |
+ // Buffer that holds RTT (in milliseconds) samples. |
+ SampleRingBuffer rtt_msec_samples_; |
+ |
base::ThreadChecker thread_checker_; |
DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |