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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/cros/cros_network_functions_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/chromeos/cros/cros_network_functions.h" 5 #include "chrome/browser/chromeos/cros/cros_network_functions.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chromeos/cros/gvalue_util.h" 10 #include "chrome/browser/chromeos/cros/gvalue_util.h"
11 #include "chromeos/dbus/cashew_client.h" 11 #include "chromeos/dbus/cashew_client.h"
12 #include "chromeos/dbus/dbus_thread_manager.h" 12 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/flimflam_device_client.h" 13 #include "chromeos/dbus/flimflam_device_client.h"
14 #include "chromeos/dbus/flimflam_ipconfig_client.h" 14 #include "chromeos/dbus/flimflam_ipconfig_client.h"
15 #include "chromeos/dbus/flimflam_manager_client.h" 15 #include "chromeos/dbus/flimflam_manager_client.h"
16 #include "chromeos/dbus/flimflam_network_client.h"
16 #include "chromeos/dbus/flimflam_profile_client.h" 17 #include "chromeos/dbus/flimflam_profile_client.h"
17 #include "chromeos/dbus/flimflam_service_client.h" 18 #include "chromeos/dbus/flimflam_service_client.h"
18 #include "dbus/object_path.h" 19 #include "dbus/object_path.h"
19 #include "third_party/cros_system_api/dbus/service_constants.h" 20 #include "third_party/cros_system_api/dbus/service_constants.h"
20 21
21 namespace chromeos { 22 namespace chromeos {
22 23
23 namespace { 24 namespace {
24 25
25 // Used as a callback for chromeos::MonitorNetwork*Properties. 26 // Used as a callback for chromeos::MonitorNetwork*Properties.
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 return DBusThreadManager::Get()->GetFlimflamIPConfigClient()-> 769 return DBusThreadManager::Get()->GetFlimflamIPConfigClient()->
769 CallRemoveAndBlock(dbus::ObjectPath(config->path)); 770 CallRemoveAndBlock(dbus::ObjectPath(config->path));
770 } 771 }
771 } 772 }
772 773
773 void CrosFreeIPConfigStatus(IPConfigStatus* status) { 774 void CrosFreeIPConfigStatus(IPConfigStatus* status) {
774 chromeos::FreeIPConfigStatus(status); 775 chromeos::FreeIPConfigStatus(status);
775 } 776 }
776 777
777 bool CrosGetWifiAccessPoints(WifiAccessPointVector* result) { 778 bool CrosGetWifiAccessPoints(WifiAccessPointVector* result) {
778 DeviceNetworkList* network_list = chromeos::GetDeviceNetworkList(); 779 if (g_libcros_network_functions_enabled) {
779 if (network_list == NULL) 780 DeviceNetworkList* network_list = chromeos::GetDeviceNetworkList();
780 return false; 781 if (network_list == NULL)
781 result->clear(); 782 return false;
782 result->reserve(network_list->network_size); 783 result->clear();
783 const base::Time now = base::Time::Now(); 784 result->reserve(network_list->network_size);
784 for (size_t i = 0; i < network_list->network_size; ++i) { 785 const base::Time now = base::Time::Now();
785 DCHECK(network_list->networks[i].address); 786 for (size_t i = 0; i < network_list->network_size; ++i) {
786 DCHECK(network_list->networks[i].name); 787 DCHECK(network_list->networks[i].address);
787 WifiAccessPoint ap; 788 DCHECK(network_list->networks[i].name);
788 ap.mac_address = SafeString(network_list->networks[i].address); 789 WifiAccessPoint ap;
789 ap.name = SafeString(network_list->networks[i].name); 790 ap.mac_address = SafeString(network_list->networks[i].address);
790 ap.timestamp = now - 791 ap.name = SafeString(network_list->networks[i].name);
791 base::TimeDelta::FromSeconds(network_list->networks[i].age_seconds); 792 ap.timestamp = now -
792 ap.signal_strength = network_list->networks[i].strength; 793 base::TimeDelta::FromSeconds(network_list->networks[i].age_seconds);
793 ap.channel = network_list->networks[i].channel; 794 ap.signal_strength = network_list->networks[i].strength;
794 result->push_back(ap); 795 ap.channel = network_list->networks[i].channel;
796 result->push_back(ap);
797 }
798 chromeos::FreeDeviceNetworkList(network_list);
799 return true;
800 } else {
801 scoped_ptr<base::DictionaryValue> manager_properties(
802 DBusThreadManager::Get()->GetFlimflamManagerClient()->
803 CallGetPropertiesAndBlock());
804 if (!manager_properties.get()) {
805 LOG(WARNING) << "Couldn't read managers's properties";
806 return false;
807 }
808
809 base::ListValue* devices = NULL;
810 if (!manager_properties->GetListWithoutPathExpansion(
811 flimflam::kDevicesProperty, &devices)) {
812 LOG(WARNING) << flimflam::kDevicesProperty << " property not found";
813 return false;
814 }
815 const base::Time now = base::Time::Now();
816 bool found_at_least_one_device = false;
817 result->clear();
818 for (size_t i = 0; i < devices->GetSize(); i++) {
819 std::string device_path;
820 if (!devices->GetString(i, &device_path)) {
821 LOG(WARNING) << "Couldn't get devices[" << i << "]";
822 continue;
823 }
824 scoped_ptr<base::DictionaryValue> device_properties(
825 DBusThreadManager::Get()->GetFlimflamDeviceClient()->
826 CallGetPropertiesAndBlock(dbus::ObjectPath(device_path)));
827 if (!device_properties.get()) {
828 LOG(WARNING) << "Couldn't read device's properties " << device_path;
829 continue;
830 }
831
832 base::ListValue* networks = NULL;
833 if (!device_properties->GetListWithoutPathExpansion(
834 flimflam::kNetworksProperty, &networks))
835 continue; // Some devices do not list networks, e.g. ethernet.
836
837 base::Value* device_powered_value = NULL;
838 bool device_powered = false;
839 if (device_properties->GetWithoutPathExpansion(
840 flimflam::kPoweredProperty, &device_powered_value) &&
841 device_powered_value->GetAsBoolean(&device_powered) &&
842 !device_powered)
843 continue; // Skip devices that are not powered up.
844
845 int scan_interval = 0;
846 device_properties->GetIntegerWithoutPathExpansion(
847 flimflam::kScanIntervalProperty, &scan_interval);
848
849 found_at_least_one_device = true;
850 for (size_t j = 0; j < networks->GetSize(); j++) {
851 std::string network_path;
852 if (!networks->GetString(j, &network_path)) {
853 LOG(WARNING) << "Couldn't get networks[" << j << "]";
854 continue;
855 }
856
857 scoped_ptr<base::DictionaryValue> network_properties(
858 DBusThreadManager::Get()->GetFlimflamNetworkClient()->
859 CallGetPropertiesAndBlock(dbus::ObjectPath(network_path)));
860 if (!network_properties.get()) {
861 LOG(WARNING) << "Couldn't read network's properties " << network_path;
862 continue;
863 }
864
865 // Using the scan interval as a proxy for approximate age.
866 // TODO(joth): Replace with actual age, when available from dbus.
867 const int age_seconds = scan_interval;
868 WifiAccessPoint ap;
869 network_properties->GetStringWithoutPathExpansion(
870 flimflam::kAddressProperty, &ap.mac_address);
871 network_properties->GetStringWithoutPathExpansion(
872 flimflam::kNameProperty, &ap.name);
873 ap.timestamp = now - base::TimeDelta::FromSeconds(age_seconds);
874 network_properties->GetIntegerWithoutPathExpansion(
875 flimflam::kSignalStrengthProperty, &ap.signal_strength);
876 network_properties->GetIntegerWithoutPathExpansion(
877 flimflam::kWifiChannelProperty, &ap.channel);
878 result->push_back(ap);
879 }
880 }
881 if (!found_at_least_one_device)
882 return false; // No powered device found that has a 'Networks' array.
883 return true;
795 } 884 }
796 chromeos::FreeDeviceNetworkList(network_list);
797 return true;
798 } 885 }
799 886
800 void CrosConfigureService(const base::DictionaryValue& properties) { 887 void CrosConfigureService(const base::DictionaryValue& properties) {
801 if (g_libcros_network_functions_enabled) { 888 if (g_libcros_network_functions_enabled) {
802 ScopedGHashTable ghash( 889 ScopedGHashTable ghash(
803 ConvertDictionaryValueToStringValueGHashTable(properties)); 890 ConvertDictionaryValueToStringValueGHashTable(properties));
804 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); 891 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL);
805 } else { 892 } else {
806 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( 893 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService(
807 properties, base::Bind(&DoNothing)); 894 properties, base::Bind(&DoNothing));
808 } 895 }
809 } 896 }
810 897
811 } // namespace chromeos 898 } // namespace chromeos
OLDNEW
« 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