diff options
Diffstat (limited to 'chromium/net/nqe')
-rw-r--r-- | chromium/net/nqe/network_qualities_prefs_manager.cc | 4 | ||||
-rw-r--r-- | chromium/net/nqe/network_quality_estimator.cc | 259 | ||||
-rw-r--r-- | chromium/net/nqe/network_quality_estimator.h | 26 | ||||
-rw-r--r-- | chromium/net/nqe/network_quality_estimator_params.cc | 21 | ||||
-rw-r--r-- | chromium/net/nqe/network_quality_estimator_params.h | 29 | ||||
-rw-r--r-- | chromium/net/nqe/network_quality_estimator_test_util.cc | 13 | ||||
-rw-r--r-- | chromium/net/nqe/network_quality_estimator_test_util.h | 8 | ||||
-rw-r--r-- | chromium/net/nqe/network_quality_estimator_unittest.cc | 222 | ||||
-rw-r--r-- | chromium/net/nqe/network_quality_estimator_util.cc | 20 | ||||
-rw-r--r-- | chromium/net/nqe/network_quality_estimator_util.h | 4 | ||||
-rw-r--r-- | chromium/net/nqe/observation_buffer.cc | 6 | ||||
-rw-r--r-- | chromium/net/nqe/throughput_analyzer.cc | 2 | ||||
-rw-r--r-- | chromium/net/nqe/throughput_analyzer.h | 1 |
13 files changed, 34 insertions, 581 deletions
diff --git a/chromium/net/nqe/network_qualities_prefs_manager.cc b/chromium/net/nqe/network_qualities_prefs_manager.cc index f960ad9a96e..6c4ad458c83 100644 --- a/chromium/net/nqe/network_qualities_prefs_manager.cc +++ b/chromium/net/nqe/network_qualities_prefs_manager.cc @@ -35,7 +35,7 @@ ParsedPrefs ConvertDictionaryValueToMap(const base::DictionaryValue* value) { DCHECK_GE(kMaxCacheSize, value->DictSize()); ParsedPrefs read_prefs; - for (const auto& it : value->DictItems()) { + for (auto it : value->DictItems()) { nqe::internal::NetworkID network_id = nqe::internal::NetworkID::FromString(it.first); @@ -135,7 +135,7 @@ void NetworkQualitiesPrefsManager::OnChangeInCachedNetworkQuality( // |kMaxCacheSize|. int index_to_delete = base::RandInt(0, kMaxCacheSize - 1); - for (const auto& it : prefs_->DictItems()) { + for (auto it : prefs_->DictItems()) { // Delete the kth element in the dictionary, not including the element // that represents the current network. k == |index_to_delete|. if (nqe::internal::NetworkID::FromString(it.first) == network_id) diff --git a/chromium/net/nqe/network_quality_estimator.cc b/chromium/net/nqe/network_quality_estimator.cc index 1ebb0b78061..13787418ff7 100644 --- a/chromium/net/nqe/network_quality_estimator.cc +++ b/chromium/net/nqe/network_quality_estimator.cc @@ -13,6 +13,7 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/check_op.h" +#include "base/cxx17_backports.h" #include "base/location.h" #include "base/metrics/field_trial_params.h" #include "base/metrics/histogram.h" @@ -22,7 +23,6 @@ #include "base/metrics/histogram_macros_local.h" #include "base/notreached.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/task/lazy_thread_pool_task_runner.h" @@ -89,49 +89,11 @@ bool RequestSchemeIsHTTPOrHTTPS(const URLRequest& request) { nqe::internal::NetworkID DoGetCurrentNetworkID( NetworkQualityEstimatorParams* params) { - // It is possible that the connection type changed between when - // GetConnectionType() was called and when the API to determine the - // network name was called. Check if that happened and retry until the - // connection type stabilizes. This is an imperfect solution but should - // capture majority of cases, and should not significantly affect estimates - // (that are approximate to begin with). - while (true) { nqe::internal::NetworkID network_id( NetworkChangeNotifier::GetConnectionType(), std::string(), INT32_MIN); - if (!params || !params->get_signal_strength_and_detailed_network_id()) - return network_id; - - switch (network_id.type) { - case NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN: - case NetworkChangeNotifier::ConnectionType::CONNECTION_NONE: - case NetworkChangeNotifier::ConnectionType::CONNECTION_BLUETOOTH: - case NetworkChangeNotifier::ConnectionType::CONNECTION_ETHERNET: - break; - case NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI: -#if defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_CHROMEOS) || \ - defined(OS_WIN) - network_id.id = GetWifiSSID(); -#endif - break; - case NetworkChangeNotifier::ConnectionType::CONNECTION_2G: - case NetworkChangeNotifier::ConnectionType::CONNECTION_3G: - case NetworkChangeNotifier::ConnectionType::CONNECTION_4G: - case NetworkChangeNotifier::ConnectionType::CONNECTION_5G: -#if defined(OS_ANDROID) - network_id.id = android::GetTelephonyNetworkOperator(); -#endif - break; - default: - NOTREACHED() << "Unexpected connection type = " << network_id.type; - break; - } - - if (network_id.type == NetworkChangeNotifier::GetConnectionType()) return network_id; } - NOTREACHED(); -} } // namespace @@ -152,23 +114,23 @@ NetworkQualityEstimator::NetworkQualityEstimator( params_.get(), tick_clock_, params_->weight_multiplier_per_second(), - params_->weight_multiplier_per_signal_strength_level()), + 1.0 /*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()), + 1.0 /*params_->weight_multiplier_per_signal_strength_level()*/), ObservationBuffer( params_.get(), tick_clock_, params_->weight_multiplier_per_second(), - params_->weight_multiplier_per_signal_strength_level()), + 1.0 /*params_->weight_multiplier_per_signal_strength_level()*/), ObservationBuffer( params_.get(), tick_clock_, params_->weight_multiplier_per_second(), - params_->weight_multiplier_per_signal_strength_level())}, + 1.0 /*params_->weight_multiplier_per_signal_strength_level()*/)}, effective_connection_type_at_last_main_frame_( EFFECTIVE_CONNECTION_TYPE_UNKNOWN), effective_connection_type_recomputation_interval_( @@ -507,7 +469,7 @@ bool NetworkQualityEstimator::RequestProvidesRTTObservation( DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); bool private_network_request = - nqe::internal::IsRequestForPrivateHost(request); + nqe::internal::IsRequestForPrivateHost(request, net_log_); return (use_localhost_requests_ || !private_network_request) && // Verify that response headers are received, so it can be ensured that @@ -540,29 +502,7 @@ void NetworkQualityEstimator::OnConnectionTypeChanged( for (int i = 0; i < nqe::internal::OBSERVATION_CATEGORY_COUNT; ++i) rtt_ms_observations_[i].Clear(); -#if defined(OS_ANDROID) - - bool is_cell_connection = - NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type); - bool is_wifi_connection = - (current_network_id_.type == NetworkChangeNotifier::CONNECTION_WIFI); - - if (params_->weight_multiplier_per_signal_strength_level() < 1.0 && - (is_cell_connection || is_wifi_connection)) { - bool signal_strength_available = - min_signal_strength_since_connection_change_ && - max_signal_strength_since_connection_change_; - - std::string histogram_name = - is_cell_connection ? "NQE.CellularSignalStrength.LevelAvailable" - : "NQE.WifiSignalStrength.LevelAvailable"; - - base::UmaHistogramBoolean(histogram_name, signal_strength_available); - } -#endif // OS_ANDROID current_network_id_.signal_strength = INT32_MIN; - min_signal_strength_since_connection_change_.reset(); - max_signal_strength_since_connection_change_.reset(); network_quality_ = nqe::internal::NetworkQuality(); end_to_end_rtt_ = absl::nullopt; effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; @@ -627,91 +567,6 @@ void NetworkQualityEstimator::ContinueGatherEstimatesForNextConnectionType( ComputeEffectiveConnectionType(); } -absl::optional<int32_t> -NetworkQualityEstimator::GetCurrentSignalStrengthWithThrottling() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - - if (!params_->get_signal_strength_and_detailed_network_id()) - return absl::nullopt; - - if (params_->weight_multiplier_per_signal_strength_level() >= 1.0) - return absl::nullopt; - - if ((current_network_id_.type != NetworkChangeNotifier::CONNECTION_WIFI) && - !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { - return absl::nullopt; - } - - // Do not call more than once per |wifi_signal_strength_query_interval| - // duration. - if (last_signal_strength_check_timestamp_.has_value() && - (tick_clock_->NowTicks() - last_signal_strength_check_timestamp_.value() < - params_->wifi_signal_strength_query_interval()) && - (last_signal_strength_check_timestamp_.value() > - last_connection_change_)) { - return absl::nullopt; - } - - last_signal_strength_check_timestamp_ = tick_clock_->NowTicks(); - - if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_WIFI) { - UMA_HISTOGRAM_BOOLEAN("NQE.SignalStrengthQueried.WiFi", true); - -#if defined(OS_ANDROID) - return android::GetWifiSignalLevel(); -#endif // OS_ANDROID - } - - if (NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { - UMA_HISTOGRAM_BOOLEAN("NQE.SignalStrengthQueried.Cellular", true); -#if defined(OS_ANDROID) - return android::cellular_signal_strength::GetSignalStrengthLevel(); -#endif // OS_ANDROID - } - - return absl::nullopt; -} - -void NetworkQualityEstimator::UpdateSignalStrength() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - - int32_t past_signal_strength = current_network_id_.signal_strength; - absl::optional<int32_t> new_signal_strength = - GetCurrentSignalStrengthWithThrottling(); - - // A fresh value is unavailable. So, return early. - if (!new_signal_strength) - return; - - // Check if there is no change in the signal strength. - if (past_signal_strength == new_signal_strength.value()) - return; - - // Check if the signal strength is unavailable. - if (new_signal_strength.value() == INT32_MIN) - return; - - DCHECK(new_signal_strength.value() >= 0 && new_signal_strength.value() <= 4); - - // Record the network quality we experienced for the previous signal strength - // (for when we return to that signal strength). - network_quality_store_->Add(current_network_id_, - nqe::internal::CachedNetworkQuality( - tick_clock_->NowTicks(), network_quality_, - effective_connection_type_)); - - current_network_id_.signal_strength = new_signal_strength.value(); - // Update network quality from cached value for new signal strength. - ReadCachedNetworkQualityEstimate(); - - min_signal_strength_since_connection_change_ = - std::min(min_signal_strength_since_connection_change_.value_or(INT32_MAX), - current_network_id_.signal_strength); - max_signal_strength_since_connection_change_ = - std::max(max_signal_strength_since_connection_change_.value_or(INT32_MIN), - current_network_id_.signal_strength); -} - void NetworkQualityEstimator::RecordNetworkIDAvailability() const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (current_network_id_.type == @@ -756,8 +611,6 @@ void NetworkQualityEstimator::RecordMetricsOnMainFrameRequest() const { void NetworkQualityEstimator::ComputeEffectiveConnectionType() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - UpdateSignalStrength(); - const base::TimeTicks now = tick_clock_->NowTicks(); const EffectiveConnectionType past_type = effective_connection_type_; @@ -775,27 +628,6 @@ void NetworkQualityEstimator::ComputeEffectiveConnectionType() { network_quality_ = nqe::internal::NetworkQuality(http_rtt, transport_rtt, downstream_throughput_kbps); - net::EffectiveConnectionType signal_strength_capped_ect = - GetCappedECTBasedOnSignalStrength(); - - if (signal_strength_capped_ect != effective_connection_type_) { - DCHECK_LE(signal_strength_capped_ect, effective_connection_type_); - UMA_HISTOGRAM_EXACT_LINEAR( - "NQE.CellularSignalStrength.ECTReduction", - effective_connection_type_ - signal_strength_capped_ect, - static_cast<int>(EFFECTIVE_CONNECTION_TYPE_LAST)); - - effective_connection_type_ = signal_strength_capped_ect; - - // Reset |network_quality_| based on the updated effective connection type. - network_quality_ = nqe::internal::NetworkQuality( - params_->TypicalNetworkQuality(effective_connection_type_).http_rtt(), - params_->TypicalNetworkQuality(effective_connection_type_) - .transport_rtt(), - params_->TypicalNetworkQuality(effective_connection_type_) - .downstream_throughput_kbps()); - } - ClampKbpsBasedOnEct(); UMA_HISTOGRAM_ENUMERATION("NQE.EffectiveConnectionType.OnECTComputation", @@ -930,85 +762,6 @@ void NetworkQualityEstimator::AdjustHttpRttBasedOnRTTCounts( *http_rtt = upper_bound_http_rtt; } -EffectiveConnectionType -NetworkQualityEstimator::GetCappedECTBasedOnSignalStrength() const { - if (!params_->cap_ect_based_on_signal_strength()) - return effective_connection_type_; - - // Check if signal strength is available. - if (current_network_id_.signal_strength == INT32_MIN) - return effective_connection_type_; - - if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN || - effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_OFFLINE) { - return effective_connection_type_; - } - - // Do not cap ECT if the signal strength is high. - if (current_network_id_.signal_strength > 2) - return effective_connection_type_; - - DCHECK_LE(0, current_network_id_.signal_strength); - - // When signal strength is 0, the device is almost offline. - if (current_network_id_.signal_strength == 0) { - switch (current_network_id_.type) { - case NetworkChangeNotifier::CONNECTION_2G: - case NetworkChangeNotifier::CONNECTION_3G: - return std::min(effective_connection_type_, - EFFECTIVE_CONNECTION_TYPE_SLOW_2G); - case NetworkChangeNotifier::CONNECTION_4G: - case NetworkChangeNotifier::CONNECTION_5G: - case NetworkChangeNotifier::CONNECTION_WIFI: - return std::min(effective_connection_type_, - EFFECTIVE_CONNECTION_TYPE_2G); - default: - NOTREACHED(); - return effective_connection_type_; - } - } - - if (current_network_id_.signal_strength == 1) { - switch (current_network_id_.type) { - case NetworkChangeNotifier::CONNECTION_2G: - return std::min(effective_connection_type_, - EFFECTIVE_CONNECTION_TYPE_SLOW_2G); - case NetworkChangeNotifier::CONNECTION_3G: - return std::min(effective_connection_type_, - EFFECTIVE_CONNECTION_TYPE_2G); - case NetworkChangeNotifier::CONNECTION_4G: - case NetworkChangeNotifier::CONNECTION_5G: - case NetworkChangeNotifier::CONNECTION_WIFI: - return std::min(effective_connection_type_, - EFFECTIVE_CONNECTION_TYPE_3G); - default: - NOTREACHED(); - return effective_connection_type_; - } - } - - if (current_network_id_.signal_strength == 2) { - switch (current_network_id_.type) { - case NetworkChangeNotifier::CONNECTION_2G: - return std::min(effective_connection_type_, - EFFECTIVE_CONNECTION_TYPE_2G); - case NetworkChangeNotifier::CONNECTION_3G: - return std::min(effective_connection_type_, - EFFECTIVE_CONNECTION_TYPE_3G); - case NetworkChangeNotifier::CONNECTION_4G: - case NetworkChangeNotifier::CONNECTION_5G: - case NetworkChangeNotifier::CONNECTION_WIFI: - return std::min(effective_connection_type_, - EFFECTIVE_CONNECTION_TYPE_4G); - default: - NOTREACHED(); - return effective_connection_type_; - } - } - NOTREACHED(); - return effective_connection_type_; -} - EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType() const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); diff --git a/chromium/net/nqe/network_quality_estimator.h b/chromium/net/nqe/network_quality_estimator.h index 4c8d636b75d..176ac2d2f45 100644 --- a/chromium/net/nqe/network_quality_estimator.h +++ b/chromium/net/nqe/network_quality_estimator.h @@ -9,7 +9,6 @@ #include <map> #include <memory> -#include <string> #include <vector> #include "base/compiler_specific.h" @@ -384,16 +383,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator // |observed_http_rtt| with the expected HTTP and transport RTT. bool IsHangingRequest(base::TimeDelta observed_http_rtt) const; - // Returns the current network signal strength by querying the platform APIs. - // Set to INT32_MIN when the value is unavailable. Otherwise, must be between - // 0 and 4 (both inclusive). This may take into account many different radio - // technology inputs. 0 represents very poor signal strength while 4 - // represents a very strong signal strength. The range is capped between 0 and - // 4 to ensure that a change in the value indicates a non-negligible change in - // the signal quality. To reduce the number of Android API calls, it returns - // a null value if the signal strength was recently obtained. - virtual absl::optional<int32_t> GetCurrentSignalStrengthWithThrottling(); - // Forces computation of effective connection type, and notifies observers // if there is a change in its value. void ComputeEffectiveConnectionType(); @@ -497,11 +486,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator // main frame request is observed. void RecordAccuracyAfterMainFrame(base::TimeDelta measuring_duration) const; - // Obtains the current cellular signal strength value and updates - // |min_signal_strength_since_connection_change_| and - // |max_signal_strength_since_connection_change_|. - void UpdateSignalStrength(); - // Updates the provided |http_rtt| based on all provided RTT values. void UpdateHttpRttUsingAllRttValues( base::TimeDelta* http_rtt, @@ -536,11 +520,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator // observations. bool ShouldSocketWatcherNotifyRTT(base::TimeTicks now); - // Caps and returns the current value of effective connection type based on - // the current signal strength. If the signal strength is reported as low, a - // value lower than |effective_connection_type_| may be returned. - EffectiveConnectionType GetCappedECTBasedOnSignalStrength() const; - // When RTT counts are low, it may be impossible to predict accurate ECT. In // that case, we just give the highest value. void AdjustHttpRttBasedOnRTTCounts(base::TimeDelta* http_rtt) const; @@ -637,11 +616,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator // |effective_connection_type_recomputation_interval_| ago). EffectiveConnectionType effective_connection_type_; - // Minimum and maximum signal strength level observed since last connection - // change. Updated on connection change and main frame requests. - absl::optional<int32_t> min_signal_strength_since_connection_change_; - absl::optional<int32_t> max_signal_strength_since_connection_change_; - // Stores the qualities of different networks. std::unique_ptr<nqe::internal::NetworkQualityStore> network_quality_store_; diff --git a/chromium/net/nqe/network_quality_estimator_params.cc b/chromium/net/nqe/network_quality_estimator_params.cc index 0940489c366..c9d17826fba 100644 --- a/chromium/net/nqe/network_quality_estimator_params.cc +++ b/chromium/net/nqe/network_quality_estimator_params.cc @@ -436,7 +436,6 @@ NetworkQualityEstimatorParams::NetworkQualityEstimatorParams( "throughput_hanging_requests_cwnd_size_multiplier", 1)), weight_multiplier_per_second_(GetWeightMultiplierPerSecond(params_)), - weight_multiplier_per_signal_strength_level_(0.8), forced_effective_connection_type_( GetInitForcedEffectiveConnectionType(params_)), forced_effective_connection_type_on_cellular_only_( @@ -499,29 +498,12 @@ NetworkQualityEstimatorParams::NetworkQualityEstimatorParams( "socket_watchers_min_notification_interval_msec", 200))), use_end_to_end_rtt_(true), - cap_ect_based_on_signal_strength_( - GetStringValueForVariationParamWithDefaultValue( - params_, - "cap_ect_based_on_signal_strength", - "true") != "false"), upper_bound_typical_kbps_multiplier_( GetDoubleValueForVariationParamWithDefaultValue( params_, "upper_bound_typical_kbps_multiplier", 3.5)), - // |get_signal_strength_and_detailed_network_id_| is false by default. - get_signal_strength_and_detailed_network_id_( - GetStringValueForVariationParamWithDefaultValue( - params_, - "get_signal_strength_and_detailed_network_id", - "false") == "true"), - // Default 30 minutes. - wifi_signal_strength_query_interval_( - base::TimeDelta::FromSeconds(GetValueForVariationParam( - params_, - "wifi_signal_strength_query_interval_seconds", - 30 * 60))), adjust_rtt_based_on_rtt_counts_( GetStringValueForVariationParamWithDefaultValue( params_, @@ -537,9 +519,6 @@ NetworkQualityEstimatorParams::NetworkQualityEstimatorParams( hanging_request_http_rtt_upper_bound_transport_rtt_multiplier_ >= hanging_request_http_rtt_upper_bound_http_rtt_multiplier_); - DCHECK_GE(1.0, weight_multiplier_per_signal_strength_level_); - DCHECK_LE(0.0, weight_multiplier_per_signal_strength_level_); - DCHECK_LT(0, hanging_request_duration_http_rtt_multiplier()); DCHECK_LT(0, hanging_request_http_rtt_upper_bound_http_rtt_multiplier()); DCHECK_LT(0, hanging_request_http_rtt_upper_bound_transport_rtt_multiplier()); diff --git a/chromium/net/nqe/network_quality_estimator_params.h b/chromium/net/nqe/network_quality_estimator_params.h index 185d2174137..dc830f82069 100644 --- a/chromium/net/nqe/network_quality_estimator_params.h +++ b/chromium/net/nqe/network_quality_estimator_params.h @@ -68,13 +68,6 @@ class NET_EXPORT NetworkQualityEstimatorParams { return weight_multiplier_per_second_; } - // Returns the factor by which the weight of an observation reduces for every - // signal strength level difference between the current signal strength, and - // the signal strength at the time when the observation was taken. - double weight_multiplier_per_signal_strength_level() const { - return weight_multiplier_per_signal_strength_level_; - } - // Returns an unset value if the effective connection type has not been forced // via the |params| provided to this class. Otherwise, returns a value set to // the effective connection type that has been forced. Forced ECT can be @@ -240,12 +233,6 @@ class NET_EXPORT NetworkQualityEstimatorParams { // quality estimate. bool use_end_to_end_rtt() const { return use_end_to_end_rtt_; } - // Return true if ECT value should be capped based on the current signal - // strength. - bool cap_ect_based_on_signal_strength() const { - return cap_ect_based_on_signal_strength_; - } - // Returns a multiplier which is used to clamp Kbps on slow connections. For // a given ECT, the upper bound on Kbps is computed based on this returned // multiplier and the typical Kbps for the given ECT. If @@ -255,18 +242,6 @@ class NET_EXPORT NetworkQualityEstimatorParams { return upper_bound_typical_kbps_multiplier_; } - // Returns true if the signal strength or detailed network ID should be - // queried. - bool get_signal_strength_and_detailed_network_id() const { - return get_signal_strength_and_detailed_network_id_; - } - - // Returns the minimum duration between two consecutuve calls for querying the - // current WiFi network's signal strength. - base::TimeDelta wifi_signal_strength_query_interval() const { - return wifi_signal_strength_query_interval_; - } - // Returns true if RTTs should be adjusted based on RTT counts. // If there are not enough transport RTT samples, end-to-end RTT samples and // the cached estimates are unavailble/too stale, then the computed value of @@ -289,7 +264,6 @@ class NET_EXPORT NetworkQualityEstimatorParams { const int throughput_min_transfer_size_kilobytes_; const double throughput_hanging_requests_cwnd_size_multiplier_; const double weight_multiplier_per_second_; - const double weight_multiplier_per_signal_strength_level_; absl::optional<EffectiveConnectionType> forced_effective_connection_type_; const bool forced_effective_connection_type_on_cellular_only_; bool persistent_cache_reading_enabled_; @@ -308,10 +282,7 @@ class NET_EXPORT NetworkQualityEstimatorParams { const bool add_default_platform_observations_; const base::TimeDelta socket_watchers_min_notification_interval_; const bool use_end_to_end_rtt_; - const bool cap_ect_based_on_signal_strength_; const double upper_bound_typical_kbps_multiplier_; - const bool get_signal_strength_and_detailed_network_id_; - const base::TimeDelta wifi_signal_strength_query_interval_; const bool adjust_rtt_based_on_rtt_counts_; bool use_small_responses_; diff --git a/chromium/net/nqe/network_quality_estimator_test_util.cc b/chromium/net/nqe/network_quality_estimator_test_util.cc index 11f4f5fadc9..8bced216f80 100644 --- a/chromium/net/nqe/network_quality_estimator_test_util.cc +++ b/chromium/net/nqe/network_quality_estimator_test_util.cc @@ -327,19 +327,6 @@ nqe::internal::NetworkID TestNetworkQualityEstimator::GetCurrentNetworkID() INT32_MIN); } -absl::optional<int32_t> -TestNetworkQualityEstimator::GetCurrentSignalStrengthWithThrottling() { - if (current_cellular_signal_strength_) { - return current_cellular_signal_strength_; - } - return NetworkQualityEstimator::GetCurrentSignalStrengthWithThrottling(); -} - -void TestNetworkQualityEstimator::SetCurrentSignalStrength( - int32_t signal_strength) { - current_cellular_signal_strength_ = signal_strength; -} - TestNetworkQualityEstimator::LocalHttpTestServer::LocalHttpTestServer( const base::FilePath& document_root) { AddDefaultHandlers(document_root); diff --git a/chromium/net/nqe/network_quality_estimator_test_util.h b/chromium/net/nqe/network_quality_estimator_test_util.h index 1b2cc87c06c..dae3df73d8b 100644 --- a/chromium/net/nqe/network_quality_estimator_test_util.h +++ b/chromium/net/nqe/network_quality_estimator_test_util.h @@ -211,8 +211,6 @@ class TestNetworkQualityEstimator : public NetworkQualityEstimator { transport_rtt_observation_count_last_ect_computation_ = count; } - void SetCurrentSignalStrength(int32_t signal_strength); - // Returns count of ping RTTs received from H2/spdy connections. size_t ping_rtt_received_count() const { return ping_rtt_received_count_; } @@ -228,10 +226,6 @@ class TestNetworkQualityEstimator : public NetworkQualityEstimator { using NetworkQualityEstimator::AddAndNotifyObserversOfThroughput; using NetworkQualityEstimator::IsHangingRequest; - // NetworkQualityEstimator implementation that returns the overridden - // network id and signal strength (instead of invoking platform APIs). - absl::optional<int32_t> GetCurrentSignalStrengthWithThrottling() override; - private: class LocalHttpTestServer : public EmbeddedTestServer { public: @@ -284,8 +278,6 @@ class TestNetworkQualityEstimator : public NetworkQualityEstimator { // If set, GetRTTEstimateInternal() would return the set value. absl::optional<base::TimeDelta> start_time_null_end_to_end_rtt_; - absl::optional<int32_t> current_cellular_signal_strength_; - LocalHttpTestServer embedded_test_server_; // If true, notifications are not sent to any of the observers. diff --git a/chromium/net/nqe/network_quality_estimator_unittest.cc b/chromium/net/nqe/network_quality_estimator_unittest.cc index 52a598124cd..e87a9f4afcc 100644 --- a/chromium/net/nqe/network_quality_estimator_unittest.cc +++ b/chromium/net/nqe/network_quality_estimator_unittest.cc @@ -17,6 +17,7 @@ #include "base/check_op.h" #include "base/macros.h" #include "base/metrics/histogram_samples.h" +#include "base/numerics/safe_conversions.h" #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "base/task/thread_pool/thread_pool_instance.h" @@ -69,20 +70,6 @@ void ExpectBucketCountAtLeast(base::HistogramTester* histogram_tester, << " expected_min_count_samples=" << expected_min_count_samples; } -size_t GetHistogramCount(base::HistogramTester* histogram_tester, - const std::string& histogram_name) { - base::ThreadPoolInstance::Get()->FlushForTesting(); - base::RunLoop().RunUntilIdle(); - - const std::vector<base::Bucket> buckets = - histogram_tester->GetAllSamples(histogram_name); - size_t total_count = 0; - for (const auto& bucket : buckets) { - total_count += bucket.count; - } - return total_count; -} - } // namespace namespace net { @@ -1028,9 +1015,9 @@ TEST_F(NetworkQualityEstimatorTest, ClampKbpsBasedOnEct) { } tests[] = { // Clamping multiplier set to 3.5 by default. {"", 3000, INT32_MAX, EFFECTIVE_CONNECTION_TYPE_SLOW_2G, - kTypicalDownlinkKbpsEffectiveConnectionType - [EFFECTIVE_CONNECTION_TYPE_SLOW_2G] * - 3.5}, + base::ClampFloor(kTypicalDownlinkKbpsEffectiveConnectionType + [EFFECTIVE_CONNECTION_TYPE_SLOW_2G] * + 3.5)}, // Clamping disabled. {"-1", 3000, INT32_MAX, EFFECTIVE_CONNECTION_TYPE_SLOW_2G, INT32_MAX}, // Clamping multiplier overridden to 1000. @@ -1050,9 +1037,9 @@ TEST_F(NetworkQualityEstimatorTest, ClampKbpsBasedOnEct) { 1000}, // Clamping multiplier set to 3.5 by default. {"", 500, INT32_MAX, EFFECTIVE_CONNECTION_TYPE_3G, - kTypicalDownlinkKbpsEffectiveConnectionType - [EFFECTIVE_CONNECTION_TYPE_3G] * - 3.5}, + base::ClampFloor(kTypicalDownlinkKbpsEffectiveConnectionType + [EFFECTIVE_CONNECTION_TYPE_3G] * + 3.5)}, // Clamping ineffective when the observed throughput is lower than the // clamped throughput. {"", 500, 100, EFFECTIVE_CONNECTION_TYPE_3G, 100}, @@ -1140,83 +1127,6 @@ TEST_F(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) { } } -// Tests that the ECT and other network quality metrics are capped based on -// signal strength. -TEST_F(NetworkQualityEstimatorTest, SignalStrengthBasedCapping) { - const struct { - bool enable_signal_strength_capping_experiment; - NetworkChangeNotifier::ConnectionType device_connection_type; - int32_t signal_strength_level; - int32_t http_rtt_msec; - EffectiveConnectionType expected_ect; - bool expected_http_rtt_overridden; - } tests[] = { - // Signal strength is unavailable. - {true, NetworkChangeNotifier::CONNECTION_4G, INT32_MIN, 20, - EFFECTIVE_CONNECTION_TYPE_4G, false}, - - // 4G device connection type: Signal strength is too low. Even though RTT - // is reported as low, - // ECT is expected to be capped to 2G. - {true, NetworkChangeNotifier::CONNECTION_4G, 0, 20, - EFFECTIVE_CONNECTION_TYPE_2G, true}, - - // WiFi device connection type: Signal strength is too low. Even though - // RTT is reported as low, ECT is expected to be capped to 2G. - {true, NetworkChangeNotifier::CONNECTION_WIFI, 0, 20, - EFFECTIVE_CONNECTION_TYPE_2G, true}, - - // When the signal strength based capping experiment is not enabled, - // ECT should be computed only on the based of |http_rtt_msec|. - {false, NetworkChangeNotifier::CONNECTION_4G, INT32_MIN, 20, - EFFECTIVE_CONNECTION_TYPE_4G, false}, - {false, NetworkChangeNotifier::CONNECTION_4G, 0, 20, - EFFECTIVE_CONNECTION_TYPE_4G, false}, - }; - - for (const auto& test : tests) { - base::HistogramTester histogram_tester; - std::map<std::string, std::string> variation_params; - variation_params["cap_ect_based_on_signal_strength"] = - test.enable_signal_strength_capping_experiment ? "true" : "false"; - - TestNetworkQualityEstimator estimator(variation_params); - - // Simulate the connection type so that GetEffectiveConnectionType - // does not return Offline if the device is offline. - estimator.SetCurrentSignalStrength(test.signal_strength_level); - - estimator.SimulateNetworkChange(test.device_connection_type, "test"); - - estimator.SetStartTimeNullHttpRtt( - base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); - estimator.set_recent_http_rtt( - base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); - estimator.set_start_time_null_downlink_throughput_kbps(INT32_MAX); - estimator.set_recent_downlink_throughput_kbps(INT32_MAX); - estimator.RunOneRequest(); - EXPECT_EQ(test.expected_ect, estimator.GetEffectiveConnectionType()); - - if (!test.expected_http_rtt_overridden) { - EXPECT_EQ(base::TimeDelta::FromMilliseconds(test.http_rtt_msec), - estimator.GetHttpRTT()); - } else { - EXPECT_EQ(estimator.params() - ->TypicalNetworkQuality(EFFECTIVE_CONNECTION_TYPE_2G) - .http_rtt(), - estimator.GetHttpRTT()); - } - - if (!test.expected_http_rtt_overridden) { - histogram_tester.ExpectTotalCount( - "NQE.CellularSignalStrength.ECTReduction", 0); - } else { - ExpectBucketCountAtLeast(&histogram_tester, - "NQE.CellularSignalStrength.ECTReduction", 2, 1); - } - } -} - // Tests that |GetEffectiveConnectionType| returns correct connection type when // both HTTP RTT and throughput thresholds are specified in the variation // params. @@ -2133,8 +2043,7 @@ TEST_F(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { TestURLRequestContext context(true); context.set_network_quality_estimator(&estimator); - std::unique_ptr<HttpNetworkSession::Context> session_context( - new HttpNetworkSession::Context); + auto session_context = std::make_unique<HttpNetworkSessionContext>(); // |estimator| should be notified of TCP RTT observations. session_context->socket_performance_watcher_factory = estimator.GetSocketPerformanceWatcherFactory(); @@ -3047,121 +2956,6 @@ TEST_F(NetworkQualityEstimatorTest, TestPeerToPeerConnectionsCountObserver) { EXPECT_EQ(3u, observer.count()); } -// Fails only for Android. https://crbug.com/1130720 -#if defined(OS_ANDROID) -#define MAYBE_CheckSignalStrength DISABLED_CheckSignalStrength -#else -#define MAYBE_CheckSignalStrength CheckSignalStrength -#endif - -// Tests that the signal strength API is not called too frequently. -TEST_F(NetworkQualityEstimatorTest, MAYBE_CheckSignalStrength) { - constexpr char histogram_name[] = "NQE.SignalStrengthQueried.WiFi"; - constexpr int kWiFiSignalStrengthQueryIntervalSeconds = 30 * 60; - - std::map<std::string, std::string> variation_params; - variation_params["get_signal_strength_and_detailed_network_id"] = "true"; - TestNetworkQualityEstimator estimator(variation_params); - - estimator.SimulateNetworkChange( - NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test"); - - base::SimpleTestTickClock tick_clock; - // SimulateNetworkChange() above can produce entries in the histogram bucket - // if the test system has real wifi or cellular connections, and can also - // leave the NQE inside its timeout. To avoid that, fastforward fake time for - // more than the query interval. - tick_clock.SetNowTicks(base::TimeTicks::Now() + - base::TimeDelta::FromSeconds( - kWiFiSignalStrengthQueryIntervalSeconds * 2)); - - estimator.SetTickClockForTesting(&tick_clock); - - base::HistogramTester histogram_tester; - absl::optional<int32_t> signal_strength = - estimator.GetCurrentSignalStrengthWithThrottling(); - - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - histogram_tester.ExpectTotalCount(histogram_name, 1); - - // Advance clock by |kWiFiSignalStrengthQueryIntervalSeconds|. The signal - // strength API should now be called. - tick_clock.Advance( - base::TimeDelta::FromSeconds(kWiFiSignalStrengthQueryIntervalSeconds)); - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - histogram_tester.ExpectTotalCount(histogram_name, 2); - - // Calling it again should return no value. - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - - tick_clock.Advance(base::TimeDelta::FromSeconds( - kWiFiSignalStrengthQueryIntervalSeconds - 3)); - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - histogram_tester.ExpectTotalCount(histogram_name, 2); - - // Move the clock by another 4 seconds. Since it's more than 30 seconds since - // the strength was last available, it should be available again. - tick_clock.Advance(base::TimeDelta::FromSeconds(3)); - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - histogram_tester.ExpectTotalCount(histogram_name, 3); - - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - histogram_tester.ExpectTotalCount(histogram_name, 3); - - // Changing the connection type should make the signal strength available - // again. Verify that the signal strength is not queried too frequently - // (currently, the threshold is set to 5). This is partially indeterminsitic - // due to the indeterminism at the connection change. - estimator.SimulateNetworkChange( - NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test"); - size_t samples_count = GetHistogramCount(&histogram_tester, histogram_name); - EXPECT_LE(4u, samples_count); - EXPECT_GE(8u, samples_count); - - tick_clock.Advance(base::TimeDelta::FromMilliseconds(2)); - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - histogram_tester.ExpectTotalCount(histogram_name, samples_count + 1); - - tick_clock.Advance(base::TimeDelta::FromMilliseconds(2)); - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - histogram_tester.ExpectTotalCount(histogram_name, samples_count + 1); -} - -TEST_F(NetworkQualityEstimatorTest, CheckSignalStrengthDisabledByDefault) { - TestNetworkQualityEstimator estimator; - - base::SimpleTestTickClock tick_clock; - tick_clock.SetNowTicks(base::TimeTicks::Now()); - - estimator.SetTickClockForTesting(&tick_clock); - - absl::optional<int32_t> signal_strength = - estimator.GetCurrentSignalStrengthWithThrottling(); - EXPECT_FALSE(signal_strength); - - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - EXPECT_FALSE(signal_strength); - - // Advance clock by 60 seconds. The signal strength API should NOT be called. - tick_clock.Advance(base::TimeDelta::FromSeconds(60)); - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - EXPECT_FALSE(signal_strength); - - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - EXPECT_FALSE(signal_strength); - - // Changing the connection type should NOT make the signal strength available - // again. - estimator.SimulateNetworkChange( - NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - EXPECT_FALSE(signal_strength); - - tick_clock.Advance(base::TimeDelta::FromMilliseconds(2)); - signal_strength = estimator.GetCurrentSignalStrengthWithThrottling(); - EXPECT_FALSE(signal_strength); -} - // Tests that the HTTP RTT and ECT are adjusted when the count of transport RTTs // is low. The test adds only HTTP RTT observations and does not add any // transport RTT observations. Absence of transport RTT observations should diff --git a/chromium/net/nqe/network_quality_estimator_util.cc b/chromium/net/nqe/network_quality_estimator_util.cc index 245e01d19c9..4364060f022 100644 --- a/chromium/net/nqe/network_quality_estimator_util.cc +++ b/chromium/net/nqe/network_quality_estimator_util.cc @@ -14,8 +14,7 @@ #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" #include "net/dns/host_resolver.h" -#include "net/dns/host_resolver_source.h" -#include "net/log/net_log_with_source.h" +#include "net/dns/public/host_resolver_source.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_context.h" @@ -27,13 +26,14 @@ namespace { bool IsPrivateHost(HostResolver* host_resolver, const HostPortPair& host_port_pair, - const NetworkIsolationKey& network_isolation_key) { + const NetworkIsolationKey& network_isolation_key, + NetLogWithSource net_log) { // Try resolving |host_port_pair.host()| synchronously. HostResolver::ResolveHostParameters parameters; parameters.source = HostResolverSource::LOCAL_ONLY; std::unique_ptr<HostResolver::ResolveHostRequest> request = host_resolver->CreateRequest(host_port_pair, network_isolation_key, - NetLogWithSource(), parameters); + net_log, parameters); int rv = request->Start(base::BindOnce([](int error) { NOTREACHED(); })); DCHECK_NE(rv, ERR_IO_PENDING); @@ -54,18 +54,20 @@ bool IsPrivateHost(HostResolver* host_resolver, namespace internal { -bool IsRequestForPrivateHost(const URLRequest& request) { +bool IsRequestForPrivateHost(const URLRequest& request, + NetLogWithSource net_log) { // Using the request's NetworkIsolationKey isn't necessary for privacy // reasons, but is needed to maximize the chances of a cache hit. - return IsPrivateHost(request.context()->host_resolver(), - HostPortPair::FromURL(request.url()), - request.isolation_info().network_isolation_key()); + return IsPrivateHost( + request.context()->host_resolver(), HostPortPair::FromURL(request.url()), + request.isolation_info().network_isolation_key(), net_log); } bool IsPrivateHostForTesting(HostResolver* host_resolver, const HostPortPair& host_port_pair, const NetworkIsolationKey& network_isolation_key) { - return IsPrivateHost(host_resolver, host_port_pair, network_isolation_key); + return IsPrivateHost(host_resolver, host_port_pair, network_isolation_key, + NetLogWithSource()); } } // namespace internal diff --git a/chromium/net/nqe/network_quality_estimator_util.h b/chromium/net/nqe/network_quality_estimator_util.h index 41e15d08380..67d2099db2b 100644 --- a/chromium/net/nqe/network_quality_estimator_util.h +++ b/chromium/net/nqe/network_quality_estimator_util.h @@ -8,6 +8,7 @@ #include <stdint.h> #include "net/base/net_export.h" +#include "net/log/net_log_with_source.h" namespace net { @@ -32,7 +33,8 @@ typedef uint64_t IPHash; // To make this determination, this method makes the best effort estimate // including trying to resolve the host from the HostResolver's cache. This // method is synchronous. -NET_EXPORT_PRIVATE bool IsRequestForPrivateHost(const URLRequest& request); +NET_EXPORT_PRIVATE bool IsRequestForPrivateHost(const URLRequest& request, + NetLogWithSource net_log); // Provides access to the method used internally by IsRequestForPrivateHost(), // for testing. diff --git a/chromium/net/nqe/observation_buffer.cc b/chromium/net/nqe/observation_buffer.cc index 0b99d81dbc3..de645b20635 100644 --- a/chromium/net/nqe/observation_buffer.cc +++ b/chromium/net/nqe/observation_buffer.cc @@ -9,9 +9,9 @@ #include <algorithm> #include <utility> +#include "base/containers/cxx20_erase.h" +#include "base/cxx17_backports.h" #include "base/macros.h" -#include "base/numerics/ranges.h" -#include "base/stl_util.h" #include "base/time/default_tick_clock.h" #include "base/time/time.h" #include "net/nqe/network_quality_estimator_params.h" @@ -150,7 +150,7 @@ void ObservationBuffer::ComputeWeightedObservations( } double weight = time_weight * signal_strength_weight; - weight = base::ClampToRange(weight, DBL_MIN, 1.0); + weight = base::clamp(weight, DBL_MIN, 1.0); weighted_observations->push_back( WeightedObservation(observation.value(), weight)); diff --git a/chromium/net/nqe/throughput_analyzer.cc b/chromium/net/nqe/throughput_analyzer.cc index 34503232ac0..b2853e20489 100644 --- a/chromium/net/nqe/throughput_analyzer.cc +++ b/chromium/net/nqe/throughput_analyzer.cc @@ -403,7 +403,7 @@ bool ThroughputAnalyzer::DegradesAccuracy(const URLRequest& request) const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); bool private_network_request = - nqe::internal::IsRequestForPrivateHost(request); + nqe::internal::IsRequestForPrivateHost(request, net_log_); return !(use_localhost_requests_for_tests_ || !private_network_request) || request.creation_time() < last_connection_change_; diff --git a/chromium/net/nqe/throughput_analyzer.h b/chromium/net/nqe/throughput_analyzer.h index a243b370da9..c6ec2438ef5 100644 --- a/chromium/net/nqe/throughput_analyzer.h +++ b/chromium/net/nqe/throughput_analyzer.h @@ -17,7 +17,6 @@ #include "base/time/time.h" #include "net/base/net_export.h" #include "net/log/net_log_with_source.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace { typedef base::RepeatingCallback<void(int32_t)> ThroughputObservationCallback; |