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 |
(...skipping 19 matching lines...) Expand all Loading... |
30 : public KeyedService, | 30 : public KeyedService, |
31 public net::NetworkQualityEstimator::NetworkQualityProvider { | 31 public net::NetworkQualityEstimator::NetworkQualityProvider { |
32 public: | 32 public: |
33 explicit UINetworkQualityEstimatorService(Profile* profile); | 33 explicit UINetworkQualityEstimatorService(Profile* profile); |
34 ~UINetworkQualityEstimatorService() override; | 34 ~UINetworkQualityEstimatorService() override; |
35 | 35 |
36 // NetworkQualityProvider implementation: | 36 // NetworkQualityProvider implementation: |
37 // Must be called on the UI thread. | 37 // Must be called on the UI thread. |
38 net::EffectiveConnectionType GetEffectiveConnectionType() const override; | 38 net::EffectiveConnectionType GetEffectiveConnectionType() const override; |
39 // Must be called on the UI thread. |observer| will be notified on the UI | 39 // Must be called on the UI thread. |observer| will be notified on the UI |
40 // thread. | 40 // thread. |observer| would be notified of the current effective connection |
| 41 // type in the next message pump, if it is still registered as an observer. |
41 void AddEffectiveConnectionTypeObserver( | 42 void AddEffectiveConnectionTypeObserver( |
42 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) | 43 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) |
43 override; | 44 override; |
44 // Must be called on the UI thread. | 45 // Must be called on the UI thread. |
45 void RemoveEffectiveConnectionTypeObserver( | 46 void RemoveEffectiveConnectionTypeObserver( |
46 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) | 47 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) |
47 override; | 48 override; |
48 | 49 |
49 // Registers the profile-specific network quality estimator prefs. | 50 // Registers the profile-specific network quality estimator prefs. |
50 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 51 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
51 | 52 |
52 // Clear the network quality estimator prefs. | 53 // Clear the network quality estimator prefs. |
53 void ClearPrefs(); | 54 void ClearPrefs(); |
54 | 55 |
55 // Tests can manually set EffectiveConnectionType, but browser tests should | 56 // Tests can manually set EffectiveConnectionType, but browser tests should |
56 // expect that the EffectiveConnectionType could change. | 57 // expect that the EffectiveConnectionType could change. |
57 void SetEffectiveConnectionTypeForTesting(net::EffectiveConnectionType type); | 58 void SetEffectiveConnectionTypeForTesting(net::EffectiveConnectionType type); |
58 | 59 |
59 // Reads the prefs from the disk, parses them into a map of NetworkIDs and | 60 // Reads the prefs from the disk, parses them into a map of NetworkIDs and |
60 // CachedNetworkQualities, and returns the map. | 61 // CachedNetworkQualities, and returns the map. |
61 std::map<net::nqe::internal::NetworkID, | 62 std::map<net::nqe::internal::NetworkID, |
62 net::nqe::internal::CachedNetworkQuality> | 63 net::nqe::internal::CachedNetworkQuality> |
63 ForceReadPrefsForTesting() const; | 64 ForceReadPrefsForTesting() const; |
64 | 65 |
65 private: | 66 private: |
66 class IONetworkQualityObserver; | 67 class IONetworkQualityObserver; |
67 | 68 |
| 69 // Notifies |observer| of the current effective connection type if |observer| |
| 70 // is still registered as an observer. |
| 71 void NotifyEffectiveConnectionTypeObserverIfPresent( |
| 72 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) |
| 73 const; |
| 74 |
68 // KeyedService implementation: | 75 // KeyedService implementation: |
69 void Shutdown() override; | 76 void Shutdown() override; |
70 | 77 |
71 // Called when the EffectiveConnectionType has updated to |type|. | 78 // Called when the EffectiveConnectionType has updated to |type|. |
72 // NetworkQualityEstimator::EffectiveConnectionType is an estimate of the | 79 // NetworkQualityEstimator::EffectiveConnectionType is an estimate of the |
73 // quality of the network that may differ from the actual network type | 80 // quality of the network that may differ from the actual network type |
74 // reported by NetworkchangeNotifier::GetConnectionType. | 81 // reported by NetworkchangeNotifier::GetConnectionType. |
75 void EffectiveConnectionTypeChanged(net::EffectiveConnectionType type); | 82 void EffectiveConnectionTypeChanged(net::EffectiveConnectionType type); |
76 | 83 |
77 // The current EffectiveConnectionType. | 84 // The current EffectiveConnectionType. |
(...skipping 11 matching lines...) Expand all Loading... |
89 // Prefs manager that is owned by this service. Created on the UI thread, but | 96 // Prefs manager that is owned by this service. Created on the UI thread, but |
90 // used and deleted on the IO thread. | 97 // used and deleted on the IO thread. |
91 std::unique_ptr<net::NetworkQualitiesPrefsManager> prefs_manager_; | 98 std::unique_ptr<net::NetworkQualitiesPrefsManager> prefs_manager_; |
92 | 99 |
93 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_; | 100 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_; |
94 | 101 |
95 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService); | 102 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService); |
96 }; | 103 }; |
97 | 104 |
98 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ | 105 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ |
OLD | NEW |