Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 = | |
|
Ilya Sherman
2014/07/16 20:03:52
nit: "ap" -> "access_point"
zqiu1
2014/07/16 20:19:11
Done.
| |
| 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 // Return if vendor information is not provided. | |
| 178 if (info.model_number.empty() && info.model_name.empty() && | |
| 179 info.device_name.empty() && info.oui_list.empty()) | |
| 180 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
| |
| 181 | |
| 182 SystemProfileProto::Network::WifiAccessPoint::VendorInformation* vendor = | |
| 183 ap_info->mutable_vendor_info(); | |
| 184 if (!info.model_number.empty()) | |
| 185 vendor->set_model_number(info.model_number); | |
| 186 if (!info.model_name.empty()) | |
| 187 vendor->set_model_name(info.model_name); | |
| 188 if (!info.device_name.empty()) | |
| 189 vendor->set_device_name(info.device_name); | |
| 190 | |
| 191 // Return if OUI list is not provided. | |
| 192 if (info.oui_list.empty()) | |
| 193 return; | |
|
stevenjb
2014/07/16 19:57:29
nit: WS after early exit
zqiu1
2014/07/16 20:01:52
Done.
| |
| 194 // Parse OUI list. | |
| 195 std::vector<std::string> oui_list; | |
| 196 base::SplitString(info.oui_list, ' ', &oui_list); | |
| 197 for (std::vector<std::string>::const_iterator it = oui_list.begin(); | |
| 198 it != oui_list.end(); | |
| 199 ++it) { | |
| 200 uint32 oui; | |
| 201 if (base::HexStringToUInt(*it, &oui)) | |
| 202 vendor->add_element_identifier(oui); | |
| 203 else | |
| 204 NOTREACHED(); | |
| 205 } | |
| 206 } | |
| OLD | NEW |