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 #include "chrome/browser/metrics/metrics_network_observer.h" |
| 6 |
| 7 #include "base/compiler_specific.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "content/public/browser/browser_thread.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 void ProbeWifiPhyMode(net::WifiPhyMode* phy_mode) { |
| 14 *phy_mode = net::GetWifiPhyMode(); |
| 15 } |
| 16 |
| 17 } // namespace |
| 18 |
| 19 MetricsNetworkObserver::MetricsNetworkObserver() |
| 20 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 21 connection_type_is_ambiguous_(false), |
| 22 wifi_phy_mode_is_ambiguous_(false) { |
| 23 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 24 Reset(); |
| 25 } |
| 26 |
| 27 MetricsNetworkObserver::~MetricsNetworkObserver() { |
| 28 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 29 } |
| 30 |
| 31 void MetricsNetworkObserver::Reset() { |
| 32 connection_type_is_ambiguous_ = false; |
| 33 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); |
| 34 wifi_phy_mode_is_ambiguous_ = false; |
| 35 wifi_phy_mode_ = net::WIFI_PHY_MODE_UNKNOWN; |
| 36 } |
| 37 |
| 38 void MetricsNetworkObserver::OnConnectionTypeChanged( |
| 39 net::NetworkChangeNotifier::ConnectionType type) { |
| 40 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) |
| 41 return; |
| 42 if (type != connection_type_ && |
| 43 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 44 connection_type_is_ambiguous_ = true; |
| 45 } |
| 46 connection_type_ = type; |
| 47 |
| 48 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 49 |
| 50 net::WifiPhyMode* phy_mode = new net::WifiPhyMode(); |
| 51 content::BrowserThread::GetBlockingPool()->PostTaskAndReply( |
| 52 FROM_HERE, |
| 53 base::Bind(&ProbeWifiPhyMode, base::Unretained(phy_mode)), |
| 54 base::Bind(&MetricsNetworkObserver::OnWifiModeChanged, |
| 55 weak_ptr_factory_.GetWeakPtr(), |
| 56 base::Owned(phy_mode))); |
| 57 } |
| 58 |
| 59 void MetricsNetworkObserver::OnWifiModeChanged(net::WifiPhyMode* mode) { |
| 60 if (*mode != wifi_phy_mode_) |
| 61 wifi_phy_mode_is_ambiguous_ = true; |
| 62 wifi_phy_mode_ = *mode; |
| 63 } |
| 64 |
OLD | NEW |