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

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

Issue 2406763003: Add Network Quality observer to NQE (Closed)
Patch Set: Fix presubmit errors (FOR_EACH_OBSERVER is deprecated) Created 4 years, 2 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
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 std::string())), 382 std::string())),
383 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), 383 downstream_throughput_kbps_observations_(weight_multiplier_per_second_),
384 rtt_observations_(weight_multiplier_per_second_), 384 rtt_observations_(weight_multiplier_per_second_),
385 effective_connection_type_at_last_main_frame_( 385 effective_connection_type_at_last_main_frame_(
386 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 386 EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
387 external_estimate_provider_(std::move(external_estimates_provider)), 387 external_estimate_provider_(std::move(external_estimates_provider)),
388 effective_connection_type_recomputation_interval_( 388 effective_connection_type_recomputation_interval_(
389 base::TimeDelta::FromSeconds(10)), 389 base::TimeDelta::FromSeconds(10)),
390 rtt_observations_size_at_last_ect_computation_(0), 390 rtt_observations_size_at_last_ect_computation_(0),
391 throughput_observations_size_at_last_ect_computation_(0), 391 throughput_observations_size_at_last_ect_computation_(0),
392 http_rtt_(nqe::internal::InvalidRTT()),
393 transport_rtt_(nqe::internal::InvalidRTT()),
394 downstream_throughput_kbps_(nqe::internal::kInvalidThroughput),
392 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 395 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
393 min_signal_strength_since_connection_change_(INT32_MAX), 396 min_signal_strength_since_connection_change_(INT32_MAX),
394 max_signal_strength_since_connection_change_(INT32_MIN), 397 max_signal_strength_since_connection_change_(INT32_MIN),
395 correlation_uma_logging_probability_( 398 correlation_uma_logging_probability_(
396 GetDoubleValueForVariationParamWithDefaultValue( 399 GetDoubleValueForVariationParamWithDefaultValue(
397 variation_params, 400 variation_params,
398 "correlation_logging_probability", 401 "correlation_logging_probability",
399 0.0)), 402 0.0)),
400 forced_effective_connection_type_set_( 403 forced_effective_connection_type_set_(
401 !GetStringValueForVariationParamWithDefaultValue( 404 !GetStringValueForVariationParamWithDefaultValue(
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 void NetworkQualityEstimator::SetUseSmallResponsesForTesting( 975 void NetworkQualityEstimator::SetUseSmallResponsesForTesting(
973 bool use_small_responses) { 976 bool use_small_responses) {
974 DCHECK(thread_checker_.CalledOnValidThread()); 977 DCHECK(thread_checker_.CalledOnValidThread());
975 use_small_responses_ = use_small_responses; 978 use_small_responses_ = use_small_responses;
976 throughput_analyzer_->SetUseSmallResponsesForTesting(use_small_responses_); 979 throughput_analyzer_->SetUseSmallResponsesForTesting(use_small_responses_);
977 } 980 }
978 981
979 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting( 982 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting(
980 EffectiveConnectionType effective_connection_type) { 983 EffectiveConnectionType effective_connection_type) {
981 DCHECK(thread_checker_.CalledOnValidThread()); 984 DCHECK(thread_checker_.CalledOnValidThread());
982 FOR_EACH_OBSERVER( 985 for (auto& observer : effective_connection_type_observer_list_)
983 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, 986 observer.OnEffectiveConnectionTypeChanged(effective_connection_type);
984 OnEffectiveConnectionTypeChanged(effective_connection_type));
985 } 987 }
986 988
987 bool NetworkQualityEstimator::RequestProvidesRTTObservation( 989 bool NetworkQualityEstimator::RequestProvidesRTTObservation(
988 const URLRequest& request) const { 990 const URLRequest& request) const {
989 DCHECK(thread_checker_.CalledOnValidThread()); 991 DCHECK(thread_checker_.CalledOnValidThread());
990 992
991 return (use_localhost_requests_ || !IsLocalhost(request.url().host())) && 993 return (use_localhost_requests_ || !IsLocalhost(request.url().host())) &&
992 // Verify that response headers are received, so it can be ensured that 994 // Verify that response headers are received, so it can be ensured that
993 // response is not cached. 995 // response is not cached.
994 !request.response_info().response_time.is_null() && 996 !request.response_info().response_time.is_null() &&
(...skipping 30 matching lines...) Expand all
1025 if (NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { 1027 if (NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) {
1026 UMA_HISTOGRAM_BOOLEAN( 1028 UMA_HISTOGRAM_BOOLEAN(
1027 "NQE.CellularSignalStrengthAvailable", 1029 "NQE.CellularSignalStrengthAvailable",
1028 min_signal_strength_since_connection_change_ != INT32_MAX && 1030 min_signal_strength_since_connection_change_ != INT32_MAX &&
1029 max_signal_strength_since_connection_change_ != INT32_MIN); 1031 max_signal_strength_since_connection_change_ != INT32_MIN);
1030 } 1032 }
1031 #endif // OS_ANDROID 1033 #endif // OS_ANDROID
1032 min_signal_strength_since_connection_change_ = INT32_MAX; 1034 min_signal_strength_since_connection_change_ = INT32_MAX;
1033 max_signal_strength_since_connection_change_ = INT32_MIN; 1035 max_signal_strength_since_connection_change_ = INT32_MIN;
1034 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality(); 1036 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality();
1037 http_rtt_ = nqe::internal::InvalidRTT();
1038 transport_rtt_ = nqe::internal::InvalidRTT();
1039 downstream_throughput_kbps_ = nqe::internal::kInvalidThroughput;
1035 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1040 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1036 effective_connection_type_at_last_main_frame_ = 1041 effective_connection_type_at_last_main_frame_ =
1037 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1042 EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1038 1043
1039 // Update the local state as part of preparation for the new connection. 1044 // Update the local state as part of preparation for the new connection.
1040 current_network_id_ = GetCurrentNetworkID(); 1045 current_network_id_ = GetCurrentNetworkID();
1041 RecordNetworkIDAvailability(); 1046 RecordNetworkIDAvailability();
1042 1047
1043 MaybeQueryExternalEstimateProvider(); 1048 MaybeQueryExternalEstimateProvider();
1044 1049
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 1210
1206 void NetworkQualityEstimator::ComputeEffectiveConnectionType() { 1211 void NetworkQualityEstimator::ComputeEffectiveConnectionType() {
1207 DCHECK(thread_checker_.CalledOnValidThread()); 1212 DCHECK(thread_checker_.CalledOnValidThread());
1208 1213
1209 const base::TimeTicks now = tick_clock_->NowTicks(); 1214 const base::TimeTicks now = tick_clock_->NowTicks();
1210 1215
1211 const EffectiveConnectionType past_type = effective_connection_type_; 1216 const EffectiveConnectionType past_type = effective_connection_type_;
1212 last_effective_connection_type_computation_ = now; 1217 last_effective_connection_type_computation_ = now;
1213 1218
1214 effective_connection_type_ = 1219 effective_connection_type_ =
1215 GetRecentEffectiveConnectionType(base::TimeTicks()); 1220 GetRecentEffectiveConnectionTypeAndNetworkQuality(
1221 base::TimeTicks(), &http_rtt_, &transport_rtt_,
1222 &downstream_throughput_kbps_);
1223 NotifyObserversOfRTTOrThroughputComputed();
1216 1224
1217 if (past_type != effective_connection_type_) 1225 if (past_type != effective_connection_type_)
1218 NotifyObserversOfEffectiveConnectionTypeChanged(); 1226 NotifyObserversOfEffectiveConnectionTypeChanged();
1219 1227
1220 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size(); 1228 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size();
1221 throughput_observations_size_at_last_ect_computation_ = 1229 throughput_observations_size_at_last_ect_computation_ =
1222 downstream_throughput_kbps_observations_.Size(); 1230 downstream_throughput_kbps_observations_.Size();
1223 } 1231 }
1224 1232
1225 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType() 1233 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType()
1226 const { 1234 const {
1227 DCHECK(thread_checker_.CalledOnValidThread()); 1235 DCHECK(thread_checker_.CalledOnValidThread());
1228 return effective_connection_type_; 1236 return effective_connection_type_;
1229 } 1237 }
1230 1238
1231 EffectiveConnectionType 1239 EffectiveConnectionType
1232 NetworkQualityEstimator::GetRecentEffectiveConnectionType( 1240 NetworkQualityEstimator::GetRecentEffectiveConnectionType(
1233 const base::TimeTicks& start_time) const { 1241 const base::TimeTicks& start_time) const {
1234 DCHECK(thread_checker_.CalledOnValidThread()); 1242 DCHECK(thread_checker_.CalledOnValidThread());
1235 1243
1244 base::TimeDelta http_rtt;
1245 base::TimeDelta transport_rtt;
1246 int32_t downstream_throughput_kbps;
1247
1248 return GetRecentEffectiveConnectionTypeAndNetworkQuality(
1249 start_time, &http_rtt, &transport_rtt, &downstream_throughput_kbps);
1250 }
1251
1252 EffectiveConnectionType
1253 NetworkQualityEstimator::GetRecentEffectiveConnectionTypeAndNetworkQuality(
1254 const base::TimeTicks& start_time,
1255 base::TimeDelta* http_rtt,
1256 base::TimeDelta* transport_rtt,
1257 int32_t* downstream_throughput_kbps) const {
1258 DCHECK(thread_checker_.CalledOnValidThread());
1259
1236 if (effective_connection_type_algorithm_ == 1260 if (effective_connection_type_algorithm_ ==
1237 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) { 1261 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) {
1238 return GetRecentEffectiveConnectionTypeUsingMetrics( 1262 return GetRecentEffectiveConnectionTypeUsingMetrics(
1239 start_time, NetworkQualityEstimator::MetricUsage:: 1263 start_time, NetworkQualityEstimator::MetricUsage::
1240 MUST_BE_USED /* http_rtt_metric */, 1264 MUST_BE_USED /* http_rtt_metric */,
1241 NetworkQualityEstimator::MetricUsage:: 1265 NetworkQualityEstimator::MetricUsage::
1242 DO_NOT_USE /* transport_rtt_metric */, 1266 DO_NOT_USE /* transport_rtt_metric */,
1243 NetworkQualityEstimator::MetricUsage:: 1267 NetworkQualityEstimator::MetricUsage::
1244 MUST_BE_USED /* downstream_throughput_kbps_metric */); 1268 MUST_BE_USED /* downstream_throughput_kbps_metric */,
1269 http_rtt, transport_rtt, downstream_throughput_kbps);
1245 } 1270 }
1246 if (effective_connection_type_algorithm_ == 1271 if (effective_connection_type_algorithm_ ==
1247 EffectiveConnectionTypeAlgorithm:: 1272 EffectiveConnectionTypeAlgorithm::
1248 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) { 1273 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) {
1249 return GetRecentEffectiveConnectionTypeUsingMetrics( 1274 return GetRecentEffectiveConnectionTypeUsingMetrics(
1250 start_time, 1275 start_time,
1251 NetworkQualityEstimator::MetricUsage::DO_NOT_USE /* http_rtt_metric */, 1276 NetworkQualityEstimator::MetricUsage::DO_NOT_USE /* http_rtt_metric */,
1252 NetworkQualityEstimator::MetricUsage:: 1277 NetworkQualityEstimator::MetricUsage::
1253 USE_IF_AVAILABLE /* transport_rtt_metric */, 1278 USE_IF_AVAILABLE /* transport_rtt_metric */,
1254 NetworkQualityEstimator::MetricUsage:: 1279 NetworkQualityEstimator::MetricUsage::
1255 USE_IF_AVAILABLE /* downstream_throughput_kbps_metric */); 1280 USE_IF_AVAILABLE /* downstream_throughput_kbps_metric */,
1281 http_rtt, transport_rtt, downstream_throughput_kbps);
1256 } 1282 }
1257 // Add additional algorithms here. 1283 // Add additional algorithms here.
1258 NOTREACHED(); 1284 NOTREACHED();
1259 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1285 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1260 } 1286 }
1261 1287
1262 bool NetworkQualityEstimator::UseTransportRTT() const { 1288 bool NetworkQualityEstimator::UseTransportRTT() const {
1263 DCHECK(thread_checker_.CalledOnValidThread()); 1289 DCHECK(thread_checker_.CalledOnValidThread());
1264 1290
1265 if (effective_connection_type_algorithm_ == 1291 if (effective_connection_type_algorithm_ ==
1266 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) { 1292 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) {
1267 return false; 1293 return false;
1268 } 1294 }
1269 if (effective_connection_type_algorithm_ == 1295 if (effective_connection_type_algorithm_ ==
1270 EffectiveConnectionTypeAlgorithm:: 1296 EffectiveConnectionTypeAlgorithm::
1271 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) { 1297 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) {
1272 return true; 1298 return true;
1273 } 1299 }
1274 // Add additional algorithms here. 1300 // Add additional algorithms here.
1275 NOTREACHED(); 1301 NOTREACHED();
1276 return false; 1302 return false;
1277 } 1303 }
1278 1304
1279 EffectiveConnectionType 1305 EffectiveConnectionType
1280 NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics( 1306 NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics(
1281 const base::TimeTicks& start_time, 1307 const base::TimeTicks& start_time,
1282 NetworkQualityEstimator::MetricUsage http_rtt_metric, 1308 NetworkQualityEstimator::MetricUsage http_rtt_metric,
1283 NetworkQualityEstimator::MetricUsage transport_rtt_metric, 1309 NetworkQualityEstimator::MetricUsage transport_rtt_metric,
1284 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric) 1310 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric,
1285 const { 1311 base::TimeDelta* http_rtt,
1312 base::TimeDelta* transport_rtt,
1313 int32_t* downstream_throughput_kbps) const {
1286 DCHECK(thread_checker_.CalledOnValidThread()); 1314 DCHECK(thread_checker_.CalledOnValidThread());
1287 1315
1316 *http_rtt = nqe::internal::InvalidRTT();
1317 *transport_rtt = nqe::internal::InvalidRTT();
1318 *downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
1319
1288 if (forced_effective_connection_type_set_) 1320 if (forced_effective_connection_type_set_)
1289 return forced_effective_connection_type_; 1321 return forced_effective_connection_type_;
1290 1322
1291 // If the device is currently offline, then return 1323 // If the device is currently offline, then return
1292 // EFFECTIVE_CONNECTION_TYPE_OFFLINE. 1324 // EFFECTIVE_CONNECTION_TYPE_OFFLINE.
1293 if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_NONE) 1325 if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_NONE)
1294 return EFFECTIVE_CONNECTION_TYPE_OFFLINE; 1326 return EFFECTIVE_CONNECTION_TYPE_OFFLINE;
1295 1327
1296 base::TimeDelta http_rtt = nqe::internal::InvalidRTT(); 1328 if (!GetRecentHttpRTT(start_time, http_rtt))
1297 if (http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1329 *http_rtt = nqe::internal::InvalidRTT();
1298 !GetRecentHttpRTT(start_time, &http_rtt)) {
1299 http_rtt = nqe::internal::InvalidRTT();
1300 }
1301 1330
1302 base::TimeDelta transport_rtt = nqe::internal::InvalidRTT(); 1331 if (!GetRecentTransportRTT(start_time, transport_rtt))
1303 if (transport_rtt_metric != 1332 *transport_rtt = nqe::internal::InvalidRTT();
1304 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1305 !GetRecentTransportRTT(start_time, &transport_rtt)) {
1306 transport_rtt = nqe::internal::InvalidRTT();
1307 }
1308 1333
1309 int32_t kbps = nqe::internal::kInvalidThroughput; 1334 if (!GetRecentDownlinkThroughputKbps(start_time, downstream_throughput_kbps))
1310 if (downstream_throughput_kbps_metric != 1335 *downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
1311 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1312 !GetRecentDownlinkThroughputKbps(start_time, &kbps)) {
1313 kbps = nqe::internal::kInvalidThroughput;
1314 }
1315 1336
1316 if (http_rtt == nqe::internal::InvalidRTT() && 1337 if (*http_rtt == nqe::internal::InvalidRTT() &&
1317 http_rtt_metric == NetworkQualityEstimator::MetricUsage::MUST_BE_USED) { 1338 http_rtt_metric == NetworkQualityEstimator::MetricUsage::MUST_BE_USED) {
1318 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1339 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1319 } 1340 }
1320 1341
1321 if (transport_rtt == nqe::internal::InvalidRTT() && 1342 if (*transport_rtt == nqe::internal::InvalidRTT() &&
1322 transport_rtt_metric == 1343 transport_rtt_metric ==
1323 NetworkQualityEstimator::MetricUsage::MUST_BE_USED) { 1344 NetworkQualityEstimator::MetricUsage::MUST_BE_USED) {
1324 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1345 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1325 } 1346 }
1326 1347
1327 if (kbps == nqe::internal::kInvalidThroughput && 1348 if (*downstream_throughput_kbps == nqe::internal::kInvalidThroughput &&
1328 downstream_throughput_kbps_metric == 1349 downstream_throughput_kbps_metric ==
1329 NetworkQualityEstimator::MetricUsage::MUST_BE_USED) { 1350 NetworkQualityEstimator::MetricUsage::MUST_BE_USED) {
1330 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1351 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1331 } 1352 }
1332 1353
1333 if (http_rtt == nqe::internal::InvalidRTT() && 1354 if (*http_rtt == nqe::internal::InvalidRTT() &&
1334 transport_rtt == nqe::internal::InvalidRTT() && 1355 *transport_rtt == nqe::internal::InvalidRTT() &&
1335 kbps == nqe::internal::kInvalidThroughput) { 1356 *downstream_throughput_kbps == nqe::internal::kInvalidThroughput) {
1336 // None of the metrics are available. 1357 // None of the metrics are available.
1337 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1358 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1338 } 1359 }
1339 1360
1340 // Search from the slowest connection type to the fastest to find the 1361 // Search from the slowest connection type to the fastest to find the
1341 // EffectiveConnectionType that best matches the current connection's 1362 // EffectiveConnectionType that best matches the current connection's
1342 // performance. The match is done by comparing RTT and throughput. 1363 // performance. The match is done by comparing RTT and throughput.
1343 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { 1364 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
1344 EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i); 1365 EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i);
1345 if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) 1366 if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
1346 continue; 1367 continue;
1347 1368
1348 const bool estimated_http_rtt_is_higher_than_threshold = 1369 const bool estimated_http_rtt_is_higher_than_threshold =
1349 http_rtt != nqe::internal::InvalidRTT() && 1370 http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1371 *http_rtt != nqe::internal::InvalidRTT() &&
1350 connection_thresholds_[i].http_rtt() != nqe::internal::InvalidRTT() && 1372 connection_thresholds_[i].http_rtt() != nqe::internal::InvalidRTT() &&
1351 http_rtt >= connection_thresholds_[i].http_rtt(); 1373 *http_rtt >= connection_thresholds_[i].http_rtt();
1352 1374
1353 const bool estimated_transport_rtt_is_higher_than_threshold = 1375 const bool estimated_transport_rtt_is_higher_than_threshold =
1354 transport_rtt != nqe::internal::InvalidRTT() && 1376 transport_rtt_metric !=
1377 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1378 *transport_rtt != nqe::internal::InvalidRTT() &&
1355 connection_thresholds_[i].transport_rtt() != 1379 connection_thresholds_[i].transport_rtt() !=
1356 nqe::internal::InvalidRTT() && 1380 nqe::internal::InvalidRTT() &&
1357 transport_rtt >= connection_thresholds_[i].transport_rtt(); 1381 *transport_rtt >= connection_thresholds_[i].transport_rtt();
1358 1382
1359 const bool estimated_throughput_is_lower_than_threshold = 1383 const bool estimated_throughput_is_lower_than_threshold =
1360 kbps != nqe::internal::kInvalidThroughput && 1384 downstream_throughput_kbps_metric !=
1385 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1386 *downstream_throughput_kbps != nqe::internal::kInvalidThroughput &&
1361 connection_thresholds_[i].downstream_throughput_kbps() != 1387 connection_thresholds_[i].downstream_throughput_kbps() !=
1362 nqe::internal::kInvalidThroughput && 1388 nqe::internal::kInvalidThroughput &&
1363 kbps <= connection_thresholds_[i].downstream_throughput_kbps(); 1389 *downstream_throughput_kbps <=
1390 connection_thresholds_[i].downstream_throughput_kbps();
1364 1391
1365 if (estimated_http_rtt_is_higher_than_threshold || 1392 if (estimated_http_rtt_is_higher_than_threshold ||
1366 estimated_transport_rtt_is_higher_than_threshold || 1393 estimated_transport_rtt_is_higher_than_threshold ||
1367 estimated_throughput_is_lower_than_threshold) { 1394 estimated_throughput_is_lower_than_threshold) {
1368 return type; 1395 return type;
1369 } 1396 }
1370 } 1397 }
1371 // Return the fastest connection type. 1398 // Return the fastest connection type.
1372 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST - 1399 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST -
1373 1); 1400 1);
1374 } 1401 }
1375 1402
1376 void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver( 1403 void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver(
1377 EffectiveConnectionTypeObserver* observer) { 1404 EffectiveConnectionTypeObserver* observer) {
1378 DCHECK(thread_checker_.CalledOnValidThread()); 1405 DCHECK(thread_checker_.CalledOnValidThread());
1379 effective_connection_type_observer_list_.AddObserver(observer); 1406 effective_connection_type_observer_list_.AddObserver(observer);
1380 } 1407 }
1381 1408
1382 void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver( 1409 void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver(
1383 EffectiveConnectionTypeObserver* observer) { 1410 EffectiveConnectionTypeObserver* observer) {
1384 DCHECK(thread_checker_.CalledOnValidThread()); 1411 DCHECK(thread_checker_.CalledOnValidThread());
1385 effective_connection_type_observer_list_.RemoveObserver(observer); 1412 effective_connection_type_observer_list_.RemoveObserver(observer);
1386 } 1413 }
1387 1414
1415 void NetworkQualityEstimator::AddRTTAndThroughputEstimatesObserver(
1416 RTTAndThroughputEstimatesObserver* observer) {
1417 DCHECK(thread_checker_.CalledOnValidThread());
1418 rtt_and_throughput_estimates_observer_list_.AddObserver(observer);
1419 }
1420
1421 void NetworkQualityEstimator::RemoveRTTAndThroughputEstimatesObserver(
1422 RTTAndThroughputEstimatesObserver* observer) {
1423 DCHECK(thread_checker_.CalledOnValidThread());
1424 rtt_and_throughput_estimates_observer_list_.RemoveObserver(observer);
1425 }
1426
1388 bool NetworkQualityEstimator::GetHttpRTT(base::TimeDelta* rtt) const { 1427 bool NetworkQualityEstimator::GetHttpRTT(base::TimeDelta* rtt) const {
1389 DCHECK(thread_checker_.CalledOnValidThread()); 1428 DCHECK(thread_checker_.CalledOnValidThread());
1390 return GetRecentHttpRTT(base::TimeTicks(), rtt); 1429 return GetRecentHttpRTT(base::TimeTicks(), rtt);
1391 } 1430 }
1392 1431
1393 bool NetworkQualityEstimator::GetTransportRTT(base::TimeDelta* rtt) const { 1432 bool NetworkQualityEstimator::GetTransportRTT(base::TimeDelta* rtt) const {
1394 DCHECK(thread_checker_.CalledOnValidThread()); 1433 DCHECK(thread_checker_.CalledOnValidThread());
1395 return GetRecentTransportRTT(base::TimeTicks(), rtt); 1434 return GetRecentTransportRTT(base::TimeTicks(), rtt);
1396 } 1435 }
1397 1436
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 cached_estimate_available); 1569 cached_estimate_available);
1531 1570
1532 if (!cached_estimate_available) 1571 if (!cached_estimate_available)
1533 return false; 1572 return false;
1534 1573
1535 const base::TimeTicks now = tick_clock_->NowTicks(); 1574 const base::TimeTicks now = tick_clock_->NowTicks();
1536 1575
1537 if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1576 if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1538 // Read the effective connection type from the cached estimate. 1577 // Read the effective connection type from the cached estimate.
1539 last_effective_connection_type_computation_ = now; 1578 last_effective_connection_type_computation_ = now;
1579 http_rtt_ = cached_network_quality.network_quality().http_rtt();
1580 transport_rtt_ = cached_network_quality.network_quality().transport_rtt();
1581 downstream_throughput_kbps_ =
1582 cached_network_quality.network_quality().downstream_throughput_kbps();
1540 effective_connection_type_ = 1583 effective_connection_type_ =
1541 cached_network_quality.effective_connection_type(); 1584 cached_network_quality.effective_connection_type();
1542 1585
1543 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) 1586 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
1544 NotifyObserversOfEffectiveConnectionTypeChanged(); 1587 NotifyObserversOfEffectiveConnectionTypeChanged();
1545 } 1588 }
1546 1589
1547 if (cached_network_quality.network_quality().downstream_throughput_kbps() != 1590 if (cached_network_quality.network_quality().downstream_throughput_kbps() !=
1548 nqe::internal::kInvalidThroughput) { 1591 nqe::internal::kInvalidThroughput) {
1549 ThroughputObservation througphput_observation( 1592 ThroughputObservation througphput_observation(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 } 1667 }
1625 1668
1626 void NetworkQualityEstimator::NotifyObserversOfRTT( 1669 void NetworkQualityEstimator::NotifyObserversOfRTT(
1627 const RttObservation& observation) { 1670 const RttObservation& observation) {
1628 DCHECK(thread_checker_.CalledOnValidThread()); 1671 DCHECK(thread_checker_.CalledOnValidThread());
1629 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value); 1672 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value);
1630 1673
1631 // Maybe recompute the effective connection type since a new RTT observation 1674 // Maybe recompute the effective connection type since a new RTT observation
1632 // is available. 1675 // is available.
1633 MaybeComputeEffectiveConnectionType(); 1676 MaybeComputeEffectiveConnectionType();
1634 FOR_EACH_OBSERVER( 1677 for (auto& observer : rtt_observer_list_) {
1635 RTTObserver, rtt_observer_list_, 1678 observer.OnRTTObservation(observation.value.InMilliseconds(),
1636 OnRTTObservation(observation.value.InMilliseconds(), 1679 observation.timestamp, observation.source);
1637 observation.timestamp, observation.source)); 1680 }
1638 } 1681 }
1639 1682
1640 void NetworkQualityEstimator::NotifyObserversOfThroughput( 1683 void NetworkQualityEstimator::NotifyObserversOfThroughput(
1641 const ThroughputObservation& observation) { 1684 const ThroughputObservation& observation) {
1642 DCHECK(thread_checker_.CalledOnValidThread()); 1685 DCHECK(thread_checker_.CalledOnValidThread());
1643 DCHECK_NE(nqe::internal::kInvalidThroughput, observation.value); 1686 DCHECK_NE(nqe::internal::kInvalidThroughput, observation.value);
1644 1687
1645 // Maybe recompute the effective connection type since a new throughput 1688 // Maybe recompute the effective connection type since a new throughput
1646 // observation is available. 1689 // observation is available.
1647 MaybeComputeEffectiveConnectionType(); 1690 MaybeComputeEffectiveConnectionType();
1648 FOR_EACH_OBSERVER( 1691 for (auto& observer : throughput_observer_list_) {
1649 ThroughputObserver, throughput_observer_list_, 1692 observer.OnThroughputObservation(observation.value, observation.timestamp,
1650 OnThroughputObservation(observation.value, observation.timestamp, 1693 observation.source);
1651 observation.source)); 1694 }
1652 } 1695 }
1653 1696
1654 void NetworkQualityEstimator::OnNewThroughputObservationAvailable( 1697 void NetworkQualityEstimator::OnNewThroughputObservationAvailable(
1655 int32_t downstream_kbps) { 1698 int32_t downstream_kbps) {
1656 DCHECK(thread_checker_.CalledOnValidThread()); 1699 DCHECK(thread_checker_.CalledOnValidThread());
1657 1700
1658 if (downstream_kbps == 0) 1701 if (downstream_kbps == 0)
1659 return; 1702 return;
1660 1703
1661 DCHECK_NE(nqe::internal::kInvalidThroughput, downstream_kbps); 1704 DCHECK_NE(nqe::internal::kInvalidThroughput, downstream_kbps);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 } 1743 }
1701 ComputeEffectiveConnectionType(); 1744 ComputeEffectiveConnectionType();
1702 } 1745 }
1703 1746
1704 void NetworkQualityEstimator:: 1747 void NetworkQualityEstimator::
1705 NotifyObserversOfEffectiveConnectionTypeChanged() { 1748 NotifyObserversOfEffectiveConnectionTypeChanged() {
1706 DCHECK(thread_checker_.CalledOnValidThread()); 1749 DCHECK(thread_checker_.CalledOnValidThread());
1707 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); 1750 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_);
1708 1751
1709 // TODO(tbansal): Add hysteresis in the notification. 1752 // TODO(tbansal): Add hysteresis in the notification.
1710 FOR_EACH_OBSERVER( 1753 for (auto& observer : effective_connection_type_observer_list_)
1711 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, 1754 observer.OnEffectiveConnectionTypeChanged(effective_connection_type_);
1712 OnEffectiveConnectionTypeChanged(effective_connection_type_));
1713 1755
1714 // Add the estimates of the current network to the cache store. 1756 // Add the estimates of the current network to the cache store.
1715 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1757 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1716 network_quality_store_->Add( 1758 network_quality_store_->Add(
1717 current_network_id_, 1759 current_network_id_,
1718 nqe::internal::CachedNetworkQuality( 1760 nqe::internal::CachedNetworkQuality(
1719 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, 1761 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_,
1720 effective_connection_type_)); 1762 effective_connection_type_));
1721 } 1763 }
1722 } 1764 }
1723 1765
1766 void NetworkQualityEstimator::NotifyObserversOfRTTOrThroughputComputed() const {
1767 DCHECK(thread_checker_.CalledOnValidThread());
1768
1769 // TODO(tbansal): Add hysteresis in the notification.
1770 for (auto& observer : rtt_and_throughput_estimates_observer_list_) {
1771 observer.OnRTTOrThroughputEstimatesComputed(http_rtt_, transport_rtt_,
1772 downstream_throughput_kbps_);
1773 }
1774 }
1775
1724 void NetworkQualityEstimator::AddNetworkQualitiesCacheObserver( 1776 void NetworkQualityEstimator::AddNetworkQualitiesCacheObserver(
1725 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* 1777 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver*
1726 observer) { 1778 observer) {
1727 DCHECK(thread_checker_.CalledOnValidThread()); 1779 DCHECK(thread_checker_.CalledOnValidThread());
1728 network_quality_store_->AddNetworkQualitiesCacheObserver(observer); 1780 network_quality_store_->AddNetworkQualitiesCacheObserver(observer);
1729 } 1781 }
1730 1782
1731 void NetworkQualityEstimator::RemoveNetworkQualitiesCacheObserver( 1783 void NetworkQualityEstimator::RemoveNetworkQualitiesCacheObserver(
1732 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* 1784 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver*
1733 observer) { 1785 observer) {
1734 DCHECK(thread_checker_.CalledOnValidThread()); 1786 DCHECK(thread_checker_.CalledOnValidThread());
1735 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer); 1787 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer);
1736 } 1788 }
1737 1789
1738 } // namespace net 1790 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698