Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2097)

Unified Diff: net/base/network_quality_estimator.h

Issue 1164713004: Store network quality samples so we can compute percentiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes to make the tests work on Windows Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/network_quality.cc ('k') | net/base/network_quality_estimator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/network_quality_estimator.h
diff --git a/net/base/network_quality_estimator.h b/net/base/network_quality_estimator.h
index 8be76c34f2bd4646bc13c4a096111dd179a16e69..824bf4d6a448cc7cbf963e4c0008ee74e7fdbbc1 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,22 +36,69 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
~NetworkQualityEstimator() override;
- // Returns an estimate of the current network quality.
+ // Returns the peak estimates (fastest RTT and peak throughput) of the
+ // current network.
// Virtualized for testing.
- virtual NetworkQuality GetEstimate() const;
+ virtual 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);
+ // Records the round trip time or throughput observation, along with the time
+ // the observation was made.
+ 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;
+ };
+
+ // Stores observations sorted by time.
+ class ObservationBuffer {
+ public:
+ ObservationBuffer();
+
+ ~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& observation);
+
+ // Returns the number of observations in this buffer.
+ size_t Size() const;
+
+ // Clears the observations stored in this buffer.
+ void Clear();
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations);
+
+ // 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;
@@ -66,6 +116,14 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
// used for network quality estimation.
explicit NetworkQualityEstimator(bool allow_local_host_requests_for_tests);
+ // Returns the maximum size of the observation buffer.
+ // Used for testing.
+ size_t GetMaximumObservationBufferSizeForTests() const;
+
+ // Returns true if the size of all observation buffers is equal to the
+ // |expected_size|. Used for testing.
+ bool VerifyBufferSizeForTests(size_t expected_size) const;
+
// NetworkChangeNotifier::ConnectionTypeObserver implementation.
void OnConnectionTypeChanged(
NetworkChangeNotifier::ConnectionType type) override;
@@ -81,18 +139,21 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
// current connection type.
NetworkChangeNotifier::ConnectionType current_connection_type_;
- // Set if any network data has been received since last connectivity change.
- bool bytes_read_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.
+ ObservationBuffer kbps_observations_;
+
+ // Buffer that holds RTT (in milliseconds) observations.
+ ObservationBuffer rtt_msec_observations_;
base::ThreadChecker thread_checker_;
« no previous file with comments | « net/base/network_quality.cc ('k') | net/base/network_quality_estimator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698