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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/metrics/wifi_access_point_info_provider_chromeos.h"
6
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"
16
17 using chromeos::NetworkHandler;
18
19 WifiAccessPointInfoProviderChromeos::WifiAccessPointInfoProviderChromeos() {
20 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE);
21
22 // Update initial connection state.
23 DefaultNetworkChanged(
24 NetworkHandler::Get()->network_state_handler()->DefaultNetwork());
25 }
26
27 WifiAccessPointInfoProviderChromeos::~WifiAccessPointInfoProviderChromeos() {
28 }
29
30 bool WifiAccessPointInfoProviderChromeos::GetInfo(WifiAccessPointInfo* info) {
31 // Wifi access point information is not provided if the BSSID is empty.
32 // This assumes the BSSID is never empty when access point information exists.
33 if (wifi_access_point_info_.bssid.empty())
34 return false;
35
36 *info = wifi_access_point_info_;
37 return true;
38 }
39
40 void WifiAccessPointInfoProviderChromeos::DefaultNetworkChanged(
41 const chromeos::NetworkState* default_network) {
42 // Reset access point info to prevent reporting of out-dated data.
43 wifi_access_point_info_ = WifiAccessPointInfo();
44
45 // Skip non-wifi connections
46 if (!default_network || default_network->type() != shill::kTypeWifi)
47 return;
48
49 // Retrieve access point info for wifi connection.
50 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
51 default_network->path(),
52 base::Bind(&WifiAccessPointInfoProviderChromeos::ParseInfo,
53 AsWeakPtr()),
54 chromeos::network_handler::ErrorCallback());
55 }
56
57 void WifiAccessPointInfoProviderChromeos::ParseInfo(
58 const std::string &service_path,
59 const base::DictionaryValue& properties) {
60 // Skip services that contain "_nomap" in the SSID.
61 std::string ssid =
62 chromeos::shill_property_util::GetSSIDFromProperties(properties, NULL);
63 if (ssid.find("_nomap", 0) != std::string::npos)
64 return;
65
66 std::string bssid;
67 properties.GetStringWithoutPathExpansion(shill::kWifiBSsid, &bssid);
stevenjb 2014/08/18 17:28:14 It's possible that the kWifiBSsid property may not
zqiu1 2014/08/18 18:02:29 Done.
68 // Filter out BSSID with local bit set in the first byte.
69 uint32 first_octet;
70 if (!base::HexStringToUInt(bssid.substr(0, 2), &first_octet))
71 NOTREACHED();
72 if (first_octet & 0x2)
73 return;
74 wifi_access_point_info_.bssid = bssid;
75
76 // Parse security info.
77 std::string security;
78 properties.GetStringWithoutPathExpansion(
79 shill::kSecurityProperty, &security);
80 wifi_access_point_info_.security = WIFI_SECURITY_UNKNOWN;
81 if (security == shill::kSecurityWpa)
82 wifi_access_point_info_.security = WIFI_SECURITY_WPA;
83 else if (security == shill::kSecurityWep)
84 wifi_access_point_info_.security = WIFI_SECURITY_WEP;
85 else if (security == shill::kSecurityRsn)
86 wifi_access_point_info_.security = WIFI_SECURITY_RSN;
87 else if (security == shill::kSecurity8021x)
88 wifi_access_point_info_.security = WIFI_SECURITY_802_1X;
89 else if (security == shill::kSecurityPsk)
90 wifi_access_point_info_.security = WIFI_SECURITY_PSK;
91 else if (security == shill::kSecurityNone)
92 wifi_access_point_info_.security = WIFI_SECURITY_NONE;
93
94 properties.GetStringWithoutPathExpansion(
95 shill::kWifiBSsid, &wifi_access_point_info_.bssid);
96 const base::DictionaryValue* vendor_dict = NULL;
97 if (!properties.GetDictionaryWithoutPathExpansion(
98 shill::kWifiVendorInformationProperty,
99 &vendor_dict))
100 return;
101
102 vendor_dict->GetStringWithoutPathExpansion(
103 shill::kVendorWPSModelNumberProperty,
104 &wifi_access_point_info_.model_number);
105 vendor_dict->GetStringWithoutPathExpansion(
106 shill::kVendorWPSModelNameProperty,
107 &wifi_access_point_info_.model_name);
108 vendor_dict->GetStringWithoutPathExpansion(
109 shill::kVendorWPSDeviceNameProperty,
110 &wifi_access_point_info_.device_name);
111 vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty,
112 &wifi_access_point_info_.oui_list);
113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698