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