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

Side by Side Diff: chromeos/network/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, 5 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 "chromeos/network/wifi_access_point_info_provider_chromeos.h"
6
7 #include "chromeos/network/device_state.h"
8 #include "chromeos/network/network_configuration_handler.h"
9 #include "chromeos/network/network_handler.h"
10 #include "chromeos/network/network_state.h"
11 #include "chromeos/network/network_state_handler.h"
12 #include "chromeos/network/shill_property_util.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h"
14
15 namespace chromeos {
16
17 WifiAccessPointInfoProviderChromeos::WifiAccessPointInfoProviderChromeos() {
18 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE);
19
20 // Update initial connection state.
21 DefaultNetworkChanged(
22 NetworkHandler::Get()->network_state_handler()->DefaultNetwork());
23 }
24
25 WifiAccessPointInfoProviderChromeos::~WifiAccessPointInfoProviderChromeos() {
26 }
27
28 bool WifiAccessPointInfoProviderChromeos::GetInfo(
29 net::WifiAccessPointInfo* info) {
30 // Wifi access point information is not provided if the BSSID is empty.
31 // This assumes the BSSID is never empty when access point information exists.
32 if (wifi_access_point_info_.bssid.empty())
33 return false;
34
35 *info = wifi_access_point_info_;
36 return true;
37 }
38
39 void WifiAccessPointInfoProviderChromeos::DefaultNetworkChanged(
40 const chromeos::NetworkState* default_network) {
41 // Reset access point info to prevent reporting of out-dated data.
42 wifi_access_point_info_ = net::WifiAccessPointInfo();
43
44 if (!default_network)
45 return;
46
47 // Retrieve access point info for wifi connection.
48 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.
49 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
50 default_network->path(),
51 base::Bind(&WifiAccessPointInfoProviderChromeos::ParseInfo,
52 AsWeakPtr()),
53 network_handler::ErrorCallback());
54 }
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 = shill_property_util::GetSSIDFromProperties(
62 properties, NULL);
63 if (ssid.find("_nomap", 0) != std::string::npos)
64 return;
65
66 // Parse security info.
67 std::string security;
68 properties.GetStringWithoutPathExpansion(
69 shill::kSecurityProperty, &security);
70 wifi_access_point_info_.security = net::WIFI_SECURITY_UNKNOWN;
71 if (security == shill::kSecurityWpa)
72 wifi_access_point_info_.security = net::WIFI_SECURITY_WPA;
73 else if (security == shill::kSecurityWep)
74 wifi_access_point_info_.security = net::WIFI_SECURITY_WEP;
75 else if (security == shill::kSecurityRsn)
76 wifi_access_point_info_.security = net::WIFI_SECURITY_RSN;
77 else if (security == shill::kSecurity8021x)
78 wifi_access_point_info_.security = net::WIFI_SECURITY_802_1X;
79 else if (security == shill::kSecurityPsk)
80 wifi_access_point_info_.security = net::WIFI_SECURITY_PSK;
81 else if (security == shill::kSecurityNone)
82 wifi_access_point_info_.security = net::WIFI_SECURITY_NONE;
83
84 properties.GetStringWithoutPathExpansion(
85 shill::kWifiBSsid, &wifi_access_point_info_.bssid);
86 const base::DictionaryValue* vendor_dict = NULL;
87
88 if (!properties.GetDictionaryWithoutPathExpansion(
89 shill::kWifiVendorInformationProperty,
90 &vendor_dict))
91 return;
92
93 vendor_dict->GetStringWithoutPathExpansion(
94 shill::kVendorWPSModelNumberProperty,
95 &wifi_access_point_info_.model_number);
96 vendor_dict->GetStringWithoutPathExpansion(
97 shill::kVendorWPSModelNameProperty,
98 &wifi_access_point_info_.model_name);
99 vendor_dict->GetStringWithoutPathExpansion(
100 shill::kVendorWPSDeviceNameProperty,
101 &wifi_access_point_info_.device_name);
102 vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty,
103 &wifi_access_point_info_.oui_list);
104 }
105
106 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698