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

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: ryansturm comments 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 base::Optional<base::TimeDelta> UINetworkQualityEstimatorService::GetHttpRTT()
244 const {
245 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
246
247 if (http_rtt_ == net::nqe::internal::InvalidRTT())
248 return base::Optional<base::TimeDelta>();
249 return http_rtt_;
250 }
251
252 base::Optional<base::TimeDelta>
253 UINetworkQualityEstimatorService::GetTransportRTT() const {
254 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
255
256 if (transport_rtt_ == net::nqe::internal::InvalidRTT())
257 return base::Optional<base::TimeDelta>();
258 return transport_rtt_;
259 }
260
261 base::Optional<int32_t>
262 UINetworkQualityEstimatorService::GetDownstreamThroughputKbps() const {
263 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
264
265 if (downstream_throughput_kbps_ == net::nqe::internal::kInvalidThroughput)
266 return base::Optional<int32_t>();
267 return downstream_throughput_kbps_;
268 }
269
242 void UINetworkQualityEstimatorService::AddRTTAndThroughputEstimatesObserver( 270 void UINetworkQualityEstimatorService::AddRTTAndThroughputEstimatesObserver(
243 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) { 271 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) {
244 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 272 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
245 rtt_throughput_observer_list_.AddObserver(observer); 273 rtt_throughput_observer_list_.AddObserver(observer);
246 274
247 // Notify the |observer| on the next message pump since |observer| may not 275 // Notify the |observer| on the next message pump since |observer| may not
248 // be completely set up for receiving the callbacks. 276 // be completely set up for receiving the callbacks.
249 content::BrowserThread::PostTask( 277 content::BrowserThread::PostTask(
250 content::BrowserThread::UI, FROM_HERE, 278 content::BrowserThread::UI, FROM_HERE,
251 base::Bind(&UINetworkQualityEstimatorService:: 279 base::Bind(&UINetworkQualityEstimatorService::
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 341
314 std::map<net::nqe::internal::NetworkID, 342 std::map<net::nqe::internal::NetworkID,
315 net::nqe::internal::CachedNetworkQuality> 343 net::nqe::internal::CachedNetworkQuality>
316 UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const { 344 UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const {
317 if (!prefs_manager_) { 345 if (!prefs_manager_) {
318 return std::map<net::nqe::internal::NetworkID, 346 return std::map<net::nqe::internal::NetworkID,
319 net::nqe::internal::CachedNetworkQuality>(); 347 net::nqe::internal::CachedNetworkQuality>();
320 } 348 }
321 return prefs_manager_->ForceReadPrefsForTesting(); 349 return prefs_manager_->ForceReadPrefsForTesting();
322 } 350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698