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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 306 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
307 histogram_name, 1, 1000 * 1000 /* 1 Gbps */, 50 /* Number of buckets */, | 307 histogram_name, 1, 1000 * 1000 /* 1 Gbps */, 50 /* Number of buckets */, |
308 base::HistogramBase::kUmaTargetedHistogramFlag); | 308 base::HistogramBase::kUmaTargetedHistogramFlag); |
309 histogram->Add(std::abs(metric)); | 309 histogram->Add(std::abs(metric)); |
310 } | 310 } |
311 | 311 |
312 void RecordEffectiveConnectionTypeAccuracy( | 312 void RecordEffectiveConnectionTypeAccuracy( |
313 const char* prefix, | 313 const char* prefix, |
314 int32_t metric, | 314 int32_t metric, |
315 base::TimeDelta measuring_duration, | 315 base::TimeDelta measuring_duration, |
316 net::NetworkQualityEstimator::EffectiveConnectionType | 316 net::EffectiveConnectionType observed_effective_connection_type) { |
317 observed_effective_connection_type) { | |
318 const std::string histogram_name = base::StringPrintf( | 317 const std::string histogram_name = base::StringPrintf( |
319 "%s.EstimatedObservedDiff.%s.%d.%s", prefix, | 318 "%s.EstimatedObservedDiff.%s.%d.%s", prefix, |
320 metric >= 0 ? "Positive" : "Negative", | 319 metric >= 0 ? "Positive" : "Negative", |
321 static_cast<int32_t>(measuring_duration.InSeconds()), | 320 static_cast<int32_t>(measuring_duration.InSeconds()), |
322 net::NetworkQualityEstimator::GetNameForEffectiveConnectionType( | 321 net::NetworkQualityEstimator::GetNameForEffectiveConnectionType( |
323 observed_effective_connection_type)); | 322 observed_effective_connection_type)); |
324 | 323 |
325 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 324 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
326 histogram_name, 0, | 325 histogram_name, 0, net::EFFECTIVE_CONNECTION_TYPE_LAST, |
327 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_LAST, | 326 net::EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, |
328 net::NetworkQualityEstimator:: | |
329 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, | |
330 base::HistogramBase::kUmaTargetedHistogramFlag); | 327 base::HistogramBase::kUmaTargetedHistogramFlag); |
331 histogram->Add(std::abs(metric)); | 328 histogram->Add(std::abs(metric)); |
332 } | 329 } |
333 | 330 |
334 } // namespace | 331 } // namespace |
335 | 332 |
336 namespace net { | 333 namespace net { |
337 | 334 |
338 NetworkQualityEstimator::NetworkQualityEstimator( | 335 NetworkQualityEstimator::NetworkQualityEstimator( |
339 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 336 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 base::Histogram::FactoryGet( | 1140 base::Histogram::FactoryGet( |
1144 std::string("NQE.MainFrame.EffectiveConnectionType.") + | 1141 std::string("NQE.MainFrame.EffectiveConnectionType.") + |
1145 GetNameForConnectionType(current_network_id_.type), | 1142 GetNameForConnectionType(current_network_id_.type), |
1146 0, EFFECTIVE_CONNECTION_TYPE_LAST, | 1143 0, EFFECTIVE_CONNECTION_TYPE_LAST, |
1147 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, | 1144 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, |
1148 base::HistogramBase::kUmaTargetedHistogramFlag); | 1145 base::HistogramBase::kUmaTargetedHistogramFlag); |
1149 | 1146 |
1150 effective_connection_type_histogram->Add(effective_connection_type); | 1147 effective_connection_type_histogram->Add(effective_connection_type); |
1151 } | 1148 } |
1152 | 1149 |
1153 NetworkQualityEstimator::EffectiveConnectionType | 1150 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType() |
1154 NetworkQualityEstimator::GetEffectiveConnectionType() const { | 1151 const { |
1155 DCHECK(thread_checker_.CalledOnValidThread()); | 1152 DCHECK(thread_checker_.CalledOnValidThread()); |
1156 return GetRecentEffectiveConnectionType(base::TimeTicks()); | 1153 return GetRecentEffectiveConnectionType(base::TimeTicks()); |
1157 } | 1154 } |
1158 | 1155 |
1159 NetworkQualityEstimator::EffectiveConnectionType | 1156 EffectiveConnectionType |
1160 NetworkQualityEstimator::GetRecentEffectiveConnectionType( | 1157 NetworkQualityEstimator::GetRecentEffectiveConnectionType( |
1161 const base::TimeTicks& start_time) const { | 1158 const base::TimeTicks& start_time) const { |
1162 DCHECK(thread_checker_.CalledOnValidThread()); | 1159 DCHECK(thread_checker_.CalledOnValidThread()); |
1163 | 1160 |
1164 if (effective_connection_type_algorithm_ == | 1161 if (effective_connection_type_algorithm_ == |
1165 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) { | 1162 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) { |
1166 return GetRecentEffectiveConnectionTypeUsingMetrics( | 1163 return GetRecentEffectiveConnectionTypeUsingMetrics( |
1167 start_time, NetworkQualityEstimator::MetricUsage:: | 1164 start_time, NetworkQualityEstimator::MetricUsage:: |
1168 MUST_BE_USED /* http_rtt_metric */, | 1165 MUST_BE_USED /* http_rtt_metric */, |
1169 NetworkQualityEstimator::MetricUsage:: | 1166 NetworkQualityEstimator::MetricUsage:: |
(...skipping 27 matching lines...) Expand all Loading... |
1197 if (effective_connection_type_algorithm_ == | 1194 if (effective_connection_type_algorithm_ == |
1198 EffectiveConnectionTypeAlgorithm:: | 1195 EffectiveConnectionTypeAlgorithm:: |
1199 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) { | 1196 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) { |
1200 return true; | 1197 return true; |
1201 } | 1198 } |
1202 // Add additional algorithms here. | 1199 // Add additional algorithms here. |
1203 NOTREACHED(); | 1200 NOTREACHED(); |
1204 return false; | 1201 return false; |
1205 } | 1202 } |
1206 | 1203 |
1207 NetworkQualityEstimator::EffectiveConnectionType | 1204 EffectiveConnectionType |
1208 NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics( | 1205 NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics( |
1209 const base::TimeTicks& start_time, | 1206 const base::TimeTicks& start_time, |
1210 NetworkQualityEstimator::MetricUsage http_rtt_metric, | 1207 NetworkQualityEstimator::MetricUsage http_rtt_metric, |
1211 NetworkQualityEstimator::MetricUsage transport_rtt_metric, | 1208 NetworkQualityEstimator::MetricUsage transport_rtt_metric, |
1212 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric) | 1209 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric) |
1213 const { | 1210 const { |
1214 DCHECK(thread_checker_.CalledOnValidThread()); | 1211 DCHECK(thread_checker_.CalledOnValidThread()); |
1215 | 1212 |
1216 // If the device is currently offline, then return | 1213 // If the device is currently offline, then return |
1217 // EFFECTIVE_CONNECTION_TYPE_OFFLINE. | 1214 // EFFECTIVE_CONNECTION_TYPE_OFFLINE. |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 case EFFECTIVE_CONNECTION_TYPE_BROADBAND: | 1534 case EFFECTIVE_CONNECTION_TYPE_BROADBAND: |
1538 return "Broadband"; | 1535 return "Broadband"; |
1539 default: | 1536 default: |
1540 NOTREACHED(); | 1537 NOTREACHED(); |
1541 break; | 1538 break; |
1542 } | 1539 } |
1543 return ""; | 1540 return ""; |
1544 } | 1541 } |
1545 | 1542 |
1546 // static | 1543 // static |
1547 NetworkQualityEstimator::EffectiveConnectionType | 1544 EffectiveConnectionType |
1548 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( | 1545 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( |
1549 const std::string& connection_type_name) { | 1546 const std::string& connection_type_name) { |
1550 if (connection_type_name == "Unknown") | 1547 if (connection_type_name == "Unknown") |
1551 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 1548 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
1552 if (connection_type_name == "Offline") | 1549 if (connection_type_name == "Offline") |
1553 return EFFECTIVE_CONNECTION_TYPE_OFFLINE; | 1550 return EFFECTIVE_CONNECTION_TYPE_OFFLINE; |
1554 if (connection_type_name == "Slow2G") | 1551 if (connection_type_name == "Slow2G") |
1555 return EFFECTIVE_CONNECTION_TYPE_SLOW_2G; | 1552 return EFFECTIVE_CONNECTION_TYPE_SLOW_2G; |
1556 if (connection_type_name == "2G") | 1553 if (connection_type_name == "2G") |
1557 return EFFECTIVE_CONNECTION_TYPE_2G; | 1554 return EFFECTIVE_CONNECTION_TYPE_2G; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 NotifyObserversOfEffectiveConnectionTypeChanged() { | 1662 NotifyObserversOfEffectiveConnectionTypeChanged() { |
1666 DCHECK(thread_checker_.CalledOnValidThread()); | 1663 DCHECK(thread_checker_.CalledOnValidThread()); |
1667 | 1664 |
1668 // TODO(tbansal): Add hysteresis in the notification. | 1665 // TODO(tbansal): Add hysteresis in the notification. |
1669 FOR_EACH_OBSERVER( | 1666 FOR_EACH_OBSERVER( |
1670 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, | 1667 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, |
1671 OnEffectiveConnectionTypeChanged(effective_connection_type_)); | 1668 OnEffectiveConnectionTypeChanged(effective_connection_type_)); |
1672 } | 1669 } |
1673 | 1670 |
1674 } // namespace net | 1671 } // namespace net |
OLD | NEW |