| 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 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 | 1469 |
| 1470 RecordExternalEstimateProviderMetrics( | 1470 RecordExternalEstimateProviderMetrics( |
| 1471 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); | 1471 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); |
| 1472 | 1472 |
| 1473 external_estimate_provider_quality_ = nqe::internal::NetworkQuality(); | 1473 external_estimate_provider_quality_ = nqe::internal::NetworkQuality(); |
| 1474 | 1474 |
| 1475 if (rtt > base::TimeDelta()) { | 1475 if (rtt > base::TimeDelta()) { |
| 1476 RecordExternalEstimateProviderMetrics( | 1476 RecordExternalEstimateProviderMetrics( |
| 1477 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); | 1477 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); |
| 1478 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); | 1478 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); |
| 1479 rtt_observations_.AddObservation(RttObservation( | 1479 RttObservation rtt_observation( |
| 1480 rtt, tick_clock_->NowTicks(), signal_strength_dbm_, | 1480 rtt, tick_clock_->NowTicks(), signal_strength_dbm_, |
| 1481 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE)); | 1481 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); |
| 1482 rtt_observations_.AddObservation(rtt_observation); |
| 1482 external_estimate_provider_quality_.set_http_rtt(rtt); | 1483 external_estimate_provider_quality_.set_http_rtt(rtt); |
| 1484 NotifyObserversOfRTT(rtt_observation); |
| 1483 } | 1485 } |
| 1484 | 1486 |
| 1485 if (downstream_throughput_kbps > 0) { | 1487 if (downstream_throughput_kbps > 0) { |
| 1486 RecordExternalEstimateProviderMetrics( | 1488 RecordExternalEstimateProviderMetrics( |
| 1487 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); | 1489 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); |
| 1488 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", | 1490 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", |
| 1489 downstream_throughput_kbps); | 1491 downstream_throughput_kbps); |
| 1492 ThroughputObservation throughput_observation( |
| 1493 downstream_throughput_kbps, tick_clock_->NowTicks(), |
| 1494 signal_strength_dbm_, |
| 1495 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); |
| 1490 downstream_throughput_kbps_observations_.AddObservation( | 1496 downstream_throughput_kbps_observations_.AddObservation( |
| 1491 ThroughputObservation( | 1497 throughput_observation); |
| 1492 downstream_throughput_kbps, tick_clock_->NowTicks(), | |
| 1493 signal_strength_dbm_, | |
| 1494 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE)); | |
| 1495 external_estimate_provider_quality_.set_downstream_throughput_kbps( | 1498 external_estimate_provider_quality_.set_downstream_throughput_kbps( |
| 1496 downstream_throughput_kbps); | 1499 downstream_throughput_kbps); |
| 1500 NotifyObserversOfThroughput(throughput_observation); |
| 1497 } | 1501 } |
| 1498 } | 1502 } |
| 1499 | 1503 |
| 1500 void NetworkQualityEstimator::SetTickClockForTesting( | 1504 void NetworkQualityEstimator::SetTickClockForTesting( |
| 1501 std::unique_ptr<base::TickClock> tick_clock) { | 1505 std::unique_ptr<base::TickClock> tick_clock) { |
| 1502 DCHECK(thread_checker_.CalledOnValidThread()); | 1506 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1503 tick_clock_ = std::move(tick_clock); | 1507 tick_clock_ = std::move(tick_clock); |
| 1504 } | 1508 } |
| 1505 | 1509 |
| 1506 double NetworkQualityEstimator::RandDouble() const { | 1510 double NetworkQualityEstimator::RandDouble() const { |
| 1507 return base::RandDouble(); | 1511 return base::RandDouble(); |
| 1508 } | 1512 } |
| 1509 | 1513 |
| 1510 void NetworkQualityEstimator::OnUpdatedRTTAvailable( | 1514 void NetworkQualityEstimator::OnUpdatedRTTAvailable( |
| 1511 SocketPerformanceWatcherFactory::Protocol protocol, | 1515 SocketPerformanceWatcherFactory::Protocol protocol, |
| 1512 const base::TimeDelta& rtt) { | 1516 const base::TimeDelta& rtt) { |
| 1513 DCHECK(thread_checker_.CalledOnValidThread()); | 1517 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1514 DCHECK_NE(nqe::internal::InvalidRTT(), rtt); | 1518 DCHECK_NE(nqe::internal::InvalidRTT(), rtt); |
| 1515 | 1519 |
| 1516 RttObservation observation(rtt, tick_clock_->NowTicks(), signal_strength_dbm_, | 1520 RttObservation observation(rtt, tick_clock_->NowTicks(), signal_strength_dbm_, |
| 1517 ProtocolSourceToObservationSource(protocol)); | 1521 ProtocolSourceToObservationSource(protocol)); |
| 1518 NotifyObserversOfRTT(observation); | 1522 NotifyObserversOfRTT(observation); |
| 1519 rtt_observations_.AddObservation(observation); | 1523 rtt_observations_.AddObservation(observation); |
| 1520 } | 1524 } |
| 1521 | 1525 |
| 1522 void NetworkQualityEstimator::NotifyObserversOfRTT( | 1526 void NetworkQualityEstimator::NotifyObserversOfRTT( |
| 1523 const RttObservation& observation) { | 1527 const RttObservation& observation) { |
| 1524 DCHECK(thread_checker_.CalledOnValidThread()); | 1528 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1525 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value); | 1529 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value); |
| 1530 DCHECK_GT(NETWORK_QUALITY_OBSERVATION_SOURCE_MAX, observation.source); |
| 1531 |
| 1532 UMA_HISTOGRAM_ENUMERATION("NQE.RTT.ObservationSource", observation.source, |
| 1533 NETWORK_QUALITY_OBSERVATION_SOURCE_MAX); |
| 1526 | 1534 |
| 1527 // Maybe recompute the effective connection type since a new RTT observation | 1535 // Maybe recompute the effective connection type since a new RTT observation |
| 1528 // is available. | 1536 // is available. |
| 1529 MaybeComputeEffectiveConnectionType(); | 1537 MaybeComputeEffectiveConnectionType(); |
| 1530 for (auto& observer : rtt_observer_list_) { | 1538 for (auto& observer : rtt_observer_list_) { |
| 1531 observer.OnRTTObservation(observation.value.InMilliseconds(), | 1539 observer.OnRTTObservation(observation.value.InMilliseconds(), |
| 1532 observation.timestamp, observation.source); | 1540 observation.timestamp, observation.source); |
| 1533 } | 1541 } |
| 1534 } | 1542 } |
| 1535 | 1543 |
| 1536 void NetworkQualityEstimator::NotifyObserversOfThroughput( | 1544 void NetworkQualityEstimator::NotifyObserversOfThroughput( |
| 1537 const ThroughputObservation& observation) { | 1545 const ThroughputObservation& observation) { |
| 1538 DCHECK(thread_checker_.CalledOnValidThread()); | 1546 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1539 DCHECK_NE(nqe::internal::kInvalidThroughput, observation.value); | 1547 DCHECK_NE(nqe::internal::kInvalidThroughput, observation.value); |
| 1548 DCHECK_GT(NETWORK_QUALITY_OBSERVATION_SOURCE_MAX, observation.source); |
| 1549 |
| 1550 UMA_HISTOGRAM_ENUMERATION("NQE.Kbps.ObservationSource", observation.source, |
| 1551 NETWORK_QUALITY_OBSERVATION_SOURCE_MAX); |
| 1540 | 1552 |
| 1541 // Maybe recompute the effective connection type since a new throughput | 1553 // Maybe recompute the effective connection type since a new throughput |
| 1542 // observation is available. | 1554 // observation is available. |
| 1543 MaybeComputeEffectiveConnectionType(); | 1555 MaybeComputeEffectiveConnectionType(); |
| 1544 for (auto& observer : throughput_observer_list_) { | 1556 for (auto& observer : throughput_observer_list_) { |
| 1545 observer.OnThroughputObservation(observation.value, observation.timestamp, | 1557 observer.OnThroughputObservation(observation.value, observation.timestamp, |
| 1546 observation.source); | 1558 observation.source); |
| 1547 } | 1559 } |
| 1548 } | 1560 } |
| 1549 | 1561 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); | 1747 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
| 1736 downstream_throughput_kbps_observations_.AddObservation( | 1748 downstream_throughput_kbps_observations_.AddObservation( |
| 1737 throughput_observation); | 1749 throughput_observation); |
| 1738 NotifyObserversOfThroughput(throughput_observation); | 1750 NotifyObserversOfThroughput(throughput_observation); |
| 1739 } | 1751 } |
| 1740 | 1752 |
| 1741 ComputeEffectiveConnectionType(); | 1753 ComputeEffectiveConnectionType(); |
| 1742 } | 1754 } |
| 1743 | 1755 |
| 1744 } // namespace net | 1756 } // namespace net |
| OLD | NEW |