| Index: net/nqe/network_quality_estimator.h
|
| diff --git a/net/nqe/network_quality_estimator.h b/net/nqe/network_quality_estimator.h
|
| index 333f2763e31e410efd5708335746de3ecc23c50f..2abc9fd7d6f7bffbcea10f7262ff497dbeb225c8 100644
|
| --- a/net/nqe/network_quality_estimator.h
|
| +++ b/net/nqe/network_quality_estimator.h
|
| @@ -32,6 +32,7 @@
|
|
|
| namespace base {
|
| class SingleThreadTaskRunner;
|
| +class TickClock;
|
| } // namespace base
|
|
|
| namespace net {
|
| @@ -76,6 +77,32 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| EFFECTIVE_CONNECTION_TYPE_LAST,
|
| };
|
|
|
| + // Observes changes in effective connection type.
|
| + class NET_EXPORT_PRIVATE EffectiveConnectionTypeObserver {
|
| + public:
|
| + // Notifies the observer of a change in the effective connection type.
|
| + // NetworkQualityEstimator computes the effective connection type once in
|
| + // every interval of duration
|
| + // |effective_connection_type_recomputation_interval_|. Additionally, when
|
| + // there is a change in the connection type of the device, then the
|
| + // effective connection type is immediately recomputed. The observer must
|
| + // register and unregister itself on the IO thread. All the observers would
|
| + // be notified on the IO thread.
|
| + //
|
| + // If the computed effective connection type is different from the
|
| + // previously notified effective connection type, then all the registered
|
| + // observers are notified of the new effective connection type.
|
| + virtual void OnEffectiveConnectionTypeChanged(
|
| + EffectiveConnectionType type) = 0;
|
| +
|
| + protected:
|
| + EffectiveConnectionTypeObserver() {}
|
| + virtual ~EffectiveConnectionTypeObserver() {}
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver);
|
| + };
|
| +
|
| // Observes measurements of round trip time.
|
| class NET_EXPORT_PRIVATE RTTObserver {
|
| public:
|
| @@ -144,6 +171,16 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // testing.
|
| virtual EffectiveConnectionType GetEffectiveConnectionType() const;
|
|
|
| + // Adds |observer| to the list of effective connection type observers. Must be
|
| + // called on the IO thread.
|
| + void AddEffectiveConnectionTypeObserver(
|
| + EffectiveConnectionTypeObserver* observer);
|
| +
|
| + // Removes |observer| from the list of effective connection type observers.
|
| + // Must be called on the IO thread.
|
| + void RemoveEffectiveConnectionTypeObserver(
|
| + EffectiveConnectionTypeObserver* observer);
|
| +
|
| // Returns true if the RTT is available and sets |rtt| to the RTT estimated at
|
| // the HTTP layer. Virtualized for testing. |rtt| should not be null. The RTT
|
| // at the HTTP layer measures the time from when the request was sent (this
|
| @@ -273,6 +310,9 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| const char* GetNameForEffectiveConnectionType(
|
| EffectiveConnectionType type) const;
|
|
|
| + // Overrides the tick clock used by |this| for testing.
|
| + void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock);
|
| +
|
| private:
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations);
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation);
|
| @@ -392,6 +432,13 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // Returns true only if the |request| can be used for RTT estimation.
|
| bool RequestProvidesRTTObservation(const URLRequest& request) const;
|
|
|
| + // Recomputes effective connection type, if it was computed more than the
|
| + // specified duration ago, or if there has been a connection change recently.
|
| + void MaybeRecomputeEffectiveConnectionType();
|
| +
|
| + // Notify observers of a change in effective connection type.
|
| + void NotifyObserversOfEffectiveConnectionTypeChanged();
|
| +
|
| // Values of external estimate provider status. This enum must remain
|
| // synchronized with the enum of the same name in
|
| // metrics/histograms/histograms.xml.
|
| @@ -422,6 +469,16 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // The factor by which the weight of an observation reduces every second.
|
| const double weight_multiplier_per_second_;
|
|
|
| + // Tick clock used by the network quality estimator.
|
| + std::unique_ptr<base::TickClock> tick_clock_;
|
| +
|
| + // Minimum duration between two consecutive computations of effective
|
| + // connection type. Set to non-zero value as a performance optimization.
|
| + const base::TimeDelta effective_connection_type_recomputation_interval_;
|
| +
|
| + // Time when the effective connection type was last computed.
|
| + base::TimeTicks last_effective_connection_type_computation_;
|
| +
|
| // Time when last connection change was observed.
|
| base::TimeTicks last_connection_change_;
|
|
|
| @@ -466,6 +523,10 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // system APIs. May be NULL.
|
| const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_;
|
|
|
| + // Observer list for changes in effective connection type.
|
| + base::ObserverList<EffectiveConnectionTypeObserver>
|
| + effective_connection_type_observer_list_;
|
| +
|
| // Observer lists for round trip times and throughput measurements.
|
| base::ObserverList<RTTObserver> rtt_observer_list_;
|
| base::ObserverList<ThroughputObserver> throughput_observer_list_;
|
| @@ -478,6 +539,12 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // estimating the throughput.
|
| std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_;
|
|
|
| + // Current effective connection type. It is updated on connection change
|
| + // events. It is also updated every time there is network traffic (provided
|
| + // the last computation was more than
|
| + // |effective_connection_type_recomputation_interval_| ago).
|
| + EffectiveConnectionType effective_connection_type_;
|
| +
|
| base::ThreadChecker thread_checker_;
|
|
|
| base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_;
|
|
|