| 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 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); | 1067 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); |
| 1068 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", | 1068 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", |
| 1069 downstream_throughput_kbps); | 1069 downstream_throughput_kbps); |
| 1070 downstream_throughput_kbps_observations_.AddObservation( | 1070 downstream_throughput_kbps_observations_.AddObservation( |
| 1071 ThroughputObservation( | 1071 ThroughputObservation( |
| 1072 downstream_throughput_kbps, tick_clock_->NowTicks(), | 1072 downstream_throughput_kbps, tick_clock_->NowTicks(), |
| 1073 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE)); | 1073 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE)); |
| 1074 } | 1074 } |
| 1075 } | 1075 } |
| 1076 | 1076 |
| 1077 // static |
| 1077 const char* NetworkQualityEstimator::GetNameForEffectiveConnectionType( | 1078 const char* NetworkQualityEstimator::GetNameForEffectiveConnectionType( |
| 1078 EffectiveConnectionType type) const { | 1079 EffectiveConnectionType type) { |
| 1079 switch (type) { | 1080 switch (type) { |
| 1080 case EFFECTIVE_CONNECTION_TYPE_UNKNOWN: | 1081 case EFFECTIVE_CONNECTION_TYPE_UNKNOWN: |
| 1081 return "Unknown"; | 1082 return "Unknown"; |
| 1082 case EFFECTIVE_CONNECTION_TYPE_OFFLINE: | 1083 case EFFECTIVE_CONNECTION_TYPE_OFFLINE: |
| 1083 return "Offline"; | 1084 return "Offline"; |
| 1084 case EFFECTIVE_CONNECTION_TYPE_SLOW_2G: | 1085 case EFFECTIVE_CONNECTION_TYPE_SLOW_2G: |
| 1085 return "Slow2G"; | 1086 return "Slow2G"; |
| 1086 case EFFECTIVE_CONNECTION_TYPE_2G: | 1087 case EFFECTIVE_CONNECTION_TYPE_2G: |
| 1087 return "2G"; | 1088 return "2G"; |
| 1088 case EFFECTIVE_CONNECTION_TYPE_3G: | 1089 case EFFECTIVE_CONNECTION_TYPE_3G: |
| 1089 return "3G"; | 1090 return "3G"; |
| 1090 case EFFECTIVE_CONNECTION_TYPE_4G: | 1091 case EFFECTIVE_CONNECTION_TYPE_4G: |
| 1091 return "4G"; | 1092 return "4G"; |
| 1092 case EFFECTIVE_CONNECTION_TYPE_BROADBAND: | 1093 case EFFECTIVE_CONNECTION_TYPE_BROADBAND: |
| 1093 return "Broadband"; | 1094 return "Broadband"; |
| 1094 default: | 1095 default: |
| 1095 NOTREACHED(); | 1096 NOTREACHED(); |
| 1096 break; | 1097 break; |
| 1097 } | 1098 } |
| 1098 return ""; | 1099 return ""; |
| 1099 } | 1100 } |
| 1100 | 1101 |
| 1102 // static |
| 1103 NetworkQualityEstimator::EffectiveConnectionType |
| 1104 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( |
| 1105 const std::string& connection_type_name) { |
| 1106 if (connection_type_name == "Unknown") |
| 1107 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
| 1108 if (connection_type_name == "Offline") |
| 1109 return EFFECTIVE_CONNECTION_TYPE_OFFLINE; |
| 1110 if (connection_type_name == "Slow2G") |
| 1111 return EFFECTIVE_CONNECTION_TYPE_SLOW_2G; |
| 1112 if (connection_type_name == "2G") |
| 1113 return EFFECTIVE_CONNECTION_TYPE_2G; |
| 1114 if (connection_type_name == "3G") |
| 1115 return EFFECTIVE_CONNECTION_TYPE_3G; |
| 1116 if (connection_type_name == "4G") |
| 1117 return EFFECTIVE_CONNECTION_TYPE_4G; |
| 1118 if (connection_type_name == "Broadband") |
| 1119 return EFFECTIVE_CONNECTION_TYPE_BROADBAND; |
| 1120 NOTREACHED(); |
| 1121 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
| 1122 } |
| 1123 |
| 1101 void NetworkQualityEstimator::SetTickClockForTesting( | 1124 void NetworkQualityEstimator::SetTickClockForTesting( |
| 1102 std::unique_ptr<base::TickClock> tick_clock) { | 1125 std::unique_ptr<base::TickClock> tick_clock) { |
| 1103 DCHECK(thread_checker_.CalledOnValidThread()); | 1126 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1104 tick_clock_ = std::move(tick_clock); | 1127 tick_clock_ = std::move(tick_clock); |
| 1105 } | 1128 } |
| 1106 | 1129 |
| 1107 void NetworkQualityEstimator::CacheNetworkQualityEstimate() { | 1130 void NetworkQualityEstimator::CacheNetworkQualityEstimate() { |
| 1108 DCHECK(thread_checker_.CalledOnValidThread()); | 1131 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1109 DCHECK_LE(cached_network_qualities_.size(), | 1132 DCHECK_LE(cached_network_qualities_.size(), |
| 1110 static_cast<size_t>(kMaximumNetworkQualityCacheSize)); | 1133 static_cast<size_t>(kMaximumNetworkQualityCacheSize)); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 NotifyObserversOfEffectiveConnectionTypeChanged() { | 1262 NotifyObserversOfEffectiveConnectionTypeChanged() { |
| 1240 DCHECK(thread_checker_.CalledOnValidThread()); | 1263 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1241 | 1264 |
| 1242 // TODO(tbansal): Add hysteresis in the notification. | 1265 // TODO(tbansal): Add hysteresis in the notification. |
| 1243 FOR_EACH_OBSERVER( | 1266 FOR_EACH_OBSERVER( |
| 1244 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, | 1267 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, |
| 1245 OnEffectiveConnectionTypeChanged(effective_connection_type_)); | 1268 OnEffectiveConnectionTypeChanged(effective_connection_type_)); |
| 1246 } | 1269 } |
| 1247 | 1270 |
| 1248 } // namespace net | 1271 } // namespace net |
| OLD | NEW |