Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1025 if (NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { | 1028 if (NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { |
| 1026 UMA_HISTOGRAM_BOOLEAN( | 1029 UMA_HISTOGRAM_BOOLEAN( |
| 1027 "NQE.CellularSignalStrengthAvailable", | 1030 "NQE.CellularSignalStrengthAvailable", |
| 1028 min_signal_strength_since_connection_change_ != INT32_MAX && | 1031 min_signal_strength_since_connection_change_ != INT32_MAX && |
| 1029 max_signal_strength_since_connection_change_ != INT32_MIN); | 1032 max_signal_strength_since_connection_change_ != INT32_MIN); |
| 1030 } | 1033 } |
| 1031 #endif // OS_ANDROID | 1034 #endif // OS_ANDROID |
| 1032 min_signal_strength_since_connection_change_ = INT32_MAX; | 1035 min_signal_strength_since_connection_change_ = INT32_MAX; |
| 1033 max_signal_strength_since_connection_change_ = INT32_MIN; | 1036 max_signal_strength_since_connection_change_ = INT32_MIN; |
| 1034 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality(); | 1037 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality(); |
| 1038 http_rtt_ = nqe::internal::InvalidRTT(); | |
| 1039 transport_rtt_ = nqe::internal::InvalidRTT(); | |
| 1040 downstream_throughput_kbps_ = nqe::internal::kInvalidThroughput; | |
| 1035 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 1041 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
| 1036 effective_connection_type_at_last_main_frame_ = | 1042 effective_connection_type_at_last_main_frame_ = |
| 1037 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 1043 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
| 1038 | 1044 |
| 1039 // Update the local state as part of preparation for the new connection. | 1045 // Update the local state as part of preparation for the new connection. |
| 1040 current_network_id_ = GetCurrentNetworkID(); | 1046 current_network_id_ = GetCurrentNetworkID(); |
| 1041 RecordNetworkIDAvailability(); | 1047 RecordNetworkIDAvailability(); |
| 1042 | 1048 |
| 1043 MaybeQueryExternalEstimateProvider(); | 1049 MaybeQueryExternalEstimateProvider(); |
| 1044 | 1050 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1205 | 1211 |
| 1206 void NetworkQualityEstimator::ComputeEffectiveConnectionType() { | 1212 void NetworkQualityEstimator::ComputeEffectiveConnectionType() { |
| 1207 DCHECK(thread_checker_.CalledOnValidThread()); | 1213 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1208 | 1214 |
| 1209 const base::TimeTicks now = tick_clock_->NowTicks(); | 1215 const base::TimeTicks now = tick_clock_->NowTicks(); |
| 1210 | 1216 |
| 1211 const EffectiveConnectionType past_type = effective_connection_type_; | 1217 const EffectiveConnectionType past_type = effective_connection_type_; |
| 1212 last_effective_connection_type_computation_ = now; | 1218 last_effective_connection_type_computation_ = now; |
| 1213 | 1219 |
| 1214 effective_connection_type_ = | 1220 effective_connection_type_ = |
| 1215 GetRecentEffectiveConnectionType(base::TimeTicks()); | 1221 GetRecentEffectiveConnectionTypeAndNetworkQuality( |
| 1222 base::TimeTicks(), &http_rtt_, &transport_rtt_, | |
| 1223 &downstream_throughput_kbps_); | |
| 1216 | 1224 |
| 1217 if (past_type != effective_connection_type_) | 1225 if (past_type != effective_connection_type_) |
|
RyanSturm
2016/10/11 01:46:26
What about comparing old RTT and kbps? Should ther
tbansal1
2016/10/11 17:46:12
Done.
| |
| 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::AddNetworkQualityObserver( | |
| 1416 NetworkQualityObserver* observer) { | |
| 1417 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1418 network_quality_observer_list_.AddObserver(observer); | |
| 1419 } | |
| 1420 | |
| 1421 void NetworkQualityEstimator::RemoveNetworkQualityObserver( | |
| 1422 NetworkQualityObserver* observer) { | |
| 1423 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1424 network_quality_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 Loading... | |
| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_EACH_OBSERVER( |
| 1711 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, | 1754 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, |
| 1712 OnEffectiveConnectionTypeChanged(effective_connection_type_)); | 1755 OnEffectiveConnectionTypeChanged(effective_connection_type_)); |
| 1756 FOR_EACH_OBSERVER(NetworkQualityObserver, network_quality_observer_list_, | |
| 1757 OnNetworkQualityChanged(http_rtt_, transport_rtt_, | |
| 1758 downstream_throughput_kbps_)); | |
| 1713 | 1759 |
| 1714 // Add the estimates of the current network to the cache store. | 1760 // Add the estimates of the current network to the cache store. |
| 1715 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { | 1761 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { |
| 1716 network_quality_store_->Add( | 1762 network_quality_store_->Add( |
| 1717 current_network_id_, | 1763 current_network_id_, |
| 1718 nqe::internal::CachedNetworkQuality( | 1764 nqe::internal::CachedNetworkQuality( |
| 1719 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, | 1765 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, |
| 1720 effective_connection_type_)); | 1766 effective_connection_type_)); |
| 1721 } | 1767 } |
| 1722 } | 1768 } |
| 1723 | 1769 |
| 1724 void NetworkQualityEstimator::AddNetworkQualitiesCacheObserver( | 1770 void NetworkQualityEstimator::AddNetworkQualitiesCacheObserver( |
| 1725 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* | 1771 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* |
| 1726 observer) { | 1772 observer) { |
| 1727 DCHECK(thread_checker_.CalledOnValidThread()); | 1773 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1728 network_quality_store_->AddNetworkQualitiesCacheObserver(observer); | 1774 network_quality_store_->AddNetworkQualitiesCacheObserver(observer); |
| 1729 } | 1775 } |
| 1730 | 1776 |
| 1731 void NetworkQualityEstimator::RemoveNetworkQualitiesCacheObserver( | 1777 void NetworkQualityEstimator::RemoveNetworkQualitiesCacheObserver( |
| 1732 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* | 1778 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* |
| 1733 observer) { | 1779 observer) { |
| 1734 DCHECK(thread_checker_.CalledOnValidThread()); | 1780 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1735 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer); | 1781 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer); |
| 1736 } | 1782 } |
| 1737 | 1783 |
| 1738 } // namespace net | 1784 } // namespace net |
| OLD | NEW |