OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ | 5 #ifndef COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ |
6 #define COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ | 6 #define COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/metrics/histogram_base.h" | 12 #include "base/metrics/histogram_base.h" |
13 #include "base/threading/thread_checker.h" | |
13 #include "components/metrics/metrics_provider.h" | 14 #include "components/metrics/metrics_provider.h" |
14 #include "components/metrics/net/wifi_access_point_info_provider.h" | 15 #include "components/metrics/net/wifi_access_point_info_provider.h" |
15 #include "components/metrics/proto/system_profile.pb.h" | 16 #include "components/metrics/proto/system_profile.pb.h" |
16 #include "net/base/network_change_notifier.h" | 17 #include "net/base/network_change_notifier.h" |
17 #include "net/base/network_interfaces.h" | 18 #include "net/base/network_interfaces.h" |
19 #include "net/nqe/effective_connection_type.h" | |
20 | |
21 namespace net { | |
22 class NetworkQualityEstimator; | |
23 } | |
18 | 24 |
19 namespace metrics { | 25 namespace metrics { |
20 | 26 |
21 // Registers as observer with net::NetworkChangeNotifier and keeps track of | 27 // Registers as observer with net::NetworkChangeNotifier and keeps track of |
22 // the network environment. | 28 // the network environment. |
23 class NetworkMetricsProvider | 29 class NetworkMetricsProvider |
24 : public MetricsProvider, | 30 : public MetricsProvider, |
25 public net::NetworkChangeNotifier::ConnectionTypeObserver { | 31 public net::NetworkChangeNotifier::ConnectionTypeObserver { |
26 public: | 32 public: |
33 // Class that provides |this| with the network quality estimator. | |
34 class NetworkQualityEstimatorProvider { | |
35 public: | |
36 virtual ~NetworkQualityEstimatorProvider() {} | |
37 | |
38 // Synchronously provides network quality estimator by calling |callback|. | |
39 // |callback| is run synchronously on the same task runner on which | |
40 // ProvideEstimator() was called. | |
41 virtual void ProvideEstimator( | |
42 const base::Callback<void(net::NetworkQualityEstimator*)>& | |
43 callback) = 0; | |
Alexei Svitkine (slow)
2017/01/04 20:54:21
Can it simply return the NetworkQualityEstimator*
tbansal1
2017/01/04 21:24:19
Done.
| |
44 | |
45 // Returns the task runner on which |this| should be used and destroyed. | |
46 virtual scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() = 0; | |
47 | |
48 protected: | |
49 NetworkQualityEstimatorProvider() {} | |
50 | |
51 private: | |
52 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimatorProvider); | |
53 }; | |
54 | |
27 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post | 55 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post |
28 // network info collection tasks. | 56 // network info collection tasks. |
29 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); | 57 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); |
58 | |
59 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post | |
60 // network info collection tasks. |network_quality_estimator_provider| | |
61 // should be set if it is useful to attach the quality of the network to the | |
62 // metrics report. | |
63 NetworkMetricsProvider(std::unique_ptr<NetworkQualityEstimatorProvider> | |
64 network_quality_estimator_provider, | |
65 base::TaskRunner* io_task_runner); | |
66 | |
30 ~NetworkMetricsProvider() override; | 67 ~NetworkMetricsProvider() override; |
31 | 68 |
32 private: | 69 private: |
70 FRIEND_TEST_ALL_PREFIXES(NetworkMetricsProviderTest, EffectiveConnectionType); | |
71 | |
72 // Listens to the changes in the effective conection type. | |
73 class EffectiveConnectionTypeObserver; | |
74 | |
33 // MetricsProvider: | 75 // MetricsProvider: |
34 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; | 76 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
35 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override; | 77 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override; |
36 | 78 |
37 // ConnectionTypeObserver: | 79 // ConnectionTypeObserver: |
38 void OnConnectionTypeChanged( | 80 void OnConnectionTypeChanged( |
39 net::NetworkChangeNotifier::ConnectionType type) override; | 81 net::NetworkChangeNotifier::ConnectionType type) override; |
40 | 82 |
41 SystemProfileProto::Network::ConnectionType GetConnectionType() const; | 83 SystemProfileProto::Network::ConnectionType GetConnectionType() const; |
42 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol() | 84 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol() |
43 const; | 85 const; |
86 SystemProfileProto::Network::EffectiveConnectionType | |
87 GetEffectiveConnectionType() const; | |
44 | 88 |
45 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool. | 89 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool. |
46 void ProbeWifiPHYLayerProtocol(); | 90 void ProbeWifiPHYLayerProtocol(); |
47 // Callback from the blocking pool with the result of | 91 // Callback from the blocking pool with the result of |
48 // net::GetWifiPHYLayerProtocol. | 92 // net::GetWifiPHYLayerProtocol. |
49 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode); | 93 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode); |
50 | 94 |
51 // Writes info about the wireless access points that this system is | 95 // Writes info about the wireless access points that this system is |
52 // connected to. | 96 // connected to. |
53 void WriteWifiAccessPointProto( | 97 void WriteWifiAccessPointProto( |
54 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, | 98 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, |
55 SystemProfileProto::Network* network_proto); | 99 SystemProfileProto::Network* network_proto); |
56 | 100 |
57 // Logs metrics that are functions of other metrics being uploaded. | 101 // Logs metrics that are functions of other metrics being uploaded. |
58 void LogAggregatedMetrics(); | 102 void LogAggregatedMetrics(); |
59 | 103 |
104 // Notifies |this| that the effective connection type of the current network | |
105 // has changed to |type|. | |
106 void OnEffectiveConnectionTypeChanged(net::EffectiveConnectionType type); | |
107 | |
60 // Task runner used for blocking file I/O. | 108 // Task runner used for blocking file I/O. |
61 base::TaskRunner* io_task_runner_; | 109 base::TaskRunner* io_task_runner_; |
62 | 110 |
63 // True if |connection_type_| changed during the lifetime of the log. | 111 // True if |connection_type_| changed during the lifetime of the log. |
64 bool connection_type_is_ambiguous_; | 112 bool connection_type_is_ambiguous_; |
65 // The connection type according to net::NetworkChangeNotifier. | 113 // The connection type according to net::NetworkChangeNotifier. |
66 net::NetworkChangeNotifier::ConnectionType connection_type_; | 114 net::NetworkChangeNotifier::ConnectionType connection_type_; |
67 | 115 |
68 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log. | 116 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log. |
69 bool wifi_phy_layer_protocol_is_ambiguous_; | 117 bool wifi_phy_layer_protocol_is_ambiguous_; |
70 // The PHY mode of the currently associated access point obtained via | 118 // The PHY mode of the currently associated access point obtained via |
71 // net::GetWifiPHYLayerProtocol. | 119 // net::GetWifiPHYLayerProtocol. |
72 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_; | 120 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_; |
73 | 121 |
74 // Helper object for retrieving connected wifi access point information. | 122 // Helper object for retrieving connected wifi access point information. |
75 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_; | 123 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_; |
76 | 124 |
77 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3 | 125 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3 |
78 // histogram. They are used to compute deltas at upload time. | 126 // histogram. They are used to compute deltas at upload time. |
79 base::HistogramBase::Count total_aborts_; | 127 base::HistogramBase::Count total_aborts_; |
80 base::HistogramBase::Count total_codes_; | 128 base::HistogramBase::Count total_codes_; |
81 | 129 |
130 // Provides the network quality estimator. May be null. | |
131 std::unique_ptr<NetworkQualityEstimatorProvider> | |
132 network_quality_estimator_provider_; | |
133 | |
134 // Listens to the changes in the effective connection type. Initialized and | |
135 // destroyed using |network_quality_task_runner_|. May be null. | |
136 std::unique_ptr<EffectiveConnectionTypeObserver> | |
137 effective_connection_type_observer_; | |
138 | |
139 // Task runner using which |effective_connection_type_observer_| is | |
140 // initialized and destroyed. May be null. | |
141 scoped_refptr<base::SequencedTaskRunner> network_quality_task_runner_; | |
142 | |
143 // Last known effective connection type. | |
144 net::EffectiveConnectionType effective_connection_type_; | |
145 | |
146 // True if |effective_connection_type_| changed during the lifetime of the | |
147 // log. | |
148 bool effective_connection_type_is_ambiguous_; | |
149 | |
150 base::ThreadChecker thread_checker_; | |
151 | |
82 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_; | 152 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_; |
83 | 153 |
84 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider); | 154 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider); |
85 }; | 155 }; |
86 | 156 |
87 } // namespace metrics | 157 } // namespace metrics |
88 | 158 |
89 #endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ | 159 #endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ |
OLD | NEW |