Update V8 to version 4.6.62.
[chromium-blink-merge.git] / components / metrics / net / wifi_access_point_info_provider_chromeos.cc
blob16471bc12ee39c2239c42c257bb3478352d1a48b
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
3 // found in the LICENSE file.
5 #include "components/metrics/net/wifi_access_point_info_provider_chromeos.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "chromeos/network/network_configuration_handler.h"
11 #include "chromeos/network/network_handler.h"
12 #include "chromeos/network/network_state.h"
13 #include "chromeos/network/network_state_handler.h"
14 #include "chromeos/network/shill_property_util.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h"
17 using chromeos::NetworkHandler;
19 namespace metrics {
21 WifiAccessPointInfoProviderChromeos::WifiAccessPointInfoProviderChromeos() {
22 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE);
24 // Update initial connection state.
25 DefaultNetworkChanged(
26 NetworkHandler::Get()->network_state_handler()->DefaultNetwork());
29 WifiAccessPointInfoProviderChromeos::~WifiAccessPointInfoProviderChromeos() {
30 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
31 FROM_HERE);
34 bool WifiAccessPointInfoProviderChromeos::GetInfo(WifiAccessPointInfo* info) {
35 // Wifi access point information is not provided if the BSSID is empty.
36 // This assumes the BSSID is never empty when access point information exists.
37 if (wifi_access_point_info_.bssid.empty())
38 return false;
40 *info = wifi_access_point_info_;
41 return true;
44 void WifiAccessPointInfoProviderChromeos::DefaultNetworkChanged(
45 const chromeos::NetworkState* default_network) {
46 // Reset access point info to prevent reporting of out-dated data.
47 wifi_access_point_info_ = WifiAccessPointInfo();
49 // Skip non-wifi connections
50 if (!default_network || default_network->type() != shill::kTypeWifi)
51 return;
53 // Retrieve access point info for wifi connection.
54 NetworkHandler::Get()->network_configuration_handler()->GetShillProperties(
55 default_network->path(),
56 base::Bind(&WifiAccessPointInfoProviderChromeos::ParseInfo, AsWeakPtr()),
57 chromeos::network_handler::ErrorCallback());
60 void WifiAccessPointInfoProviderChromeos::ParseInfo(
61 const std::string &service_path,
62 const base::DictionaryValue& properties) {
63 // Skip services that contain "_nomap" in the SSID.
64 std::string ssid = chromeos::shill_property_util::GetSSIDFromProperties(
65 properties, false /* verbose_logging */, nullptr);
66 if (ssid.find("_nomap", 0) != std::string::npos)
67 return;
69 std::string bssid;
70 if (!properties.GetStringWithoutPathExpansion(shill::kWifiBSsid, &bssid) ||
71 bssid.empty())
72 return;
74 // Filter out BSSID with local bit set in the first byte.
75 uint32 first_octet;
76 if (!base::HexStringToUInt(bssid.substr(0, 2), &first_octet))
77 NOTREACHED();
78 if (first_octet & 0x2)
79 return;
80 wifi_access_point_info_.bssid = bssid;
82 // Parse security info.
83 std::string security;
84 properties.GetStringWithoutPathExpansion(
85 shill::kSecurityProperty, &security);
86 wifi_access_point_info_.security = WIFI_SECURITY_UNKNOWN;
87 if (security == shill::kSecurityWpa)
88 wifi_access_point_info_.security = WIFI_SECURITY_WPA;
89 else if (security == shill::kSecurityWep)
90 wifi_access_point_info_.security = WIFI_SECURITY_WEP;
91 else if (security == shill::kSecurityRsn)
92 wifi_access_point_info_.security = WIFI_SECURITY_RSN;
93 else if (security == shill::kSecurity8021x)
94 wifi_access_point_info_.security = WIFI_SECURITY_802_1X;
95 else if (security == shill::kSecurityPsk)
96 wifi_access_point_info_.security = WIFI_SECURITY_PSK;
97 else if (security == shill::kSecurityNone)
98 wifi_access_point_info_.security = WIFI_SECURITY_NONE;
100 properties.GetStringWithoutPathExpansion(
101 shill::kWifiBSsid, &wifi_access_point_info_.bssid);
102 const base::DictionaryValue* vendor_dict = NULL;
103 if (!properties.GetDictionaryWithoutPathExpansion(
104 shill::kWifiVendorInformationProperty,
105 &vendor_dict))
106 return;
108 vendor_dict->GetStringWithoutPathExpansion(
109 shill::kVendorWPSModelNumberProperty,
110 &wifi_access_point_info_.model_number);
111 vendor_dict->GetStringWithoutPathExpansion(
112 shill::kVendorWPSModelNameProperty,
113 &wifi_access_point_info_.model_name);
114 vendor_dict->GetStringWithoutPathExpansion(
115 shill::kVendorWPSDeviceNameProperty,
116 &wifi_access_point_info_.device_name);
117 vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty,
118 &wifi_access_point_info_.oui_list);
121 } // namespace metrics