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 @@ ...@@ -17,6 +17,7 @@
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
...@@ -230,6 +231,22 @@ NetworkQualityEstimator::NetworkQualityEstimator( ...@@ -230,6 +231,22 @@ NetworkQualityEstimator::NetworkQualityEstimator(
tick_clock_, tick_clock_,
params_->weight_multiplier_per_second(), params_->weight_multiplier_per_second(),
params_->weight_multiplier_per_signal_strength_level()), 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_at_last_main_frame_(
EFFECTIVE_CONNECTION_TYPE_UNKNOWN), EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
effective_connection_type_recomputation_interval_( effective_connection_type_recomputation_interval_(
...@@ -246,12 +263,8 @@ NetworkQualityEstimator::NetworkQualityEstimator( ...@@ -246,12 +263,8 @@ NetworkQualityEstimator::NetworkQualityEstimator(
net::NetLogSourceType::NETWORK_QUALITY_ESTIMATOR)), net::NetLogSourceType::NETWORK_QUALITY_ESTIMATOR)),
event_creator_(net_log_), event_creator_(net_log_),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
rtt_ms_observations_.reserve(nqe::internal::OBSERVATION_CATEGORY_COUNT); DCHECK_EQ(nqe::internal::OBSERVATION_CATEGORY_COUNT,
for (int i = 0; i < nqe::internal::OBSERVATION_CATEGORY_COUNT; ++i) { base::size(rtt_ms_observations_));
rtt_ms_observations_.push_back(ObservationBuffer(
params_.get(), tick_clock_, params_->weight_multiplier_per_second(),
params_->weight_multiplier_per_signal_strength_level()));
}
network_quality_store_.reset(new nqe::internal::NetworkQualityStore()); network_quality_store_.reset(new nqe::internal::NetworkQualityStore());
NetworkChangeNotifier::AddConnectionTypeObserver(this); NetworkChangeNotifier::AddConnectionTypeObserver(this);
...@@ -695,6 +708,8 @@ bool NetworkQualityEstimator::RequestProvidesRTTObservation( ...@@ -695,6 +708,8 @@ bool NetworkQualityEstimator::RequestProvidesRTTObservation(
void NetworkQualityEstimator::OnConnectionTypeChanged( void NetworkQualityEstimator::OnConnectionTypeChanged(
NetworkChangeNotifier::ConnectionType type) { NetworkChangeNotifier::ConnectionType type) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 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. // Write the estimates of the previous network to the cache.
network_quality_store_->Add( network_quality_store_->Add(
...@@ -1232,6 +1247,8 @@ base::TimeDelta NetworkQualityEstimator::GetRTTEstimateInternal( ...@@ -1232,6 +1247,8 @@ base::TimeDelta NetworkQualityEstimator::GetRTTEstimateInternal(
int percentile, int percentile,
size_t* observations_count) const { size_t* observations_count) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 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 // RTT observations are sorted by duration from shortest to longest, thus
// a higher percentile RTT will have a longer RTT than a lower percentile. // a higher percentile RTT will have a longer RTT than a lower percentile.
...@@ -1480,6 +1497,8 @@ void NetworkQualityEstimator::OnNewThroughputObservationAvailable( ...@@ -1480,6 +1497,8 @@ void NetworkQualityEstimator::OnNewThroughputObservationAvailable(
bool NetworkQualityEstimator::ShouldComputeEffectiveConnectionType() const { bool NetworkQualityEstimator::ShouldComputeEffectiveConnectionType() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 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(); const base::TimeTicks now = tick_clock_->NowTicks();
// Recompute effective connection type only if // Recompute effective connection type only if
......
...@@ -567,11 +567,11 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator ...@@ -567,11 +567,11 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
// Buffer that holds RTT observations with different observation categories. // Buffer that holds RTT observations with different observation categories.
// The entries in |rtt_ms_observations_| are in the same order as the // The entries in |rtt_ms_observations_| are in the same order as the
// entries in the nqe::internal:ObservationCategory enum. Size of // entries in the nqe::internal:ObservationCategory enum.
// |rtt_ms_observations_| is nqe::internal::OBSERVATION_CATEGORY_COUNT.
// Each observation buffer in |rtt_ms_observations_| stores RTT observations // Each observation buffer in |rtt_ms_observations_| stores RTT observations
// in milliseconds. Within a buffer, the observations are sorted by timestamp. // 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. // Time when the transaction for the last main frame request was started.
base::TimeTicks last_main_frame_request_; 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