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

Unified Diff: chrome/browser/chromeos/cros/cros_network_functions.cc

Issue 10202009: Reimplement CrosGetWifiAccessPoints without Libcros (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/cros/cros_network_functions_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/cros/cros_network_functions.cc
diff --git a/chrome/browser/chromeos/cros/cros_network_functions.cc b/chrome/browser/chromeos/cros/cros_network_functions.cc
index e0fdd818dd930cc09d0e23858cc3b583bab4abf0..20a696e73717f4de5645df542475f345d13347f3 100644
--- a/chrome/browser/chromeos/cros/cros_network_functions.cc
+++ b/chrome/browser/chromeos/cros/cros_network_functions.cc
@@ -13,6 +13,7 @@
#include "chromeos/dbus/flimflam_device_client.h"
#include "chromeos/dbus/flimflam_ipconfig_client.h"
#include "chromeos/dbus/flimflam_manager_client.h"
+#include "chromeos/dbus/flimflam_network_client.h"
#include "chromeos/dbus/flimflam_profile_client.h"
#include "chromeos/dbus/flimflam_service_client.h"
#include "dbus/object_path.h"
@@ -775,26 +776,112 @@ void CrosFreeIPConfigStatus(IPConfigStatus* status) {
}
bool CrosGetWifiAccessPoints(WifiAccessPointVector* result) {
- DeviceNetworkList* network_list = chromeos::GetDeviceNetworkList();
- if (network_list == NULL)
- return false;
- result->clear();
- result->reserve(network_list->network_size);
- const base::Time now = base::Time::Now();
- for (size_t i = 0; i < network_list->network_size; ++i) {
- DCHECK(network_list->networks[i].address);
- DCHECK(network_list->networks[i].name);
- WifiAccessPoint ap;
- ap.mac_address = SafeString(network_list->networks[i].address);
- ap.name = SafeString(network_list->networks[i].name);
- ap.timestamp = now -
- base::TimeDelta::FromSeconds(network_list->networks[i].age_seconds);
- ap.signal_strength = network_list->networks[i].strength;
- ap.channel = network_list->networks[i].channel;
- result->push_back(ap);
- }
- chromeos::FreeDeviceNetworkList(network_list);
- return true;
+ if (g_libcros_network_functions_enabled) {
+ DeviceNetworkList* network_list = chromeos::GetDeviceNetworkList();
+ if (network_list == NULL)
+ return false;
+ result->clear();
+ result->reserve(network_list->network_size);
+ const base::Time now = base::Time::Now();
+ for (size_t i = 0; i < network_list->network_size; ++i) {
+ DCHECK(network_list->networks[i].address);
+ DCHECK(network_list->networks[i].name);
+ WifiAccessPoint ap;
+ ap.mac_address = SafeString(network_list->networks[i].address);
+ ap.name = SafeString(network_list->networks[i].name);
+ ap.timestamp = now -
+ base::TimeDelta::FromSeconds(network_list->networks[i].age_seconds);
+ ap.signal_strength = network_list->networks[i].strength;
+ ap.channel = network_list->networks[i].channel;
+ result->push_back(ap);
+ }
+ chromeos::FreeDeviceNetworkList(network_list);
+ return true;
+ } else {
+ scoped_ptr<base::DictionaryValue> manager_properties(
+ DBusThreadManager::Get()->GetFlimflamManagerClient()->
+ CallGetPropertiesAndBlock());
+ if (!manager_properties.get()) {
+ LOG(WARNING) << "Couldn't read managers's properties";
+ return false;
+ }
+
+ base::ListValue* devices = NULL;
+ if (!manager_properties->GetListWithoutPathExpansion(
+ flimflam::kDevicesProperty, &devices)) {
+ LOG(WARNING) << flimflam::kDevicesProperty << " property not found";
+ return false;
+ }
+ const base::Time now = base::Time::Now();
+ bool found_at_least_one_device = false;
+ result->clear();
+ for (size_t i = 0; i < devices->GetSize(); i++) {
+ std::string device_path;
+ if (!devices->GetString(i, &device_path)) {
+ LOG(WARNING) << "Couldn't get devices[" << i << "]";
+ continue;
+ }
+ scoped_ptr<base::DictionaryValue> device_properties(
+ DBusThreadManager::Get()->GetFlimflamDeviceClient()->
+ CallGetPropertiesAndBlock(dbus::ObjectPath(device_path)));
+ if (!device_properties.get()) {
+ LOG(WARNING) << "Couldn't read device's properties " << device_path;
+ continue;
+ }
+
+ base::ListValue* networks = NULL;
+ if (!device_properties->GetListWithoutPathExpansion(
+ flimflam::kNetworksProperty, &networks))
+ continue; // Some devices do not list networks, e.g. ethernet.
+
+ base::Value* device_powered_value = NULL;
+ bool device_powered = false;
+ if (device_properties->GetWithoutPathExpansion(
+ flimflam::kPoweredProperty, &device_powered_value) &&
+ device_powered_value->GetAsBoolean(&device_powered) &&
+ !device_powered)
+ continue; // Skip devices that are not powered up.
+
+ int scan_interval = 0;
+ device_properties->GetIntegerWithoutPathExpansion(
+ flimflam::kScanIntervalProperty, &scan_interval);
+
+ found_at_least_one_device = true;
+ for (size_t j = 0; j < networks->GetSize(); j++) {
+ std::string network_path;
+ if (!networks->GetString(j, &network_path)) {
+ LOG(WARNING) << "Couldn't get networks[" << j << "]";
+ continue;
+ }
+
+ scoped_ptr<base::DictionaryValue> network_properties(
+ DBusThreadManager::Get()->GetFlimflamNetworkClient()->
+ CallGetPropertiesAndBlock(dbus::ObjectPath(network_path)));
+ if (!network_properties.get()) {
+ LOG(WARNING) << "Couldn't read network's properties " << network_path;
+ continue;
+ }
+
+ // Using the scan interval as a proxy for approximate age.
+ // TODO(joth): Replace with actual age, when available from dbus.
+ const int age_seconds = scan_interval;
+ WifiAccessPoint ap;
+ network_properties->GetStringWithoutPathExpansion(
+ flimflam::kAddressProperty, &ap.mac_address);
+ network_properties->GetStringWithoutPathExpansion(
+ flimflam::kNameProperty, &ap.name);
+ ap.timestamp = now - base::TimeDelta::FromSeconds(age_seconds);
+ network_properties->GetIntegerWithoutPathExpansion(
+ flimflam::kSignalStrengthProperty, &ap.signal_strength);
+ network_properties->GetIntegerWithoutPathExpansion(
+ flimflam::kWifiChannelProperty, &ap.channel);
+ result->push_back(ap);
+ }
+ }
+ if (!found_at_least_one_device)
+ return false; // No powered device found that has a 'Networks' array.
+ return true;
+ }
}
void CrosConfigureService(const base::DictionaryValue& properties) {
« no previous file with comments | « no previous file | chrome/browser/chromeos/cros/cros_network_functions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698