Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Unified Diff: net/base/network_quality_estimator.cc

Issue 1831383002: Add SocketWatcherFactory as a helper class to NQE (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased, removed cyclic dependency between SPWF and SPW Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/network_quality_estimator.cc
diff --git a/net/base/network_quality_estimator.cc b/net/base/network_quality_estimator.cc
index dfc243ef490a0ff7106a9b08df97061f75aa468f..4be379b13e21455996b6745cc3ba1a4007b2be94 100644
--- a/net/base/network_quality_estimator.cc
+++ b/net/base/network_quality_estimator.cc
@@ -11,10 +11,12 @@
#include <utility>
#include <vector>
+#include "base/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_base.h"
#include "base/strings/string_number_conversions.h"
+#include "base/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "net/base/load_flags.h"
#include "net/base/load_timing_info.h"
@@ -141,7 +143,8 @@ NetworkQualityEstimator::NetworkQualityEstimator(
downstream_throughput_kbps_observations_(
GetWeightMultiplierPerSecond(variation_params)),
rtt_observations_(GetWeightMultiplierPerSecond(variation_params)),
- external_estimate_provider_(std::move(external_estimates_provider)) {
+ external_estimate_provider_(std::move(external_estimates_provider)),
+ weak_ptr_factory_(this) {
static_assert(kMinRequestDurationMicroseconds > 0,
"Minimum request duration must be > 0");
static_assert(kDefaultHalfLifeSeconds > 0,
@@ -166,6 +169,11 @@ NetworkQualityEstimator::NetworkQualityEstimator(
}
current_network_id_ = GetCurrentNetworkID();
AddDefaultEstimates();
+
+ watcher_factory_.reset(new SocketWatcherFactory(
+ base::ThreadTaskRunnerHandle::Get(),
+ base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable,
+ GetWeakPtr())));
}
// static
@@ -376,6 +384,13 @@ void NetworkQualityEstimator::RemoveThroughputObserver(
throughput_observer_list_.RemoveObserver(throughput_observer);
}
+SocketPerformanceWatcherFactory*
+NetworkQualityEstimator::GetSocketPerformanceWatcherFactory() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ return watcher_factory_.get();
+}
+
void NetworkQualityEstimator::RecordRTTUMA(int32_t estimated_value_msec,
int32_t actual_value_msec) const {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -633,6 +648,39 @@ base::TimeDelta NetworkQualityEstimator::GetURLRequestRTTEstimateInternal(
return rtt;
}
+NetworkQualityEstimator::SocketWatcherFactory::SocketWatcherFactory(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
+ RTTUpdateCallback rtt_update_callback)
+ : task_runner_(task_runner),
+ rtt_update_callback_(rtt_update_callback),
+ weak_ptr_factory_(this) {
+ DCHECK(task_runner_);
+}
+
+NetworkQualityEstimator::SocketWatcherFactory::~SocketWatcherFactory() {}
+
+scoped_ptr<SocketPerformanceWatcher>
+NetworkQualityEstimator::SocketWatcherFactory::CreateSocketPerformanceWatcher(
+ const Protocol protocol) {
+ return scoped_ptr<SocketPerformanceWatcher>(new SocketPerformanceWatcher(
+ protocol, base::Bind(&SocketWatcherFactory::OnUpdatedRTTAvailable,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&SocketWatcherFactory::OnWatcherReset,
+ weak_ptr_factory_.GetWeakPtr())));
+}
+
+void NetworkQualityEstimator::SocketWatcherFactory::OnUpdatedRTTAvailable(
+ const Protocol protocol,
+ const base::TimeDelta& rtt) {
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(rtt_update_callback_, protocol, rtt));
+}
+
+void NetworkQualityEstimator::SocketWatcherFactory::OnWatcherReset() {
+ // Nothing needs to be done for RTT observations since SocketWatcherFactory
+ // does not maintain any watcher-specific state.
+}
+
int32_t NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimateInternal(
const base::TimeTicks& begin_timestamp,
int percentile) const {
@@ -904,25 +952,16 @@ void NetworkQualityEstimator::CacheNetworkQualityEstimate() {
static_cast<size_t>(kMaximumNetworkQualityCacheSize));
}
-scoped_ptr<SocketPerformanceWatcher>
-NetworkQualityEstimator::CreateSocketPerformanceWatcher(
- const Protocol protocol) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- return scoped_ptr<SocketPerformanceWatcher>(
- new SocketPerformanceWatcher(protocol, this));
-}
-
void NetworkQualityEstimator::OnUpdatedRTTAvailable(
- const Protocol protocol,
+ SocketPerformanceWatcherFactory::Protocol protocol,
const base::TimeDelta& rtt) {
DCHECK(thread_checker_.CalledOnValidThread());
switch (protocol) {
- case PROTOCOL_TCP:
+ case SocketPerformanceWatcherFactory::PROTOCOL_TCP:
NotifyObserversOfRTT(RttObservation(rtt, base::TimeTicks::Now(), TCP));
return;
- case PROTOCOL_QUIC:
+ case SocketPerformanceWatcherFactory::PROTOCOL_QUIC:
NotifyObserversOfRTT(RttObservation(rtt, base::TimeTicks::Now(), QUIC));
return;
default:
@@ -946,6 +985,12 @@ void NetworkQualityEstimator::NotifyObserversOfThroughput(
observation.source));
}
+base::WeakPtr<NetworkQualityEstimator> NetworkQualityEstimator::GetWeakPtr() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ return weak_ptr_factory_.GetWeakPtr();
+}
+
NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality(
const NetworkQuality& network_quality)
: last_update_time_(base::TimeTicks::Now()),

Powered by Google App Engine
This is Rietveld 408576698