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

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: Addressed rsleevi comments 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..22c5460913645cfce902c37b1d87575f2b940a94 100644
--- a/net/base/network_quality_estimator.cc
+++ b/net/base/network_quality_estimator.cc
@@ -15,6 +15,7 @@
#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 +142,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 +168,9 @@ NetworkQualityEstimator::NetworkQualityEstimator(
}
current_network_id_ = GetCurrentNetworkID();
AddDefaultEstimates();
+
+ watcher_factory_.reset(new SocketWatcherFactory(
+ base::ThreadTaskRunnerHandle::Get(), GetWeakPtr()));
Ryan Sleevi 2016/04/02 00:48:20 s/GetWeakPtr()/weak_factory_.GetWeakPtr())
tbansal1 2016/04/04 16:55:44 Done.
}
// static
@@ -376,6 +381,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 +645,55 @@ base::TimeDelta NetworkQualityEstimator::GetURLRequestRTTEstimateInternal(
return rtt;
}
+NetworkQualityEstimator::SocketWatcherFactory::SocketWatcherFactory(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
+ const base::WeakPtr<NetworkQualityEstimator>& network_quality_estimator)
+ : task_runner_(task_runner),
+ network_quality_estimator_(network_quality_estimator) {
+ DCHECK(task_runner_);
+}
+
+NetworkQualityEstimator::SocketWatcherFactory::~SocketWatcherFactory() {}
+
+scoped_ptr<SocketPerformanceWatcher>
+NetworkQualityEstimator::SocketWatcherFactory::CreateSocketPerformanceWatcher(
+ SocketPerformanceWatcherFactory::Protocol protocol) {
+ return scoped_ptr<SocketPerformanceWatcher>(
+ new SocketWatcher(protocol, task_runner_, network_quality_estimator_));
+}
+
+NetworkQualityEstimator::SocketWatcher::SocketWatcher(
+ SocketPerformanceWatcherFactory::Protocol protocol,
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
+ const base::WeakPtr<NetworkQualityEstimator>& network_quality_estimator)
+ : protocol_(protocol),
+ task_runner_(task_runner),
+ network_quality_estimator_(network_quality_estimator) {
+ DCHECK(task_runner_);
+ DCHECK(network_quality_estimator_);
+}
+
+NetworkQualityEstimator::SocketWatcher::~SocketWatcher() {}
+
+void NetworkQualityEstimator::SocketWatcher::OnUpdatedRTTAvailable(
+ const base::TimeDelta& rtt) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ task_runner_->PostTask(
+ FROM_HERE, base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable,
+ network_quality_estimator_, protocol_, rtt));
+}
+
+bool NetworkQualityEstimator::SocketWatcher::ShouldNotifyUpdatedRTT() const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ return true;
+}
+
+void NetworkQualityEstimator::SocketWatcher::Reset() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+}
+
int32_t NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimateInternal(
const base::TimeTicks& begin_timestamp,
int percentile) const {
@@ -904,25 +965,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 +998,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