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

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: some more IWYU fixes 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
42 // thread. |observer| would be notified of the current effective connection
43 // type in the next message pump.
44 void AddEffectiveConnectionTypeObserver( 43 void AddEffectiveConnectionTypeObserver(
45 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) 44 net::EffectiveConnectionTypeObserver* observer) override;
46 override;
47 // Must be called on the UI thread.
48 void RemoveEffectiveConnectionTypeObserver( 45 void RemoveEffectiveConnectionTypeObserver(
49 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) 46 net::EffectiveConnectionTypeObserver* observer) override;
50 override;
51 base::Optional<base::TimeDelta> GetHttpRTT() const override; 47 base::Optional<base::TimeDelta> GetHttpRTT() const override;
52 base::Optional<base::TimeDelta> GetTransportRTT() const override; 48 base::Optional<base::TimeDelta> GetTransportRTT() const override;
53 base::Optional<int32_t> GetDownstreamThroughputKbps() const override; 49 base::Optional<int32_t> GetDownstreamThroughputKbps() const override;
54
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,
57 // transport RTT or throughput. |observer| would be notified of the current
58 // values in the next message pump.
59 void AddRTTAndThroughputEstimatesObserver( 50 void AddRTTAndThroughputEstimatesObserver(
60 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) 51 net::RTTAndThroughputEstimatesObserver* observer) override;
61 override;
62
63 // Removes |observer| from the list of RTT and throughput estimate observers.
64 // Must be called on the UI thread.
65 void RemoveRTTAndThroughputEstimatesObserver( 52 void RemoveRTTAndThroughputEstimatesObserver(
66 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) 53 net::RTTAndThroughputEstimatesObserver* observer) override;
67 override;
68 54
69 // Registers the profile-specific network quality estimator prefs. 55 // Registers the profile-specific network quality estimator prefs.
70 static void RegisterProfilePrefs(PrefRegistrySimple* registry); 56 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
71 57
72 // Clear the network quality estimator prefs. 58 // Clear the network quality estimator prefs.
73 void ClearPrefs(); 59 void ClearPrefs();
74 60
75 // Tests can manually set EffectiveConnectionType, but browser tests should 61 // Tests can manually set EffectiveConnectionType, but browser tests should
76 // expect that the EffectiveConnectionType could change. 62 // expect that the EffectiveConnectionType could change.
77 void SetEffectiveConnectionTypeForTesting(net::EffectiveConnectionType type); 63 void SetEffectiveConnectionTypeForTesting(net::EffectiveConnectionType type);
78 64
79 // Reads the prefs from the disk, parses them into a map of NetworkIDs and 65 // Reads the prefs from the disk, parses them into a map of NetworkIDs and
80 // CachedNetworkQualities, and returns the map. 66 // CachedNetworkQualities, and returns the map.
81 std::map<net::nqe::internal::NetworkID, 67 std::map<net::nqe::internal::NetworkID,
82 net::nqe::internal::CachedNetworkQuality> 68 net::nqe::internal::CachedNetworkQuality>
83 ForceReadPrefsForTesting() const; 69 ForceReadPrefsForTesting() const;
84 70
85 private: 71 private:
86 class IONetworkQualityObserver; 72 class IONetworkQualityObserver;
87 73
88 // Notifies |observer| of the current effective connection type if |observer| 74 // Notifies |observer| of the current effective connection type if |observer|
89 // is still registered as an observer. 75 // is still registered as an observer.
90 void NotifyEffectiveConnectionTypeObserverIfPresent( 76 void NotifyEffectiveConnectionTypeObserverIfPresent(
91 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) 77 net::EffectiveConnectionTypeObserver* observer) const;
92 const;
93 78
94 // Notifies |observer| of the current effective connection type if |observer| 79 // Notifies |observer| of the current effective connection type if |observer|
95 // is still registered as an observer. 80 // is still registered as an observer.
96 void NotifyRTTAndThroughputObserverIfPresent( 81 void NotifyRTTAndThroughputObserverIfPresent(
97 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) 82 net::RTTAndThroughputEstimatesObserver* observer) const;
98 const;
99 83
100 // KeyedService implementation: 84 // KeyedService implementation:
101 void Shutdown() override; 85 void Shutdown() override;
102 86
103 // Called when the EffectiveConnectionType has updated to |type|. 87 // Called when the EffectiveConnectionType has updated to |type|.
104 // NetworkQualityEstimator::EffectiveConnectionType is an estimate of the 88 // NetworkQualityEstimator::EffectiveConnectionType is an estimate of the
105 // quality of the network that may differ from the actual network type 89 // quality of the network that may differ from the actual network type
106 // reported by NetworkchangeNotifier::GetConnectionType. 90 // reported by NetworkchangeNotifier::GetConnectionType.
107 void EffectiveConnectionTypeChanged(net::EffectiveConnectionType type); 91 void EffectiveConnectionTypeChanged(net::EffectiveConnectionType type);
108 92
109 // Called when the estimated HTTP RTT, estimated transport RTT or estimated 93 // Called when the estimated HTTP RTT, estimated transport RTT or estimated
110 // downstream throughput is computed. 94 // downstream throughput is computed.
111 void RTTOrThroughputComputed(base::TimeDelta http_rtt, 95 void RTTOrThroughputComputed(base::TimeDelta http_rtt,
112 base::TimeDelta transport_rtt, 96 base::TimeDelta transport_rtt,
113 int32_t downstream_throughput_kbps); 97 int32_t downstream_throughput_kbps);
114 98
115 // The current EffectiveConnectionType. 99 // The current EffectiveConnectionType.
116 net::EffectiveConnectionType type_; 100 net::EffectiveConnectionType type_;
117 101
118 // Current network quality metrics. 102 // Current network quality metrics.
119 base::TimeDelta http_rtt_; 103 base::TimeDelta http_rtt_;
120 base::TimeDelta transport_rtt_; 104 base::TimeDelta transport_rtt_;
121 int32_t downstream_throughput_kbps_; 105 int32_t downstream_throughput_kbps_;
122 106
123 // IO thread based observer that is owned by this service. Created on the UI 107 // IO thread based observer that is owned by this service. Created on the UI
124 // thread, but used and deleted on the IO thread. 108 // thread, but used and deleted on the IO thread.
125 std::unique_ptr<IONetworkQualityObserver> io_observer_; 109 std::unique_ptr<IONetworkQualityObserver> io_observer_;
126 110
127 // Observer list for changes in effective connection type. 111 // Observer list for changes in effective connection type.
128 base::ObserverList< 112 base::ObserverList<net::EffectiveConnectionTypeObserver>
129 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver>
130 effective_connection_type_observer_list_; 113 effective_connection_type_observer_list_;
131 114
132 // Observer list for changes in RTT or throughput values. 115 // Observer list for changes in RTT or throughput values.
133 base::ObserverList< 116 base::ObserverList<net::RTTAndThroughputEstimatesObserver>
134 net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver>
135 rtt_throughput_observer_list_; 117 rtt_throughput_observer_list_;
136 118
137 // Prefs manager that is owned by this service. Created on the UI thread, but 119 // Prefs manager that is owned by this service. Created on the UI thread, but
138 // used and deleted on the IO thread. 120 // used and deleted on the IO thread.
139 std::unique_ptr<net::NetworkQualitiesPrefsManager> prefs_manager_; 121 std::unique_ptr<net::NetworkQualitiesPrefsManager> prefs_manager_;
140 122
141 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_; 123 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_;
142 124
143 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService); 125 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService);
144 }; 126 };
145 127
146 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ 128 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.h ('k') | chrome/browser/net/nqe/ui_network_quality_estimator_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698