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

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

Powered by Google App Engine
This is Rietveld 408576698