Chromium Code Reviews| Index: net/base/network_quality_estimator.h |
| diff --git a/net/base/network_quality_estimator.h b/net/base/network_quality_estimator.h |
| index aba0313b6ec924c68376ced83ecd7eeb5391c207..47de83a07ef503a056ca949ab097afa781ffdcab 100644 |
| --- a/net/base/network_quality_estimator.h |
| +++ b/net/base/network_quality_estimator.h |
| @@ -13,7 +13,9 @@ |
| #include "base/gtest_prod_util.h" |
| #include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/observer_list.h" |
| #include "base/threading/thread_checker.h" |
| #include "base/time/time.h" |
| #include "net/base/external_estimate_provider.h" |
| @@ -39,6 +41,64 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| public ExternalEstimateProvider::UpdatedEstimateDelegate, |
| public SocketPerformanceWatcherFactory { |
| public: |
| + // On Android, a Java counterpart will be generated for this enum. |
| + // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
| + // GENERATED_JAVA_CLASS_NAME_OVERRIDE: NetworkQualityObservationSource |
| + // GENERATED_JAVA_PREFIX_TO_STRIP: OBSERVATION_SOURCE_ |
| + enum ObservationSource { |
| + // The observation was taken at the request layer, e.g., a round trip time |
| + // is recorded as the time between the request being sent and the first byte |
| + // being received. |
| + OBSERVATION_SOURCE_URL_REQUEST, |
|
pauljensen
2015/09/18 16:07:52
why are these prefixed with "OBSERVATION_SOURCE_"?
bengr
2015/09/18 23:13:42
This is the convention in c++ Chromium afaik, e.g.
pauljensen
2015/09/22 16:03:03
Let's not be redundant in C++. In Java they'll ha
|
| + // The observation is taken from TCP statistics maintained by the kernel. |
| + OBSERVATION_SOURCE_TCP, |
| + // The observation is taken at the QUIC layer. |
| + OBSERVATION_SOURCE_QUIC, |
| + // The observation is a previously cached estimate of the metric. |
| + OBSERVATION_SOURCE_CACHED_ESTIMATE, |
| + // The observation is derived from network connection information provided |
| + // by the platform. For example, typical RTT and throughput values are used |
| + // for a given type of network connection. |
| + OBSERVATION_SOURCE_DEFAULT_FROM_PLATFORM, |
| + // The observation came from a Chromium-external source. |
| + OBSERVATION_SOURCE_EXTERNAL_ESTIMATE |
| + }; |
| + |
| + // 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. |
| + virtual void OnRTTObservation(int32_t rtt_ms, |
| + const base::TimeTicks& timestamp, |
| + ObservationSource source) = 0; |
| + |
| + protected: |
| + RTTObserver() {} |
| + virtual ~RTTObserver() {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(RTTObserver); |
| + }; |
| + |
| + // Observes measurements of throughput. |
| + class NET_EXPORT_PRIVATE ThroughputObserver { |
| + public: |
| + // Will be called when a new throughput observation is available. |
| + // Throughput is specified in kilobits per second. |
| + virtual void OnThroughputObservation(int32_t throughput_kbps, |
| + const base::TimeTicks& timestamp, |
| + ObservationSource source) = 0; |
| + |
| + protected: |
| + ThroughputObserver() {} |
| + virtual ~ThroughputObserver() {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ThroughputObserver); |
| + }; |
| + |
| // Creates a new NetworkQualityEstimator. |
| // |variation_params| is the map containing all field trial parameters |
| // related to NetworkQualityEstimator field trial. |
| @@ -85,6 +145,29 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| scoped_ptr<SocketPerformanceWatcher> CreateUDPSocketPerformanceWatcher() |
| const override; |
| + // Adds |rtt_observer| to the list of round trip time observers. Must be |
| + // called on the IO thread. |
| + void AddRTTObserver(RTTObserver* rtt_observer); |
| + |
| + // Removes |rtt_observer| from the list of round trip time observers if it |
| + // is on the list of observers. Must be called on the IO thread. |
| + void RemoveRTTObserver(RTTObserver* rtt_observer); |
| + |
| + // Adds |throughput_observer| to the list of throughput observers. Must be |
| + // called on the IO thread. |
| + void AddThroughputObserver(ThroughputObserver* throughput_observer); |
| + |
| + // Removes |throughput_observer| from the list of throughput observers if it |
| + // is on the list of observers. Must be called on the IO thread. |
| + void RemoveThroughputObserver(ThroughputObserver* throughput_observer); |
| + |
| + // Configure for testing. If true, |allow_local_host_requests| will include |
| + // observations from localhost, and |allow_smaller_responses| will remove |
| + // the requirement of throughtput observations that response size be above |
| + // a threshold. |
| + void ConfigureForTests(bool allow_local_host_requests, |
| + bool allow_smaller_responses); |
| + |
| protected: |
| // NetworkID is used to uniquely identify a network. |
| // For the purpose of network quality estimation and caching, a network is |
| @@ -222,9 +305,15 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| }; |
| // Records the round trip time or throughput observation, along with the time |
| - // the observation was made. |
| + // the observation was made. The units of value are type specific. For round |
| + // trip time observations, the value is in milliseconds. For throughput, |
| + // the value is in kilobits per second. Observations can be made at several |
| + // places in the network stack, thus the observation source is provided as |
| + // well. |
| struct NET_EXPORT_PRIVATE Observation { |
| - Observation(int32_t value, base::TimeTicks timestamp); |
| + Observation(int32_t value, |
| + base::TimeTicks timestamp, |
| + ObservationSource source); |
| ~Observation(); |
| // Value of the observation. |
| @@ -232,6 +321,9 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| // Time when the observation was taken. |
| const base::TimeTicks timestamp; |
| + |
| + // The source of the observation. |
| + const ObservationSource source; |
| }; |
| // Holds an observation and its weight. |
| @@ -387,6 +479,10 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| // Writes the estimated quality of the current network to the cache. |
| void CacheNetworkQualityEstimate(); |
| + void NotifyObserversOfRTT(const Observation& observation); |
| + |
| + void NotifyObserversOfThroughput(const Observation& observation); |
| + |
| // Records the UMA related to RTT. |
| void RecordRTTUMA(int32_t estimated_value_msec, |
| int32_t actual_value_msec) const; |
| @@ -398,12 +494,12 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| // 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_; |
| + bool allow_localhost_requests_; |
| // Determines if the responses smaller than |kMinTransferSizeInBytes| |
| // or shorter than |kMinTransferSizeInBytes| can be used in estimating the |
| // network quality. Set to true only for tests. |
| - const bool allow_small_responses_; |
| + bool allow_small_responses_; |
| // Time when last connection change was observed. |
| base::TimeTicks last_connection_change_; |
| @@ -441,6 +537,10 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| // system APIs. May be NULL. |
| const scoped_ptr<ExternalEstimateProvider> external_estimates_provider_; |
| + // Observer lists for round trip times and throughput measurements. |
| + base::ObserverList<RTTObserver> rtt_observer_list_; |
| + base::ObserverList<ThroughputObserver> throughput_observer_list_; |
| + |
| base::ThreadChecker thread_checker_; |
| DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |