Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/browser/metrics/metrics_network_observer.cc

Issue 12082090: [net] Add WifiPhyMode to SystemProfile (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ensure to probe the current WifiPhyMode on Reset Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 ReadWifiPhyMode(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 ProbeWifiPhyMode();
Ilya Sherman 2013/02/13 01:54:33 Should you invalidate existing WeakPtrs as part of
szym 2013/02/13 05:09:34 On second thought, I realized there's no need to P
37 }
38
39 void MetricsNetworkObserver::OnConnectionTypeChanged(
40 net::NetworkChangeNotifier::ConnectionType type) {
41 if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
42 return;
43 if (type != connection_type_ &&
44 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) {
45 connection_type_is_ambiguous_ = true;
46 }
47 connection_type_ = type;
48
49 ProbeWifiPhyMode();
50 }
51
52 void MetricsNetworkObserver::ProbeWifiPhyMode() {
53 weak_ptr_factory_.InvalidateWeakPtrs();
Ilya Sherman 2013/02/13 01:54:33 Are you sure you want to invalidate any existing W
szym 2013/02/13 05:09:34 I don't think it matters in practice, since GetWif
54 net::WifiPhyMode* phy_mode = new net::WifiPhyMode();
55 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(
56 FROM_HERE,
57 base::Bind(&ReadWifiPhyMode, base::Unretained(phy_mode)),
58 base::Bind(&MetricsNetworkObserver::OnWifiPhyModeResult,
59 weak_ptr_factory_.GetWeakPtr(),
60 base::Owned(phy_mode)));
61 }
62
63 void MetricsNetworkObserver::OnWifiPhyModeResult(net::WifiPhyMode* mode) {
64 if (wifi_phy_mode_ != net::WIFI_PHY_MODE_UNKNOWN && *mode != wifi_phy_mode_)
65 wifi_phy_mode_is_ambiguous_ = true;
66 wifi_phy_mode_ = *mode;
67 }
68
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698