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.
5 #ifndef CHROME_BROWSER_METRICS_NETWORK_METRICS_PROVIDER_H_
6 #define CHROME_BROWSER_METRICS_NETWORK_METRICS_PROVIDER_H_
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"
12 #include "components/metrics/proto/system_profile.pb.h"
13 #include "net/base/net_util.h"
14 #include "net/base/network_change_notifier.h"
16 // Registers as observer with net::NetworkChangeNotifier and keeps track of
17 // the network environment.
18 class NetworkMetricsProvider
19 : public metrics::MetricsProvider
,
20 public net::NetworkChangeNotifier::ConnectionTypeObserver
{
22 NetworkMetricsProvider();
23 virtual ~NetworkMetricsProvider();
25 // metrics::MetricsProvider:
26 virtual void ProvideSystemProfileMetrics(
27 metrics::SystemProfileProto
* system_profile
) OVERRIDE
;
29 // ConnectionTypeObserver:
30 virtual void OnConnectionTypeChanged(
31 net::NetworkChangeNotifier::ConnectionType type
) OVERRIDE
;
34 metrics::SystemProfileProto::Network::ConnectionType
35 GetConnectionType() const;
36 metrics::SystemProfileProto::Network::WifiPHYLayerProtocol
37 GetWifiPHYLayerProtocol() const;
39 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool.
40 void ProbeWifiPHYLayerProtocol();
41 // Callback from the blocking pool with the result of
42 // net::GetWifiPHYLayerProtocol.
43 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode
);
45 // True if |connection_type_| changed during the lifetime of the log.
46 bool connection_type_is_ambiguous_
;
47 // The connection type according to net::NetworkChangeNotifier.
48 net::NetworkChangeNotifier::ConnectionType connection_type_
;
50 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log.
51 bool wifi_phy_layer_protocol_is_ambiguous_
;
52 // The PHY mode of the currently associated access point obtained via
53 // net::GetWifiPHYLayerProtocol.
54 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_
;
56 base::WeakPtrFactory
<NetworkMetricsProvider
> weak_ptr_factory_
;
58 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider
);
61 #endif // CHROME_BROWSER_METRICS_NETWORK_METRICS_PROVIDER_H_