[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
gunsch | 043f360 | 2014-09-11 21:05:03 | [diff] [blame] | 5 | #ifndef COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ |
6 | #define COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ | ||||
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 7 | |
dcheng | d99c42a | 2016-04-21 21:54:13 | [diff] [blame^] | 8 | #include <memory> |
9 | |||||
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 11 | #include "base/memory/weak_ptr.h" |
csharrison | 305ab90 | 2016-03-17 19:51:27 | [diff] [blame] | 12 | #include "base/metrics/histogram_base.h" |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 13 | #include "components/metrics/metrics_provider.h" |
gunsch | 043f360 | 2014-09-11 21:05:03 | [diff] [blame] | 14 | #include "components/metrics/net/wifi_access_point_info_provider.h" |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 15 | #include "components/metrics/proto/system_profile.pb.h" |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 16 | #include "net/base/network_change_notifier.h" |
olli.raula | 80a44be | 2015-09-01 07:41:53 | [diff] [blame] | 17 | #include "net/base/network_interfaces.h" |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 18 | |
asvitkine | a63d19e | 2014-10-24 16:19:39 | [diff] [blame] | 19 | namespace metrics { |
20 | |||||
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 21 | // Registers as observer with net::NetworkChangeNotifier and keeps track of |
22 | // the network environment. | ||||
23 | class NetworkMetricsProvider | ||||
asvitkine | a63d19e | 2014-10-24 16:19:39 | [diff] [blame] | 24 | : public MetricsProvider, |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 25 | public net::NetworkChangeNotifier::ConnectionTypeObserver { |
26 | public: | ||||
gunsch | 043f360 | 2014-09-11 21:05:03 | [diff] [blame] | 27 | // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post |
28 | // network info collection tasks. | ||||
29 | explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); | ||||
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 30 | ~NetworkMetricsProvider() override; |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 31 | |
asvitkine | bbde62b | 2014-09-03 16:33:21 | [diff] [blame] | 32 | private: |
asvitkine | a63d19e | 2014-10-24 16:19:39 | [diff] [blame] | 33 | // MetricsProvider: |
bmcquade | 3f55de79 | 2016-02-26 22:10:37 | [diff] [blame] | 34 | void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
asvitkine | a63d19e | 2014-10-24 16:19:39 | [diff] [blame] | 35 | void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override; |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 36 | |
37 | // ConnectionTypeObserver: | ||||
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 38 | void OnConnectionTypeChanged( |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 39 | net::NetworkChangeNotifier::ConnectionType type) override; |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 40 | |
asvitkine | a63d19e | 2014-10-24 16:19:39 | [diff] [blame] | 41 | SystemProfileProto::Network::ConnectionType GetConnectionType() const; |
42 | SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol() | ||||
43 | const; | ||||
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 44 | |
45 | // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool. | ||||
46 | void ProbeWifiPHYLayerProtocol(); | ||||
47 | // Callback from the blocking pool with the result of | ||||
48 | // net::GetWifiPHYLayerProtocol. | ||||
49 | void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode); | ||||
50 | |||||
[email protected] | 2434789 | 2014-08-18 20:12:07 | [diff] [blame] | 51 | // Writes info about the wireless access points that this system is |
52 | // connected to. | ||||
53 | void WriteWifiAccessPointProto( | ||||
54 | const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, | ||||
asvitkine | a63d19e | 2014-10-24 16:19:39 | [diff] [blame] | 55 | SystemProfileProto::Network* network_proto); |
[email protected] | 2434789 | 2014-08-18 20:12:07 | [diff] [blame] | 56 | |
csharrison | 305ab90 | 2016-03-17 19:51:27 | [diff] [blame] | 57 | // Logs metrics that are functions of other metrics being uploaded. |
58 | void LogAggregatedMetrics(); | ||||
59 | |||||
gunsch | 043f360 | 2014-09-11 21:05:03 | [diff] [blame] | 60 | // Task runner used for blocking file I/O. |
61 | base::TaskRunner* io_task_runner_; | ||||
62 | |||||
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 63 | // True if |connection_type_| changed during the lifetime of the log. |
64 | bool connection_type_is_ambiguous_; | ||||
65 | // The connection type according to net::NetworkChangeNotifier. | ||||
66 | net::NetworkChangeNotifier::ConnectionType connection_type_; | ||||
67 | |||||
68 | // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log. | ||||
69 | bool wifi_phy_layer_protocol_is_ambiguous_; | ||||
70 | // The PHY mode of the currently associated access point obtained via | ||||
71 | // net::GetWifiPHYLayerProtocol. | ||||
72 | net::WifiPHYLayerProtocol wifi_phy_layer_protocol_; | ||||
73 | |||||
[email protected] | 2434789 | 2014-08-18 20:12:07 | [diff] [blame] | 74 | // Helper object for retrieving connected wifi access point information. |
dcheng | d99c42a | 2016-04-21 21:54:13 | [diff] [blame^] | 75 | std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_; |
[email protected] | 2434789 | 2014-08-18 20:12:07 | [diff] [blame] | 76 | |
csharrison | 305ab90 | 2016-03-17 19:51:27 | [diff] [blame] | 77 | // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3 |
78 | // histogram. They are used to compute deltas at upload time. | ||||
79 | base::HistogramBase::Count total_aborts_; | ||||
80 | base::HistogramBase::Count total_codes_; | ||||
81 | |||||
anujk.sharma | 59b96827 | 2014-09-16 16:52:38 | [diff] [blame] | 82 | base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_; |
83 | |||||
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 84 | DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider); |
85 | }; | ||||
86 | |||||
asvitkine | a63d19e | 2014-10-24 16:19:39 | [diff] [blame] | 87 | } // namespace metrics |
88 | |||||
gunsch | 043f360 | 2014-09-11 21:05:03 | [diff] [blame] | 89 | #endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ |