Commit 44366bff authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Replace std::vector in NQE by an array

Replace std::vector in Network Quality Estimator (NQE) by an array.
This is an attempt to avoid the crash that happens only on
Windows when rtt_ms_observations_ vector is referenced.

Change-Id: I8a3e0e45be6881bfb02442a62c7403aaa5b8078f
Bug: 899808
TBR: ryansturm@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/c/1343345Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609530}
parent 300338ab
......@@ -17,6 +17,7 @@
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
......@@ -230,6 +231,22 @@ NetworkQualityEstimator::NetworkQualityEstimator(
tick_clock_,
params_->weight_multiplier_per_second(),
params_->weight_multiplier_per_signal_strength_level()),
rtt_ms_observations_{
ObservationBuffer(
params_.get(),
tick_clock_,
params_->weight_multiplier_per_second(),
params_->weight_multiplier_per_signal_strength_level()),
ObservationBuffer(
params_.get(),
tick_clock_,
params_->weight_multiplier_per_second(),
params_->weight_multiplier_per_signal_strength_level()),
ObservationBuffer(
params_.get(),
tick_clock_,
params_->weight_multiplier_per_second(),
params_->weight_multiplier_per_signal_strength_level())},
effective_connection_type_at_last_main_frame_(
EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
effective_connection_type_recomputation_interval_(
......@@ -246,12 +263,8 @@ NetworkQualityEstimator::NetworkQualityEstimator(
net::NetLogSourceType::NETWORK_QUALITY_ESTIMATOR)),
event_creator_(net_log_),
weak_ptr_factory_(this) {
rtt_ms_observations_.reserve(nqe::internal::OBSERVATION_CATEGORY_COUNT);
for (int i = 0; i < nqe::internal::OBSERVATION_CATEGORY_COUNT; ++i) {
rtt_ms_observations_.push_back(ObservationBuffer(
params_.get(), tick_clock_, params_->weight_multiplier_per_second(),
params_->weight_multiplier_per_signal_strength_level()));
}
DCHECK_EQ(nqe::internal::OBSERVATION_CATEGORY_COUNT,
base::size(rtt_ms_observations_));
network_quality_store_.reset(new nqe::internal::NetworkQualityStore());
NetworkChangeNotifier::AddConnectionTypeObserver(this);
......@@ -695,6 +708,8 @@ bool NetworkQualityEstimator::RequestProvidesRTTObservation(
void NetworkQualityEstimator::OnConnectionTypeChanged(
NetworkChangeNotifier::ConnectionType type) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(nqe::internal::OBSERVATION_CATEGORY_COUNT,
base::size(rtt_ms_observations_));
// Write the estimates of the previous network to the cache.
network_quality_store_->Add(
......@@ -1232,6 +1247,8 @@ base::TimeDelta NetworkQualityEstimator::GetRTTEstimateInternal(
int percentile,
size_t* observations_count) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(nqe::internal::OBSERVATION_CATEGORY_COUNT,
base::size(rtt_ms_observations_));
// RTT observations are sorted by duration from shortest to longest, thus
// a higher percentile RTT will have a longer RTT than a lower percentile.
......@@ -1480,6 +1497,8 @@ void NetworkQualityEstimator::OnNewThroughputObservationAvailable(
bool NetworkQualityEstimator::ShouldComputeEffectiveConnectionType() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(nqe::internal::OBSERVATION_CATEGORY_COUNT,
base::size(rtt_ms_observations_));
const base::TimeTicks now = tick_clock_->NowTicks();
// Recompute effective connection type only if
......
......@@ -567,11 +567,11 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
// Buffer that holds RTT observations with different observation categories.
// The entries in |rtt_ms_observations_| are in the same order as the
// entries in the nqe::internal:ObservationCategory enum. Size of
// |rtt_ms_observations_| is nqe::internal::OBSERVATION_CATEGORY_COUNT.
// entries in the nqe::internal:ObservationCategory enum.
// Each observation buffer in |rtt_ms_observations_| stores RTT observations
// in milliseconds. Within a buffer, the observations are sorted by timestamp.
std::vector<ObservationBuffer> rtt_ms_observations_;
ObservationBuffer
rtt_ms_observations_[nqe::internal::OBSERVATION_CATEGORY_COUNT];
// Time when the transaction for the last main frame request was started.
base::TimeTicks last_main_frame_request_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment