Index: net/base/network_quality_estimator.h |
diff --git a/net/base/network_quality_estimator.h b/net/base/network_quality_estimator.h |
index 32e1a3ef8a8b41672fed1eba59c03f43d94dec1a..35cbd1d80d3c57b269dcdcc195573b6bf439be2b 100644 |
--- a/net/base/network_quality_estimator.h |
+++ b/net/base/network_quality_estimator.h |
@@ -13,10 +13,12 @@ |
#include <string> |
#include <tuple> |
+#include "base/callback.h" |
#include "base/gtest_prod_util.h" |
#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
#include "base/observer_list.h" |
#include "base/threading/thread_checker.h" |
#include "base/time/time.h" |
@@ -26,6 +28,10 @@ |
#include "net/base/socket_performance_watcher.h" |
#include "net/base/socket_performance_watcher_factory.h" |
+namespace base { |
+class SingleThreadTaskRunner; |
+} // namespace base |
+ |
namespace net { |
class URLRequest; |
@@ -40,8 +46,7 @@ class URLRequest; |
// observed traffic characteristics. |
class NET_EXPORT_PRIVATE NetworkQualityEstimator |
: public NetworkChangeNotifier::ConnectionTypeObserver, |
- public ExternalEstimateProvider::UpdatedEstimateDelegate, |
- public SocketPerformanceWatcherFactory { |
+ public ExternalEstimateProvider::UpdatedEstimateDelegate { |
public: |
// On Android, a Java counterpart will be generated for this enum. |
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
@@ -168,12 +173,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
const base::TimeTicks& begin_timestamp, |
int32_t* kbps) const; |
- // SocketPerformanceWatcherFactory implementation: |
- scoped_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher( |
- const Protocol protocol) override; |
- void OnUpdatedRTTAvailable(const Protocol protocol, |
- const base::TimeDelta& rtt) override; |
- |
// Adds |rtt_observer| to the list of round trip time observers. Must be |
// called on the IO thread. |
void AddRTTObserver(RTTObserver* rtt_observer); |
@@ -190,6 +189,9 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
// is on the list of observers. Must be called on the IO thread. |
void RemoveThroughputObserver(ThroughputObserver* throughput_observer); |
+ // Virtualized for testing. |
+ virtual SocketPerformanceWatcherFactory* GetSocketPerformanceWatcherFactory(); |
+ |
protected: |
// NetworkID is used to uniquely identify a network. |
// For the purpose of network quality estimation and caching, a network is |
@@ -443,6 +445,39 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
DISALLOW_COPY_AND_ASSIGN(ObservationBuffer); |
}; |
+ typedef base::Callback<void( |
+ SocketPerformanceWatcherFactory::Protocol protocol, |
+ const base::TimeDelta& rtt)> |
+ RTTUpdateCallback; |
+ |
+ // SocketWatcherFactory implements SocketPerformanceWatcherFactory, and is |
+ // owned by |NetworkQualityEstimator|. |SocketWatcherFactory| is thread safe. |
+ class NET_EXPORT_PRIVATE SocketWatcherFactory |
+ : public SocketPerformanceWatcherFactory { |
+ public: |
+ SocketWatcherFactory( |
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
+ RTTUpdateCallback rtt_update_callback); |
+ ~SocketWatcherFactory() override; |
+ |
+ // SocketPerformanceWatcherFactory implementation: |
+ scoped_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher( |
+ const Protocol protocol) override; |
+ void OnUpdatedRTTAvailable(const Protocol protocol, |
+ const base::TimeDelta& rtt) override; |
+ void OnWatcherReset() override; |
+ |
+ private: |
+ // TaskRunner on which the |rtt_update_callback_| is invoked. |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
+ |
+ RTTUpdateCallback rtt_update_callback_; |
+ |
+ base::WeakPtrFactory<SocketWatcherFactory> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SocketWatcherFactory); |
+ }; |
+ |
// Value of round trip time observations is in base::TimeDelta. |
typedef net::NetworkQualityEstimator::Observation<base::TimeDelta> |
RttObservation; |
@@ -498,6 +533,10 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
// should discard RTT if it is set to the value returned by |InvalidRTT()|. |
static const base::TimeDelta InvalidRTT(); |
+ // Notifies |this| of a new transport layer RTT. |
+ void OnUpdatedRTTAvailable(SocketPerformanceWatcherFactory::Protocol protocol, |
+ const base::TimeDelta& rtt); |
+ |
// Queries the external estimate provider for the latest network quality |
// estimates, and adds those estimates to the current observation buffer. |
void QueryExternalEstimateProvider(); |
@@ -535,6 +574,8 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
void NotifyObserversOfThroughput(const ThroughputObservation& observation); |
+ base::WeakPtr<NetworkQualityEstimator> GetWeakPtr(); |
+ |
// Records the UMA related to RTT. |
void RecordRTTUMA(int32_t estimated_value_msec, |
int32_t actual_value_msec) const; |
@@ -610,8 +651,12 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
base::ObserverList<RTTObserver> rtt_observer_list_; |
base::ObserverList<ThroughputObserver> throughput_observer_list_; |
+ scoped_ptr<SocketPerformanceWatcherFactory> watcher_factory_; |
+ |
base::ThreadChecker thread_checker_; |
+ base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
+ |
DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
}; |