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

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_.reset(
53 new WifiAccessPointInfoProviderChromeos());
54 #else
55 wifi_access_point_info_provider_.reset(
56 new WifiAccessPointInfoProvider());
57 #endif // OS_CHROMEOS
58 }
59
60 // Connected wifi access point information.
61 WifiAccessPointInfoProvider::WifiAccessPointInfo info;
62 if (wifi_access_point_info_provider_->GetInfo(&info))
63 WriteWifiAccessPointProto(info, network);
42 } 64 }
43 65
44 void NetworkMetricsProvider::OnConnectionTypeChanged( 66 void NetworkMetricsProvider::OnConnectionTypeChanged(
45 net::NetworkChangeNotifier::ConnectionType type) { 67 net::NetworkChangeNotifier::ConnectionType type) {
46 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) 68 if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
47 return; 69 return;
48 if (type != connection_type_ && 70 if (type != connection_type_ &&
49 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { 71 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) {
50 connection_type_is_ambiguous_ = true; 72 connection_type_is_ambiguous_ = true;
51 } 73 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 131 }
110 132
111 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( 133 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult(
112 net::WifiPHYLayerProtocol mode) { 134 net::WifiPHYLayerProtocol mode) {
113 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && 135 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN &&
114 mode != wifi_phy_layer_protocol_) { 136 mode != wifi_phy_layer_protocol_) {
115 wifi_phy_layer_protocol_is_ambiguous_ = true; 137 wifi_phy_layer_protocol_is_ambiguous_ = true;
116 } 138 }
117 wifi_phy_layer_protocol_ = mode; 139 wifi_phy_layer_protocol_ = mode;
118 } 140 }
141
142 void NetworkMetricsProvider::WriteWifiAccessPointProto(
143 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info,
144 SystemProfileProto::Network* network_proto) {
145 SystemProfileProto::Network::WifiAccessPoint* access_point_info =
146 network_proto->mutable_access_point_info();
147 SystemProfileProto::Network::WifiAccessPoint::SecurityMode security =
148 SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN;
149 switch (info.security) {
150 case WifiAccessPointInfoProvider::WIFI_SECURITY_NONE:
151 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_NONE;
152 break;
153 case WifiAccessPointInfoProvider::WIFI_SECURITY_WPA:
154 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WPA;
155 break;
156 case WifiAccessPointInfoProvider::WIFI_SECURITY_WEP:
157 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WEP;
158 break;
159 case WifiAccessPointInfoProvider::WIFI_SECURITY_RSN:
160 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_RSN;
161 break;
162 case WifiAccessPointInfoProvider::WIFI_SECURITY_802_1X:
163 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_802_1X;
164 break;
165 case WifiAccessPointInfoProvider::WIFI_SECURITY_PSK:
166 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_PSK;
167 break;
168 case WifiAccessPointInfoProvider::WIFI_SECURITY_UNKNOWN:
169 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN;
170 break;
171 }
172 access_point_info->set_security_mode(security);
173
174 // |bssid| is xx:xx:xx:xx:xx:xx, extract the first three components and
175 // pack into a uint32.
176 std::string bssid = info.bssid;
177 if (bssid.size() == 17 && bssid[2] == ':' && bssid[5] == ':' &&
178 bssid[8] == ':' && bssid[11] == ':' && bssid[14] == ':') {
179 std::string vendor_prefix_str;
180 uint32 vendor_prefix;
181
182 base::RemoveChars(bssid.substr(0, 9), ":", &vendor_prefix_str);
183 DCHECK_EQ(6U, vendor_prefix_str.size());
184 if (base::HexStringToUInt(vendor_prefix_str, &vendor_prefix))
185 access_point_info->set_vendor_prefix(vendor_prefix);
186 else
187 NOTREACHED();
188 }
189
190 // Return if vendor information is not provided.
191 if (info.model_number.empty() && info.model_name.empty() &&
192 info.device_name.empty() && info.oui_list.empty())
193 return;
194
195 SystemProfileProto::Network::WifiAccessPoint::VendorInformation* vendor =
196 access_point_info->mutable_vendor_info();
197 if (!info.model_number.empty())
198 vendor->set_model_number(info.model_number);
199 if (!info.model_name.empty())
200 vendor->set_model_name(info.model_name);
201 if (!info.device_name.empty())
202 vendor->set_device_name(info.device_name);
203
204 // Return if OUI list is not provided.
205 if (info.oui_list.empty())
206 return;
207
208 // Parse OUI list.
209 std::vector<std::string> oui_list;
210 base::SplitString(info.oui_list, ' ', &oui_list);
211 for (std::vector<std::string>::const_iterator it = oui_list.begin();
212 it != oui_list.end();
213 ++it) {
214 uint32 oui;
215 if (base::HexStringToUInt(*it, &oui))
216 vendor->add_element_identifier(oui);
217 else
218 NOTREACHED();
219 }
220 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/network_metrics_provider.h ('k') | chrome/browser/metrics/wifi_access_point_info_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698