Chromium Code Reviews| Index: chromeos/network/wifi_access_point_info_provider_chromeos.cc |
| diff --git a/chromeos/network/wifi_access_point_info_provider_chromeos.cc b/chromeos/network/wifi_access_point_info_provider_chromeos.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..579b35218775d6e4131f95493b138bdacfa1e1f9 |
| --- /dev/null |
| +++ b/chromeos/network/wifi_access_point_info_provider_chromeos.cc |
| @@ -0,0 +1,106 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chromeos/network/wifi_access_point_info_provider_chromeos.h" |
| + |
| +#include "chromeos/network/device_state.h" |
| +#include "chromeos/network/network_configuration_handler.h" |
| +#include "chromeos/network/network_handler.h" |
| +#include "chromeos/network/network_state.h" |
| +#include "chromeos/network/network_state_handler.h" |
| +#include "chromeos/network/shill_property_util.h" |
| +#include "third_party/cros_system_api/dbus/service_constants.h" |
| + |
| +namespace chromeos { |
| + |
| +WifiAccessPointInfoProviderChromeos::WifiAccessPointInfoProviderChromeos() { |
| + NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); |
| + |
| + // Update initial connection state. |
| + DefaultNetworkChanged( |
| + NetworkHandler::Get()->network_state_handler()->DefaultNetwork()); |
| +} |
| + |
| +WifiAccessPointInfoProviderChromeos::~WifiAccessPointInfoProviderChromeos() { |
| +} |
| + |
| +bool WifiAccessPointInfoProviderChromeos::GetInfo( |
| + net::WifiAccessPointInfo* info) { |
| + // Wifi access point information is not provided if the BSSID is empty. |
| + // This assumes the BSSID is never empty when access point information exists. |
| + if (wifi_access_point_info_.bssid.empty()) |
| + return false; |
| + |
| + *info = wifi_access_point_info_; |
| + return true; |
| +} |
| + |
| +void WifiAccessPointInfoProviderChromeos::DefaultNetworkChanged( |
| + const chromeos::NetworkState* default_network) { |
| + // Reset access point info to prevent reporting of out-dated data. |
| + wifi_access_point_info_ = net::WifiAccessPointInfo(); |
| + |
| + if (!default_network) |
| + return; |
| + |
| + // Retrieve access point info for wifi connection. |
| + if (default_network->type() == shill::kTypeWifi) { |
|
stevenjb
2014/07/23 22:21:16
nit: early exit instead (could combine with !defau
zqiu1
2014/07/23 22:41:32
Done.
|
| + NetworkHandler::Get()->network_configuration_handler()->GetProperties( |
| + default_network->path(), |
| + base::Bind(&WifiAccessPointInfoProviderChromeos::ParseInfo, |
| + AsWeakPtr()), |
| + network_handler::ErrorCallback()); |
| + } |
| +} |
| + |
| +void WifiAccessPointInfoProviderChromeos::ParseInfo( |
| + const std::string &service_path, |
| + const base::DictionaryValue& properties) { |
| + // Skip services that contain "_nomap" in the SSID. |
| + std::string ssid = shill_property_util::GetSSIDFromProperties( |
| + properties, NULL); |
| + if (ssid.find("_nomap", 0) != std::string::npos) |
| + return; |
| + |
| + // Parse security info. |
| + std::string security; |
| + properties.GetStringWithoutPathExpansion( |
| + shill::kSecurityProperty, &security); |
| + wifi_access_point_info_.security = net::WIFI_SECURITY_UNKNOWN; |
| + if (security == shill::kSecurityWpa) |
| + wifi_access_point_info_.security = net::WIFI_SECURITY_WPA; |
| + else if (security == shill::kSecurityWep) |
| + wifi_access_point_info_.security = net::WIFI_SECURITY_WEP; |
| + else if (security == shill::kSecurityRsn) |
| + wifi_access_point_info_.security = net::WIFI_SECURITY_RSN; |
| + else if (security == shill::kSecurity8021x) |
| + wifi_access_point_info_.security = net::WIFI_SECURITY_802_1X; |
| + else if (security == shill::kSecurityPsk) |
| + wifi_access_point_info_.security = net::WIFI_SECURITY_PSK; |
| + else if (security == shill::kSecurityNone) |
| + wifi_access_point_info_.security = net::WIFI_SECURITY_NONE; |
| + |
| + properties.GetStringWithoutPathExpansion( |
| + shill::kWifiBSsid, &wifi_access_point_info_.bssid); |
| + const base::DictionaryValue* vendor_dict = NULL; |
| + |
| + if (!properties.GetDictionaryWithoutPathExpansion( |
| + shill::kWifiVendorInformationProperty, |
| + &vendor_dict)) |
| + return; |
| + |
| + vendor_dict->GetStringWithoutPathExpansion( |
| + shill::kVendorWPSModelNumberProperty, |
| + &wifi_access_point_info_.model_number); |
| + vendor_dict->GetStringWithoutPathExpansion( |
| + shill::kVendorWPSModelNameProperty, |
| + &wifi_access_point_info_.model_name); |
| + vendor_dict->GetStringWithoutPathExpansion( |
| + shill::kVendorWPSDeviceNameProperty, |
| + &wifi_access_point_info_.device_name); |
| + vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty, |
| + &wifi_access_point_info_.oui_list); |
| +} |
| + |
| +} // namespace chromeos |