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 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 } | 1140 } |
1141 } | 1141 } |
1142 // Return the fastest connection type. | 1142 // Return the fastest connection type. |
1143 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST - | 1143 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST - |
1144 1); | 1144 1); |
1145 } | 1145 } |
1146 | 1146 |
1147 void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver( | 1147 void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver( |
1148 EffectiveConnectionTypeObserver* observer) { | 1148 EffectiveConnectionTypeObserver* observer) { |
1149 DCHECK(thread_checker_.CalledOnValidThread()); | 1149 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1150 DCHECK(observer); |
1150 effective_connection_type_observer_list_.AddObserver(observer); | 1151 effective_connection_type_observer_list_.AddObserver(observer); |
| 1152 |
| 1153 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1154 FROM_HERE, base::Bind(&NetworkQualityEstimator:: |
| 1155 NotifyEffectiveConnectionTypeObserverIfPresent, |
| 1156 weak_ptr_factory_.GetWeakPtr(), observer)); |
1151 } | 1157 } |
1152 | 1158 |
1153 void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver( | 1159 void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver( |
1154 EffectiveConnectionTypeObserver* observer) { | 1160 EffectiveConnectionTypeObserver* observer) { |
1155 DCHECK(thread_checker_.CalledOnValidThread()); | 1161 DCHECK(thread_checker_.CalledOnValidThread()); |
1156 effective_connection_type_observer_list_.RemoveObserver(observer); | 1162 effective_connection_type_observer_list_.RemoveObserver(observer); |
1157 } | 1163 } |
1158 | 1164 |
1159 void NetworkQualityEstimator::AddRTTAndThroughputEstimatesObserver( | 1165 void NetworkQualityEstimator::AddRTTAndThroughputEstimatesObserver( |
1160 RTTAndThroughputEstimatesObserver* observer) { | 1166 RTTAndThroughputEstimatesObserver* observer) { |
1161 DCHECK(thread_checker_.CalledOnValidThread()); | 1167 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1168 DCHECK(observer); |
1162 rtt_and_throughput_estimates_observer_list_.AddObserver(observer); | 1169 rtt_and_throughput_estimates_observer_list_.AddObserver(observer); |
| 1170 |
| 1171 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1172 FROM_HERE, |
| 1173 base::Bind(&NetworkQualityEstimator:: |
| 1174 NotifyRTTAndThroughputEstimatesObserverIfPresent, |
| 1175 weak_ptr_factory_.GetWeakPtr(), observer)); |
1163 } | 1176 } |
1164 | 1177 |
1165 void NetworkQualityEstimator::RemoveRTTAndThroughputEstimatesObserver( | 1178 void NetworkQualityEstimator::RemoveRTTAndThroughputEstimatesObserver( |
1166 RTTAndThroughputEstimatesObserver* observer) { | 1179 RTTAndThroughputEstimatesObserver* observer) { |
1167 DCHECK(thread_checker_.CalledOnValidThread()); | 1180 DCHECK(thread_checker_.CalledOnValidThread()); |
1168 rtt_and_throughput_estimates_observer_list_.RemoveObserver(observer); | 1181 rtt_and_throughput_estimates_observer_list_.RemoveObserver(observer); |
1169 } | 1182 } |
1170 | 1183 |
1171 bool NetworkQualityEstimator::GetRecentHttpRTT( | 1184 bool NetworkQualityEstimator::GetRecentHttpRTT( |
1172 const base::TimeTicks& start_time, | 1185 const base::TimeTicks& start_time, |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 DCHECK(thread_checker_.CalledOnValidThread()); | 1507 DCHECK(thread_checker_.CalledOnValidThread()); |
1495 | 1508 |
1496 // TODO(tbansal): Add hysteresis in the notification. | 1509 // TODO(tbansal): Add hysteresis in the notification. |
1497 for (auto& observer : rtt_and_throughput_estimates_observer_list_) { | 1510 for (auto& observer : rtt_and_throughput_estimates_observer_list_) { |
1498 observer.OnRTTOrThroughputEstimatesComputed( | 1511 observer.OnRTTOrThroughputEstimatesComputed( |
1499 network_quality_.http_rtt(), network_quality_.transport_rtt(), | 1512 network_quality_.http_rtt(), network_quality_.transport_rtt(), |
1500 network_quality_.downstream_throughput_kbps()); | 1513 network_quality_.downstream_throughput_kbps()); |
1501 } | 1514 } |
1502 } | 1515 } |
1503 | 1516 |
| 1517 void NetworkQualityEstimator::NotifyEffectiveConnectionTypeObserverIfPresent( |
| 1518 EffectiveConnectionTypeObserver* observer) const { |
| 1519 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1520 |
| 1521 if (!effective_connection_type_observer_list_.HasObserver(observer)) |
| 1522 return; |
| 1523 if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) |
| 1524 return; |
| 1525 observer->OnEffectiveConnectionTypeChanged(effective_connection_type_); |
| 1526 } |
| 1527 |
| 1528 void NetworkQualityEstimator::NotifyRTTAndThroughputEstimatesObserverIfPresent( |
| 1529 RTTAndThroughputEstimatesObserver* observer) const { |
| 1530 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1531 |
| 1532 if (!rtt_and_throughput_estimates_observer_list_.HasObserver(observer)) |
| 1533 return; |
| 1534 observer->OnRTTOrThroughputEstimatesComputed( |
| 1535 network_quality_.http_rtt(), network_quality_.transport_rtt(), |
| 1536 network_quality_.downstream_throughput_kbps()); |
| 1537 } |
| 1538 |
1504 void NetworkQualityEstimator::AddNetworkQualitiesCacheObserver( | 1539 void NetworkQualityEstimator::AddNetworkQualitiesCacheObserver( |
1505 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* | 1540 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* |
1506 observer) { | 1541 observer) { |
1507 DCHECK(thread_checker_.CalledOnValidThread()); | 1542 DCHECK(thread_checker_.CalledOnValidThread()); |
1508 network_quality_store_->AddNetworkQualitiesCacheObserver(observer); | 1543 network_quality_store_->AddNetworkQualitiesCacheObserver(observer); |
1509 } | 1544 } |
1510 | 1545 |
1511 void NetworkQualityEstimator::RemoveNetworkQualitiesCacheObserver( | 1546 void NetworkQualityEstimator::RemoveNetworkQualitiesCacheObserver( |
1512 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* | 1547 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* |
1513 observer) { | 1548 observer) { |
1514 DCHECK(thread_checker_.CalledOnValidThread()); | 1549 DCHECK(thread_checker_.CalledOnValidThread()); |
1515 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer); | 1550 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer); |
1516 } | 1551 } |
1517 | 1552 |
1518 void NetworkQualityEstimator::OnPrefsRead( | 1553 void NetworkQualityEstimator::OnPrefsRead( |
1519 const std::map<nqe::internal::NetworkID, | 1554 const std::map<nqe::internal::NetworkID, |
1520 nqe::internal::CachedNetworkQuality> read_prefs) { | 1555 nqe::internal::CachedNetworkQuality> read_prefs) { |
1521 DCHECK(thread_checker_.CalledOnValidThread()); | 1556 DCHECK(thread_checker_.CalledOnValidThread()); |
1522 UMA_HISTOGRAM_COUNTS("NQE.Prefs.ReadSize", read_prefs.size()); | 1557 UMA_HISTOGRAM_COUNTS("NQE.Prefs.ReadSize", read_prefs.size()); |
1523 // TODO(tbansal): crbug.com/490870. Incorporate the network quality into the | 1558 // TODO(tbansal): crbug.com/490870. Incorporate the network quality into the |
1524 // current estimates. | 1559 // current estimates. |
1525 } | 1560 } |
1526 | 1561 |
1527 } // namespace net | 1562 } // namespace net |
OLD | NEW |