| Index: net/base/network_quality_estimator.h | 
| diff --git a/net/base/network_quality_estimator.h b/net/base/network_quality_estimator.h | 
| index f951bd4f7fa533b72dd88a7ec01243c31cf6d38f..d6a32a0b293f16804b25e7bd499028e6acb85f85 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" | 
| @@ -39,6 +41,64 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator | 
| public ExternalEstimateProvider::UpdatedEstimateDelegate, | 
| public SocketPerformanceWatcherFactory { | 
| 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: | 
| +  enum ObservationSource { | 
| +    // The observation was taken at the request layer, e.g., a round trip time | 
| +    // is recorded as the time between the request being sent and the first byte | 
| +    // being received. | 
| +    URL_REQUEST, | 
| +    // The observation is taken from TCP statistics maintained by the kernel. | 
| +    TCP, | 
| +    // The observation is taken at the QUIC layer. | 
| +    QUIC, | 
| +    // The observation is a previously cached estimate of the metric. | 
| +    CACHED_ESTIMATE, | 
| +    // The observation is derived from network connection information provided | 
| +    // by the platform. For example, typical RTT and throughput values are used | 
| +    // for a given type of network connection. | 
| +    DEFAULT_FROM_PLATFORM, | 
| +    // The observation came from a Chromium-external 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 | 
| +    // time is specified in milliseconds. The time when the observation was | 
| +    // taken and the source of the observation are provided. | 
| +    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. | 
| @@ -85,6 +145,29 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator | 
| scoped_ptr<SocketPerformanceWatcher> CreateUDPSocketPerformanceWatcher() | 
| const override; | 
|  | 
| +  // 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 throughput 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 | 
| @@ -229,9 +312,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. | 
| @@ -239,6 +328,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. | 
| @@ -400,6 +492,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; | 
| @@ -427,12 +523,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_; | 
| @@ -470,6 +566,10 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator | 
| // system APIs. May be NULL. | 
| const scoped_ptr<ExternalEstimateProvider> external_estimate_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); | 
|  |