| 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 #ifndef CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ |
| 6 #define CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ | 6 #define CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 10 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
| 13 #include "net/nqe/cached_network_quality.h" |
| 11 #include "net/nqe/effective_connection_type.h" | 14 #include "net/nqe/effective_connection_type.h" |
| 15 #include "net/nqe/network_id.h" |
| 12 #include "net/nqe/network_quality_estimator.h" | 16 #include "net/nqe/network_quality_estimator.h" |
| 13 | 17 |
| 18 class PrefRegistrySimple; |
| 19 class Profile; |
| 20 |
| 21 namespace net { |
| 22 class NetworkQualitiesPrefsManager; |
| 23 } |
| 24 |
| 14 // UI service to determine the current EffectiveConnectionType. | 25 // UI service to determine the current EffectiveConnectionType. |
| 15 class UINetworkQualityEstimatorService | 26 class UINetworkQualityEstimatorService |
| 16 : public KeyedService, | 27 : public KeyedService, |
| 17 public net::NetworkQualityEstimator::NetworkQualityProvider { | 28 public net::NetworkQualityEstimator::NetworkQualityProvider { |
| 18 public: | 29 public: |
| 19 UINetworkQualityEstimatorService(); | 30 explicit UINetworkQualityEstimatorService(Profile* profile); |
| 20 ~UINetworkQualityEstimatorService() override; | 31 ~UINetworkQualityEstimatorService() override; |
| 21 | 32 |
| 33 // Registers the profile-specific network quality estimator prefs. |
| 34 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 35 |
| 22 // The current EffectiveConnectionType. | 36 // The current EffectiveConnectionType. |
| 23 net::EffectiveConnectionType GetEffectiveConnectionType() const override; | 37 net::EffectiveConnectionType GetEffectiveConnectionType() const override; |
| 24 | 38 |
| 25 // Tests can manually set EffectiveConnectionType, but browser tests should | 39 // Tests can manually set EffectiveConnectionType, but browser tests should |
| 26 // expect that the EffectiveConnectionType could change. | 40 // expect that the EffectiveConnectionType could change. |
| 27 void SetEffectiveConnectionTypeForTesting(net::EffectiveConnectionType type); | 41 void SetEffectiveConnectionTypeForTesting(net::EffectiveConnectionType type); |
| 28 | 42 |
| 43 // Reads the prefs from the disk, parses them into a map of NetworkIDs and |
| 44 // CachedNetworkQualities, and returns the map. |
| 45 std::map<net::nqe::internal::NetworkID, |
| 46 net::nqe::internal::CachedNetworkQuality> |
| 47 ForceReadPrefsForTesting() const; |
| 48 |
| 29 private: | 49 private: |
| 30 class IONetworkQualityObserver; | 50 class IONetworkQualityObserver; |
| 31 | 51 |
| 32 // KeyedService implementation: | 52 // KeyedService implementation: |
| 33 void Shutdown() override; | 53 void Shutdown() override; |
| 34 | 54 |
| 35 // Called when the EffectiveConnectionType has updated to |type|. | 55 // Called when the EffectiveConnectionType has updated to |type|. |
| 36 // NetworkQualityEstimator::EffectiveConnectionType is an estimate of the | 56 // NetworkQualityEstimator::EffectiveConnectionType is an estimate of the |
| 37 // quality of the network that may differ from the actual network type | 57 // quality of the network that may differ from the actual network type |
| 38 // reported by NetworkchangeNotifier::GetConnectionType. | 58 // reported by NetworkchangeNotifier::GetConnectionType. |
| 39 void EffectiveConnectionTypeChanged(net::EffectiveConnectionType type); | 59 void EffectiveConnectionTypeChanged(net::EffectiveConnectionType type); |
| 40 | 60 |
| 41 // The current EffectiveConnectionType. | 61 // The current EffectiveConnectionType. |
| 42 net::EffectiveConnectionType type_; | 62 net::EffectiveConnectionType type_; |
| 43 | 63 |
| 44 // IO thread based observer that is owned by this service. Created on the UI | 64 // IO thread based observer that is owned by this service. Created on the UI |
| 45 // thread, but used and deleted on the IO thread. | 65 // thread, but used and deleted on the IO thread. |
| 46 IONetworkQualityObserver* io_observer_; | 66 IONetworkQualityObserver* io_observer_; |
| 47 | 67 |
| 68 // Prefs manager that is owned by this service. Created on the UI thread, but |
| 69 // used and deleted on the IO thread. |
| 70 net::NetworkQualitiesPrefsManager* prefs_manager_; |
| 71 |
| 48 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_; | 72 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_; |
| 49 | 73 |
| 50 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService); | 74 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService); |
| 51 }; | 75 }; |
| 52 | 76 |
| 53 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ | 77 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ |
| OLD | NEW |