blob: da47689d2746187f5e7ba4e874a07c867327139b [file] [log] [blame]
[email protected]536324e2014-05-22 18:50:191// 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
gunsch043f3602014-09-11 21:05:035#ifndef COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_
6#define COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_
[email protected]536324e2014-05-22 18:50:197
dchengd99c42a2016-04-21 21:54:138#include <memory>
9
avi26062922015-12-26 00:14:1810#include "base/macros.h"
[email protected]536324e2014-05-22 18:50:1911#include "base/memory/weak_ptr.h"
csharrison305ab902016-03-17 19:51:2712#include "base/metrics/histogram_base.h"
[email protected]536324e2014-05-22 18:50:1913#include "components/metrics/metrics_provider.h"
gunsch043f3602014-09-11 21:05:0314#include "components/metrics/net/wifi_access_point_info_provider.h"
[email protected]536324e2014-05-22 18:50:1915#include "components/metrics/proto/system_profile.pb.h"
[email protected]536324e2014-05-22 18:50:1916#include "net/base/network_change_notifier.h"
olli.raula80a44be2015-09-01 07:41:5317#include "net/base/network_interfaces.h"
[email protected]536324e2014-05-22 18:50:1918
asvitkinea63d19e2014-10-24 16:19:3919namespace metrics {
20
[email protected]536324e2014-05-22 18:50:1921// Registers as observer with net::NetworkChangeNotifier and keeps track of
22// the network environment.
23class NetworkMetricsProvider
asvitkinea63d19e2014-10-24 16:19:3924 : public MetricsProvider,
[email protected]536324e2014-05-22 18:50:1925 public net::NetworkChangeNotifier::ConnectionTypeObserver {
26 public:
gunsch043f3602014-09-11 21:05:0327 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post
28 // network info collection tasks.
29 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner);
dcheng00ea022b2014-10-21 11:24:5630 ~NetworkMetricsProvider() override;
[email protected]536324e2014-05-22 18:50:1931
asvitkinebbde62b2014-09-03 16:33:2132 private:
asvitkinea63d19e2014-10-24 16:19:3933 // MetricsProvider:
bmcquade3f55de792016-02-26 22:10:3734 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override;
asvitkinea63d19e2014-10-24 16:19:3935 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override;
[email protected]536324e2014-05-22 18:50:1936
37 // ConnectionTypeObserver:
dcheng00ea022b2014-10-21 11:24:5638 void OnConnectionTypeChanged(
mostynbfe59f482014-10-06 15:04:4639 net::NetworkChangeNotifier::ConnectionType type) override;
[email protected]536324e2014-05-22 18:50:1940
asvitkinea63d19e2014-10-24 16:19:3941 SystemProfileProto::Network::ConnectionType GetConnectionType() const;
42 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol()
43 const;
[email protected]536324e2014-05-22 18:50:1944
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]24347892014-08-18 20:12:0751 // Writes info about the wireless access points that this system is
52 // connected to.
53 void WriteWifiAccessPointProto(
54 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info,
asvitkinea63d19e2014-10-24 16:19:3955 SystemProfileProto::Network* network_proto);
[email protected]24347892014-08-18 20:12:0756
csharrison305ab902016-03-17 19:51:2757 // Logs metrics that are functions of other metrics being uploaded.
58 void LogAggregatedMetrics();
59
gunsch043f3602014-09-11 21:05:0360 // Task runner used for blocking file I/O.
61 base::TaskRunner* io_task_runner_;
62
[email protected]536324e2014-05-22 18:50:1963 // 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]24347892014-08-18 20:12:0774 // Helper object for retrieving connected wifi access point information.
dchengd99c42a2016-04-21 21:54:1375 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_;
[email protected]24347892014-08-18 20:12:0776
csharrison305ab902016-03-17 19:51:2777 // 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.sharma59b968272014-09-16 16:52:3882 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_;
83
[email protected]536324e2014-05-22 18:50:1984 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider);
85};
86
asvitkinea63d19e2014-10-24 16:19:3987} // namespace metrics
88
gunsch043f3602014-09-11 21:05:0389#endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_