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..62ff4877807b90427c8724b79c2036facf7e3fd1 |
--- /dev/null |
+++ b/chrome/browser/metrics/metrics_network_observer.h |
@@ -0,0 +1,96 @@ |
+// 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(); |
+ |
+ // 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; |
+ } |
+ |
+ bool wifi_phy_mode_is_ambiguous() const { |
+ 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; |
+ } |
+ |
+ private: |
+ class WifiPhyModeJob; |
+ |
+ void OnWifiModeChanged(net::WifiPhyMode* mode); |
+ |
+ base::WeakPtrFactory<MetricsNetworkObserver> weak_ptr_factory_; |
+ |
+ bool connection_type_is_ambiguous_; |
+ net::NetworkChangeNotifier::ConnectionType connection_type_; |
+ |
+ bool wifi_phy_mode_is_ambiguous_; |
+ net::WifiPhyMode wifi_phy_mode_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MetricsNetworkObserver); |
+}; |
+ |
+#endif // CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_ |