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

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: Add default constructor/destructor to WifiAccessPointInfo struct to fix compilation error on certai… 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),
(...skipping 14 matching lines...) Expand all
32 network->set_connection_type(GetConnectionType()); 35 network->set_connection_type(GetConnectionType());
33 network->set_wifi_phy_layer_protocol_is_ambiguous( 36 network->set_wifi_phy_layer_protocol_is_ambiguous(
34 wifi_phy_layer_protocol_is_ambiguous_); 37 wifi_phy_layer_protocol_is_ambiguous_);
35 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol()); 38 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol());
36 39
37 // Resets the "ambiguous" flags, since a new metrics log session has started. 40 // Resets the "ambiguous" flags, since a new metrics log session has started.
38 connection_type_is_ambiguous_ = false; 41 connection_type_is_ambiguous_ = false;
39 // TODO(isherman): This line seems unnecessary. 42 // TODO(isherman): This line seems unnecessary.
40 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); 43 connection_type_ = net::NetworkChangeNotifier::GetConnectionType();
41 wifi_phy_layer_protocol_is_ambiguous_ = false; 44 wifi_phy_layer_protocol_is_ambiguous_ = false;
45
46 // Connected wifi access point information.
47 net::NetworkChangeNotifier::WifiAccessPointInfo info;
48 if (net::NetworkChangeNotifier::GetWifiAccessPointInfo(&info))
49 WriteWifiAccessPointProto(info, network);
42 } 50 }
43 51
44 void NetworkMetricsProvider::OnConnectionTypeChanged( 52 void NetworkMetricsProvider::OnConnectionTypeChanged(
45 net::NetworkChangeNotifier::ConnectionType type) { 53 net::NetworkChangeNotifier::ConnectionType type) {
46 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) 54 if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
47 return; 55 return;
48 if (type != connection_type_ && 56 if (type != connection_type_ &&
49 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { 57 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) {
50 connection_type_is_ambiguous_ = true; 58 connection_type_is_ambiguous_ = true;
51 } 59 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 117 }
110 118
111 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( 119 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult(
112 net::WifiPHYLayerProtocol mode) { 120 net::WifiPHYLayerProtocol mode) {
113 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && 121 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN &&
114 mode != wifi_phy_layer_protocol_) { 122 mode != wifi_phy_layer_protocol_) {
115 wifi_phy_layer_protocol_is_ambiguous_ = true; 123 wifi_phy_layer_protocol_is_ambiguous_ = true;
116 } 124 }
117 wifi_phy_layer_protocol_ = mode; 125 wifi_phy_layer_protocol_ = mode;
118 } 126 }
127
128 void NetworkMetricsProvider::WriteWifiAccessPointProto(
129 const net::NetworkChangeNotifier::WifiAccessPointInfo& info,
130 SystemProfileProto::Network* network_proto) {
131 SystemProfileProto::Network::WifiAccessPoint* ap_info =
132 network_proto->mutable_access_point_info();
133
134 SystemProfileProto::Network::WifiAccessPoint::SecurityMode security =
135 SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN;
136 switch (info.security) {
137 case net::NetworkChangeNotifier::WIFI_SECURITY_NONE:
138 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_NONE;
139 break;
140 case net::NetworkChangeNotifier::WIFI_SECURITY_WPA:
141 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WPA;
142 break;
143 case net::NetworkChangeNotifier::WIFI_SECURITY_WEP:
144 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WEP;
145 break;
146 case net::NetworkChangeNotifier::WIFI_SECURITY_RSN:
147 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_RSN;
148 break;
149 case net::NetworkChangeNotifier::WIFI_SECURITY_802_1X:
150 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_802_1X;
151 break;
152 case net::NetworkChangeNotifier::WIFI_SECURITY_PSK:
153 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_PSK;
154 break;
155 case net::NetworkChangeNotifier::WIFI_SECURITY_UNKNOWN:
156 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN;
157 break;
158 }
159 ap_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 ap_info->set_vendor_prefix(vendor_prefix);
173 else
174 NOTREACHED();
175 }
176
177 // Add vendor information if it is provided.
178 if (!info.model_number.empty() || !info.model_name.empty() ||
179 !info.device_name.empty() || !info.oui_list.empty()) {
stevenjb 2014/07/15 18:16:14 nit: early exit
zqiu1 2014/07/15 19:34:01 Done.
180 SystemProfileProto::Network::WifiAccessPoint::VendorInformation* vendor =
181 ap_info->mutable_vendor_info();
182 if (!info.model_number.empty())
183 vendor->set_model_number(info.model_number);
184 if (!info.model_name.empty())
185 vendor->set_model_name(info.model_name);
186 if (!info.device_name.empty())
187 vendor->set_device_name(info.device_name);
188 // Parse OUI list.
189 if (!info.oui_list.empty()) {
stevenjb 2014/07/15 18:16:14 nit: early exit
zqiu1 2014/07/15 19:34:01 Done.
190 std::vector<std::string> oui_list;
191 base::SplitString(info.oui_list, ' ', &oui_list);
192 for (std::vector<std::string>::const_iterator it = oui_list.begin();
193 it != oui_list.end();
194 ++it) {
195 uint32 oui;
196 if (base::HexStringToUInt(*it, &oui))
197 vendor->add_element_identifier(oui);
198 else
199 NOTREACHED();
200 }
201 }
202 }
203 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698