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" | |
| 11 #include "base/strings/utf_string_conversions.h" | |
|
Ilya Sherman
2014/07/10 00:39:09
Where do you use UTF string conversions? (Am I ju
zqiu1
2014/07/10 18:11:55
Not needed. Will remove.
| |
| 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 AP information. | |
| 48 net::NetworkChangeNotifier::WifiApInfo info; | |
| 49 if (net::NetworkChangeNotifier::GetWifiApInfo(&info)) { | |
| 50 WriteWifiApProto(info, network); | |
| 51 } | |
|
Ilya Sherman
2014/07/10 00:39:10
nit: No need for curly braces.
zqiu1
2014/07/10 18:11:55
Done.
| |
| 42 } | 52 } |
| 43 | 53 |
| 44 void NetworkMetricsProvider::OnConnectionTypeChanged( | 54 void NetworkMetricsProvider::OnConnectionTypeChanged( |
| 45 net::NetworkChangeNotifier::ConnectionType type) { | 55 net::NetworkChangeNotifier::ConnectionType type) { |
| 46 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) | 56 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) |
| 47 return; | 57 return; |
| 48 if (type != connection_type_ && | 58 if (type != connection_type_ && |
| 49 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { | 59 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 50 connection_type_is_ambiguous_ = true; | 60 connection_type_is_ambiguous_ = true; |
| 51 } | 61 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 } | 119 } |
| 110 | 120 |
| 111 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( | 121 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( |
| 112 net::WifiPHYLayerProtocol mode) { | 122 net::WifiPHYLayerProtocol mode) { |
| 113 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && | 123 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && |
| 114 mode != wifi_phy_layer_protocol_) { | 124 mode != wifi_phy_layer_protocol_) { |
| 115 wifi_phy_layer_protocol_is_ambiguous_ = true; | 125 wifi_phy_layer_protocol_is_ambiguous_ = true; |
| 116 } | 126 } |
| 117 wifi_phy_layer_protocol_ = mode; | 127 wifi_phy_layer_protocol_ = mode; |
| 118 } | 128 } |
| 129 | |
| 130 void NetworkMetricsProvider::WriteWifiApProto( | |
| 131 const net::NetworkChangeNotifier::WifiApInfo &info, | |
| 132 SystemProfileProto::Network *network_proto) { | |
|
Ilya Sherman
2014/07/10 00:39:09
Note: The nit from the header file applies here as
zqiu1
2014/07/10 18:11:55
Done.
| |
| 133 SystemProfileProto::Network::WifiAccessPoint* ap_info = | |
| 134 network_proto->mutable_access_point_info(); | |
| 135 | |
| 136 SystemProfileProto::Network::WifiAccessPoint::SecurityMode security; | |
| 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 default: | |
|
Ilya Sherman
2014/07/10 00:39:10
Please replace the default case with explicit hand
zqiu1
2014/07/10 18:11:55
Done.
| |
| 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() > 9 && bssid[2] == ':' && bssid[5] == ':' && | |
| 166 bssid[8] == ':') { | |
|
Ilya Sherman
2014/07/10 00:39:09
Why not check the full format, rather than just th
Ilya Sherman
2014/07/10 00:39:10
nit: Please de-indent this line by two spaces.
zqiu1
2014/07/10 18:11:55
I think the reason was that we only care about the
| |
| 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 base::HexStringToUInt(vendor_prefix_str, &vendor_prefix); | |
|
Ilya Sherman
2014/07/10 00:39:10
What if this conversion fails?
zqiu1
2014/07/10 18:11:55
We will log a warning message.
| |
| 173 | |
| 174 ap_info->set_vendor_prefix(vendor_prefix); | |
| 175 } | |
| 176 | |
| 177 // Fill in vendor information if it is provided. | |
| 178 if (!info.model_number.empty() || !info.model_name.empty() || | |
| 179 !info.device_name.empty() || !info.oui_list.empty()) { | |
|
Ilya Sherman
2014/07/10 00:39:09
Hmm, how about creating a local VendorInformation
zqiu1
2014/07/10 18:11:55
The outer if-stmts are not needed, I will just obt
| |
| 180 SystemProfileProto::Network::WifiAccessPoint::VendorInformation *vendor = | |
|
Ilya Sherman
2014/07/10 00:39:09
nit: Swap the space and asterisk
zqiu1
2014/07/10 18:11:55
Done.
| |
| 181 ap_info->mutable_vendor_info(); | |
| 182 if (!info.model_number.empty()) { | |
| 183 vendor->set_model_number(info.model_number); | |
| 184 } | |
| 185 if (!info.model_name.empty()) { | |
| 186 vendor->set_model_name(info.model_name); | |
| 187 } | |
| 188 if (!info.device_name.empty()) { | |
| 189 vendor->set_device_name(info.device_name); | |
| 190 } | |
|
Ilya Sherman
2014/07/10 00:39:09
nit: No need for curly braces for one-line if-stmt
zqiu1
2014/07/10 18:11:55
Done.
| |
| 191 | |
| 192 // Parse OUI list. | |
| 193 if (!info.oui_list.empty()) { | |
| 194 std::vector<std::string> oui_list; | |
| 195 base::SplitString(info.oui_list, ' ', &oui_list); | |
| 196 for (std::vector<std::string>::const_iterator i = oui_list.begin(); | |
|
Ilya Sherman
2014/07/10 00:39:10
nit: "i" -> "it"
zqiu1
2014/07/10 18:11:55
Done.
| |
| 197 i != oui_list.end(); | |
| 198 ++i) { | |
| 199 uint32 oui; | |
| 200 base::HexStringToUInt(*i, &oui); | |
|
Ilya Sherman
2014/07/10 00:39:09
What happens if this conversion fails?
zqiu1
2014/07/10 18:11:55
We will log a warning message.
| |
| 201 vendor->add_element_identifier(oui); | |
| 202 } | |
| 203 } | |
| 204 } | |
| 205 } | |
| OLD | NEW |