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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 // type based on field trial params. Returns an empty string if a valid | 194 // type based on field trial params. Returns an empty string if a valid |
| 195 // algorithm paramter is not present in the field trial params. | 195 // algorithm paramter is not present in the field trial params. |
| 196 std::string GetEffectiveConnectionTypeAlgorithm( | 196 std::string GetEffectiveConnectionTypeAlgorithm( |
| 197 const std::map<std::string, std::string>& variation_params) { | 197 const std::map<std::string, std::string>& variation_params) { |
| 198 const auto it = variation_params.find("effective_connection_type_algorithm"); | 198 const auto it = variation_params.find("effective_connection_type_algorithm"); |
| 199 if (it == variation_params.end()) | 199 if (it == variation_params.end()) |
| 200 return std::string(); | 200 return std::string(); |
| 201 return it->second; | 201 return it->second; |
| 202 } | 202 } |
| 203 | 203 |
| 204 net::NetworkQualityObservationSource ProtocolSourceToObservationSource( | |
| 205 net::SocketPerformanceWatcherFactory::Protocol protocol) { | |
| 206 switch (protocol) { | |
| 207 case net::SocketPerformanceWatcherFactory::PROTOCOL_TCP: | |
| 208 return net::NETWORK_QUALITY_OBSERVATION_SOURCE_TCP; | |
| 209 case net::SocketPerformanceWatcherFactory::PROTOCOL_QUIC: | |
| 210 return net::NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC; | |
| 211 } | |
| 212 NOTREACHED(); | |
| 213 return net::NETWORK_QUALITY_OBSERVATION_SOURCE_TCP; | |
| 214 } | |
| 215 | |
| 216 // Returns true if the scheme of the |request| is either HTTP or HTTPS. | 204 // Returns true if the scheme of the |request| is either HTTP or HTTPS. |
| 217 bool RequestSchemeIsHTTPOrHTTPS(const net::URLRequest& request) { | 205 bool RequestSchemeIsHTTPOrHTTPS(const net::URLRequest& request) { |
| 218 return request.url().is_valid() && request.url().SchemeIsHTTPOrHTTPS(); | 206 return request.url().is_valid() && request.url().SchemeIsHTTPOrHTTPS(); |
| 219 } | 207 } |
| 220 | 208 |
| 221 // Returns the suffix of the histogram that should be used for recording the | 209 // Returns the suffix of the histogram that should be used for recording the |
| 222 // accuracy when the observed RTT is |observed_rtt|. The width of the intervals | 210 // accuracy when the observed RTT is |observed_rtt|. The width of the intervals |
| 223 // are in exponentially increasing order. | 211 // are in exponentially increasing order. |
| 224 const char* GetHistogramSuffixObservedRTT(const base::TimeDelta& observed_rtt) { | 212 const char* GetHistogramSuffixObservedRTT(const base::TimeDelta& observed_rtt) { |
| 225 const float rtt_milliseconds = observed_rtt.InMillisecondsF(); | 213 const float rtt_milliseconds = observed_rtt.InMillisecondsF(); |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 } | 593 } |
| 606 | 594 |
| 607 void NetworkQualityEstimator::AddDefaultEstimates() { | 595 void NetworkQualityEstimator::AddDefaultEstimates() { |
| 608 DCHECK(thread_checker_.CalledOnValidThread()); | 596 DCHECK(thread_checker_.CalledOnValidThread()); |
| 609 | 597 |
| 610 if (default_observations_[current_network_id_.type].http_rtt() != | 598 if (default_observations_[current_network_id_.type].http_rtt() != |
| 611 nqe::internal::InvalidRTT()) { | 599 nqe::internal::InvalidRTT()) { |
| 612 RttObservation rtt_observation( | 600 RttObservation rtt_observation( |
| 613 default_observations_[current_network_id_.type].http_rtt(), | 601 default_observations_[current_network_id_.type].http_rtt(), |
| 614 tick_clock_->NowTicks(), | 602 tick_clock_->NowTicks(), |
| 615 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_FROM_PLATFORM); | 603 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); |
| 616 rtt_observations_.AddObservation(rtt_observation); | 604 rtt_observations_.AddObservation(rtt_observation); |
| 617 NotifyObserversOfRTT(rtt_observation); | 605 NotifyObserversOfRTT(rtt_observation); |
| 618 } | 606 } |
| 619 | 607 |
| 620 if (default_observations_[current_network_id_.type] | 608 if (default_observations_[current_network_id_.type] |
| 621 .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) { | 609 .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) { |
| 622 ThroughputObservation throughput_observation( | 610 ThroughputObservation throughput_observation( |
| 623 default_observations_[current_network_id_.type] | 611 default_observations_[current_network_id_.type] |
| 624 .downstream_throughput_kbps(), | 612 .downstream_throughput_kbps(), |
| 625 tick_clock_->NowTicks(), | 613 tick_clock_->NowTicks(), |
| 626 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_FROM_PLATFORM); | 614 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); |
| 627 downstream_throughput_kbps_observations_.AddObservation( | 615 downstream_throughput_kbps_observations_.AddObservation( |
| 628 throughput_observation); | 616 throughput_observation); |
| 629 NotifyObserversOfThroughput(throughput_observation); | 617 NotifyObserversOfThroughput(throughput_observation); |
| 630 } | 618 } |
| 631 } | 619 } |
| 632 | 620 |
| 633 NetworkQualityEstimator::~NetworkQualityEstimator() { | 621 NetworkQualityEstimator::~NetworkQualityEstimator() { |
| 634 DCHECK(thread_checker_.CalledOnValidThread()); | 622 DCHECK(thread_checker_.CalledOnValidThread()); |
| 635 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 623 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 636 } | 624 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 base::TimeDelta observed_http_rtt = | 710 base::TimeDelta observed_http_rtt = |
| 723 load_timing_info.receive_headers_end - load_timing_info.send_start; | 711 load_timing_info.receive_headers_end - load_timing_info.send_start; |
| 724 DCHECK_GE(observed_http_rtt, base::TimeDelta()); | 712 DCHECK_GE(observed_http_rtt, base::TimeDelta()); |
| 725 if (observed_http_rtt < peak_network_quality_.http_rtt() || | 713 if (observed_http_rtt < peak_network_quality_.http_rtt() || |
| 726 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) { | 714 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) { |
| 727 peak_network_quality_ = nqe::internal::NetworkQuality( | 715 peak_network_quality_ = nqe::internal::NetworkQuality( |
| 728 observed_http_rtt, peak_network_quality_.transport_rtt(), | 716 observed_http_rtt, peak_network_quality_.transport_rtt(), |
| 729 peak_network_quality_.downstream_throughput_kbps()); | 717 peak_network_quality_.downstream_throughput_kbps()); |
| 730 } | 718 } |
| 731 | 719 |
| 732 RttObservation http_rtt_observation( | 720 RttObservation http_rtt_observation(observed_http_rtt, now, |
| 733 observed_http_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); | 721 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); |
| 734 rtt_observations_.AddObservation(http_rtt_observation); | 722 rtt_observations_.AddObservation(http_rtt_observation); |
| 735 NotifyObserversOfRTT(http_rtt_observation); | 723 NotifyObserversOfRTT(http_rtt_observation); |
| 736 } | 724 } |
| 737 | 725 |
| 738 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame( | 726 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame( |
| 739 base::TimeDelta measuring_duration) const { | 727 base::TimeDelta measuring_duration) const { |
| 740 DCHECK(thread_checker_.CalledOnValidThread()); | 728 DCHECK(thread_checker_.CalledOnValidThread()); |
| 741 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000); | 729 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000); |
| 742 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration)); | 730 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration)); |
| 743 | 731 |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1121 if (GetHttpRTT(&rtt)) { | 1109 if (GetHttpRTT(&rtt)) { |
| 1122 // Add the 50th percentile value. | 1110 // Add the 50th percentile value. |
| 1123 base::HistogramBase* rtt_percentile = | 1111 base::HistogramBase* rtt_percentile = |
| 1124 GetHistogram("RTT.Percentile50.", current_network_id_.type, 10 * 1000); | 1112 GetHistogram("RTT.Percentile50.", current_network_id_.type, 10 * 1000); |
| 1125 rtt_percentile->Add(rtt.InMilliseconds()); | 1113 rtt_percentile->Add(rtt.InMilliseconds()); |
| 1126 | 1114 |
| 1127 // Add the remaining percentile values. | 1115 // Add the remaining percentile values. |
| 1128 static const int kPercentiles[] = {0, 10, 90, 100}; | 1116 static const int kPercentiles[] = {0, 10, 90, 100}; |
| 1129 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 1117 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
| 1130 disallowed_observation_sources.push_back( | 1118 disallowed_observation_sources.push_back( |
| 1131 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); | 1119 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT); |
|
bengr
2016/11/04 16:38:13
I don't understand why this is necessary. Won't so
tbansal1
2016/11/04 20:11:20
My plan is to cache the transport RTT and HTTP RTT
| |
| 1132 disallowed_observation_sources.push_back( | |
| 1133 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); | |
| 1134 for (size_t i = 0; i < arraysize(kPercentiles); ++i) { | 1120 for (size_t i = 0; i < arraysize(kPercentiles); ++i) { |
| 1135 rtt = GetRTTEstimateInternal(disallowed_observation_sources, | 1121 rtt = GetRTTEstimateInternal(disallowed_observation_sources, |
| 1136 base::TimeTicks(), kPercentiles[i]); | 1122 base::TimeTicks(), kPercentiles[i]); |
| 1137 | 1123 |
| 1138 rtt_percentile = GetHistogram( | 1124 rtt_percentile = GetHistogram( |
| 1139 "RTT.Percentile" + base::IntToString(kPercentiles[i]) + ".", | 1125 "RTT.Percentile" + base::IntToString(kPercentiles[i]) + ".", |
| 1140 current_network_id_.type, 10 * 1000); // 10 seconds | 1126 current_network_id_.type, 10 * 1000); // 10 seconds |
| 1141 rtt_percentile->Add(rtt.InMilliseconds()); | 1127 rtt_percentile->Add(rtt.InMilliseconds()); |
| 1142 } | 1128 } |
| 1143 } | 1129 } |
| 1144 | 1130 |
| 1145 if (GetTransportRTT(&rtt)) { | 1131 if (GetTransportRTT(&rtt)) { |
| 1146 // Add the 50th percentile value. | 1132 // Add the 50th percentile value. |
| 1147 base::HistogramBase* transport_rtt_percentile = GetHistogram( | 1133 base::HistogramBase* transport_rtt_percentile = GetHistogram( |
| 1148 "TransportRTT.Percentile50.", current_network_id_.type, 10 * 1000); | 1134 "TransportRTT.Percentile50.", current_network_id_.type, 10 * 1000); |
| 1149 transport_rtt_percentile->Add(rtt.InMilliseconds()); | 1135 transport_rtt_percentile->Add(rtt.InMilliseconds()); |
| 1150 | 1136 |
| 1151 // Add the remaining percentile values. | 1137 // Add the remaining percentile values. |
| 1152 static const int kPercentiles[] = {0, 10, 90, 100}; | 1138 static const int kPercentiles[] = {0, 10, 90, 100}; |
| 1153 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 1139 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
| 1154 disallowed_observation_sources.push_back( | 1140 disallowed_observation_sources.push_back( |
| 1155 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); | 1141 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); |
| 1156 // Disallow external estimate provider since it provides RTT at HTTP layer. | 1142 // Disallow external estimate provider since it provides RTT at HTTP layer. |
| 1157 disallowed_observation_sources.push_back( | 1143 disallowed_observation_sources.push_back( |
| 1158 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE); | 1144 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); |
| 1159 disallowed_observation_sources.push_back( | 1145 disallowed_observation_sources.push_back( |
| 1160 NETWORK_QUALITY_OBSERVATION_SOURCE_CACHED_ESTIMATE); | 1146 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
| 1161 disallowed_observation_sources.push_back( | 1147 disallowed_observation_sources.push_back( |
| 1162 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_FROM_PLATFORM); | 1148 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); |
| 1163 for (size_t i = 0; i < arraysize(kPercentiles); ++i) { | 1149 for (size_t i = 0; i < arraysize(kPercentiles); ++i) { |
| 1164 rtt = GetRTTEstimateInternal(disallowed_observation_sources, | 1150 rtt = GetRTTEstimateInternal(disallowed_observation_sources, |
| 1165 base::TimeTicks(), kPercentiles[i]); | 1151 base::TimeTicks(), kPercentiles[i]); |
| 1166 | 1152 |
| 1167 transport_rtt_percentile = GetHistogram( | 1153 transport_rtt_percentile = GetHistogram( |
| 1168 "TransportRTT.Percentile" + base::IntToString(kPercentiles[i]) + ".", | 1154 "TransportRTT.Percentile" + base::IntToString(kPercentiles[i]) + ".", |
| 1169 current_network_id_.type, 10 * 1000); // 10 seconds | 1155 current_network_id_.type, 10 * 1000); // 10 seconds |
| 1170 transport_rtt_percentile->Add(rtt.InMilliseconds()); | 1156 transport_rtt_percentile->Add(rtt.InMilliseconds()); |
| 1171 } | 1157 } |
| 1172 } | 1158 } |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1460 DCHECK(thread_checker_.CalledOnValidThread()); | 1446 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1461 return GetRecentDownlinkThroughputKbps(base::TimeTicks(), kbps); | 1447 return GetRecentDownlinkThroughputKbps(base::TimeTicks(), kbps); |
| 1462 } | 1448 } |
| 1463 | 1449 |
| 1464 bool NetworkQualityEstimator::GetRecentHttpRTT( | 1450 bool NetworkQualityEstimator::GetRecentHttpRTT( |
| 1465 const base::TimeTicks& start_time, | 1451 const base::TimeTicks& start_time, |
| 1466 base::TimeDelta* rtt) const { | 1452 base::TimeDelta* rtt) const { |
| 1467 DCHECK(thread_checker_.CalledOnValidThread()); | 1453 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1468 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 1454 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
| 1469 disallowed_observation_sources.push_back( | 1455 disallowed_observation_sources.push_back( |
| 1470 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); | 1456 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT); |
| 1471 disallowed_observation_sources.push_back( | |
| 1472 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); | |
| 1473 *rtt = GetRTTEstimateInternal(disallowed_observation_sources, start_time, 50); | 1457 *rtt = GetRTTEstimateInternal(disallowed_observation_sources, start_time, 50); |
| 1474 return (*rtt != nqe::internal::InvalidRTT()); | 1458 return (*rtt != nqe::internal::InvalidRTT()); |
| 1475 } | 1459 } |
| 1476 | 1460 |
| 1477 bool NetworkQualityEstimator::GetRecentTransportRTT( | 1461 bool NetworkQualityEstimator::GetRecentTransportRTT( |
| 1478 const base::TimeTicks& start_time, | 1462 const base::TimeTicks& start_time, |
| 1479 base::TimeDelta* rtt) const { | 1463 base::TimeDelta* rtt) const { |
| 1480 DCHECK(thread_checker_.CalledOnValidThread()); | 1464 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1481 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 1465 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
| 1482 disallowed_observation_sources.push_back( | 1466 disallowed_observation_sources.push_back( |
| 1483 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); | 1467 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); |
| 1484 // Disallow external estimate provider since it provides RTT at HTTP layer. | 1468 // Disallow external estimate provider since it provides RTT at HTTP layer. |
| 1485 disallowed_observation_sources.push_back( | 1469 disallowed_observation_sources.push_back( |
| 1486 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE); | 1470 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); |
| 1487 disallowed_observation_sources.push_back( | 1471 disallowed_observation_sources.push_back( |
| 1488 NETWORK_QUALITY_OBSERVATION_SOURCE_CACHED_ESTIMATE); | 1472 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
| 1489 disallowed_observation_sources.push_back( | 1473 disallowed_observation_sources.push_back( |
| 1490 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_FROM_PLATFORM); | 1474 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); |
| 1491 | 1475 |
| 1492 *rtt = GetRTTEstimateInternal(disallowed_observation_sources, start_time, 50); | 1476 *rtt = GetRTTEstimateInternal(disallowed_observation_sources, start_time, 50); |
| 1493 return (*rtt != nqe::internal::InvalidRTT()); | 1477 return (*rtt != nqe::internal::InvalidRTT()); |
| 1494 } | 1478 } |
| 1495 | 1479 |
| 1496 bool NetworkQualityEstimator::GetRecentDownlinkThroughputKbps( | 1480 bool NetworkQualityEstimator::GetRecentDownlinkThroughputKbps( |
| 1497 const base::TimeTicks& start_time, | 1481 const base::TimeTicks& start_time, |
| 1498 int32_t* kbps) const { | 1482 int32_t* kbps) const { |
| 1499 DCHECK(thread_checker_.CalledOnValidThread()); | 1483 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1500 *kbps = GetDownlinkThroughputKbpsEstimateInternal(start_time, 50); | 1484 *kbps = GetDownlinkThroughputKbpsEstimateInternal(start_time, 50); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1606 cached_network_quality.effective_connection_type(); | 1590 cached_network_quality.effective_connection_type(); |
| 1607 | 1591 |
| 1608 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) | 1592 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) |
| 1609 NotifyObserversOfEffectiveConnectionTypeChanged(); | 1593 NotifyObserversOfEffectiveConnectionTypeChanged(); |
| 1610 } | 1594 } |
| 1611 | 1595 |
| 1612 if (cached_network_quality.network_quality().downstream_throughput_kbps() != | 1596 if (cached_network_quality.network_quality().downstream_throughput_kbps() != |
| 1613 nqe::internal::kInvalidThroughput) { | 1597 nqe::internal::kInvalidThroughput) { |
| 1614 ThroughputObservation througphput_observation( | 1598 ThroughputObservation througphput_observation( |
| 1615 cached_network_quality.network_quality().downstream_throughput_kbps(), | 1599 cached_network_quality.network_quality().downstream_throughput_kbps(), |
| 1616 now, NETWORK_QUALITY_OBSERVATION_SOURCE_CACHED_ESTIMATE); | 1600 now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
| 1617 downstream_throughput_kbps_observations_.AddObservation( | 1601 downstream_throughput_kbps_observations_.AddObservation( |
| 1618 througphput_observation); | 1602 througphput_observation); |
| 1619 NotifyObserversOfThroughput(througphput_observation); | 1603 NotifyObserversOfThroughput(througphput_observation); |
| 1620 } | 1604 } |
| 1621 | 1605 |
| 1622 if (cached_network_quality.network_quality().http_rtt() != | 1606 if (cached_network_quality.network_quality().http_rtt() != |
| 1623 nqe::internal::InvalidRTT()) { | 1607 nqe::internal::InvalidRTT()) { |
| 1624 RttObservation rtt_observation( | 1608 RttObservation rtt_observation( |
| 1625 cached_network_quality.network_quality().http_rtt(), now, | 1609 cached_network_quality.network_quality().http_rtt(), now, |
| 1626 NETWORK_QUALITY_OBSERVATION_SOURCE_CACHED_ESTIMATE); | 1610 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
| 1627 rtt_observations_.AddObservation(rtt_observation); | 1611 rtt_observations_.AddObservation(rtt_observation); |
| 1628 NotifyObserversOfRTT(rtt_observation); | 1612 NotifyObserversOfRTT(rtt_observation); |
| 1629 } | 1613 } |
| 1630 return true; | 1614 return true; |
| 1631 } | 1615 } |
| 1632 | 1616 |
| 1633 void NetworkQualityEstimator::OnUpdatedEstimateAvailable( | 1617 void NetworkQualityEstimator::OnUpdatedEstimateAvailable( |
| 1634 const base::TimeDelta& rtt, | 1618 const base::TimeDelta& rtt, |
| 1635 int32_t downstream_throughput_kbps, | 1619 int32_t downstream_throughput_kbps, |
| 1636 int32_t upstream_throughput_kbps) { | 1620 int32_t upstream_throughput_kbps) { |
| 1637 DCHECK(thread_checker_.CalledOnValidThread()); | 1621 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1638 DCHECK(external_estimate_provider_); | 1622 DCHECK(external_estimate_provider_); |
| 1639 | 1623 |
| 1640 RecordExternalEstimateProviderMetrics( | 1624 RecordExternalEstimateProviderMetrics( |
| 1641 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); | 1625 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); |
| 1642 | 1626 |
| 1643 external_estimate_provider_quality_ = nqe::internal::NetworkQuality(); | 1627 external_estimate_provider_quality_ = nqe::internal::NetworkQuality(); |
| 1644 | 1628 |
| 1645 if (rtt > base::TimeDelta()) { | 1629 if (rtt > base::TimeDelta()) { |
| 1646 RecordExternalEstimateProviderMetrics( | 1630 RecordExternalEstimateProviderMetrics( |
| 1647 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); | 1631 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); |
| 1648 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); | 1632 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); |
| 1649 rtt_observations_.AddObservation( | 1633 rtt_observations_.AddObservation(RttObservation( |
| 1650 RttObservation(rtt, tick_clock_->NowTicks(), | 1634 rtt, tick_clock_->NowTicks(), |
| 1651 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE)); | 1635 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE)); |
| 1652 external_estimate_provider_quality_.set_http_rtt(rtt); | 1636 external_estimate_provider_quality_.set_http_rtt(rtt); |
| 1653 } | 1637 } |
| 1654 | 1638 |
| 1655 if (downstream_throughput_kbps > 0) { | 1639 if (downstream_throughput_kbps > 0) { |
| 1656 RecordExternalEstimateProviderMetrics( | 1640 RecordExternalEstimateProviderMetrics( |
| 1657 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); | 1641 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); |
| 1658 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", | 1642 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", |
| 1659 downstream_throughput_kbps); | 1643 downstream_throughput_kbps); |
| 1660 downstream_throughput_kbps_observations_.AddObservation( | 1644 downstream_throughput_kbps_observations_.AddObservation( |
| 1661 ThroughputObservation( | 1645 ThroughputObservation( |
| 1662 downstream_throughput_kbps, tick_clock_->NowTicks(), | 1646 downstream_throughput_kbps, tick_clock_->NowTicks(), |
| 1663 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE)); | 1647 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE)); |
| 1664 external_estimate_provider_quality_.set_downstream_throughput_kbps( | 1648 external_estimate_provider_quality_.set_downstream_throughput_kbps( |
| 1665 downstream_throughput_kbps); | 1649 downstream_throughput_kbps); |
| 1666 } | 1650 } |
| 1667 } | 1651 } |
| 1668 | 1652 |
| 1669 void NetworkQualityEstimator::SetTickClockForTesting( | 1653 void NetworkQualityEstimator::SetTickClockForTesting( |
| 1670 std::unique_ptr<base::TickClock> tick_clock) { | 1654 std::unique_ptr<base::TickClock> tick_clock) { |
| 1671 DCHECK(thread_checker_.CalledOnValidThread()); | 1655 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1672 tick_clock_ = std::move(tick_clock); | 1656 tick_clock_ = std::move(tick_clock); |
| 1673 } | 1657 } |
| 1674 | 1658 |
| 1675 double NetworkQualityEstimator::RandDouble() const { | 1659 double NetworkQualityEstimator::RandDouble() const { |
| 1676 return base::RandDouble(); | 1660 return base::RandDouble(); |
| 1677 } | 1661 } |
| 1678 | 1662 |
| 1679 void NetworkQualityEstimator::OnUpdatedRTTAvailable( | 1663 void NetworkQualityEstimator::OnUpdatedRTTAvailable( |
| 1680 SocketPerformanceWatcherFactory::Protocol protocol, | 1664 SocketPerformanceWatcherFactory::Protocol protocol, |
| 1681 const base::TimeDelta& rtt) { | 1665 const base::TimeDelta& rtt) { |
| 1682 DCHECK(thread_checker_.CalledOnValidThread()); | 1666 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1683 DCHECK_NE(nqe::internal::InvalidRTT(), rtt); | 1667 DCHECK_NE(nqe::internal::InvalidRTT(), rtt); |
| 1684 | 1668 |
| 1685 RttObservation observation(rtt, tick_clock_->NowTicks(), | 1669 RttObservation observation(rtt, tick_clock_->NowTicks(), |
| 1686 ProtocolSourceToObservationSource(protocol)); | 1670 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT); |
| 1687 NotifyObserversOfRTT(observation); | 1671 NotifyObserversOfRTT(observation); |
| 1688 rtt_observations_.AddObservation(observation); | 1672 rtt_observations_.AddObservation(observation); |
| 1689 } | 1673 } |
| 1690 | 1674 |
| 1691 void NetworkQualityEstimator::NotifyObserversOfRTT( | 1675 void NetworkQualityEstimator::NotifyObserversOfRTT( |
| 1692 const RttObservation& observation) { | 1676 const RttObservation& observation) { |
| 1693 DCHECK(thread_checker_.CalledOnValidThread()); | 1677 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1694 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value); | 1678 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value); |
| 1695 | 1679 |
| 1696 // Maybe recompute the effective connection type since a new RTT observation | 1680 // Maybe recompute the effective connection type since a new RTT observation |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1727 | 1711 |
| 1728 if (downstream_kbps > peak_network_quality_.downstream_throughput_kbps() || | 1712 if (downstream_kbps > peak_network_quality_.downstream_throughput_kbps() || |
| 1729 peak_network_quality_.downstream_throughput_kbps() == | 1713 peak_network_quality_.downstream_throughput_kbps() == |
| 1730 nqe::internal::kInvalidThroughput) { | 1714 nqe::internal::kInvalidThroughput) { |
| 1731 peak_network_quality_ = nqe::internal::NetworkQuality( | 1715 peak_network_quality_ = nqe::internal::NetworkQuality( |
| 1732 peak_network_quality_.http_rtt(), peak_network_quality_.transport_rtt(), | 1716 peak_network_quality_.http_rtt(), peak_network_quality_.transport_rtt(), |
| 1733 downstream_kbps); | 1717 downstream_kbps); |
| 1734 } | 1718 } |
| 1735 ThroughputObservation throughput_observation( | 1719 ThroughputObservation throughput_observation( |
| 1736 downstream_kbps, tick_clock_->NowTicks(), | 1720 downstream_kbps, tick_clock_->NowTicks(), |
| 1737 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); | 1721 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); |
| 1738 downstream_throughput_kbps_observations_.AddObservation( | 1722 downstream_throughput_kbps_observations_.AddObservation( |
| 1739 throughput_observation); | 1723 throughput_observation); |
| 1740 NotifyObserversOfThroughput(throughput_observation); | 1724 NotifyObserversOfThroughput(throughput_observation); |
| 1741 } | 1725 } |
| 1742 | 1726 |
| 1743 void NetworkQualityEstimator::MaybeComputeEffectiveConnectionType() { | 1727 void NetworkQualityEstimator::MaybeComputeEffectiveConnectionType() { |
| 1744 DCHECK(thread_checker_.CalledOnValidThread()); | 1728 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1745 | 1729 |
| 1746 const base::TimeTicks now = tick_clock_->NowTicks(); | 1730 const base::TimeTicks now = tick_clock_->NowTicks(); |
| 1747 // Recompute effective connection type only if | 1731 // Recompute effective connection type only if |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1814 void NetworkQualityEstimator::OnPrefsRead( | 1798 void NetworkQualityEstimator::OnPrefsRead( |
| 1815 const std::map<nqe::internal::NetworkID, | 1799 const std::map<nqe::internal::NetworkID, |
| 1816 nqe::internal::CachedNetworkQuality> read_prefs) { | 1800 nqe::internal::CachedNetworkQuality> read_prefs) { |
| 1817 DCHECK(thread_checker_.CalledOnValidThread()); | 1801 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1818 UMA_HISTOGRAM_COUNTS("NQE.Prefs.ReadSize", read_prefs.size()); | 1802 UMA_HISTOGRAM_COUNTS("NQE.Prefs.ReadSize", read_prefs.size()); |
| 1819 // TODO(tbansal): crbug.com/490870. Incorporate the network quality into the | 1803 // TODO(tbansal): crbug.com/490870. Incorporate the network quality into the |
| 1820 // current estimates. | 1804 // current estimates. |
| 1821 } | 1805 } |
| 1822 | 1806 |
| 1823 } // namespace net | 1807 } // namespace net |
| OLD | NEW |