OLD | NEW |
(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 #ifndef CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ |
| 6 #define CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 14 #include "components/keyed_service/core/keyed_service.h" |
| 15 #include "net/nqe/network_quality_estimator.h" |
| 16 |
| 17 class Profile; |
| 18 |
| 19 namespace chrome_browser_net { |
| 20 |
| 21 // UI service to determine the current EffectiveConnectionType. |
| 22 class UINetworkQualityEstimatorService : public KeyedService { |
| 23 public: |
| 24 explicit UINetworkQualityEstimatorService(Profile* profile); |
| 25 ~UINetworkQualityEstimatorService() override; |
| 26 |
| 27 // KeyedService implementation: |
| 28 void Shutdown() override; |
| 29 |
| 30 // Called when the EffectiveConnectionType has updated to |type|. |
| 31 void EffectiveConnectionTypeChanged( |
| 32 net::NetworkQualityEstimator::EffectiveConnectionType type); |
| 33 |
| 34 // Creates |io_observer_|, and posts a task to initialize it. |
| 35 void Initialize( |
| 36 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| 37 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 38 |
| 39 // The current EffectiveConnectionType. |
| 40 net::NetworkQualityEstimator::EffectiveConnectionType type() const; |
| 41 |
| 42 private: |
| 43 class IONetworkQualityObserver; |
| 44 |
| 45 // The current EffectiveConnectionType. |
| 46 net::NetworkQualityEstimator::EffectiveConnectionType type_; |
| 47 |
| 48 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 49 |
| 50 // IO thread based observer that is owned by this service. Created on the UI |
| 51 // thread, but used and deleted on the IO thread. |
| 52 IONetworkQualityObserver* io_observer_; |
| 53 base::ThreadChecker thread_checker_; |
| 54 |
| 55 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService); |
| 58 }; |
| 59 |
| 60 } // namespace chrome_browser_net |
| 61 |
| 62 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ |
OLD | NEW |