| 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..e80ca62c526b71ac25f941d910e64568a260b668 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_threadsafe.h"
|
| #include "base/threading/thread_checker.h"
|
| #include "base/time/time.h"
|
| #include "net/base/external_estimate_provider.h"
|
| @@ -36,6 +38,55 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| : public NetworkChangeNotifier::ConnectionTypeObserver,
|
| public ExternalEstimateProvider::UpdatedEstimateDelegate {
|
| public:
|
| + enum ObservationType { DOWNLINK_THROUGHPUT, RTT };
|
| +
|
| + // 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,
|
| + 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.
|
| + 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.
|
| @@ -76,6 +127,13 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| const base::TimeTicks& begin_timestamp,
|
| int32_t* kbps) const;
|
|
|
| + void AddRTTObserver(RTTObserver* rtt_observer);
|
| + void RemoveRTTObserver(RTTObserver* rtt_observer);
|
| + void AddThroughputObserver(ThroughputObserver* throughput_observer);
|
| + void RemoveThroughputObserver(ThroughputObserver* throughput_observer);
|
| +
|
| + void Configure(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 +271,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 +287,9 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
|
|
| // Time when the observation was taken.
|
| const base::TimeTicks timestamp;
|
| +
|
| + // The source of the observation.
|
| + ObservationSource source;
|
| };
|
|
|
| // Holds an observation and its weight.
|
| @@ -378,6 +445,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 +460,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 +503,11 @@ 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.
|
| + scoped_refptr<base::ObserverListThreadSafe<RTTObserver>> rtt_observer_list_;
|
| + scoped_refptr<base::ObserverListThreadSafe<ThroughputObserver>>
|
| + throughput_observer_list_;
|
| +
|
| base::ThreadChecker thread_checker_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator);
|
|
|