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

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

Issue 2103323007: Exposing NQE on the Browser UI thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/net/nqe/io_network_quality_observer.h"
6
7 #include "base/bind.h"
8 #include "base/task_runner.h"
9 #include "chrome/browser/io_thread.h"
10 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
11
12 IONetworkQualityObserver::IONetworkQualityObserver(
13 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
14 base::WeakPtr<UINetworkQualityEstimatorService> service)
15 : ui_task_runner_(ui_task_runner), service_(service) {
16 }
17
18 IONetworkQualityObserver::~IONetworkQualityObserver() {
19 if (network_quality_estimator_)
20 network_quality_estimator_->RemoveEffectiveConnectionTypeObserver(this);
21 }
22
23 void IONetworkQualityObserver::InitializeOnIOThread(IOThread* io_thread) {
24 DCHECK(io_thread->globals()->network_quality_estimator);
tbansal1 2016/07/01 22:22:02 Is it guaranteed that nqe will be initialized when
RyanSturm 2016/07/11 22:00:19 Acknowledged.
25 network_quality_estimator_ =
26 io_thread->globals()->network_quality_estimator->GetWeakPtr();
27 network_quality_estimator_->AddEffectiveConnectionTypeObserver(this);
28 ui_task_runner_->PostTask(
29 FROM_HERE,
30 base::Bind(
31 &UINetworkQualityEstimatorService::EffectiveConnectionTypeChanged,
32 service_, network_quality_estimator_->GetEffectiveConnectionType()));
33 }
34
35 void IONetworkQualityObserver::OnEffectiveConnectionTypeChanged(
36 net::NetworkQualityEstimator::EffectiveConnectionType type) {
37 ui_task_runner_->PostTask(
38 FROM_HERE,
39 base::Bind(
40 &UINetworkQualityEstimatorService::EffectiveConnectionTypeChanged,
41 service_, type));
42 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698