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

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 "chromeos/network/network_configuration_handler.h"
10 #include "chromeos/network/network_handler.h"
11 #include "chromeos/network/network_state.h"
12 #include "chromeos/network/network_state_handler.h"
13 #include "chromeos/network/shill_property_util.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h"
15
16 using chromeos::NetworkHandler;
17
18 WifiAccessPointInfoProviderChromeos::WifiAccessPointInfoProviderChromeos() {
19 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE);
20
21 // Update initial connection state.
22 DefaultNetworkChanged(
23 NetworkHandler::Get()->network_state_handler()->DefaultNetwork());
24 }
25
26 WifiAccessPointInfoProviderChromeos::~WifiAccessPointInfoProviderChromeos() {
27 }
28
29 bool WifiAccessPointInfoProviderChromeos::GetInfo(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_ = WifiAccessPointInfo();
43
44 // Skip non-wifi connections
45 if (!default_network || default_network->type() != shill::kTypeWifi)
46 return;
47
48 // Retrieve access point info for wifi connection.
49 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
50 default_network->path(),
51 base::Bind(&WifiAccessPointInfoProviderChromeos::ParseInfo,
52 AsWeakPtr()),
53 chromeos::network_handler::ErrorCallback());
54 }
55
56 void WifiAccessPointInfoProviderChromeos::ParseInfo(
57 const std::string &service_path,
58 const base::DictionaryValue& properties) {
59 // Skip services that contain "_nomap" in the SSID.
60 std::string ssid =
61 chromeos::shill_property_util::GetSSIDFromProperties(properties, NULL);
62 if (ssid.find("_nomap", 0) != std::string::npos)
63 return;
64
65 // Parse security info.
66 std::string security;
67 properties.GetStringWithoutPathExpansion(
68 shill::kSecurityProperty, &security);
69 wifi_access_point_info_.security = WIFI_SECURITY_UNKNOWN;
70 if (security == shill::kSecurityWpa)
71 wifi_access_point_info_.security = WIFI_SECURITY_WPA;
72 else if (security == shill::kSecurityWep)
73 wifi_access_point_info_.security = WIFI_SECURITY_WEP;
74 else if (security == shill::kSecurityRsn)
75 wifi_access_point_info_.security = WIFI_SECURITY_RSN;
76 else if (security == shill::kSecurity8021x)
77 wifi_access_point_info_.security = WIFI_SECURITY_802_1X;
78 else if (security == shill::kSecurityPsk)
79 wifi_access_point_info_.security = WIFI_SECURITY_PSK;
80 else if (security == shill::kSecurityNone)
81 wifi_access_point_info_.security = WIFI_SECURITY_NONE;
82
83 properties.GetStringWithoutPathExpansion(
84 shill::kWifiBSsid, &wifi_access_point_info_.bssid);
85 const base::DictionaryValue* vendor_dict = NULL;
86 if (!properties.GetDictionaryWithoutPathExpansion(
87 shill::kWifiVendorInformationProperty,
88 &vendor_dict))
89 return;
90
91 vendor_dict->GetStringWithoutPathExpansion(
92 shill::kVendorWPSModelNumberProperty,
93 &wifi_access_point_info_.model_number);
94 vendor_dict->GetStringWithoutPathExpansion(
95 shill::kVendorWPSModelNameProperty,
96 &wifi_access_point_info_.model_name);
97 vendor_dict->GetStringWithoutPathExpansion(
98 shill::kVendorWPSDeviceNameProperty,
99 &wifi_access_point_info_.device_name);
100 vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty,
101 &wifi_access_point_info_.oui_list);
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698