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

Side by Side Diff: content/browser/geolocation/wifi_data_provider_linux.cc

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 12 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Provides wifi scan API binding for suitable for typical linux distributions. 5 // Provides wifi scan API binding for suitable for typical linux distributions.
6 // Currently, only the NetworkManager API is used, accessed via D-Bus (in turn 6 // Currently, only the NetworkManager API is used, accessed via D-Bus (in turn
7 // accessed via the GLib wrapper). 7 // accessed via the GLib wrapper).
8 8
9 #include "content/browser/geolocation/wifi_data_provider_linux.h" 9 #include "content/browser/geolocation/wifi_data_provider_linux.h"
10 10
11 #include <stddef.h>
12 #include <stdint.h>
13
14 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
14 #include "content/browser/geolocation/wifi_data_provider_manager.h" 18 #include "content/browser/geolocation/wifi_data_provider_manager.h"
15 #include "dbus/bus.h" 19 #include "dbus/bus.h"
16 #include "dbus/message.h" 20 #include "dbus/message.h"
17 #include "dbus/object_path.h" 21 #include "dbus/object_path.h"
18 #include "dbus/object_proxy.h" 22 #include "dbus/object_proxy.h"
19 23
20 namespace content { 24 namespace content {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 scoped_ptr<dbus::Response> response( 152 scoped_ptr<dbus::Response> response(
149 device_proxy->CallMethodAndBlock( 153 device_proxy->CallMethodAndBlock(
150 &method_call, 154 &method_call,
151 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 155 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
152 if (!response) { 156 if (!response) {
153 LOG(WARNING) << "Failed to get the device type for " 157 LOG(WARNING) << "Failed to get the device type for "
154 << device_path.value(); 158 << device_path.value();
155 continue; // Check the next device. 159 continue; // Check the next device.
156 } 160 }
157 dbus::MessageReader reader(response.get()); 161 dbus::MessageReader reader(response.get());
158 uint32 device_type = 0; 162 uint32_t device_type = 0;
159 if (!reader.PopVariantOfUint32(&device_type)) { 163 if (!reader.PopVariantOfUint32(&device_type)) {
160 LOG(WARNING) << "Unexpected response for " << device_type << ": " 164 LOG(WARNING) << "Unexpected response for " << device_type << ": "
161 << response->ToString(); 165 << response->ToString();
162 continue; // Check the next device. 166 continue; // Check the next device.
163 } 167 }
164 VLOG(1) << "Device type: " << device_type; 168 VLOG(1) << "Device type: " << device_type;
165 169
166 if (device_type == NM_DEVICE_TYPE_WIFI) { // Found a wlan adapter 170 if (device_type == NM_DEVICE_TYPE_WIFI) { // Found a wlan adapter
167 if (GetAccessPointsForAdapter(device_path, data)) 171 if (GetAccessPointsForAdapter(device_path, data))
168 ++success_count; 172 ++success_count;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 if (!response) 244 if (!response)
241 continue; 245 continue;
242 // The response should contain a variant that contains an array of bytes. 246 // The response should contain a variant that contains an array of bytes.
243 dbus::MessageReader reader(response.get()); 247 dbus::MessageReader reader(response.get());
244 dbus::MessageReader variant_reader(response.get()); 248 dbus::MessageReader variant_reader(response.get());
245 if (!reader.PopVariant(&variant_reader)) { 249 if (!reader.PopVariant(&variant_reader)) {
246 LOG(WARNING) << "Unexpected response for " << access_point_path.value() 250 LOG(WARNING) << "Unexpected response for " << access_point_path.value()
247 << ": " << response->ToString(); 251 << ": " << response->ToString();
248 continue; 252 continue;
249 } 253 }
250 const uint8* ssid_bytes = NULL; 254 const uint8_t* ssid_bytes = NULL;
251 size_t ssid_length = 0; 255 size_t ssid_length = 0;
252 if (!variant_reader.PopArrayOfBytes(&ssid_bytes, &ssid_length)) { 256 if (!variant_reader.PopArrayOfBytes(&ssid_bytes, &ssid_length)) {
253 LOG(WARNING) << "Unexpected response for " << access_point_path.value() 257 LOG(WARNING) << "Unexpected response for " << access_point_path.value()
254 << ": " << response->ToString(); 258 << ": " << response->ToString();
255 continue; 259 continue;
256 } 260 }
257 std::string ssid(ssid_bytes, ssid_bytes + ssid_length); 261 std::string ssid(ssid_bytes, ssid_bytes + ssid_length);
258 access_point_data.ssid = base::UTF8ToUTF16(ssid); 262 access_point_data.ssid = base::UTF8ToUTF16(ssid);
259 } 263 }
260 264
261 { // Read the mac address 265 { // Read the mac address
262 scoped_ptr<dbus::Response> response( 266 scoped_ptr<dbus::Response> response(
263 GetAccessPointProperty(access_point_proxy, "HwAddress")); 267 GetAccessPointProperty(access_point_proxy, "HwAddress"));
264 if (!response) 268 if (!response)
265 continue; 269 continue;
266 dbus::MessageReader reader(response.get()); 270 dbus::MessageReader reader(response.get());
267 std::string mac; 271 std::string mac;
268 if (!reader.PopVariantOfString(&mac)) { 272 if (!reader.PopVariantOfString(&mac)) {
269 LOG(WARNING) << "Unexpected response for " << access_point_path.value() 273 LOG(WARNING) << "Unexpected response for " << access_point_path.value()
270 << ": " << response->ToString(); 274 << ": " << response->ToString();
271 continue; 275 continue;
272 } 276 }
273 277
274 base::ReplaceSubstringsAfterOffset(&mac, 0U, ":", base::StringPiece()); 278 base::ReplaceSubstringsAfterOffset(&mac, 0U, ":", base::StringPiece());
275 std::vector<uint8> mac_bytes; 279 std::vector<uint8_t> mac_bytes;
276 if (!base::HexStringToBytes(mac, &mac_bytes) || mac_bytes.size() != 6) { 280 if (!base::HexStringToBytes(mac, &mac_bytes) || mac_bytes.size() != 6) {
277 LOG(WARNING) << "Can't parse mac address (found " << mac_bytes.size() 281 LOG(WARNING) << "Can't parse mac address (found " << mac_bytes.size()
278 << " bytes) so using raw string: " << mac; 282 << " bytes) so using raw string: " << mac;
279 access_point_data.mac_address = base::UTF8ToUTF16(mac); 283 access_point_data.mac_address = base::UTF8ToUTF16(mac);
280 } else { 284 } else {
281 access_point_data.mac_address = MacAddressAsString16(&mac_bytes[0]); 285 access_point_data.mac_address = MacAddressAsString16(&mac_bytes[0]);
282 } 286 }
283 } 287 }
284 288
285 { // Read signal strength. 289 { // Read signal strength.
286 scoped_ptr<dbus::Response> response( 290 scoped_ptr<dbus::Response> response(
287 GetAccessPointProperty(access_point_proxy, "Strength")); 291 GetAccessPointProperty(access_point_proxy, "Strength"));
288 if (!response) 292 if (!response)
289 continue; 293 continue;
290 dbus::MessageReader reader(response.get()); 294 dbus::MessageReader reader(response.get());
291 uint8 strength = 0; 295 uint8_t strength = 0;
292 if (!reader.PopVariantOfByte(&strength)) { 296 if (!reader.PopVariantOfByte(&strength)) {
293 LOG(WARNING) << "Unexpected response for " << access_point_path.value() 297 LOG(WARNING) << "Unexpected response for " << access_point_path.value()
294 << ": " << response->ToString(); 298 << ": " << response->ToString();
295 continue; 299 continue;
296 } 300 }
297 // Convert strength as a percentage into dBs. 301 // Convert strength as a percentage into dBs.
298 access_point_data.radio_signal_strength = -100 + strength / 2; 302 access_point_data.radio_signal_strength = -100 + strength / 2;
299 } 303 }
300 304
301 { // Read the channel 305 { // Read the channel
302 scoped_ptr<dbus::Response> response( 306 scoped_ptr<dbus::Response> response(
303 GetAccessPointProperty(access_point_proxy, "Frequency")); 307 GetAccessPointProperty(access_point_proxy, "Frequency"));
304 if (!response) 308 if (!response)
305 continue; 309 continue;
306 dbus::MessageReader reader(response.get()); 310 dbus::MessageReader reader(response.get());
307 uint32 frequency = 0; 311 uint32_t frequency = 0;
308 if (!reader.PopVariantOfUint32(&frequency)) { 312 if (!reader.PopVariantOfUint32(&frequency)) {
309 LOG(WARNING) << "Unexpected response for " << access_point_path.value() 313 LOG(WARNING) << "Unexpected response for " << access_point_path.value()
310 << ": " << response->ToString(); 314 << ": " << response->ToString();
311 continue; 315 continue;
312 } 316 }
313 317
314 // NetworkManager returns frequency in MHz. 318 // NetworkManager returns frequency in MHz.
315 access_point_data.channel = 319 access_point_data.channel =
316 frquency_in_khz_to_channel(frequency * 1000); 320 frquency_in_khz_to_channel(frequency * 1000);
317 } 321 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 376
373 WifiDataProviderCommon::WlanApiInterface* 377 WifiDataProviderCommon::WlanApiInterface*
374 WifiDataProviderLinux::NewWlanApiForTesting(dbus::Bus* bus) { 378 WifiDataProviderLinux::NewWlanApiForTesting(dbus::Bus* bus) {
375 scoped_ptr<NetworkManagerWlanApi> wlan_api(new NetworkManagerWlanApi); 379 scoped_ptr<NetworkManagerWlanApi> wlan_api(new NetworkManagerWlanApi);
376 if (wlan_api->InitWithBus(bus)) 380 if (wlan_api->InitWithBus(bus))
377 return wlan_api.release(); 381 return wlan_api.release();
378 return NULL; 382 return NULL;
379 } 383 }
380 384
381 } // namespace content 385 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698