Index: net/nqe/throughput_analyzer.cc |
diff --git a/net/nqe/throughput_analyzer.cc b/net/nqe/throughput_analyzer.cc |
index 6785d1438053a2b79f5f2a2f2917ac21c8686796..de1b0efacc574381e543eee71733c1268b583d39 100644 |
--- a/net/nqe/throughput_analyzer.cc |
+++ b/net/nqe/throughput_analyzer.cc |
@@ -10,6 +10,7 @@ |
#include "base/single_thread_task_runner.h" |
#include "net/base/network_activity_monitor.h" |
#include "net/base/url_util.h" |
+#include "net/nqe/network_quality_estimator_params.h" |
#include "net/url_request/url_request.h" |
#if defined(OS_ANDROID) |
@@ -35,11 +36,13 @@ namespace nqe { |
namespace internal { |
ThroughputAnalyzer::ThroughputAnalyzer( |
+ const NetworkQualityEstimatorParams* params, |
scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
ThroughputObservationCallback throughput_observation_callback, |
bool use_local_host_requests_for_tests, |
bool use_smaller_responses_for_tests) |
- : task_runner_(task_runner), |
+ : params_(params), |
+ task_runner_(task_runner), |
throughput_observation_callback_(throughput_observation_callback), |
last_connection_change_(base::TimeTicks::Now()), |
window_start_time_(base::TimeTicks()), |
@@ -47,6 +50,7 @@ ThroughputAnalyzer::ThroughputAnalyzer( |
disable_throughput_measurements_(false), |
use_localhost_requests_for_tests_(use_local_host_requests_for_tests), |
use_small_responses_for_tests_(use_smaller_responses_for_tests) { |
+ DCHECK(params_); |
DCHECK(task_runner_); |
DCHECK(!IsCurrentlyTrackingThroughput()); |
} |
@@ -66,7 +70,8 @@ void ThroughputAnalyzer::MaybeStartThroughputObservationWindow() { |
// started, and there is at least one active request that does not degrade |
// throughput computation accuracy. |
if (accuracy_degrading_requests_.size() > 0 || |
- IsCurrentlyTrackingThroughput() || requests_.size() <= 0) { |
+ IsCurrentlyTrackingThroughput() || |
+ requests_.size() < params_->throughput_min_requests_in_flight()) { |
return; |
} |
window_start_time_ = base::TimeTicks::Now(); |
@@ -96,6 +101,8 @@ bool ThroughputAnalyzer::IsCurrentlyTrackingThroughput() const { |
// requests should be currently active. |
DCHECK_EQ(0U, accuracy_degrading_requests_.size()); |
+ DCHECK_LE(params_->throughput_min_requests_in_flight(), requests_.size()); |
+ |
return true; |
} |
@@ -141,7 +148,7 @@ void ThroughputAnalyzer::NotifyRequestCompleted(const URLRequest& request) { |
} |
int32_t downstream_kbps; |
- if (MayBeGetThroughputObservation(&downstream_kbps)) { |
+ if (MaybeGetThroughputObservation(&downstream_kbps)) { |
// Notify the provided callback. |
task_runner_->PostTask( |
FROM_HERE, |
@@ -164,7 +171,7 @@ void ThroughputAnalyzer::NotifyRequestCompleted(const URLRequest& request) { |
if (requests_.erase(&request) == 1u) { |
// If there is no network activity, stop tracking throughput to prevent |
// recording of any observations. |
- if (requests_.size() == 0) |
+ if (requests_.size() < params_->throughput_min_requests_in_flight()) |
EndThroughputObservationWindow(); |
return; |
} |
@@ -172,7 +179,7 @@ void ThroughputAnalyzer::NotifyRequestCompleted(const URLRequest& request) { |
NOTREACHED(); |
} |
-bool ThroughputAnalyzer::MayBeGetThroughputObservation( |
+bool ThroughputAnalyzer::MaybeGetThroughputObservation( |
int32_t* downstream_kbps) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK(downstream_kbps); |