Chromium Code Reviews| Index: chrome/browser/metrics/network_metrics_provider.cc |
| diff --git a/chrome/browser/metrics/network_metrics_provider.cc b/chrome/browser/metrics/network_metrics_provider.cc |
| index b339d4b93adcddd000756500e58073e19f3c359a..ecfad85c74e339ca7aaff0e7d5460b13e9d2e24d 100644 |
| --- a/chrome/browser/metrics/network_metrics_provider.cc |
| +++ b/chrome/browser/metrics/network_metrics_provider.cc |
| @@ -5,6 +5,9 @@ |
| #include "chrome/browser/metrics/network_metrics_provider.h" |
| #include "base/compiler_specific.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_split.h" |
| +#include "base/strings/string_util.h" |
| #include "base/task_runner_util.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -39,6 +42,11 @@ void NetworkMetricsProvider::ProvideSystemProfileMetrics( |
| // TODO(isherman): This line seems unnecessary. |
| connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); |
| wifi_phy_layer_protocol_is_ambiguous_ = false; |
| + |
| + // Connected wifi access point information. |
| + net::NetworkChangeNotifier::WifiAccessPointInfo info; |
| + if (net::NetworkChangeNotifier::GetWifiAccessPointInfo(&info)) |
| + WriteWifiAccessPointProto(info, network); |
| } |
| void NetworkMetricsProvider::OnConnectionTypeChanged( |
| @@ -116,3 +124,83 @@ void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( |
| } |
| wifi_phy_layer_protocol_ = mode; |
| } |
| + |
| +void NetworkMetricsProvider::WriteWifiAccessPointProto( |
| + const net::NetworkChangeNotifier::WifiAccessPointInfo& info, |
| + SystemProfileProto::Network* network_proto) { |
| + SystemProfileProto::Network::WifiAccessPoint* ap_info = |
|
Ilya Sherman
2014/07/16 20:03:52
nit: "ap" -> "access_point"
zqiu1
2014/07/16 20:19:11
Done.
|
| + network_proto->mutable_access_point_info(); |
| + |
| + SystemProfileProto::Network::WifiAccessPoint::SecurityMode security = |
| + SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN; |
| + switch (info.security) { |
| + case net::NetworkChangeNotifier::WIFI_SECURITY_NONE: |
| + security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_NONE; |
| + break; |
| + case net::NetworkChangeNotifier::WIFI_SECURITY_WPA: |
| + security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WPA; |
| + break; |
| + case net::NetworkChangeNotifier::WIFI_SECURITY_WEP: |
| + security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WEP; |
| + break; |
| + case net::NetworkChangeNotifier::WIFI_SECURITY_RSN: |
| + security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_RSN; |
| + break; |
| + case net::NetworkChangeNotifier::WIFI_SECURITY_802_1X: |
| + security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_802_1X; |
| + break; |
| + case net::NetworkChangeNotifier::WIFI_SECURITY_PSK: |
| + security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_PSK; |
| + break; |
| + case net::NetworkChangeNotifier::WIFI_SECURITY_UNKNOWN: |
| + security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN; |
| + break; |
| + } |
| + ap_info->set_security_mode(security); |
| + |
| + // |bssid| is xx:xx:xx:xx:xx:xx, extract the first three components and |
| + // pack into a uint32. |
| + std::string bssid = info.bssid; |
| + if (bssid.size() == 17 && bssid[2] == ':' && bssid[5] == ':' && |
| + bssid[8] == ':' && bssid[11] == ':' && bssid[14] == ':') { |
| + std::string vendor_prefix_str; |
| + uint32 vendor_prefix; |
| + |
| + base::RemoveChars(bssid.substr(0, 9), ":", &vendor_prefix_str); |
| + DCHECK_EQ(6U, vendor_prefix_str.size()); |
| + if (base::HexStringToUInt(vendor_prefix_str, &vendor_prefix)) |
| + ap_info->set_vendor_prefix(vendor_prefix); |
| + else |
| + NOTREACHED(); |
| + } |
| + |
| + // Return if vendor information is not provided. |
| + if (info.model_number.empty() && info.model_name.empty() && |
| + info.device_name.empty() && info.oui_list.empty()) |
| + return; |
|
stevenjb
2014/07/16 19:57:29
nit: Actually, this isn't really necessary since w
zqiu1
2014/07/16 20:01:52
This is needed so we don't create a message for Ve
Ilya Sherman
2014/07/16 20:03:52
This *is* necessary, because ap_info->mutable_vend
|
| + |
| + SystemProfileProto::Network::WifiAccessPoint::VendorInformation* vendor = |
| + ap_info->mutable_vendor_info(); |
| + if (!info.model_number.empty()) |
| + vendor->set_model_number(info.model_number); |
| + if (!info.model_name.empty()) |
| + vendor->set_model_name(info.model_name); |
| + if (!info.device_name.empty()) |
| + vendor->set_device_name(info.device_name); |
| + |
| + // Return if OUI list is not provided. |
| + if (info.oui_list.empty()) |
| + return; |
|
stevenjb
2014/07/16 19:57:29
nit: WS after early exit
zqiu1
2014/07/16 20:01:52
Done.
|
| + // Parse OUI list. |
| + std::vector<std::string> oui_list; |
| + base::SplitString(info.oui_list, ' ', &oui_list); |
| + for (std::vector<std::string>::const_iterator it = oui_list.begin(); |
| + it != oui_list.end(); |
| + ++it) { |
| + uint32 oui; |
| + if (base::HexStringToUInt(*it, &oui)) |
| + vendor->add_element_identifier(oui); |
| + else |
| + NOTREACHED(); |
| + } |
| +} |