| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" | 5 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 DCHECK(deleted); | 200 DCHECK(deleted); |
| 201 // Silence unused variable warning in release builds. | 201 // Silence unused variable warning in release builds. |
| 202 (void)deleted; | 202 (void)deleted; |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 void UINetworkQualityEstimatorService::EffectiveConnectionTypeChanged( | 206 void UINetworkQualityEstimatorService::EffectiveConnectionTypeChanged( |
| 207 net::EffectiveConnectionType type) { | 207 net::EffectiveConnectionType type) { |
| 208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 209 type_ = type; | 209 type_ = type; |
| 210 for (auto& observer : effective_connection_type_observer_list_) |
| 211 observer.OnEffectiveConnectionTypeChanged(type); |
| 212 } |
| 213 |
| 214 void UINetworkQualityEstimatorService::AddEffectiveConnectionTypeObserver( |
| 215 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) { |
| 216 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 217 effective_connection_type_observer_list_.AddObserver(observer); |
| 218 } |
| 219 |
| 220 void UINetworkQualityEstimatorService::RemoveEffectiveConnectionTypeObserver( |
| 221 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) { |
| 222 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 223 effective_connection_type_observer_list_.RemoveObserver(observer); |
| 210 } | 224 } |
| 211 | 225 |
| 212 void UINetworkQualityEstimatorService::SetEffectiveConnectionTypeForTesting( | 226 void UINetworkQualityEstimatorService::SetEffectiveConnectionTypeForTesting( |
| 213 net::EffectiveConnectionType type) { | 227 net::EffectiveConnectionType type) { |
| 214 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 228 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 215 type_ = type; | 229 EffectiveConnectionTypeChanged(type); |
| 216 } | 230 } |
| 217 | 231 |
| 218 net::EffectiveConnectionType | 232 net::EffectiveConnectionType |
| 219 UINetworkQualityEstimatorService::GetEffectiveConnectionType() const { | 233 UINetworkQualityEstimatorService::GetEffectiveConnectionType() const { |
| 220 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 234 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 221 return type_; | 235 return type_; |
| 222 } | 236 } |
| 223 | 237 |
| 224 // static | 238 // static |
| 225 void UINetworkQualityEstimatorService::RegisterProfilePrefs( | 239 void UINetworkQualityEstimatorService::RegisterProfilePrefs( |
| 226 PrefRegistrySimple* registry) { | 240 PrefRegistrySimple* registry) { |
| 227 registry->RegisterDictionaryPref(prefs::kNetworkQualities, | 241 registry->RegisterDictionaryPref(prefs::kNetworkQualities, |
| 228 PrefRegistry::LOSSY_PREF); | 242 PrefRegistry::LOSSY_PREF); |
| 229 } | 243 } |
| 230 | 244 |
| 231 std::map<net::nqe::internal::NetworkID, | 245 std::map<net::nqe::internal::NetworkID, |
| 232 net::nqe::internal::CachedNetworkQuality> | 246 net::nqe::internal::CachedNetworkQuality> |
| 233 UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const { | 247 UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const { |
| 234 if (!prefs_manager_) { | 248 if (!prefs_manager_) { |
| 235 return std::map<net::nqe::internal::NetworkID, | 249 return std::map<net::nqe::internal::NetworkID, |
| 236 net::nqe::internal::CachedNetworkQuality>(); | 250 net::nqe::internal::CachedNetworkQuality>(); |
| 237 } | 251 } |
| 238 return prefs_manager_->ForceReadPrefsForTesting(); | 252 return prefs_manager_->ForceReadPrefsForTesting(); |
| 239 } | 253 } |
| OLD | NEW |