1 // Copyright (c) 2013 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_METRICS_NETWORK_OBSERVER_H_
6 #define CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "chrome/common/metrics/proto/system_profile.pb.h"
12 #include "net/base/net_util.h"
13 #include "net/base/network_change_notifier.h"
15 using metrics::SystemProfileProto
;
17 // Registers as observer with net::NetworkChangeNotifier and keeps track of
18 // the network environment.
19 class MetricsNetworkObserver
20 : public net::NetworkChangeNotifier::ConnectionTypeObserver
{
22 MetricsNetworkObserver();
23 virtual ~MetricsNetworkObserver();
25 // Resets the "ambiguous" flags. Call when the environment is recorded.
28 // ConnectionTypeObserver:
29 virtual void OnConnectionTypeChanged(
30 net::NetworkChangeNotifier::ConnectionType type
) OVERRIDE
;
32 bool connection_type_is_ambiguous() const {
33 return connection_type_is_ambiguous_
;
36 SystemProfileProto::Network::ConnectionType
connection_type() const;
38 bool wifi_phy_layer_protocol_is_ambiguous() const {
39 return wifi_phy_layer_protocol_is_ambiguous_
;
42 SystemProfileProto::Network::WifiPHYLayerProtocol
43 wifi_phy_layer_protocol() const;
46 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool.
47 void ProbeWifiPHYLayerProtocol();
48 // Callback from the blocking pool with the result of
49 // net::GetWifiPHYLayerProtocol.
50 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode
);
52 base::WeakPtrFactory
<MetricsNetworkObserver
> weak_ptr_factory_
;
54 // True if |connection_type_| changed during the lifetime of the log.
55 bool connection_type_is_ambiguous_
;
56 // The connection type according to net::NetworkChangeNotifier.
57 net::NetworkChangeNotifier::ConnectionType connection_type_
;
59 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log.
60 bool wifi_phy_layer_protocol_is_ambiguous_
;
61 // The PHY mode of the currently associated access point obtained via
62 // net::GetWifiPHYLayerProtocol.
63 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_
;
65 DISALLOW_COPY_AND_ASSIGN(MetricsNetworkObserver
);
68 #endif // CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_