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

Side by Side Diff: net/nqe/network_quality_estimator.cc

Issue 2221103003: Compute effective connection type dynamically (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/nqe/network_quality_estimator.h" 5 #include "net/nqe/network_quality_estimator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 weight_multiplier_per_second_( 356 weight_multiplier_per_second_(
357 GetWeightMultiplierPerSecond(variation_params)), 357 GetWeightMultiplierPerSecond(variation_params)),
358 effective_connection_type_algorithm_( 358 effective_connection_type_algorithm_(
359 algorithm_name_to_enum_.find(GetEffectiveConnectionTypeAlgorithm( 359 algorithm_name_to_enum_.find(GetEffectiveConnectionTypeAlgorithm(
360 variation_params)) == algorithm_name_to_enum_.end() 360 variation_params)) == algorithm_name_to_enum_.end()
361 ? kDefaultEffectiveConnectionTypeAlgorithm 361 ? kDefaultEffectiveConnectionTypeAlgorithm
362 : algorithm_name_to_enum_ 362 : algorithm_name_to_enum_
363 .find(GetEffectiveConnectionTypeAlgorithm(variation_params)) 363 .find(GetEffectiveConnectionTypeAlgorithm(variation_params))
364 ->second), 364 ->second),
365 tick_clock_(new base::DefaultTickClock()), 365 tick_clock_(new base::DefaultTickClock()),
366 effective_connection_type_recomputation_interval_(
367 base::TimeDelta::FromSeconds(15)),
368 last_connection_change_(tick_clock_->NowTicks()), 366 last_connection_change_(tick_clock_->NowTicks()),
369 current_network_id_(nqe::internal::NetworkID( 367 current_network_id_(nqe::internal::NetworkID(
370 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, 368 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN,
371 std::string())), 369 std::string())),
372 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), 370 downstream_throughput_kbps_observations_(weight_multiplier_per_second_),
373 rtt_observations_(weight_multiplier_per_second_), 371 rtt_observations_(weight_multiplier_per_second_),
374 effective_connection_type_at_last_main_frame_( 372 effective_connection_type_at_last_main_frame_(
375 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 373 EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
376 external_estimate_provider_(std::move(external_estimates_provider)), 374 external_estimate_provider_(std::move(external_estimates_provider)),
375 effective_connection_type_recomputation_interval_(
376 base::TimeDelta::FromSeconds(15)),
377 rtt_observations_size_at_last_ect_computation_(0),
378 throughput_observations_size_at_last_ect_computation_(0),
377 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 379 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
378 min_signal_strength_since_connection_change_(INT32_MAX), 380 min_signal_strength_since_connection_change_(INT32_MAX),
379 max_signal_strength_since_connection_change_(INT32_MIN), 381 max_signal_strength_since_connection_change_(INT32_MIN),
380 correlation_uma_logging_probability_( 382 correlation_uma_logging_probability_(
381 GetDoubleValueForVariationParamWithDefaultValue( 383 GetDoubleValueForVariationParamWithDefaultValue(
382 variation_params, 384 variation_params,
383 "correlation_logging_probability", 385 "correlation_logging_probability",
384 0.0)), 386 0.0)),
385 weak_ptr_factory_(this) { 387 weak_ptr_factory_(this) {
386 static_assert(kDefaultHalfLifeSeconds > 0, 388 static_assert(kDefaultHalfLifeSeconds > 0,
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 1645
1644 const base::TimeTicks now = tick_clock_->NowTicks(); 1646 const base::TimeTicks now = tick_clock_->NowTicks();
1645 // Recompute effective connection type only if 1647 // Recompute effective connection type only if
1646 // |effective_connection_type_recomputation_interval_| has passed since it was 1648 // |effective_connection_type_recomputation_interval_| has passed since it was
1647 // last computed or a connection change event was observed since the last 1649 // last computed or a connection change event was observed since the last
1648 // computation. Strict inequalities are used to ensure that effective 1650 // computation. Strict inequalities are used to ensure that effective
1649 // connection type is recomputed on connection change events even if the clock 1651 // connection type is recomputed on connection change events even if the clock
1650 // has not updated. 1652 // has not updated.
1651 if (now - last_effective_connection_type_computation_ < 1653 if (now - last_effective_connection_type_computation_ <
1652 effective_connection_type_recomputation_interval_ && 1654 effective_connection_type_recomputation_interval_ &&
1653 last_connection_change_ < last_effective_connection_type_computation_) { 1655 last_connection_change_ < last_effective_connection_type_computation_ &&
1656 // Recompute the effective connection type if the previously computed
1657 // effective connection type was unknown.
1658 effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN &&
1659 // Recompute the effective connection type if the number of samples
1660 // available now are more than twice in count than the number of
1661 // samples that were available when the effective connection type was
1662 // last computed.
1663 rtt_observations_size_at_last_ect_computation_ * 2 >=
1664 rtt_observations_.Size() &&
1665 throughput_observations_size_at_last_ect_computation_ * 2 >=
1666 downstream_throughput_kbps_observations_.Size()) {
1654 return; 1667 return;
1655 } 1668 }
1656 1669
1657 const EffectiveConnectionType past_type = effective_connection_type_; 1670 const EffectiveConnectionType past_type = effective_connection_type_;
1658 last_effective_connection_type_computation_ = now; 1671 last_effective_connection_type_computation_ = now;
1659 effective_connection_type_ = GetEffectiveConnectionType(); 1672 effective_connection_type_ = GetEffectiveConnectionType();
1660 1673
1661 if (past_type != effective_connection_type_) 1674 if (past_type != effective_connection_type_)
1662 NotifyObserversOfEffectiveConnectionTypeChanged(); 1675 NotifyObserversOfEffectiveConnectionTypeChanged();
1676
1677 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size();
1678 throughput_observations_size_at_last_ect_computation_ =
1679 downstream_throughput_kbps_observations_.Size();
1663 } 1680 }
1664 1681
1665 void NetworkQualityEstimator:: 1682 void NetworkQualityEstimator::
1666 NotifyObserversOfEffectiveConnectionTypeChanged() { 1683 NotifyObserversOfEffectiveConnectionTypeChanged() {
1667 DCHECK(thread_checker_.CalledOnValidThread()); 1684 DCHECK(thread_checker_.CalledOnValidThread());
1668 1685
1669 // TODO(tbansal): Add hysteresis in the notification. 1686 // TODO(tbansal): Add hysteresis in the notification.
1670 FOR_EACH_OBSERVER( 1687 FOR_EACH_OBSERVER(
1671 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, 1688 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_,
1672 OnEffectiveConnectionTypeChanged(effective_connection_type_)); 1689 OnEffectiveConnectionTypeChanged(effective_connection_type_));
1673 } 1690 }
1674 1691
1675 } // namespace net 1692 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698