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 dadce886e93624982efc1af620701e04912fc3c1..6ca7af93648d7a2f88b5eb45324d326bbf866c8f 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/net_export.h" |
| @@ -33,6 +35,51 @@ namespace net { |
| class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| : public NetworkChangeNotifier::ConnectionTypeObserver { |
| public: |
| + enum ObservationType { DOWNLINK_BANDWIDTH, 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 |
| + }; |
| + |
| + class NET_EXPORT RTTObserver { |
|
mef
2015/08/11 17:16:27
Why is this class NET_EXPORT but parent is NET_EXP
bengr
2015/08/25 23:43:34
Done.
|
| + public: |
| + // Will be called when a new RTT observation is available. |
| + virtual void OnRTTObservation(int32_t value, |
|
mef
2015/08/11 17:16:27
Need to specify units of |value|. Also below.
bengr
2015/08/25 23:43:34
Done.
|
| + const base::TimeTicks& timestamp, |
| + ObservationSource source) = 0; |
| + |
| + protected: |
| + RTTObserver() {} |
| + virtual ~RTTObserver() {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(RTTObserver); |
| + }; |
| + |
| + class NET_EXPORT BandwidthObserver { |
|
mef
2015/08/11 17:16:27
add class comment?
bengr
2015/08/25 23:43:34
Done.
|
| + public: |
| + // Will be called when a new Bandwidth observation is available. |
| + virtual void OnBandwidthObservation(int32_t value, |
| + const base::TimeTicks& timestamp, |
| + ObservationSource source) = 0; |
| + |
| + protected: |
| + BandwidthObserver() {} |
| + virtual ~BandwidthObserver() {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(BandwidthObserver); |
| + }; |
| + |
| // Creates a new NetworkQualityEstimator. |
| // |variation_params| is the map containing all field trial parameters |
| // related to NetworkQualityEstimator field trial. |
| @@ -65,6 +112,13 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| int64_t cumulative_prefilter_bytes_read, |
| int64_t prefiltered_bytes_read); |
| + void AddRTTObserver(RTTObserver* rtt_observer); |
| + void RemoveRTTObserver(RTTObserver* rtt_observer); |
| + void AddBandwidthObserver(BandwidthObserver* bandwidth_observer); |
| + void RemoveBandwidthObserver(BandwidthObserver* bandwidth_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 |
| @@ -170,7 +224,9 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| // Records the round trip time or throughput observation, along with the time |
| // the observation was made. |
| 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. |
| @@ -178,6 +234,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. |
| @@ -305,18 +364,22 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| // Writes the estimated quality of the current network to the cache. |
| void CacheNetworkQualityEstimate(); |
| + void NotifyObserversOfRTT(const Observation& observation); |
| + |
| + void NotifyObserversOfBandwidth(const Observation& observation); |
| + |
| // Records the UMA related to RTT. |
| void RecordRTTUMA(int32_t estimated_value_msec, |
| int32_t actual_value_msec) const; |
| // 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_; |
| @@ -350,6 +413,9 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| // Estimated network quality. Updated on mainframe requests. |
| NetworkQuality estimated_median_network_quality_; |
| + base::ObserverList<RTTObserver> rtt_observer_list_; |
| + base::ObserverList<BandwidthObserver> bandwidth_observer_list_; |
| + |
| base::ThreadChecker thread_checker_; |
| DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |