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

Side by Side Diff: chrome/browser/net/nqe/ui_network_quality_estimator_service.h

Issue 2927453002: Make NQE a derived class of NetworkQualityProvider (Closed)
Patch Set: ps Created 3 years, 6 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
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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/keyed_service/core/keyed_service.h"
18 #include "net/nqe/cached_network_quality.h" 18 #include "net/nqe/cached_network_quality.h"
19 #include "net/nqe/effective_connection_type.h" 19 #include "net/nqe/effective_connection_type.h"
20 #include "net/nqe/network_id.h" 20 #include "net/nqe/network_id.h"
21 #include "net/nqe/network_quality_estimator.h" 21 #include "net/nqe/network_quality_estimator.h"
22 22
23 class PrefRegistrySimple; 23 class PrefRegistrySimple;
24 class Profile; 24 class Profile;
25 25
26 namespace net { 26 namespace net {
27 class EffectiveConnectionTypeObserver;
27 class NetworkQualitiesPrefsManager; 28 class NetworkQualitiesPrefsManager;
29 class RTTAndThroughputEstimatesObserver;
28 } 30 }
29 31
30 // UI service to determine the current EffectiveConnectionType. 32 // UI service to determine the current EffectiveConnectionType.
31 class UINetworkQualityEstimatorService 33 class UINetworkQualityEstimatorService
32 : public KeyedService, 34 : public KeyedService,
33 public net::NetworkQualityEstimator::NetworkQualityProvider { 35 public net::NetworkQualityEstimator::NetworkQualityProvider {
34 public: 36 public:
35 explicit UINetworkQualityEstimatorService(Profile* profile); 37 explicit UINetworkQualityEstimatorService(Profile* profile);
36 ~UINetworkQualityEstimatorService() override; 38 ~UINetworkQualityEstimatorService() override;
37 39
38 // NetworkQualityProvider implementation: 40 // NetworkQualityProvider implementation:
39 // Must be called on the UI thread. 41 // Must be called on the UI thread.
40 net::EffectiveConnectionType GetEffectiveConnectionType() const override; 42 net::EffectiveConnectionType GetEffectiveConnectionType() const override;
41 // Must be called on the UI thread. |observer| will be notified on the UI 43 // Must be called on the UI thread. |observer| will be notified on the UI
42 // thread. |observer| would be notified of the current effective connection 44 // thread. |observer| would be notified of the current effective connection
43 // type in the next message pump. 45 // type in the next message pump.
44 void AddEffectiveConnectionTypeObserver( 46 void AddEffectiveConnectionTypeObserver(
45 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) 47 net::EffectiveConnectionTypeObserver* observer) override;
46 override;
47 // Must be called on the UI thread. 48 // Must be called on the UI thread.
48 void RemoveEffectiveConnectionTypeObserver( 49 void RemoveEffectiveConnectionTypeObserver(
49 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) 50 net::EffectiveConnectionTypeObserver* observer) override;
50 override;
51 base::Optional<base::TimeDelta> GetHttpRTT() const override; 51 base::Optional<base::TimeDelta> GetHttpRTT() const override;
52 base::Optional<base::TimeDelta> GetTransportRTT() const override; 52 base::Optional<base::TimeDelta> GetTransportRTT() const override;
53 base::Optional<int32_t> GetDownstreamThroughputKbps() const override; 53 base::Optional<int32_t> GetDownstreamThroughputKbps() const override;
54 54
55 // Must be called on the UI thread. |observer| will be notified on the UI 55 // Must be called on the UI thread. |observer| will be notified on the UI
56 // thread. |observer| would be notified of the changes in the HTTP RTT, 56 // thread. |observer| would be notified of the changes in the HTTP RTT,
57 // transport RTT or throughput. |observer| would be notified of the current 57 // transport RTT or throughput. |observer| would be notified of the current
58 // values in the next message pump. 58 // values in the next message pump.
59 void AddRTTAndThroughputEstimatesObserver( 59 void AddRTTAndThroughputEstimatesObserver(
60 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) 60 net::RTTAndThroughputEstimatesObserver* observer) override;
61 override;
62 61
63 // Removes |observer| from the list of RTT and throughput estimate observers. 62 // Removes |observer| from the list of RTT and throughput estimate observers.
64 // Must be called on the UI thread. 63 // Must be called on the UI thread.
65 void RemoveRTTAndThroughputEstimatesObserver( 64 void RemoveRTTAndThroughputEstimatesObserver(
66 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) 65 net::RTTAndThroughputEstimatesObserver* observer) override;
67 override;
68 66
69 // Registers the profile-specific network quality estimator prefs. 67 // Registers the profile-specific network quality estimator prefs.
70 static void RegisterProfilePrefs(PrefRegistrySimple* registry); 68 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
71 69
72 // Clear the network quality estimator prefs. 70 // Clear the network quality estimator prefs.
73 void ClearPrefs(); 71 void ClearPrefs();
74 72
75 // Tests can manually set EffectiveConnectionType, but browser tests should 73 // Tests can manually set EffectiveConnectionType, but browser tests should
76 // expect that the EffectiveConnectionType could change. 74 // expect that the EffectiveConnectionType could change.
77 void SetEffectiveConnectionTypeForTesting(net::EffectiveConnectionType type); 75 void SetEffectiveConnectionTypeForTesting(net::EffectiveConnectionType type);
78 76
79 // Reads the prefs from the disk, parses them into a map of NetworkIDs and 77 // Reads the prefs from the disk, parses them into a map of NetworkIDs and
80 // CachedNetworkQualities, and returns the map. 78 // CachedNetworkQualities, and returns the map.
81 std::map<net::nqe::internal::NetworkID, 79 std::map<net::nqe::internal::NetworkID,
82 net::nqe::internal::CachedNetworkQuality> 80 net::nqe::internal::CachedNetworkQuality>
83 ForceReadPrefsForTesting() const; 81 ForceReadPrefsForTesting() const;
84 82
85 private: 83 private:
86 class IONetworkQualityObserver; 84 class IONetworkQualityObserver;
87 85
88 // Notifies |observer| of the current effective connection type if |observer| 86 // Notifies |observer| of the current effective connection type if |observer|
89 // is still registered as an observer. 87 // is still registered as an observer.
90 void NotifyEffectiveConnectionTypeObserverIfPresent( 88 void NotifyEffectiveConnectionTypeObserverIfPresent(
91 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) 89 net::EffectiveConnectionTypeObserver* observer) const;
92 const;
93 90
94 // Notifies |observer| of the current effective connection type if |observer| 91 // Notifies |observer| of the current effective connection type if |observer|
95 // is still registered as an observer. 92 // is still registered as an observer.
96 void NotifyRTTAndThroughputObserverIfPresent( 93 void NotifyRTTAndThroughputObserverIfPresent(
97 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) 94 net::RTTAndThroughputEstimatesObserver* observer) const;
98 const;
99 95
100 // KeyedService implementation: 96 // KeyedService implementation:
101 void Shutdown() override; 97 void Shutdown() override;
102 98
103 // Called when the EffectiveConnectionType has updated to |type|. 99 // Called when the EffectiveConnectionType has updated to |type|.
104 // NetworkQualityEstimator::EffectiveConnectionType is an estimate of the 100 // NetworkQualityEstimator::EffectiveConnectionType is an estimate of the
105 // quality of the network that may differ from the actual network type 101 // quality of the network that may differ from the actual network type
106 // reported by NetworkchangeNotifier::GetConnectionType. 102 // reported by NetworkchangeNotifier::GetConnectionType.
107 void EffectiveConnectionTypeChanged(net::EffectiveConnectionType type); 103 void EffectiveConnectionTypeChanged(net::EffectiveConnectionType type);
108 104
109 // Called when the estimated HTTP RTT, estimated transport RTT or estimated 105 // Called when the estimated HTTP RTT, estimated transport RTT or estimated
110 // downstream throughput is computed. 106 // downstream throughput is computed.
111 void RTTOrThroughputComputed(base::TimeDelta http_rtt, 107 void RTTOrThroughputComputed(base::TimeDelta http_rtt,
112 base::TimeDelta transport_rtt, 108 base::TimeDelta transport_rtt,
113 int32_t downstream_throughput_kbps); 109 int32_t downstream_throughput_kbps);
114 110
115 // The current EffectiveConnectionType. 111 // The current EffectiveConnectionType.
116 net::EffectiveConnectionType type_; 112 net::EffectiveConnectionType type_;
117 113
118 // Current network quality metrics. 114 // Current network quality metrics.
119 base::TimeDelta http_rtt_; 115 base::TimeDelta http_rtt_;
120 base::TimeDelta transport_rtt_; 116 base::TimeDelta transport_rtt_;
121 int32_t downstream_throughput_kbps_; 117 int32_t downstream_throughput_kbps_;
122 118
123 // IO thread based observer that is owned by this service. Created on the UI 119 // IO thread based observer that is owned by this service. Created on the UI
124 // thread, but used and deleted on the IO thread. 120 // thread, but used and deleted on the IO thread.
125 std::unique_ptr<IONetworkQualityObserver> io_observer_; 121 std::unique_ptr<IONetworkQualityObserver> io_observer_;
126 122
127 // Observer list for changes in effective connection type. 123 // Observer list for changes in effective connection type.
128 base::ObserverList< 124 base::ObserverList<net::EffectiveConnectionTypeObserver>
129 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver>
130 effective_connection_type_observer_list_; 125 effective_connection_type_observer_list_;
131 126
132 // Observer list for changes in RTT or throughput values. 127 // Observer list for changes in RTT or throughput values.
133 base::ObserverList< 128 base::ObserverList<net::RTTAndThroughputEstimatesObserver>
134 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver>
135 rtt_throughput_observer_list_; 129 rtt_throughput_observer_list_;
136 130
137 // Prefs manager that is owned by this service. Created on the UI thread, but 131 // Prefs manager that is owned by this service. Created on the UI thread, but
138 // used and deleted on the IO thread. 132 // used and deleted on the IO thread.
139 std::unique_ptr<net::NetworkQualitiesPrefsManager> prefs_manager_; 133 std::unique_ptr<net::NetworkQualitiesPrefsManager> prefs_manager_;
140 134
141 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_; 135 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_;
142 136
143 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService); 137 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService);
144 }; 138 };
145 139
146 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ 140 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698