| 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" |
| 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(network, &info); |
| 51 } |
| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 117 } |
| 108 | 118 |
| 109 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( | 119 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( |
| 110 net::WifiPHYLayerProtocol mode) { | 120 net::WifiPHYLayerProtocol mode) { |
| 111 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && | 121 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && |
| 112 mode != wifi_phy_layer_protocol_) { | 122 mode != wifi_phy_layer_protocol_) { |
| 113 wifi_phy_layer_protocol_is_ambiguous_ = true; | 123 wifi_phy_layer_protocol_is_ambiguous_ = true; |
| 114 } | 124 } |
| 115 wifi_phy_layer_protocol_ = mode; | 125 wifi_phy_layer_protocol_ = mode; |
| 116 } | 126 } |
| 127 |
| 128 void NetworkMetricsProvider::WriteWifiApProto( |
| 129 SystemProfileProto::Network *network_proto, |
| 130 const net::NetworkChangeNotifier::WifiApInfo *info) { |
| 131 SystemProfileProto::Network::WifiAp* ap_info = |
| 132 network_proto->mutable_ap_info(); |
| 133 |
| 134 // |bssid| is xx:xx:xx:xx:xx:xx, extract the first three components and |
| 135 // pack into a uint32. |
| 136 std::string bssid = info->bssid; |
| 137 if (bssid.size() > 9 && bssid[2] == ':' && bssid[5] == ':' && |
| 138 bssid[8] == ':') { |
| 139 std::string vendor_prefix_str; |
| 140 uint32 vendor_prefix; |
| 141 |
| 142 base::RemoveChars(bssid.substr(0, 9), ":", &vendor_prefix_str); |
| 143 DCHECK_EQ(6U, vendor_prefix_str.size()); |
| 144 base::HexStringToUInt(vendor_prefix_str, &vendor_prefix); |
| 145 |
| 146 ap_info->set_vendor_prefix(vendor_prefix); |
| 147 } |
| 148 if (!info->security.empty()) { |
| 149 ap_info->set_security_mode(info->security); |
| 150 } |
| 151 |
| 152 // Fill in vendor information if it is provided. |
| 153 if (!info->model_number.empty() || !info->model_name.empty() || |
| 154 !info->device_name.empty() || !info->manufacturer.empty() || |
| 155 !info->oui_list.empty()) { |
| 156 SystemProfileProto::Network::WifiAp::VendorInformation *vendor_info = |
| 157 ap_info->mutable_vendor_info(); |
| 158 if (!info->model_number.empty()) { |
| 159 vendor_info->set_model_number(info->model_number); |
| 160 } |
| 161 if (!info->model_name.empty()) { |
| 162 vendor_info->set_model_name(info->model_name); |
| 163 } |
| 164 if (!info->device_name.empty()) { |
| 165 vendor_info->set_device_name(info->device_name); |
| 166 } |
| 167 if (!info->manufacturer.empty()) { |
| 168 vendor_info->set_manufacturer(info->manufacturer); |
| 169 } |
| 170 |
| 171 // Parse OUI list. |
| 172 if (!info->oui_list.empty()) { |
| 173 std::vector<std::string> oui_list; |
| 174 base::SplitString(info->oui_list, ' ', &oui_list); |
| 175 for (std::vector<std::string>::const_iterator i = oui_list.begin(); |
| 176 i != oui_list.end(); |
| 177 ++i) { |
| 178 uint32 oui; |
| 179 base::HexStringToUInt(*i, &oui); |
| 180 vendor_info->add_oui(oui); |
| 181 } |
| 182 } |
| 183 } |
| 184 } |
| OLD | NEW |