blob: d11f9300e7f4423665436980c6cb556bb74943f4 [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
8#include "base/basictypes.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/memory/weak_ptr.h"
11#include "components/metrics/metrics_provider.h"
gunsch043f3602014-09-11 21:05:0312#include "components/metrics/net/wifi_access_point_info_provider.h"
[email protected]536324e2014-05-22 18:50:1913#include "components/metrics/proto/system_profile.pb.h"
[email protected]536324e2014-05-22 18:50:1914#include "net/base/network_change_notifier.h"
olli.raula80a44be2015-09-01 07:41:5315#include "net/base/network_interfaces.h"
[email protected]536324e2014-05-22 18:50:1916
asvitkinea63d19e2014-10-24 16:19:3917namespace metrics {
18
[email protected]536324e2014-05-22 18:50:1919// Registers as observer with net::NetworkChangeNotifier and keeps track of
20// the network environment.
21class NetworkMetricsProvider
asvitkinea63d19e2014-10-24 16:19:3922 : public MetricsProvider,
[email protected]536324e2014-05-22 18:50:1923 public net::NetworkChangeNotifier::ConnectionTypeObserver {
24 public:
gunsch043f3602014-09-11 21:05:0325 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post
26 // network info collection tasks.
27 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner);
dcheng00ea022b2014-10-21 11:24:5628 ~NetworkMetricsProvider() override;
[email protected]536324e2014-05-22 18:50:1929
asvitkinebbde62b2014-09-03 16:33:2130 private:
asvitkinea63d19e2014-10-24 16:19:3931 // MetricsProvider:
dcheng00ea022b2014-10-21 11:24:5632 void OnDidCreateMetricsLog() override;
asvitkinea63d19e2014-10-24 16:19:3933 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override;
[email protected]536324e2014-05-22 18:50:1934
35 // ConnectionTypeObserver:
dcheng00ea022b2014-10-21 11:24:5636 void OnConnectionTypeChanged(
mostynbfe59f482014-10-06 15:04:4637 net::NetworkChangeNotifier::ConnectionType type) override;
[email protected]536324e2014-05-22 18:50:1938
asvitkinea63d19e2014-10-24 16:19:3939 SystemProfileProto::Network::ConnectionType GetConnectionType() const;
40 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol()
41 const;
[email protected]536324e2014-05-22 18:50:1942
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]24347892014-08-18 20:12:0749 // Writes info about the wireless access points that this system is
50 // connected to.
51 void WriteWifiAccessPointProto(
52 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info,
asvitkinea63d19e2014-10-24 16:19:3953 SystemProfileProto::Network* network_proto);
[email protected]24347892014-08-18 20:12:0754
gunsch043f3602014-09-11 21:05:0355 // Task runner used for blocking file I/O.
56 base::TaskRunner* io_task_runner_;
57
[email protected]536324e2014-05-22 18:50:1958 // 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]24347892014-08-18 20:12:0769 // Helper object for retrieving connected wifi access point information.
70 scoped_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_;
71
anujk.sharma59b968272014-09-16 16:52:3872 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_;
73
[email protected]536324e2014-05-22 18:50:1974 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider);
75};
76
asvitkinea63d19e2014-10-24 16:19:3977} // namespace metrics
78
gunsch043f3602014-09-11 21:05:0379#endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_