[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 | |
| 8 | #include "base/basictypes.h" |
| 9 | #include "base/memory/scoped_ptr.h" |
| 10 | #include "base/memory/weak_ptr.h" |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 11 | #include "components/metrics/metrics_provider.h" |
gunsch | 043f360 | 2014-09-11 21:05:03 | [diff] [blame] | 12 | #include "components/metrics/net/wifi_access_point_info_provider.h" |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 13 | #include "components/metrics/proto/system_profile.pb.h" |
| 14 | #include "net/base/net_util.h" |
| 15 | #include "net/base/network_change_notifier.h" |
| 16 | |
| 17 | // Registers as observer with net::NetworkChangeNotifier and keeps track of |
| 18 | // the network environment. |
| 19 | class NetworkMetricsProvider |
| 20 | : public metrics::MetricsProvider, |
| 21 | public net::NetworkChangeNotifier::ConnectionTypeObserver { |
| 22 | public: |
gunsch | 043f360 | 2014-09-11 21:05:03 | [diff] [blame] | 23 | // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post |
| 24 | // network info collection tasks. |
| 25 | explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame^] | 26 | ~NetworkMetricsProvider() override; |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 27 | |
asvitkine | bbde62b | 2014-09-03 16:33:21 | [diff] [blame] | 28 | private: |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 29 | // metrics::MetricsProvider: |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame^] | 30 | void OnDidCreateMetricsLog() override; |
| 31 | void ProvideSystemProfileMetrics( |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 32 | metrics::SystemProfileProto* system_profile) override; |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 33 | |
| 34 | // ConnectionTypeObserver: |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame^] | 35 | void OnConnectionTypeChanged( |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 36 | net::NetworkChangeNotifier::ConnectionType type) override; |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 37 | |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 38 | metrics::SystemProfileProto::Network::ConnectionType |
| 39 | GetConnectionType() const; |
| 40 | metrics::SystemProfileProto::Network::WifiPHYLayerProtocol |
| 41 | GetWifiPHYLayerProtocol() const; |
| 42 | |
| 43 | // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool. |
| 44 | void ProbeWifiPHYLayerProtocol(); |
| 45 | // Callback from the blocking pool with the result of |
| 46 | // net::GetWifiPHYLayerProtocol. |
| 47 | void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode); |
| 48 | |
[email protected] | 2434789 | 2014-08-18 20:12:07 | [diff] [blame] | 49 | // Writes info about the wireless access points that this system is |
| 50 | // connected to. |
| 51 | void WriteWifiAccessPointProto( |
| 52 | const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, |
| 53 | metrics::SystemProfileProto::Network* network_proto); |
| 54 | |
gunsch | 043f360 | 2014-09-11 21:05:03 | [diff] [blame] | 55 | // Task runner used for blocking file I/O. |
| 56 | base::TaskRunner* io_task_runner_; |
| 57 | |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 58 | // True if |connection_type_| changed during the lifetime of the log. |
| 59 | bool connection_type_is_ambiguous_; |
| 60 | // The connection type according to net::NetworkChangeNotifier. |
| 61 | net::NetworkChangeNotifier::ConnectionType connection_type_; |
| 62 | |
| 63 | // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log. |
| 64 | bool wifi_phy_layer_protocol_is_ambiguous_; |
| 65 | // The PHY mode of the currently associated access point obtained via |
| 66 | // net::GetWifiPHYLayerProtocol. |
| 67 | net::WifiPHYLayerProtocol wifi_phy_layer_protocol_; |
| 68 | |
[email protected] | 2434789 | 2014-08-18 20:12:07 | [diff] [blame] | 69 | // Helper object for retrieving connected wifi access point information. |
| 70 | scoped_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_; |
| 71 | |
anujk.sharma | 59b96827 | 2014-09-16 16:52:38 | [diff] [blame] | 72 | base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_; |
| 73 | |
[email protected] | 536324e | 2014-05-22 18:50:19 | [diff] [blame] | 74 | DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider); |
| 75 | }; |
| 76 | |
gunsch | 043f360 | 2014-09-11 21:05:03 | [diff] [blame] | 77 | #endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ |