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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 | 119 |
120 void InitializeOnIOThread(IOThread* io_thread) { | 120 void InitializeOnIOThread(IOThread* io_thread) { |
121 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 121 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
122 if (!io_thread->globals()->network_quality_estimator) | 122 if (!io_thread->globals()->network_quality_estimator) |
123 return; | 123 return; |
124 network_quality_estimator_ = | 124 network_quality_estimator_ = |
125 io_thread->globals()->network_quality_estimator.get(); | 125 io_thread->globals()->network_quality_estimator.get(); |
126 if (!network_quality_estimator_) | 126 if (!network_quality_estimator_) |
127 return; | 127 return; |
128 network_quality_estimator_->AddEffectiveConnectionTypeObserver(this); | 128 network_quality_estimator_->AddEffectiveConnectionTypeObserver(this); |
129 content::BrowserThread::PostTask( | |
130 content::BrowserThread::UI, FROM_HERE, | |
131 base::Bind( | |
132 &UINetworkQualityEstimatorService::EffectiveConnectionTypeChanged, | |
133 service_, | |
134 network_quality_estimator_->GetEffectiveConnectionType())); | |
135 } | 129 } |
136 | 130 |
137 // net::NetworkQualityEstimator::EffectiveConnectionTypeObserver | 131 // net::NetworkQualityEstimator::EffectiveConnectionTypeObserver |
138 // implementation: | 132 // implementation: |
139 void OnEffectiveConnectionTypeChanged( | 133 void OnEffectiveConnectionTypeChanged( |
140 net::EffectiveConnectionType type) override { | 134 net::EffectiveConnectionType type) override { |
141 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 135 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
142 content::BrowserThread::PostTask( | 136 content::BrowserThread::PostTask( |
143 content::BrowserThread::UI, FROM_HERE, | 137 content::BrowserThread::UI, FROM_HERE, |
144 base::Bind( | 138 base::Bind( |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 } | 198 } |
205 | 199 |
206 void UINetworkQualityEstimatorService::EffectiveConnectionTypeChanged( | 200 void UINetworkQualityEstimatorService::EffectiveConnectionTypeChanged( |
207 net::EffectiveConnectionType type) { | 201 net::EffectiveConnectionType type) { |
208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 202 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
209 type_ = type; | 203 type_ = type; |
210 for (auto& observer : effective_connection_type_observer_list_) | 204 for (auto& observer : effective_connection_type_observer_list_) |
211 observer.OnEffectiveConnectionTypeChanged(type); | 205 observer.OnEffectiveConnectionTypeChanged(type); |
212 } | 206 } |
213 | 207 |
214 void UINetworkQualityEstimatorService::AddEffectiveConnectionTypeObserver( | 208 void UINetworkQualityEstimatorService::AddEffectiveConnectionTypeObserver( |
RyanSturm
2016/11/10 22:21:34
Add the same behavior for this.
tbansal1
2016/11/10 22:55:21
Done.
| |
215 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) { | 209 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) { |
216 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 210 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
217 effective_connection_type_observer_list_.AddObserver(observer); | 211 effective_connection_type_observer_list_.AddObserver(observer); |
218 } | 212 } |
219 | 213 |
220 void UINetworkQualityEstimatorService::RemoveEffectiveConnectionTypeObserver( | 214 void UINetworkQualityEstimatorService::RemoveEffectiveConnectionTypeObserver( |
221 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) { | 215 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) { |
222 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 216 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
223 effective_connection_type_observer_list_.RemoveObserver(observer); | 217 effective_connection_type_observer_list_.RemoveObserver(observer); |
224 } | 218 } |
(...skipping 26 matching lines...) Expand all Loading... | |
251 | 245 |
252 std::map<net::nqe::internal::NetworkID, | 246 std::map<net::nqe::internal::NetworkID, |
253 net::nqe::internal::CachedNetworkQuality> | 247 net::nqe::internal::CachedNetworkQuality> |
254 UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const { | 248 UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const { |
255 if (!prefs_manager_) { | 249 if (!prefs_manager_) { |
256 return std::map<net::nqe::internal::NetworkID, | 250 return std::map<net::nqe::internal::NetworkID, |
257 net::nqe::internal::CachedNetworkQuality>(); | 251 net::nqe::internal::CachedNetworkQuality>(); |
258 } | 252 } |
259 return prefs_manager_->ForceReadPrefsForTesting(); | 253 return prefs_manager_->ForceReadPrefsForTesting(); |
260 } | 254 } |
OLD | NEW |