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

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 if (!properties.GetStringWithoutPathExpansion(shill::kWifiBSsid, &bssid) ||
68 bssid.empty())
69 return;
70
71 // Filter out BSSID with local bit set in the first byte.
72 uint32 first_octet;
73 if (!base::HexStringToUInt(bssid.substr(0, 2), &first_octet))
74 NOTREACHED();
75 if (first_octet & 0x2)
76 return;
77 wifi_access_point_info_.bssid = bssid;
78
79 // Parse security info.
80 std::string security;
81 properties.GetStringWithoutPathExpansion(
82 shill::kSecurityProperty, &security);
83 wifi_access_point_info_.security = WIFI_SECURITY_UNKNOWN;
84 if (security == shill::kSecurityWpa)
85 wifi_access_point_info_.security = WIFI_SECURITY_WPA;
86 else if (security == shill::kSecurityWep)
87 wifi_access_point_info_.security = WIFI_SECURITY_WEP;
88 else if (security == shill::kSecurityRsn)
89 wifi_access_point_info_.security = WIFI_SECURITY_RSN;
90 else if (security == shill::kSecurity8021x)
91 wifi_access_point_info_.security = WIFI_SECURITY_802_1X;
92 else if (security == shill::kSecurityPsk)
93 wifi_access_point_info_.security = WIFI_SECURITY_PSK;
94 else if (security == shill::kSecurityNone)
95 wifi_access_point_info_.security = WIFI_SECURITY_NONE;
96
97 properties.GetStringWithoutPathExpansion(
98 shill::kWifiBSsid, &wifi_access_point_info_.bssid);
99 const base::DictionaryValue* vendor_dict = NULL;
100 if (!properties.GetDictionaryWithoutPathExpansion(
101 shill::kWifiVendorInformationProperty,
102 &vendor_dict))
103 return;
104
105 vendor_dict->GetStringWithoutPathExpansion(
106 shill::kVendorWPSModelNumberProperty,
107 &wifi_access_point_info_.model_number);
108 vendor_dict->GetStringWithoutPathExpansion(
109 shill::kVendorWPSModelNameProperty,
110 &wifi_access_point_info_.model_name);
111 vendor_dict->GetStringWithoutPathExpansion(
112 shill::kVendorWPSDeviceNameProperty,
113 &wifi_access_point_info_.device_name);
114 vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty,
115 &wifi_access_point_info_.oui_list);
116 }
OLDNEW
« 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