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 a32264f89703e90cfb600f25f82dad5ebbf8b6cc..6629145da6f07c041fdb84a617b4f0ee2bdfef22 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" |
| @@ -36,6 +38,53 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| : public NetworkChangeNotifier::ConnectionTypeObserver, |
| public ExternalEstimateProvider::UpdatedEstimateDelegate { |
| 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 { |
| + OBSERVATION_SOURCE_URL_REQUEST, |
| + OBSERVATION_SOURCE_TCP, |
| + OBSERVATION_SOURCE_QUIC, |
| + OBSERVATION_SOURCE_CACHED_ESTIMATE, |
| + OBSERVATION_SOURCE_DEFAULT_FROM_PLATFORM, |
|
pauljensen
2015/09/02 16:54:48
Each of these needs a comment explaining it.
bengr
2015/09/14 21:04:35
Done.
|
| + 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 |
| + // times is specified in milliseconds. |
|
pauljensen
2015/09/02 16:54:48
times->time
bengr
2015/09/14 21:04:35
Done.
|
| + virtual void OnRTTObservation(int32_t rtt_ms, |
| + const base::TimeTicks& timestamp, |
|
pauljensen
2015/09/02 16:54:48
You might want to explain what |timestamp| is a ti
bengr
2015/09/14 21:04:35
Right. I wanted to decouple this so that there wou
|
| + 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. |
| @@ -76,6 +125,29 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| const base::TimeTicks& begin_timestamp, |
| int32_t* kbps) const; |
| + // 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 |
| @@ -213,9 +285,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. |
| @@ -223,6 +301,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. |
| @@ -378,6 +459,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; |
| @@ -389,12 +474,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_; |
| @@ -432,6 +517,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); |