OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 | |
5 #ifndef CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_ | |
6 #define CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_ | |
7 | |
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" | |
14 | |
15 using metrics::SystemProfileProto; | |
16 | |
17 // Registers as observer with net::NetworkChangeNotifier and keeps track of | |
18 // the network environment. | |
19 class MetricsNetworkObserver | |
20 : public net::NetworkChangeNotifier::ConnectionTypeObserver { | |
21 public: | |
22 MetricsNetworkObserver(); | |
23 virtual ~MetricsNetworkObserver(); | |
24 | |
25 void Reset(); | |
Ilya Sherman
2013/02/13 01:54:33
nit: Docs.
szym
2013/02/13 05:09:34
Done.
| |
26 | |
27 // ConnectionTypeObserver: | |
28 virtual void OnConnectionTypeChanged( | |
29 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | |
30 | |
31 bool connection_type_is_ambiguous() const { | |
32 return connection_type_is_ambiguous_; | |
33 } | |
34 | |
35 SystemProfileProto::Network::ConnectionType connection_type() const { | |
36 switch (connection_type_) { | |
37 case net::NetworkChangeNotifier::CONNECTION_NONE: | |
38 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: | |
39 return SystemProfileProto::Network::CONNECTION_UNKNOWN; | |
40 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | |
41 return SystemProfileProto::Network::CONNECTION_ETHERNET; | |
42 case net::NetworkChangeNotifier::CONNECTION_WIFI: | |
43 return SystemProfileProto::Network::CONNECTION_WIFI; | |
44 case net::NetworkChangeNotifier::CONNECTION_2G: | |
45 return SystemProfileProto::Network::CONNECTION_2G; | |
46 case net::NetworkChangeNotifier::CONNECTION_3G: | |
47 return SystemProfileProto::Network::CONNECTION_3G; | |
48 case net::NetworkChangeNotifier::CONNECTION_4G: | |
49 return SystemProfileProto::Network::CONNECTION_4G; | |
50 } | |
51 NOTREACHED(); | |
52 return SystemProfileProto::Network::CONNECTION_UNKNOWN; | |
53 } | |
Ilya Sherman
2013/02/13 01:54:33
nit: Please move this method into the implementati
szym
2013/02/13 05:09:34
Done.
| |
54 | |
55 bool wifi_phy_mode_is_ambiguous() const { | |
Ilya Sherman
2013/02/13 01:54:33
nit: Please spell out whatever term "phy" represen
szym
2013/02/13 05:09:34
Are you suggesting I replace "phy" with "physical_
Ilya Sherman
2013/02/13 08:05:54
Yes. Actually, I'd suggest a name like "WifiProto
szym
2013/02/13 08:48:08
Done, although IMO this is ambiguous, since 802.11
| |
56 return wifi_phy_mode_is_ambiguous_; | |
57 } | |
58 | |
59 SystemProfileProto::Network::WifiPhyMode wifi_phy_mode() const { | |
60 switch (wifi_phy_mode_) { | |
61 case net::WIFI_PHY_MODE_NONE: | |
62 return SystemProfileProto::Network::WIFI_PHY_MODE_NONE; | |
63 case net::WIFI_PHY_MODE_ANCIENT: | |
64 return SystemProfileProto::Network::WIFI_PHY_MODE_ANCIENT; | |
65 case net::WIFI_PHY_MODE_A: | |
66 return SystemProfileProto::Network::WIFI_PHY_MODE_A; | |
67 case net::WIFI_PHY_MODE_B: | |
68 return SystemProfileProto::Network::WIFI_PHY_MODE_B; | |
69 case net::WIFI_PHY_MODE_G: | |
70 return SystemProfileProto::Network::WIFI_PHY_MODE_G; | |
71 case net::WIFI_PHY_MODE_N: | |
72 return SystemProfileProto::Network::WIFI_PHY_MODE_N; | |
73 case net::WIFI_PHY_MODE_UNKNOWN: | |
74 return SystemProfileProto::Network::WIFI_PHY_MODE_UNKNOWN; | |
75 } | |
76 NOTREACHED(); | |
77 return SystemProfileProto::Network::WIFI_PHY_MODE_UNKNOWN; | |
78 } | |
Ilya Sherman
2013/02/13 01:54:33
nit: Ditto.
szym
2013/02/13 05:09:34
Done.
| |
79 | |
80 private: | |
81 void ProbeWifiPhyMode(); | |
82 void OnWifiPhyModeResult(net::WifiPhyMode* mode); | |
Ilya Sherman
2013/02/13 01:54:33
nit: Docs.
szym
2013/02/13 05:09:34
Done.
| |
83 | |
84 base::WeakPtrFactory<MetricsNetworkObserver> weak_ptr_factory_; | |
85 | |
86 bool connection_type_is_ambiguous_; | |
87 net::NetworkChangeNotifier::ConnectionType connection_type_; | |
Ilya Sherman
2013/02/13 01:54:33
nit: Docs.
szym
2013/02/13 05:09:34
Done.
| |
88 | |
89 bool wifi_phy_mode_is_ambiguous_; | |
90 net::WifiPhyMode wifi_phy_mode_; | |
Ilya Sherman
2013/02/13 01:54:33
nit: Docs.
szym
2013/02/13 05:09:34
Done.
| |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(MetricsNetworkObserver); | |
93 }; | |
94 | |
95 #endif // CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_ | |
OLD | NEW |