| OLD | NEW |
| 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 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // NetworkManager. Return true on success. | 60 // NetworkManager. Return true on success. |
| 61 bool GetAdapterDeviceList(std::vector<dbus::ObjectPath>* device_paths); | 61 bool GetAdapterDeviceList(std::vector<dbus::ObjectPath>* device_paths); |
| 62 | 62 |
| 63 // Given the NetworkManager path to a wireless adapater, dumps the wifi scan | 63 // Given the NetworkManager path to a wireless adapater, dumps the wifi scan |
| 64 // results and appends them to |data|. Returns false if a fatal error is | 64 // results and appends them to |data|. Returns false if a fatal error is |
| 65 // encountered such that the data set could not be populated. | 65 // encountered such that the data set could not be populated. |
| 66 bool GetAccessPointsForAdapter(const dbus::ObjectPath& adapter_path, | 66 bool GetAccessPointsForAdapter(const dbus::ObjectPath& adapter_path, |
| 67 WifiData::AccessPointDataSet* data); | 67 WifiData::AccessPointDataSet* data); |
| 68 | 68 |
| 69 // Internal method used by |GetAccessPointsForAdapter|, given a wifi access | 69 // Internal method used by |GetAccessPointsForAdapter|, given a wifi access |
| 70 // point proxy retrieves the named property and returns it. Returns NULL if | 70 // point proxy retrieves the named property and returns it. Returns NULL in |
| 71 // the property could not be read. | 71 // a scoped_ptr if the property could not be read. |
| 72 dbus::Response* GetAccessPointProperty(dbus::ObjectProxy* proxy, | 72 scoped_ptr<dbus::Response> GetAccessPointProperty( |
| 73 const std::string& property_name); | 73 dbus::ObjectProxy* proxy, |
| 74 const std::string& property_name); |
| 74 | 75 |
| 75 scoped_refptr<dbus::Bus> system_bus_; | 76 scoped_refptr<dbus::Bus> system_bus_; |
| 76 dbus::ObjectProxy* network_manager_proxy_; | 77 dbus::ObjectProxy* network_manager_proxy_; |
| 77 | 78 |
| 78 DISALLOW_COPY_AND_ASSIGN(NetworkManagerWlanApi); | 79 DISALLOW_COPY_AND_ASSIGN(NetworkManagerWlanApi); |
| 79 }; | 80 }; |
| 80 | 81 |
| 81 // Convert a wifi frequency to the corresponding channel. Adapted from | 82 // Convert a wifi frequency to the corresponding channel. Adapted from |
| 82 // geolocaiton/wifilib.cc in googleclient (internal to google). | 83 // geolocaiton/wifilib.cc in googleclient (internal to google). |
| 83 int frquency_in_khz_to_channel(int frequency_khz) { | 84 int frquency_in_khz_to_channel(int frequency_khz) { |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 << "SSID: " << access_point_data.ssid << ", " | 318 << "SSID: " << access_point_data.ssid << ", " |
| 318 << "MAC: " << access_point_data.mac_address << ", " | 319 << "MAC: " << access_point_data.mac_address << ", " |
| 319 << "Strength: " << access_point_data.radio_signal_strength << ", " | 320 << "Strength: " << access_point_data.radio_signal_strength << ", " |
| 320 << "Channel: " << access_point_data.channel; | 321 << "Channel: " << access_point_data.channel; |
| 321 | 322 |
| 322 data->insert(access_point_data); | 323 data->insert(access_point_data); |
| 323 } | 324 } |
| 324 return true; | 325 return true; |
| 325 } | 326 } |
| 326 | 327 |
| 327 dbus::Response* NetworkManagerWlanApi::GetAccessPointProperty( | 328 scoped_ptr<dbus::Response> NetworkManagerWlanApi::GetAccessPointProperty( |
| 328 dbus::ObjectProxy* access_point_proxy, | 329 dbus::ObjectProxy* access_point_proxy, |
| 329 const std::string& property_name) { | 330 const std::string& property_name) { |
| 330 dbus::MethodCall method_call(DBUS_INTERFACE_PROPERTIES, "Get"); | 331 dbus::MethodCall method_call(DBUS_INTERFACE_PROPERTIES, "Get"); |
| 331 dbus::MessageWriter builder(&method_call); | 332 dbus::MessageWriter builder(&method_call); |
| 332 builder.AppendString("org.freedesktop.NetworkManager.AccessPoint"); | 333 builder.AppendString("org.freedesktop.NetworkManager.AccessPoint"); |
| 333 builder.AppendString(property_name); | 334 builder.AppendString(property_name); |
| 334 dbus::Response* response = access_point_proxy->CallMethodAndBlock( | 335 scoped_ptr<dbus::Response> response = access_point_proxy->CallMethodAndBlock( |
| 335 &method_call, | 336 &method_call, |
| 336 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); | 337 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); |
| 337 if (!response) { | 338 if (!response.get()) { |
| 338 LOG(WARNING) << "Failed to get property for " << property_name; | 339 LOG(WARNING) << "Failed to get property for " << property_name; |
| 339 } | 340 } |
| 340 return response; | 341 return response.Pass(); |
| 341 } | 342 } |
| 342 | 343 |
| 343 } // namespace | 344 } // namespace |
| 344 | 345 |
| 345 // static | 346 // static |
| 346 template<> | 347 template<> |
| 347 WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() { | 348 WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() { |
| 348 return new WifiDataProviderLinux(); | 349 return new WifiDataProviderLinux(); |
| 349 } | 350 } |
| 350 | 351 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 371 | 372 |
| 372 WifiDataProviderCommon::WlanApiInterface* | 373 WifiDataProviderCommon::WlanApiInterface* |
| 373 WifiDataProviderLinux::NewWlanApiForTesting(dbus::Bus* bus) { | 374 WifiDataProviderLinux::NewWlanApiForTesting(dbus::Bus* bus) { |
| 374 scoped_ptr<NetworkManagerWlanApi> wlan_api(new NetworkManagerWlanApi); | 375 scoped_ptr<NetworkManagerWlanApi> wlan_api(new NetworkManagerWlanApi); |
| 375 if (wlan_api->InitWithBus(bus)) | 376 if (wlan_api->InitWithBus(bus)) |
| 376 return wlan_api.release(); | 377 return wlan_api.release(); |
| 377 return NULL; | 378 return NULL; |
| 378 } | 379 } |
| 379 | 380 |
| 380 } // namespace content | 381 } // namespace content |
| OLD | NEW |