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

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: Created 6 years, 4 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
15 #if defined(OS_CHROMEOS)
16 #include "chrome/browser/metrics/wifi_access_point_info_provider_chromeos.h"
17 #endif // OS_CHROMEOS
18
12 using metrics::SystemProfileProto; 19 using metrics::SystemProfileProto;
13 20
14 NetworkMetricsProvider::NetworkMetricsProvider() 21 NetworkMetricsProvider::NetworkMetricsProvider()
15 : connection_type_is_ambiguous_(false), 22 : connection_type_is_ambiguous_(false),
16 wifi_phy_layer_protocol_is_ambiguous_(false), 23 wifi_phy_layer_protocol_is_ambiguous_(false),
17 wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN), 24 wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN),
18 weak_ptr_factory_(this) { 25 weak_ptr_factory_(this) {
19 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 26 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
20 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); 27 connection_type_ = net::NetworkChangeNotifier::GetConnectionType();
21 ProbeWifiPHYLayerProtocol(); 28 ProbeWifiPHYLayerProtocol();
(...skipping 10 matching lines...) Expand all
32 network->set_connection_type(GetConnectionType()); 39 network->set_connection_type(GetConnectionType());
33 network->set_wifi_phy_layer_protocol_is_ambiguous( 40 network->set_wifi_phy_layer_protocol_is_ambiguous(
34 wifi_phy_layer_protocol_is_ambiguous_); 41 wifi_phy_layer_protocol_is_ambiguous_);
35 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol()); 42 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol());
36 43
37 // Resets the "ambiguous" flags, since a new metrics log session has started. 44 // Resets the "ambiguous" flags, since a new metrics log session has started.
38 connection_type_is_ambiguous_ = false; 45 connection_type_is_ambiguous_ = false;
39 // TODO(isherman): This line seems unnecessary. 46 // TODO(isherman): This line seems unnecessary.
40 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); 47 connection_type_ = net::NetworkChangeNotifier::GetConnectionType();
41 wifi_phy_layer_protocol_is_ambiguous_ = false; 48 wifi_phy_layer_protocol_is_ambiguous_ = false;
49
50 if (!wifi_access_point_info_provider_.get()) {
51 #if defined(OS_CHROMEOS)
52 wifi_access_point_info_provider_ =
53 scoped_ptr<WifiAccessPointInfoProvider>(
54 new WifiAccessPointInfoProviderChromeos());
stevenjb 2014/08/18 17:28:14 wifi_access_point_info_provider_.reset(new WifiAcc
zqiu1 2014/08/18 18:02:29 Done.
55 #else
56 wifi_access_point_info_provider_ =
57 scoped_ptr<WifiAccessPointInfoProvider>(
58 new WifiAccessPointInfoProvider());
stevenjb 2014/08/18 17:28:14 ditto
zqiu1 2014/08/18 18:02:29 Done.
59 #endif // OS_CHROMEOS
60 }
61
62 // Connected wifi access point information.
63 WifiAccessPointInfoProvider::WifiAccessPointInfo info;
64 if (wifi_access_point_info_provider_->GetInfo(&info))
65 WriteWifiAccessPointProto(info, network);
42 } 66 }
43 67
44 void NetworkMetricsProvider::OnConnectionTypeChanged( 68 void NetworkMetricsProvider::OnConnectionTypeChanged(
45 net::NetworkChangeNotifier::ConnectionType type) { 69 net::NetworkChangeNotifier::ConnectionType type) {
46 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) 70 if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
47 return; 71 return;
48 if (type != connection_type_ && 72 if (type != connection_type_ &&
49 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { 73 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) {
50 connection_type_is_ambiguous_ = true; 74 connection_type_is_ambiguous_ = true;
51 } 75 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 133 }
110 134
111 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( 135 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult(
112 net::WifiPHYLayerProtocol mode) { 136 net::WifiPHYLayerProtocol mode) {
113 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && 137 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN &&
114 mode != wifi_phy_layer_protocol_) { 138 mode != wifi_phy_layer_protocol_) {
115 wifi_phy_layer_protocol_is_ambiguous_ = true; 139 wifi_phy_layer_protocol_is_ambiguous_ = true;
116 } 140 }
117 wifi_phy_layer_protocol_ = mode; 141 wifi_phy_layer_protocol_ = mode;
118 } 142 }
143
144 void NetworkMetricsProvider::WriteWifiAccessPointProto(
145 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info,
146 SystemProfileProto::Network* network_proto) {
147 SystemProfileProto::Network::WifiAccessPoint* access_point_info =
148 network_proto->mutable_access_point_info();
149 SystemProfileProto::Network::WifiAccessPoint::SecurityMode security =
150 SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN;
151 switch (info.security) {
152 case WifiAccessPointInfoProvider::WIFI_SECURITY_NONE:
153 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_NONE;
154 break;
155 case WifiAccessPointInfoProvider::WIFI_SECURITY_WPA:
156 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WPA;
157 break;
158 case WifiAccessPointInfoProvider::WIFI_SECURITY_WEP:
159 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WEP;
160 break;
161 case WifiAccessPointInfoProvider::WIFI_SECURITY_RSN:
162 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_RSN;
163 break;
164 case WifiAccessPointInfoProvider::WIFI_SECURITY_802_1X:
165 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_802_1X;
166 break;
167 case WifiAccessPointInfoProvider::WIFI_SECURITY_PSK:
168 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_PSK;
169 break;
170 case WifiAccessPointInfoProvider::WIFI_SECURITY_UNKNOWN:
171 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN;
172 break;
173 }
174 access_point_info->set_security_mode(security);
175
176 // |bssid| is xx:xx:xx:xx:xx:xx, extract the first three components and
177 // pack into a uint32.
178 std::string bssid = info.bssid;
179 if (bssid.size() == 17 && bssid[2] == ':' && bssid[5] == ':' &&
180 bssid[8] == ':' && bssid[11] == ':' && bssid[14] == ':') {
181 std::string vendor_prefix_str;
182 uint32 vendor_prefix;
183
184 base::RemoveChars(bssid.substr(0, 9), ":", &vendor_prefix_str);
185 DCHECK_EQ(6U, vendor_prefix_str.size());
186 if (base::HexStringToUInt(vendor_prefix_str, &vendor_prefix))
187 access_point_info->set_vendor_prefix(vendor_prefix);
188 else
189 NOTREACHED();
190 }
191
192 // Return if vendor information is not provided.
193 if (info.model_number.empty() && info.model_name.empty() &&
194 info.device_name.empty() && info.oui_list.empty())
195 return;
196
197 SystemProfileProto::Network::WifiAccessPoint::VendorInformation* vendor =
198 access_point_info->mutable_vendor_info();
199 if (!info.model_number.empty())
200 vendor->set_model_number(info.model_number);
201 if (!info.model_name.empty())
202 vendor->set_model_name(info.model_name);
203 if (!info.device_name.empty())
204 vendor->set_device_name(info.device_name);
205
206 // Return if OUI list is not provided.
207 if (info.oui_list.empty())
208 return;
209
210 // Parse OUI list.
211 std::vector<std::string> oui_list;
212 base::SplitString(info.oui_list, ' ', &oui_list);
213 for (std::vector<std::string>::const_iterator it = oui_list.begin();
214 it != oui_list.end();
215 ++it) {
216 uint32 oui;
217 if (base::HexStringToUInt(*it, &oui))
218 vendor->add_element_identifier(oui);
219 else
220 NOTREACHED();
221 }
222 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698