Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/net/nqe/ui_network_quality_estimator_service.cc

Issue 2742293004: Expose getters methods for NQE on UI thread (Closed)
Patch Set: ps Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/threading/thread_checker.h" 12 #include "base/threading/thread_checker.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/io_thread.h" 15 #include "chrome/browser/io_thread.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "components/prefs/pref_registry.h" 18 #include "components/prefs/pref_registry.h"
19 #include "components/prefs/pref_registry_simple.h" 19 #include "components/prefs/pref_registry_simple.h"
20 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
21 #include "components/variations/variations_associated_data.h" 21 #include "components/variations/variations_associated_data.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "net/nqe/network_qualities_prefs_manager.h" 23 #include "net/nqe/network_qualities_prefs_manager.h"
24 #include "net/nqe/network_quality.h"
24 25
25 namespace { 26 namespace {
26 27
27 // PrefDelegateImpl writes the provided dictionary value to the network quality 28 // PrefDelegateImpl writes the provided dictionary value to the network quality
28 // estimator prefs on the disk. 29 // estimator prefs on the disk.
29 class PrefDelegateImpl 30 class PrefDelegateImpl
30 : public net::NetworkQualitiesPrefsManager::PrefDelegate { 31 : public net::NetworkQualitiesPrefsManager::PrefDelegate {
31 public: 32 public:
32 // |pref_service| is used to read and write prefs from/to the disk. 33 // |pref_service| is used to read and write prefs from/to the disk.
33 explicit PrefDelegateImpl(PrefService* pref_service) 34 explicit PrefDelegateImpl(PrefService* pref_service)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 private: 139 private:
139 base::WeakPtr<UINetworkQualityEstimatorService> service_; 140 base::WeakPtr<UINetworkQualityEstimatorService> service_;
140 net::NetworkQualityEstimator* network_quality_estimator_; 141 net::NetworkQualityEstimator* network_quality_estimator_;
141 142
142 DISALLOW_COPY_AND_ASSIGN(IONetworkQualityObserver); 143 DISALLOW_COPY_AND_ASSIGN(IONetworkQualityObserver);
143 }; 144 };
144 145
145 UINetworkQualityEstimatorService::UINetworkQualityEstimatorService( 146 UINetworkQualityEstimatorService::UINetworkQualityEstimatorService(
146 Profile* profile) 147 Profile* profile)
147 : type_(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 148 : type_(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
148 http_rtt_(base::TimeDelta::FromMilliseconds(-1)), 149 http_rtt_(net::nqe::internal::InvalidRTT()),
149 transport_rtt_(base::TimeDelta::FromMilliseconds(-1)), 150 transport_rtt_(net::nqe::internal::InvalidRTT()),
150 downstream_throughput_kbps_(-1), 151 downstream_throughput_kbps_(net::nqe::internal::kInvalidThroughput),
151 weak_factory_(this) { 152 weak_factory_(this) {
152 DCHECK(profile); 153 DCHECK(profile);
153 // If this is running in a context without an IOThread, don't try to create 154 // If this is running in a context without an IOThread, don't try to create
154 // the IO object. 155 // the IO object.
155 if (!g_browser_process->io_thread()) 156 if (!g_browser_process->io_thread())
156 return; 157 return;
157 io_observer_ = base::WrapUnique( 158 io_observer_ = base::WrapUnique(
158 new IONetworkQualityObserver(weak_factory_.GetWeakPtr())); 159 new IONetworkQualityObserver(weak_factory_.GetWeakPtr()));
159 std::unique_ptr<PrefDelegateImpl> pref_delegate( 160 std::unique_ptr<PrefDelegateImpl> pref_delegate(
160 new PrefDelegateImpl(profile->GetPrefs())); 161 new PrefDelegateImpl(profile->GetPrefs()));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 NotifyEffectiveConnectionTypeObserverIfPresent, 233 NotifyEffectiveConnectionTypeObserverIfPresent,
233 weak_factory_.GetWeakPtr(), observer)); 234 weak_factory_.GetWeakPtr(), observer));
234 } 235 }
235 236
236 void UINetworkQualityEstimatorService::RemoveEffectiveConnectionTypeObserver( 237 void UINetworkQualityEstimatorService::RemoveEffectiveConnectionTypeObserver(
237 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) { 238 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) {
238 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 239 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
239 effective_connection_type_observer_list_.RemoveObserver(observer); 240 effective_connection_type_observer_list_.RemoveObserver(observer);
240 } 241 }
241 242
243 bool UINetworkQualityEstimatorService::GetHttpRTT(
244 base::TimeDelta* http_rtt) const {
245 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
246
247 if (http_rtt_ == net::nqe::internal::InvalidRTT())
248 return false;
249 *http_rtt = http_rtt_;
250 return true;
251 }
252
253 bool UINetworkQualityEstimatorService::GetTransportRTT(
254 base::TimeDelta* transport_rtt) const {
255 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
256
257 if (transport_rtt_ == net::nqe::internal::InvalidRTT())
258 return false;
259 *transport_rtt = transport_rtt_;
260 return true;
261 }
262
263 bool UINetworkQualityEstimatorService::GetDownstreamThroughputKbps(
264 int32_t* downstream_throughput_kbps) const {
265 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
266
267 if (downstream_throughput_kbps_ == net::nqe::internal::kInvalidThroughput)
268 return false;
269 *downstream_throughput_kbps = downstream_throughput_kbps_;
270 return true;
271 }
272
242 void UINetworkQualityEstimatorService::AddRTTAndThroughputEstimatesObserver( 273 void UINetworkQualityEstimatorService::AddRTTAndThroughputEstimatesObserver(
243 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) { 274 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) {
244 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 275 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
245 rtt_throughput_observer_list_.AddObserver(observer); 276 rtt_throughput_observer_list_.AddObserver(observer);
246 277
247 // Notify the |observer| on the next message pump since |observer| may not 278 // Notify the |observer| on the next message pump since |observer| may not
248 // be completely set up for receiving the callbacks. 279 // be completely set up for receiving the callbacks.
249 content::BrowserThread::PostTask( 280 content::BrowserThread::PostTask(
250 content::BrowserThread::UI, FROM_HERE, 281 content::BrowserThread::UI, FROM_HERE,
251 base::Bind(&UINetworkQualityEstimatorService:: 282 base::Bind(&UINetworkQualityEstimatorService::
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 344
314 std::map<net::nqe::internal::NetworkID, 345 std::map<net::nqe::internal::NetworkID,
315 net::nqe::internal::CachedNetworkQuality> 346 net::nqe::internal::CachedNetworkQuality>
316 UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const { 347 UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const {
317 if (!prefs_manager_) { 348 if (!prefs_manager_) {
318 return std::map<net::nqe::internal::NetworkID, 349 return std::map<net::nqe::internal::NetworkID,
319 net::nqe::internal::CachedNetworkQuality>(); 350 net::nqe::internal::CachedNetworkQuality>();
320 } 351 }
321 return prefs_manager_->ForceReadPrefsForTesting(); 352 return prefs_manager_->ForceReadPrefsForTesting();
322 } 353 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698