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/logging.h" | |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/strings/string_split.h" | |
| 11 #include "base/strings/string_util.h" | |
| 8 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 11 | 15 |
| 12 using metrics::SystemProfileProto; | 16 using metrics::SystemProfileProto; |
| 13 | 17 |
| 14 NetworkMetricsProvider::NetworkMetricsProvider() | 18 NetworkMetricsProvider::NetworkMetricsProvider() |
| 15 : connection_type_is_ambiguous_(false), | 19 : connection_type_is_ambiguous_(false), |
| 16 wifi_phy_layer_protocol_is_ambiguous_(false), | 20 wifi_phy_layer_protocol_is_ambiguous_(false), |
| 17 wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN), | 21 wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 32 network->set_connection_type(GetConnectionType()); | 36 network->set_connection_type(GetConnectionType()); |
| 33 network->set_wifi_phy_layer_protocol_is_ambiguous( | 37 network->set_wifi_phy_layer_protocol_is_ambiguous( |
| 34 wifi_phy_layer_protocol_is_ambiguous_); | 38 wifi_phy_layer_protocol_is_ambiguous_); |
| 35 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol()); | 39 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol()); |
| 36 | 40 |
| 37 // Resets the "ambiguous" flags, since a new metrics log session has started. | 41 // Resets the "ambiguous" flags, since a new metrics log session has started. |
| 38 connection_type_is_ambiguous_ = false; | 42 connection_type_is_ambiguous_ = false; |
| 39 // TODO(isherman): This line seems unnecessary. | 43 // TODO(isherman): This line seems unnecessary. |
| 40 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); | 44 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); |
| 41 wifi_phy_layer_protocol_is_ambiguous_ = false; | 45 wifi_phy_layer_protocol_is_ambiguous_ = false; |
| 46 | |
| 47 // Connected wifi access point information. | |
| 48 net::NetworkChangeNotifier::WifiAccessPointInfo info; | |
| 49 if (net::NetworkChangeNotifier::GetWifiAccessPointInfo(&info)) | |
| 50 WriteWifiAccessPointProto(info, network); | |
| 42 } | 51 } |
| 43 | 52 |
| 44 void NetworkMetricsProvider::OnConnectionTypeChanged( | 53 void NetworkMetricsProvider::OnConnectionTypeChanged( |
| 45 net::NetworkChangeNotifier::ConnectionType type) { | 54 net::NetworkChangeNotifier::ConnectionType type) { |
| 46 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) | 55 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) |
| 47 return; | 56 return; |
| 48 if (type != connection_type_ && | 57 if (type != connection_type_ && |
| 49 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { | 58 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 50 connection_type_is_ambiguous_ = true; | 59 connection_type_is_ambiguous_ = true; |
| 51 } | 60 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 } | 118 } |
| 110 | 119 |
| 111 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( | 120 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( |
| 112 net::WifiPHYLayerProtocol mode) { | 121 net::WifiPHYLayerProtocol mode) { |
| 113 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && | 122 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && |
| 114 mode != wifi_phy_layer_protocol_) { | 123 mode != wifi_phy_layer_protocol_) { |
| 115 wifi_phy_layer_protocol_is_ambiguous_ = true; | 124 wifi_phy_layer_protocol_is_ambiguous_ = true; |
| 116 } | 125 } |
| 117 wifi_phy_layer_protocol_ = mode; | 126 wifi_phy_layer_protocol_ = mode; |
| 118 } | 127 } |
| 128 | |
| 129 void NetworkMetricsProvider::WriteWifiAccessPointProto( | |
| 130 const net::NetworkChangeNotifier::WifiAccessPointInfo& info, | |
| 131 SystemProfileProto::Network* network_proto) { | |
| 132 SystemProfileProto::Network::WifiAccessPoint* ap_info = | |
| 133 network_proto->mutable_access_point_info(); | |
| 134 | |
| 135 SystemProfileProto::Network::WifiAccessPoint::SecurityMode security = | |
| 136 SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN; | |
| 137 switch (info.security) { | |
| 138 case net::NetworkChangeNotifier::WIFI_SECURITY_NONE: | |
| 139 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_NONE; | |
| 140 break; | |
| 141 case net::NetworkChangeNotifier::WIFI_SECURITY_WPA: | |
| 142 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WPA; | |
| 143 break; | |
| 144 case net::NetworkChangeNotifier::WIFI_SECURITY_WEP: | |
| 145 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WEP; | |
| 146 break; | |
| 147 case net::NetworkChangeNotifier::WIFI_SECURITY_RSN: | |
| 148 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_RSN; | |
| 149 break; | |
| 150 case net::NetworkChangeNotifier::WIFI_SECURITY_802_1X: | |
| 151 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_802_1X; | |
| 152 break; | |
| 153 case net::NetworkChangeNotifier::WIFI_SECURITY_PSK: | |
| 154 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_PSK; | |
| 155 break; | |
| 156 case net::NetworkChangeNotifier::WIFI_SECURITY_UNKNOWN: | |
| 157 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN; | |
| 158 break; | |
| 159 } | |
| 160 ap_info->set_security_mode(security); | |
| 161 | |
| 162 // |bssid| is xx:xx:xx:xx:xx:xx, extract the first three components and | |
| 163 // pack into a uint32. | |
| 164 std::string bssid = info.bssid; | |
| 165 if (bssid.size() == 17 && bssid[2] == ':' && bssid[5] == ':' && | |
| 166 bssid[8] == ':' && bssid[11] == ':' && bssid[14] == ':') { | |
| 167 std::string vendor_prefix_str; | |
| 168 uint32 vendor_prefix; | |
| 169 | |
| 170 base::RemoveChars(bssid.substr(0, 9), ":", &vendor_prefix_str); | |
| 171 DCHECK_EQ(6U, vendor_prefix_str.size()); | |
| 172 if (base::HexStringToUInt(vendor_prefix_str, &vendor_prefix)) | |
| 173 ap_info->set_vendor_prefix(vendor_prefix); | |
| 174 else | |
| 175 LOG(WARNING) << "Failed to convert vendor prefix: " << vendor_prefix_str; | |
|
Ilya Sherman
2014/07/11 01:32:17
Can this be a NOTREACHED() instead? If not, I'd a
zqiu1
2014/07/14 17:21:57
Will change to NOTREACHED()
| |
| 176 } | |
| 177 | |
| 178 SystemProfileProto::Network::WifiAccessPoint::VendorInformation* vendor = | |
| 179 ap_info->mutable_vendor_info(); | |
|
Ilya Sherman
2014/07/11 01:32:17
This actually sets creates a vendor_info field. P
zqiu1
2014/07/14 17:21:57
Then that's no different than my original implemen
Ilya Sherman
2014/07/14 21:25:54
I agree that the functionality is equivalent -- my
| |
| 180 if (!info.model_number.empty()) | |
| 181 vendor->set_model_number(info.model_number); | |
| 182 if (!info.model_name.empty()) | |
| 183 vendor->set_model_name(info.model_name); | |
| 184 if (!info.device_name.empty()) | |
| 185 vendor->set_device_name(info.device_name); | |
| 186 // Parse OUI list. | |
| 187 if (!info.oui_list.empty()) { | |
| 188 std::vector<std::string> oui_list; | |
| 189 base::SplitString(info.oui_list, ' ', &oui_list); | |
| 190 for (std::vector<std::string>::const_iterator it = oui_list.begin(); | |
| 191 it != oui_list.end(); | |
| 192 ++it) { | |
| 193 uint32 oui; | |
| 194 if (base::HexStringToUInt(*it, &oui)) | |
| 195 vendor->add_element_identifier(oui); | |
| 196 else | |
| 197 LOG(WARNING) << "Failed to convert element identifier: " << *it; | |
|
Ilya Sherman
2014/07/11 01:32:17
Ditto.
zqiu1
2014/07/14 17:21:57
Done.
| |
| 198 } | |
| 199 } | |
| 200 } | |
| OLD | NEW |