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

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

Issue 328793002: Add wifi AP info to system profile metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Using new interface to provide wifi access point information. Created 6 years, 5 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/network_metrics_provider.h" 5 #include "chrome/browser/metrics/network_metrics_provider.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h"
8 #include "base/task_runner_util.h" 11 #include "base/task_runner_util.h"
9 #include "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
10 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
11 14
12 using metrics::SystemProfileProto; 15 using metrics::SystemProfileProto;
13 16
14 NetworkMetricsProvider::NetworkMetricsProvider() 17 NetworkMetricsProvider::NetworkMetricsProvider()
15 : connection_type_is_ambiguous_(false), 18 : connection_type_is_ambiguous_(false),
16 wifi_phy_layer_protocol_is_ambiguous_(false), 19 wifi_phy_layer_protocol_is_ambiguous_(false),
17 wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN), 20 wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN),
18 weak_ptr_factory_(this) { 21 weak_ptr_factory_(this) {
19 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 22 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
20 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); 23 connection_type_ = net::NetworkChangeNotifier::GetConnectionType();
24 wifi_access_point_info_provider_ = net::WifiAccessPointInfoProvider::Create();
21 ProbeWifiPHYLayerProtocol(); 25 ProbeWifiPHYLayerProtocol();
22 } 26 }
23 27
24 NetworkMetricsProvider::~NetworkMetricsProvider() { 28 NetworkMetricsProvider::~NetworkMetricsProvider() {
25 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 29 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
26 } 30 }
27 31
28 void NetworkMetricsProvider::ProvideSystemProfileMetrics( 32 void NetworkMetricsProvider::ProvideSystemProfileMetrics(
29 SystemProfileProto* system_profile) { 33 SystemProfileProto* system_profile) {
30 SystemProfileProto::Network* network = system_profile->mutable_network(); 34 SystemProfileProto::Network* network = system_profile->mutable_network();
31 network->set_connection_type_is_ambiguous(connection_type_is_ambiguous_); 35 network->set_connection_type_is_ambiguous(connection_type_is_ambiguous_);
32 network->set_connection_type(GetConnectionType()); 36 network->set_connection_type(GetConnectionType());
33 network->set_wifi_phy_layer_protocol_is_ambiguous( 37 network->set_wifi_phy_layer_protocol_is_ambiguous(
34 wifi_phy_layer_protocol_is_ambiguous_); 38 wifi_phy_layer_protocol_is_ambiguous_);
35 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol()); 39 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol());
36 40
37 // Resets the "ambiguous" flags, since a new metrics log session has started. 41 // Resets the "ambiguous" flags, since a new metrics log session has started.
38 connection_type_is_ambiguous_ = false; 42 connection_type_is_ambiguous_ = false;
39 // TODO(isherman): This line seems unnecessary. 43 // TODO(isherman): This line seems unnecessary.
40 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); 44 connection_type_ = net::NetworkChangeNotifier::GetConnectionType();
41 wifi_phy_layer_protocol_is_ambiguous_ = false; 45 wifi_phy_layer_protocol_is_ambiguous_ = false;
46
47 // Connected wifi access point information.
48 net::WifiAccessPointInfo info;
49 if (wifi_access_point_info_provider_->GetInfo(&info))
50 WriteWifiAccessPointProto(info, network);
42 } 51 }
43 52
44 void NetworkMetricsProvider::OnConnectionTypeChanged( 53 void NetworkMetricsProvider::OnConnectionTypeChanged(
45 net::NetworkChangeNotifier::ConnectionType type) { 54 net::NetworkChangeNotifier::ConnectionType type) {
46 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) 55 if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
47 return; 56 return;
48 if (type != connection_type_ && 57 if (type != connection_type_ &&
49 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { 58 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) {
50 connection_type_is_ambiguous_ = true; 59 connection_type_is_ambiguous_ = true;
51 } 60 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 118 }
110 119
111 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( 120 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult(
112 net::WifiPHYLayerProtocol mode) { 121 net::WifiPHYLayerProtocol mode) {
113 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && 122 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN &&
114 mode != wifi_phy_layer_protocol_) { 123 mode != wifi_phy_layer_protocol_) {
115 wifi_phy_layer_protocol_is_ambiguous_ = true; 124 wifi_phy_layer_protocol_is_ambiguous_ = true;
116 } 125 }
117 wifi_phy_layer_protocol_ = mode; 126 wifi_phy_layer_protocol_ = mode;
118 } 127 }
128
129 void NetworkMetricsProvider::WriteWifiAccessPointProto(
130 const net::WifiAccessPointInfo& info,
131 SystemProfileProto::Network* network_proto) {
132 SystemProfileProto::Network::WifiAccessPoint* access_point_info =
133 network_proto->mutable_access_point_info();
134 SystemProfileProto::Network::WifiAccessPoint::SecurityMode security =
135 SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN;
136 switch (info.security) {
137 case net::WIFI_SECURITY_NONE:
138 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_NONE;
139 break;
140 case net::WIFI_SECURITY_WPA:
141 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WPA;
142 break;
143 case net::WIFI_SECURITY_WEP:
144 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WEP;
145 break;
146 case net::WIFI_SECURITY_RSN:
147 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_RSN;
148 break;
149 case net::WIFI_SECURITY_802_1X:
150 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_802_1X;
151 break;
152 case net::WIFI_SECURITY_PSK:
153 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_PSK;
154 break;
155 case net::WIFI_SECURITY_UNKNOWN:
156 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN;
157 break;
158 }
159 access_point_info->set_security_mode(security);
160
161 // |bssid| is xx:xx:xx:xx:xx:xx, extract the first three components and
162 // pack into a uint32.
163 std::string bssid = info.bssid;
164 if (bssid.size() == 17 && bssid[2] == ':' && bssid[5] == ':' &&
165 bssid[8] == ':' && bssid[11] == ':' && bssid[14] == ':') {
166 std::string vendor_prefix_str;
167 uint32 vendor_prefix;
168
169 base::RemoveChars(bssid.substr(0, 9), ":", &vendor_prefix_str);
170 DCHECK_EQ(6U, vendor_prefix_str.size());
171 if (base::HexStringToUInt(vendor_prefix_str, &vendor_prefix))
172 access_point_info->set_vendor_prefix(vendor_prefix);
173 else
174 NOTREACHED();
175 }
176
177 // Return if vendor information is not provided.
178 if (info.model_number.empty() && info.model_name.empty() &&
179 info.device_name.empty() && info.oui_list.empty())
180 return;
181
182 SystemProfileProto::Network::WifiAccessPoint::VendorInformation* vendor =
183 access_point_info->mutable_vendor_info();
184 if (!info.model_number.empty())
185 vendor->set_model_number(info.model_number);
186 if (!info.model_name.empty())
187 vendor->set_model_name(info.model_name);
188 if (!info.device_name.empty())
189 vendor->set_device_name(info.device_name);
190
191 // Return if OUI list is not provided.
192 if (info.oui_list.empty())
193 return;
194
195 // Parse OUI list.
196 std::vector<std::string> oui_list;
197 base::SplitString(info.oui_list, ' ', &oui_list);
198 for (std::vector<std::string>::const_iterator it = oui_list.begin();
199 it != oui_list.end();
200 ++it) {
201 uint32 oui;
202 if (base::HexStringToUInt(*it, &oui))
203 vendor->add_element_identifier(oui);
204 else
205 NOTREACHED();
206 }
207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698