Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: chrome/browser/metrics/wifi_access_point_info_provider_chromeos.cc

Issue 328793002: Add wifi AP info to system profile metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/metrics/wifi_access_point_info_provider_chromeos.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/metrics/wifi_access_point_info_provider_chromeos.cc
diff --git a/chrome/browser/metrics/wifi_access_point_info_provider_chromeos.cc b/chrome/browser/metrics/wifi_access_point_info_provider_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..04a232ebac0423e69df0ff4dc81caf29d762c908
--- /dev/null
+++ b/chrome/browser/metrics/wifi_access_point_info_provider_chromeos.cc
@@ -0,0 +1,116 @@
+// 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 "chrome/browser/metrics/wifi_access_point_info_provider_chromeos.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/strings/string_number_conversions.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"
+
+using chromeos::NetworkHandler;
+
+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(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_ = WifiAccessPointInfo();
+
+ // Skip non-wifi connections
+ if (!default_network || default_network->type() != shill::kTypeWifi)
+ return;
+
+ // Retrieve access point info for wifi connection.
+ NetworkHandler::Get()->network_configuration_handler()->GetProperties(
+ default_network->path(),
+ base::Bind(&WifiAccessPointInfoProviderChromeos::ParseInfo,
+ AsWeakPtr()),
+ chromeos::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 =
+ chromeos::shill_property_util::GetSSIDFromProperties(properties, NULL);
+ if (ssid.find("_nomap", 0) != std::string::npos)
+ return;
+
+ std::string bssid;
+ if (!properties.GetStringWithoutPathExpansion(shill::kWifiBSsid, &bssid) ||
+ bssid.empty())
+ return;
+
+ // Filter out BSSID with local bit set in the first byte.
+ uint32 first_octet;
+ if (!base::HexStringToUInt(bssid.substr(0, 2), &first_octet))
+ NOTREACHED();
+ if (first_octet & 0x2)
+ return;
+ wifi_access_point_info_.bssid = bssid;
+
+ // Parse security info.
+ std::string security;
+ properties.GetStringWithoutPathExpansion(
+ shill::kSecurityProperty, &security);
+ wifi_access_point_info_.security = WIFI_SECURITY_UNKNOWN;
+ if (security == shill::kSecurityWpa)
+ wifi_access_point_info_.security = WIFI_SECURITY_WPA;
+ else if (security == shill::kSecurityWep)
+ wifi_access_point_info_.security = WIFI_SECURITY_WEP;
+ else if (security == shill::kSecurityRsn)
+ wifi_access_point_info_.security = WIFI_SECURITY_RSN;
+ else if (security == shill::kSecurity8021x)
+ wifi_access_point_info_.security = WIFI_SECURITY_802_1X;
+ else if (security == shill::kSecurityPsk)
+ wifi_access_point_info_.security = WIFI_SECURITY_PSK;
+ else if (security == shill::kSecurityNone)
+ wifi_access_point_info_.security = 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);
+}
« no previous file with comments | « chrome/browser/metrics/wifi_access_point_info_provider_chromeos.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698