Chromium Code Reviews| Index: chrome/browser/metrics/metrics_network_observer.h |
| diff --git a/chrome/browser/metrics/metrics_network_observer.h b/chrome/browser/metrics/metrics_network_observer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..55e2a219a06364e1556eeecc60aba35f47954953 |
| --- /dev/null |
| +++ b/chrome/browser/metrics/metrics_network_observer.h |
| @@ -0,0 +1,95 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_ |
| +#define CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_ |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "chrome/common/metrics/proto/system_profile.pb.h" |
| +#include "net/base/net_util.h" |
| +#include "net/base/network_change_notifier.h" |
| + |
| +using metrics::SystemProfileProto; |
| + |
| +// Registers as observer with net::NetworkChangeNotifier and keeps track of |
| +// the network environment. |
| +class MetricsNetworkObserver |
| + : public net::NetworkChangeNotifier::ConnectionTypeObserver { |
| + public: |
| + MetricsNetworkObserver(); |
| + virtual ~MetricsNetworkObserver(); |
| + |
| + void Reset(); |
|
Ilya Sherman
2013/02/13 01:54:33
nit: Docs.
szym
2013/02/13 05:09:34
Done.
|
| + |
| + // ConnectionTypeObserver: |
| + virtual void OnConnectionTypeChanged( |
| + net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| + |
| + bool connection_type_is_ambiguous() const { |
| + return connection_type_is_ambiguous_; |
| + } |
| + |
| + SystemProfileProto::Network::ConnectionType connection_type() const { |
| + switch (connection_type_) { |
| + case net::NetworkChangeNotifier::CONNECTION_NONE: |
| + case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: |
| + return SystemProfileProto::Network::CONNECTION_UNKNOWN; |
| + case net::NetworkChangeNotifier::CONNECTION_ETHERNET: |
| + return SystemProfileProto::Network::CONNECTION_ETHERNET; |
| + case net::NetworkChangeNotifier::CONNECTION_WIFI: |
| + return SystemProfileProto::Network::CONNECTION_WIFI; |
| + case net::NetworkChangeNotifier::CONNECTION_2G: |
| + return SystemProfileProto::Network::CONNECTION_2G; |
| + case net::NetworkChangeNotifier::CONNECTION_3G: |
| + return SystemProfileProto::Network::CONNECTION_3G; |
| + case net::NetworkChangeNotifier::CONNECTION_4G: |
| + return SystemProfileProto::Network::CONNECTION_4G; |
| + } |
| + NOTREACHED(); |
| + return SystemProfileProto::Network::CONNECTION_UNKNOWN; |
| + } |
|
Ilya Sherman
2013/02/13 01:54:33
nit: Please move this method into the implementati
szym
2013/02/13 05:09:34
Done.
|
| + |
| + 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
|
| + return wifi_phy_mode_is_ambiguous_; |
| + } |
| + |
| + SystemProfileProto::Network::WifiPhyMode wifi_phy_mode() const { |
| + switch (wifi_phy_mode_) { |
| + case net::WIFI_PHY_MODE_NONE: |
| + return SystemProfileProto::Network::WIFI_PHY_MODE_NONE; |
| + case net::WIFI_PHY_MODE_ANCIENT: |
| + return SystemProfileProto::Network::WIFI_PHY_MODE_ANCIENT; |
| + case net::WIFI_PHY_MODE_A: |
| + return SystemProfileProto::Network::WIFI_PHY_MODE_A; |
| + case net::WIFI_PHY_MODE_B: |
| + return SystemProfileProto::Network::WIFI_PHY_MODE_B; |
| + case net::WIFI_PHY_MODE_G: |
| + return SystemProfileProto::Network::WIFI_PHY_MODE_G; |
| + case net::WIFI_PHY_MODE_N: |
| + return SystemProfileProto::Network::WIFI_PHY_MODE_N; |
| + case net::WIFI_PHY_MODE_UNKNOWN: |
| + return SystemProfileProto::Network::WIFI_PHY_MODE_UNKNOWN; |
| + } |
| + NOTREACHED(); |
| + return SystemProfileProto::Network::WIFI_PHY_MODE_UNKNOWN; |
| + } |
|
Ilya Sherman
2013/02/13 01:54:33
nit: Ditto.
szym
2013/02/13 05:09:34
Done.
|
| + |
| + private: |
| + void ProbeWifiPhyMode(); |
| + void OnWifiPhyModeResult(net::WifiPhyMode* mode); |
|
Ilya Sherman
2013/02/13 01:54:33
nit: Docs.
szym
2013/02/13 05:09:34
Done.
|
| + |
| + base::WeakPtrFactory<MetricsNetworkObserver> weak_ptr_factory_; |
| + |
| + bool connection_type_is_ambiguous_; |
| + net::NetworkChangeNotifier::ConnectionType connection_type_; |
|
Ilya Sherman
2013/02/13 01:54:33
nit: Docs.
szym
2013/02/13 05:09:34
Done.
|
| + |
| + bool wifi_phy_mode_is_ambiguous_; |
| + net::WifiPhyMode wifi_phy_mode_; |
|
Ilya Sherman
2013/02/13 01:54:33
nit: Docs.
szym
2013/02/13 05:09:34
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(MetricsNetworkObserver); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_ |