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

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

Issue 2406763003: Add Network Quality observer to NQE (Closed)
Patch Set: typo fix 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
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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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_);
1224 NotifyObserversOfRTTOrThroughputComputed();
1216 1225
1217 if (past_type != effective_connection_type_) 1226 if (past_type != effective_connection_type_)
1218 NotifyObserversOfEffectiveConnectionTypeChanged(); 1227 NotifyObserversOfEffectiveConnectionTypeChanged();
1219 1228
1220 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size(); 1229 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size();
1221 throughput_observations_size_at_last_ect_computation_ = 1230 throughput_observations_size_at_last_ect_computation_ =
1222 downstream_throughput_kbps_observations_.Size(); 1231 downstream_throughput_kbps_observations_.Size();
1223 } 1232 }
1224 1233
1225 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType() 1234 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType()
1226 const { 1235 const {
1227 DCHECK(thread_checker_.CalledOnValidThread()); 1236 DCHECK(thread_checker_.CalledOnValidThread());
1228 return effective_connection_type_; 1237 return effective_connection_type_;
1229 } 1238 }
1230 1239
1231 EffectiveConnectionType 1240 EffectiveConnectionType
1232 NetworkQualityEstimator::GetRecentEffectiveConnectionType( 1241 NetworkQualityEstimator::GetRecentEffectiveConnectionType(
1233 const base::TimeTicks& start_time) const { 1242 const base::TimeTicks& start_time) const {
1234 DCHECK(thread_checker_.CalledOnValidThread()); 1243 DCHECK(thread_checker_.CalledOnValidThread());
1235 1244
1245 base::TimeDelta http_rtt;
1246 base::TimeDelta transport_rtt;
1247 int32_t downstream_throughput_kbps;
1248
1249 return GetRecentEffectiveConnectionTypeAndNetworkQuality(
1250 start_time, &http_rtt, &transport_rtt, &downstream_throughput_kbps);
1251 }
1252
1253 EffectiveConnectionType
1254 NetworkQualityEstimator::GetRecentEffectiveConnectionTypeAndNetworkQuality(
1255 const base::TimeTicks& start_time,
1256 base::TimeDelta* http_rtt,
1257 base::TimeDelta* transport_rtt,
1258 int32_t* downstream_throughput_kbps) const {
1259 DCHECK(thread_checker_.CalledOnValidThread());
1260
1236 if (effective_connection_type_algorithm_ == 1261 if (effective_connection_type_algorithm_ ==
1237 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) { 1262 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) {
1238 return GetRecentEffectiveConnectionTypeUsingMetrics( 1263 return GetRecentEffectiveConnectionTypeUsingMetrics(
1239 start_time, NetworkQualityEstimator::MetricUsage:: 1264 start_time, NetworkQualityEstimator::MetricUsage::
1240 MUST_BE_USED /* http_rtt_metric */, 1265 MUST_BE_USED /* http_rtt_metric */,
1241 NetworkQualityEstimator::MetricUsage:: 1266 NetworkQualityEstimator::MetricUsage::
1242 DO_NOT_USE /* transport_rtt_metric */, 1267 DO_NOT_USE /* transport_rtt_metric */,
1243 NetworkQualityEstimator::MetricUsage:: 1268 NetworkQualityEstimator::MetricUsage::
1244 MUST_BE_USED /* downstream_throughput_kbps_metric */); 1269 MUST_BE_USED /* downstream_throughput_kbps_metric */,
1270 http_rtt, transport_rtt, downstream_throughput_kbps);
1245 } 1271 }
1246 if (effective_connection_type_algorithm_ == 1272 if (effective_connection_type_algorithm_ ==
1247 EffectiveConnectionTypeAlgorithm:: 1273 EffectiveConnectionTypeAlgorithm::
1248 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) { 1274 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) {
1249 return GetRecentEffectiveConnectionTypeUsingMetrics( 1275 return GetRecentEffectiveConnectionTypeUsingMetrics(
1250 start_time, 1276 start_time,
1251 NetworkQualityEstimator::MetricUsage::DO_NOT_USE /* http_rtt_metric */, 1277 NetworkQualityEstimator::MetricUsage::DO_NOT_USE /* http_rtt_metric */,
1252 NetworkQualityEstimator::MetricUsage:: 1278 NetworkQualityEstimator::MetricUsage::
1253 USE_IF_AVAILABLE /* transport_rtt_metric */, 1279 USE_IF_AVAILABLE /* transport_rtt_metric */,
1254 NetworkQualityEstimator::MetricUsage:: 1280 NetworkQualityEstimator::MetricUsage::
1255 USE_IF_AVAILABLE /* downstream_throughput_kbps_metric */); 1281 USE_IF_AVAILABLE /* downstream_throughput_kbps_metric */,
1282 http_rtt, transport_rtt, downstream_throughput_kbps);
1256 } 1283 }
1257 // Add additional algorithms here. 1284 // Add additional algorithms here.
1258 NOTREACHED(); 1285 NOTREACHED();
1259 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1286 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1260 } 1287 }
1261 1288
1262 bool NetworkQualityEstimator::UseTransportRTT() const { 1289 bool NetworkQualityEstimator::UseTransportRTT() const {
1263 DCHECK(thread_checker_.CalledOnValidThread()); 1290 DCHECK(thread_checker_.CalledOnValidThread());
1264 1291
1265 if (effective_connection_type_algorithm_ == 1292 if (effective_connection_type_algorithm_ ==
1266 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) { 1293 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) {
1267 return false; 1294 return false;
1268 } 1295 }
1269 if (effective_connection_type_algorithm_ == 1296 if (effective_connection_type_algorithm_ ==
1270 EffectiveConnectionTypeAlgorithm:: 1297 EffectiveConnectionTypeAlgorithm::
1271 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) { 1298 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) {
1272 return true; 1299 return true;
1273 } 1300 }
1274 // Add additional algorithms here. 1301 // Add additional algorithms here.
1275 NOTREACHED(); 1302 NOTREACHED();
1276 return false; 1303 return false;
1277 } 1304 }
1278 1305
1279 EffectiveConnectionType 1306 EffectiveConnectionType
1280 NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics( 1307 NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics(
1281 const base::TimeTicks& start_time, 1308 const base::TimeTicks& start_time,
1282 NetworkQualityEstimator::MetricUsage http_rtt_metric, 1309 NetworkQualityEstimator::MetricUsage http_rtt_metric,
1283 NetworkQualityEstimator::MetricUsage transport_rtt_metric, 1310 NetworkQualityEstimator::MetricUsage transport_rtt_metric,
1284 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric) 1311 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric,
1285 const { 1312 base::TimeDelta* http_rtt,
1313 base::TimeDelta* transport_rtt,
1314 int32_t* downstream_throughput_kbps) const {
1286 DCHECK(thread_checker_.CalledOnValidThread()); 1315 DCHECK(thread_checker_.CalledOnValidThread());
1287 1316
1317 *http_rtt = nqe::internal::InvalidRTT();
1318 *transport_rtt = nqe::internal::InvalidRTT();
1319 *downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
1320
1288 if (forced_effective_connection_type_set_) 1321 if (forced_effective_connection_type_set_)
1289 return forced_effective_connection_type_; 1322 return forced_effective_connection_type_;
1290 1323
1291 // If the device is currently offline, then return 1324 // If the device is currently offline, then return
1292 // EFFECTIVE_CONNECTION_TYPE_OFFLINE. 1325 // EFFECTIVE_CONNECTION_TYPE_OFFLINE.
1293 if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_NONE) 1326 if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_NONE)
1294 return EFFECTIVE_CONNECTION_TYPE_OFFLINE; 1327 return EFFECTIVE_CONNECTION_TYPE_OFFLINE;
1295 1328
1296 base::TimeDelta http_rtt = nqe::internal::InvalidRTT(); 1329 if (!GetRecentHttpRTT(start_time, http_rtt))
1297 if (http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1330 *http_rtt = nqe::internal::InvalidRTT();
1298 !GetRecentHttpRTT(start_time, &http_rtt)) {
1299 http_rtt = nqe::internal::InvalidRTT();
1300 }
1301 1331
1302 base::TimeDelta transport_rtt = nqe::internal::InvalidRTT(); 1332 if (!GetRecentTransportRTT(start_time, transport_rtt))
1303 if (transport_rtt_metric != 1333 *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 1334
1309 int32_t kbps = nqe::internal::kInvalidThroughput; 1335 if (!GetRecentDownlinkThroughputKbps(start_time, downstream_throughput_kbps))
1310 if (downstream_throughput_kbps_metric != 1336 *downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
1311 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1312 !GetRecentDownlinkThroughputKbps(start_time, &kbps)) {
1313 kbps = nqe::internal::kInvalidThroughput;
1314 }
1315 1337
1316 if (http_rtt == nqe::internal::InvalidRTT() && 1338 if (*http_rtt == nqe::internal::InvalidRTT() &&
1317 http_rtt_metric == NetworkQualityEstimator::MetricUsage::MUST_BE_USED) { 1339 http_rtt_metric == NetworkQualityEstimator::MetricUsage::MUST_BE_USED) {
1318 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1340 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1319 } 1341 }
1320 1342
1321 if (transport_rtt == nqe::internal::InvalidRTT() && 1343 if (*transport_rtt == nqe::internal::InvalidRTT() &&
1322 transport_rtt_metric == 1344 transport_rtt_metric ==
1323 NetworkQualityEstimator::MetricUsage::MUST_BE_USED) { 1345 NetworkQualityEstimator::MetricUsage::MUST_BE_USED) {
1324 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1346 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1325 } 1347 }
1326 1348
1327 if (kbps == nqe::internal::kInvalidThroughput && 1349 if (*downstream_throughput_kbps == nqe::internal::kInvalidThroughput &&
1328 downstream_throughput_kbps_metric == 1350 downstream_throughput_kbps_metric ==
1329 NetworkQualityEstimator::MetricUsage::MUST_BE_USED) { 1351 NetworkQualityEstimator::MetricUsage::MUST_BE_USED) {
1330 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1352 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1331 } 1353 }
1332 1354
1333 if (http_rtt == nqe::internal::InvalidRTT() && 1355 if (*http_rtt == nqe::internal::InvalidRTT() &&
1334 transport_rtt == nqe::internal::InvalidRTT() && 1356 *transport_rtt == nqe::internal::InvalidRTT() &&
1335 kbps == nqe::internal::kInvalidThroughput) { 1357 *downstream_throughput_kbps == nqe::internal::kInvalidThroughput) {
1336 // None of the metrics are available. 1358 // None of the metrics are available.
1337 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 1359 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
1338 } 1360 }
1339 1361
1340 // Search from the slowest connection type to the fastest to find the 1362 // Search from the slowest connection type to the fastest to find the
1341 // EffectiveConnectionType that best matches the current connection's 1363 // EffectiveConnectionType that best matches the current connection's
1342 // performance. The match is done by comparing RTT and throughput. 1364 // performance. The match is done by comparing RTT and throughput.
1343 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { 1365 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
1344 EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i); 1366 EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i);
1345 if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) 1367 if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
1346 continue; 1368 continue;
1347 1369
1348 const bool estimated_http_rtt_is_higher_than_threshold = 1370 const bool estimated_http_rtt_is_higher_than_threshold =
1349 http_rtt != nqe::internal::InvalidRTT() && 1371 http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1372 *http_rtt != nqe::internal::InvalidRTT() &&
1350 connection_thresholds_[i].http_rtt() != nqe::internal::InvalidRTT() && 1373 connection_thresholds_[i].http_rtt() != nqe::internal::InvalidRTT() &&
1351 http_rtt >= connection_thresholds_[i].http_rtt(); 1374 *http_rtt >= connection_thresholds_[i].http_rtt();
1352 1375
1353 const bool estimated_transport_rtt_is_higher_than_threshold = 1376 const bool estimated_transport_rtt_is_higher_than_threshold =
1354 transport_rtt != nqe::internal::InvalidRTT() && 1377 transport_rtt_metric !=
1378 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1379 *transport_rtt != nqe::internal::InvalidRTT() &&
1355 connection_thresholds_[i].transport_rtt() != 1380 connection_thresholds_[i].transport_rtt() !=
1356 nqe::internal::InvalidRTT() && 1381 nqe::internal::InvalidRTT() &&
1357 transport_rtt >= connection_thresholds_[i].transport_rtt(); 1382 *transport_rtt >= connection_thresholds_[i].transport_rtt();
1358 1383
1359 const bool estimated_throughput_is_lower_than_threshold = 1384 const bool estimated_throughput_is_lower_than_threshold =
1360 kbps != nqe::internal::kInvalidThroughput && 1385 downstream_throughput_kbps_metric !=
1386 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1387 *downstream_throughput_kbps != nqe::internal::kInvalidThroughput &&
1361 connection_thresholds_[i].downstream_throughput_kbps() != 1388 connection_thresholds_[i].downstream_throughput_kbps() !=
1362 nqe::internal::kInvalidThroughput && 1389 nqe::internal::kInvalidThroughput &&
1363 kbps <= connection_thresholds_[i].downstream_throughput_kbps(); 1390 *downstream_throughput_kbps <=
1391 connection_thresholds_[i].downstream_throughput_kbps();
1364 1392
1365 if (estimated_http_rtt_is_higher_than_threshold || 1393 if (estimated_http_rtt_is_higher_than_threshold ||
1366 estimated_transport_rtt_is_higher_than_threshold || 1394 estimated_transport_rtt_is_higher_than_threshold ||
1367 estimated_throughput_is_lower_than_threshold) { 1395 estimated_throughput_is_lower_than_threshold) {
1368 return type; 1396 return type;
1369 } 1397 }
1370 } 1398 }
1371 // Return the fastest connection type. 1399 // Return the fastest connection type.
1372 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST - 1400 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST -
1373 1); 1401 1);
1374 } 1402 }
1375 1403
1376 void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver( 1404 void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver(
1377 EffectiveConnectionTypeObserver* observer) { 1405 EffectiveConnectionTypeObserver* observer) {
1378 DCHECK(thread_checker_.CalledOnValidThread()); 1406 DCHECK(thread_checker_.CalledOnValidThread());
1379 effective_connection_type_observer_list_.AddObserver(observer); 1407 effective_connection_type_observer_list_.AddObserver(observer);
1380 } 1408 }
1381 1409
1382 void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver( 1410 void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver(
1383 EffectiveConnectionTypeObserver* observer) { 1411 EffectiveConnectionTypeObserver* observer) {
1384 DCHECK(thread_checker_.CalledOnValidThread()); 1412 DCHECK(thread_checker_.CalledOnValidThread());
1385 effective_connection_type_observer_list_.RemoveObserver(observer); 1413 effective_connection_type_observer_list_.RemoveObserver(observer);
1386 } 1414 }
1387 1415
1416 void NetworkQualityEstimator::AddRTTAndThroughputEstimatesObserver(
1417 RTTAndThroughputEstimatesObserver* observer) {
1418 DCHECK(thread_checker_.CalledOnValidThread());
1419 rtt_and_throughput_estimates_observer_list_.AddObserver(observer);
1420 }
1421
1422 void NetworkQualityEstimator::RemoveRTTAndThroughputEstimatesObserver(
1423 RTTAndThroughputEstimatesObserver* observer) {
1424 DCHECK(thread_checker_.CalledOnValidThread());
1425 rtt_and_throughput_estimates_observer_list_.RemoveObserver(observer);
1426 }
1427
1388 bool NetworkQualityEstimator::GetHttpRTT(base::TimeDelta* rtt) const { 1428 bool NetworkQualityEstimator::GetHttpRTT(base::TimeDelta* rtt) const {
1389 DCHECK(thread_checker_.CalledOnValidThread()); 1429 DCHECK(thread_checker_.CalledOnValidThread());
1390 return GetRecentHttpRTT(base::TimeTicks(), rtt); 1430 return GetRecentHttpRTT(base::TimeTicks(), rtt);
1391 } 1431 }
1392 1432
1393 bool NetworkQualityEstimator::GetTransportRTT(base::TimeDelta* rtt) const { 1433 bool NetworkQualityEstimator::GetTransportRTT(base::TimeDelta* rtt) const {
1394 DCHECK(thread_checker_.CalledOnValidThread()); 1434 DCHECK(thread_checker_.CalledOnValidThread());
1395 return GetRecentTransportRTT(base::TimeTicks(), rtt); 1435 return GetRecentTransportRTT(base::TimeTicks(), rtt);
1396 } 1436 }
1397 1437
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 cached_estimate_available); 1570 cached_estimate_available);
1531 1571
1532 if (!cached_estimate_available) 1572 if (!cached_estimate_available)
1533 return false; 1573 return false;
1534 1574
1535 const base::TimeTicks now = tick_clock_->NowTicks(); 1575 const base::TimeTicks now = tick_clock_->NowTicks();
1536 1576
1537 if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1577 if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1538 // Read the effective connection type from the cached estimate. 1578 // Read the effective connection type from the cached estimate.
1539 last_effective_connection_type_computation_ = now; 1579 last_effective_connection_type_computation_ = now;
1580 http_rtt_ = cached_network_quality.network_quality().http_rtt();
1581 transport_rtt_ = cached_network_quality.network_quality().transport_rtt();
1582 downstream_throughput_kbps_ =
1583 cached_network_quality.network_quality().downstream_throughput_kbps();
1540 effective_connection_type_ = 1584 effective_connection_type_ =
1541 cached_network_quality.effective_connection_type(); 1585 cached_network_quality.effective_connection_type();
1542 1586
1543 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) 1587 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
1544 NotifyObserversOfEffectiveConnectionTypeChanged(); 1588 NotifyObserversOfEffectiveConnectionTypeChanged();
1545 } 1589 }
1546 1590
1547 if (cached_network_quality.network_quality().downstream_throughput_kbps() != 1591 if (cached_network_quality.network_quality().downstream_throughput_kbps() !=
1548 nqe::internal::kInvalidThroughput) { 1592 nqe::internal::kInvalidThroughput) {
1549 ThroughputObservation througphput_observation( 1593 ThroughputObservation througphput_observation(
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 // Add the estimates of the current network to the cache store. 1758 // Add the estimates of the current network to the cache store.
1715 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1759 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1716 network_quality_store_->Add( 1760 network_quality_store_->Add(
1717 current_network_id_, 1761 current_network_id_,
1718 nqe::internal::CachedNetworkQuality( 1762 nqe::internal::CachedNetworkQuality(
1719 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, 1763 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_,
1720 effective_connection_type_)); 1764 effective_connection_type_));
1721 } 1765 }
1722 } 1766 }
1723 1767
1768 void NetworkQualityEstimator::NotifyObserversOfRTTOrThroughputComputed() {
1769 DCHECK(thread_checker_.CalledOnValidThread());
1770
1771 // TODO(tbansal): Add hysteresis in the notification.
1772 FOR_EACH_OBSERVER(
1773 RTTAndThroughputEstimatesObserver,
1774 rtt_and_throughput_estimates_observer_list_,
1775 OnRTTOrThroughputEstimatesComputed(http_rtt_, transport_rtt_,
1776 downstream_throughput_kbps_));
1777 }
1778
1724 void NetworkQualityEstimator::AddNetworkQualitiesCacheObserver( 1779 void NetworkQualityEstimator::AddNetworkQualitiesCacheObserver(
1725 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* 1780 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver*
1726 observer) { 1781 observer) {
1727 DCHECK(thread_checker_.CalledOnValidThread()); 1782 DCHECK(thread_checker_.CalledOnValidThread());
1728 network_quality_store_->AddNetworkQualitiesCacheObserver(observer); 1783 network_quality_store_->AddNetworkQualitiesCacheObserver(observer);
1729 } 1784 }
1730 1785
1731 void NetworkQualityEstimator::RemoveNetworkQualitiesCacheObserver( 1786 void NetworkQualityEstimator::RemoveNetworkQualitiesCacheObserver(
1732 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* 1787 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver*
1733 observer) { 1788 observer) {
1734 DCHECK(thread_checker_.CalledOnValidThread()); 1789 DCHECK(thread_checker_.CalledOnValidThread());
1735 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer); 1790 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer);
1736 } 1791 }
1737 1792
1738 } // namespace net 1793 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698