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 // Returns the network quality estimator. May be nullptr. |
| 39 virtual net::NetworkQualityEstimator* GetNetworkQualityEstimator() = 0; |
| 40 |
| 41 // Returns the task runner on which |this| should be used and destroyed. |
| 42 virtual scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() = 0; |
| 43 |
| 44 protected: |
| 45 NetworkQualityEstimatorProvider() {} |
| 46 |
| 47 private: |
| 48 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimatorProvider); |
| 49 }; |
| 50 |
27 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post | 51 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post |
28 // network info collection tasks. | 52 // network info collection tasks. |
29 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); | 53 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); |
| 54 |
| 55 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post |
| 56 // network info collection tasks. |network_quality_estimator_provider| |
| 57 // should be set if it is useful to attach the quality of the network to the |
| 58 // metrics report. |
| 59 NetworkMetricsProvider(std::unique_ptr<NetworkQualityEstimatorProvider> |
| 60 network_quality_estimator_provider, |
| 61 base::TaskRunner* io_task_runner); |
| 62 |
30 ~NetworkMetricsProvider() override; | 63 ~NetworkMetricsProvider() override; |
31 | 64 |
32 private: | 65 private: |
| 66 FRIEND_TEST_ALL_PREFIXES(NetworkMetricsProviderTest, EffectiveConnectionType); |
| 67 |
| 68 // Listens to the changes in the effective conection type. |
| 69 class EffectiveConnectionTypeObserver; |
| 70 |
33 // MetricsProvider: | 71 // MetricsProvider: |
34 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; | 72 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
35 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override; | 73 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override; |
36 | 74 |
37 // ConnectionTypeObserver: | 75 // ConnectionTypeObserver: |
38 void OnConnectionTypeChanged( | 76 void OnConnectionTypeChanged( |
39 net::NetworkChangeNotifier::ConnectionType type) override; | 77 net::NetworkChangeNotifier::ConnectionType type) override; |
40 | 78 |
41 SystemProfileProto::Network::ConnectionType GetConnectionType() const; | 79 SystemProfileProto::Network::ConnectionType GetConnectionType() const; |
42 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol() | 80 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol() |
43 const; | 81 const; |
| 82 SystemProfileProto::Network::EffectiveConnectionType |
| 83 GetEffectiveConnectionType() const; |
44 | 84 |
45 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool. | 85 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool. |
46 void ProbeWifiPHYLayerProtocol(); | 86 void ProbeWifiPHYLayerProtocol(); |
47 // Callback from the blocking pool with the result of | 87 // Callback from the blocking pool with the result of |
48 // net::GetWifiPHYLayerProtocol. | 88 // net::GetWifiPHYLayerProtocol. |
49 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode); | 89 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode); |
50 | 90 |
51 // Writes info about the wireless access points that this system is | 91 // Writes info about the wireless access points that this system is |
52 // connected to. | 92 // connected to. |
53 void WriteWifiAccessPointProto( | 93 void WriteWifiAccessPointProto( |
54 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, | 94 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, |
55 SystemProfileProto::Network* network_proto); | 95 SystemProfileProto::Network* network_proto); |
56 | 96 |
57 // Logs metrics that are functions of other metrics being uploaded. | 97 // Logs metrics that are functions of other metrics being uploaded. |
58 void LogAggregatedMetrics(); | 98 void LogAggregatedMetrics(); |
59 | 99 |
| 100 // Notifies |this| that the effective connection type of the current network |
| 101 // has changed to |type|. |
| 102 void OnEffectiveConnectionTypeChanged(net::EffectiveConnectionType type); |
| 103 |
60 // Task runner used for blocking file I/O. | 104 // Task runner used for blocking file I/O. |
61 base::TaskRunner* io_task_runner_; | 105 base::TaskRunner* io_task_runner_; |
62 | 106 |
63 // True if |connection_type_| changed during the lifetime of the log. | 107 // True if |connection_type_| changed during the lifetime of the log. |
64 bool connection_type_is_ambiguous_; | 108 bool connection_type_is_ambiguous_; |
65 // The connection type according to net::NetworkChangeNotifier. | 109 // The connection type according to net::NetworkChangeNotifier. |
66 net::NetworkChangeNotifier::ConnectionType connection_type_; | 110 net::NetworkChangeNotifier::ConnectionType connection_type_; |
67 | 111 |
68 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log. | 112 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log. |
69 bool wifi_phy_layer_protocol_is_ambiguous_; | 113 bool wifi_phy_layer_protocol_is_ambiguous_; |
70 // The PHY mode of the currently associated access point obtained via | 114 // The PHY mode of the currently associated access point obtained via |
71 // net::GetWifiPHYLayerProtocol. | 115 // net::GetWifiPHYLayerProtocol. |
72 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_; | 116 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_; |
73 | 117 |
74 // Helper object for retrieving connected wifi access point information. | 118 // Helper object for retrieving connected wifi access point information. |
75 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_; | 119 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_; |
76 | 120 |
77 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3 | 121 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3 |
78 // histogram. They are used to compute deltas at upload time. | 122 // histogram. They are used to compute deltas at upload time. |
79 base::HistogramBase::Count total_aborts_; | 123 base::HistogramBase::Count total_aborts_; |
80 base::HistogramBase::Count total_codes_; | 124 base::HistogramBase::Count total_codes_; |
81 | 125 |
| 126 // Provides the network quality estimator. May be null. |
| 127 std::unique_ptr<NetworkQualityEstimatorProvider> |
| 128 network_quality_estimator_provider_; |
| 129 |
| 130 // Listens to the changes in the effective connection type. Initialized and |
| 131 // destroyed using |network_quality_task_runner_|. May be null. |
| 132 std::unique_ptr<EffectiveConnectionTypeObserver> |
| 133 effective_connection_type_observer_; |
| 134 |
| 135 // Task runner using which |effective_connection_type_observer_| is |
| 136 // initialized and destroyed. May be null. |
| 137 scoped_refptr<base::SequencedTaskRunner> network_quality_task_runner_; |
| 138 |
| 139 // Last known effective connection type. |
| 140 net::EffectiveConnectionType effective_connection_type_; |
| 141 |
| 142 // True if |effective_connection_type_| changed during the lifetime of the |
| 143 // log. |
| 144 bool effective_connection_type_is_ambiguous_; |
| 145 |
| 146 base::ThreadChecker thread_checker_; |
| 147 |
82 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_; | 148 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_; |
83 | 149 |
84 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider); | 150 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider); |
85 }; | 151 }; |
86 | 152 |
87 } // namespace metrics | 153 } // namespace metrics |
88 | 154 |
89 #endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ | 155 #endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ |
OLD | NEW |