blob: 5dbb5593b2491b0e358b6eeb1b3f72551b5c277a [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
avi26062922015-12-26 00:14:188#include "base/macros.h"
[email protected]536324e2014-05-22 18:50:199#include "base/memory/scoped_ptr.h"
10#include "base/memory/weak_ptr.h"
csharrison305ab902016-03-17 19:51:2711#include "base/metrics/histogram_base.h"
[email protected]536324e2014-05-22 18:50:1912#include "components/metrics/metrics_provider.h"
gunsch043f3602014-09-11 21:05:0313#include "components/metrics/net/wifi_access_point_info_provider.h"
[email protected]536324e2014-05-22 18:50:1914#include "components/metrics/proto/system_profile.pb.h"
[email protected]536324e2014-05-22 18:50:1915#include "net/base/network_change_notifier.h"
olli.raula80a44be2015-09-01 07:41:5316#include "net/base/network_interfaces.h"
[email protected]536324e2014-05-22 18:50:1917
asvitkinea63d19e2014-10-24 16:19:3918namespace metrics {
19
[email protected]536324e2014-05-22 18:50:1920// Registers as observer with net::NetworkChangeNotifier and keeps track of
21// the network environment.
22class NetworkMetricsProvider
asvitkinea63d19e2014-10-24 16:19:3923 : public MetricsProvider,
[email protected]536324e2014-05-22 18:50:1924 public net::NetworkChangeNotifier::ConnectionTypeObserver {
25 public:
gunsch043f3602014-09-11 21:05:0326 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post
27 // network info collection tasks.
28 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner);
dcheng00ea022b2014-10-21 11:24:5629 ~NetworkMetricsProvider() override;
[email protected]536324e2014-05-22 18:50:1930
asvitkinebbde62b2014-09-03 16:33:2131 private:
asvitkinea63d19e2014-10-24 16:19:3932 // MetricsProvider:
bmcquade3f55de792016-02-26 22:10:3733 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override;
asvitkinea63d19e2014-10-24 16:19:3934 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override;
[email protected]536324e2014-05-22 18:50:1935
36 // ConnectionTypeObserver:
dcheng00ea022b2014-10-21 11:24:5637 void OnConnectionTypeChanged(
mostynbfe59f482014-10-06 15:04:4638 net::NetworkChangeNotifier::ConnectionType type) override;
[email protected]536324e2014-05-22 18:50:1939
asvitkinea63d19e2014-10-24 16:19:3940 SystemProfileProto::Network::ConnectionType GetConnectionType() const;
41 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol()
42 const;
[email protected]536324e2014-05-22 18:50:1943
44 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool.
45 void ProbeWifiPHYLayerProtocol();
46 // Callback from the blocking pool with the result of
47 // net::GetWifiPHYLayerProtocol.
48 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode);
49
[email protected]24347892014-08-18 20:12:0750 // Writes info about the wireless access points that this system is
51 // connected to.
52 void WriteWifiAccessPointProto(
53 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info,
asvitkinea63d19e2014-10-24 16:19:3954 SystemProfileProto::Network* network_proto);
[email protected]24347892014-08-18 20:12:0755
csharrison305ab902016-03-17 19:51:2756 // Logs metrics that are functions of other metrics being uploaded.
57 void LogAggregatedMetrics();
58
gunsch043f3602014-09-11 21:05:0359 // Task runner used for blocking file I/O.
60 base::TaskRunner* io_task_runner_;
61
[email protected]536324e2014-05-22 18:50:1962 // True if |connection_type_| changed during the lifetime of the log.
63 bool connection_type_is_ambiguous_;
64 // The connection type according to net::NetworkChangeNotifier.
65 net::NetworkChangeNotifier::ConnectionType connection_type_;
66
67 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log.
68 bool wifi_phy_layer_protocol_is_ambiguous_;
69 // The PHY mode of the currently associated access point obtained via
70 // net::GetWifiPHYLayerProtocol.
71 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_;
72
[email protected]24347892014-08-18 20:12:0773 // Helper object for retrieving connected wifi access point information.
74 scoped_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_;
75
csharrison305ab902016-03-17 19:51:2776 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3
77 // histogram. They are used to compute deltas at upload time.
78 base::HistogramBase::Count total_aborts_;
79 base::HistogramBase::Count total_codes_;
80
anujk.sharma59b968272014-09-16 16:52:3881 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_;
82
[email protected]536324e2014-05-22 18:50:1983 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider);
84};
85
asvitkinea63d19e2014-10-24 16:19:3986} // namespace metrics
87
gunsch043f3602014-09-11 21:05:0388#endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_