Chromium Code Reviews| Index: net/nqe/network_quality_estimator.h |
| diff --git a/net/nqe/network_quality_estimator.h b/net/nqe/network_quality_estimator.h |
| index fd51a61499febb3b757eed73700cc40ccc0149a3..131c67ade43c68f3bd63a4edbc80049aee29c299 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,29 @@ 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 change in the effective connection type. |
|
bengr
2016/05/31 17:39:25
of -> of a
tbansal1
2016/05/31 21:40:25
Done.
|
| + // NetworkQualityEstimator computes effective connection type once in every |
|
bengr
2016/05/31 17:39:25
computes -> computes the
tbansal1
2016/05/31 21:40:25
Done.
|
| + // 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. |
| + // |
| + // 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( |
|
bengr
2016/05/31 17:39:25
This is not threadsafe, right? Say so.
tbansal1
2016/05/31 21:40:26
Done.
|
| + 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 +168,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 |
| @@ -271,6 +305,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); |
| @@ -391,6 +428,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 change in effective connection type. |
|
bengr
2016/05/31 17:39:24
of -> of a
tbansal1
2016/05/31 21:40:25
Done.
|
| + 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. |
| @@ -421,6 +465,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 network quality estimator. |
|
bengr
2016/05/31 17:39:24
by -> by the
tbansal1
2016/05/31 21:40:25
Done.
|
| + std::unique_ptr<base::TickClock> tick_clock_; |
| + |
| + // Minimum duration between two consecutive computations of effective |
| + // connection type. |
|
bengr
2016/05/31 17:39:25
Add "Non-zero as a performance optimization."
tbansal1
2016/05/31 21:40:25
Done.
|
| + 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_; |
| @@ -465,6 +519,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_; |
| @@ -477,6 +535,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_; |