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

Side by Side Diff: chromeos/network/cros_network_functions.cc

Issue 11887008: Deprecate ShillNetworkClient and add GeolocationHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unittest Created 7 years, 11 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
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 "chromeos/network/cros_network_functions.h" 5 #include "chromeos/network/cros_network_functions.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chromeos/dbus/dbus_thread_manager.h" 11 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "chromeos/dbus/shill_device_client.h" 12 #include "chromeos/dbus/shill_device_client.h"
13 #include "chromeos/dbus/shill_ipconfig_client.h" 13 #include "chromeos/dbus/shill_ipconfig_client.h"
14 #include "chromeos/dbus/shill_manager_client.h" 14 #include "chromeos/dbus/shill_manager_client.h"
15 #include "chromeos/dbus/shill_network_client.h"
16 #include "chromeos/dbus/shill_profile_client.h" 15 #include "chromeos/dbus/shill_profile_client.h"
17 #include "chromeos/dbus/shill_property_changed_observer.h" 16 #include "chromeos/dbus/shill_property_changed_observer.h"
18 #include "chromeos/dbus/shill_service_client.h" 17 #include "chromeos/dbus/shill_service_client.h"
19 #include "chromeos/network/network_util.h" 18 #include "chromeos/network/network_util.h"
20 #include "chromeos/network/sms_watcher.h" 19 #include "chromeos/network/sms_watcher.h"
21 #include "dbus/object_path.h" 20 #include "dbus/object_path.h"
22 #include "third_party/cros_system_api/dbus/service_constants.h" 21 #include "third_party/cros_system_api/dbus/service_constants.h"
23 22
24 using base::DoNothing; 23 using base::DoNothing;
25 24
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 hardware_address); 642 hardware_address);
644 return true; 643 return true;
645 } 644 }
646 645
647 void CrosRequestIPConfigRefresh(const std::string& ipconfig_path) { 646 void CrosRequestIPConfigRefresh(const std::string& ipconfig_path) {
648 DBusThreadManager::Get()->GetShillIPConfigClient()->Refresh( 647 DBusThreadManager::Get()->GetShillIPConfigClient()->Refresh(
649 dbus::ObjectPath(ipconfig_path), 648 dbus::ObjectPath(ipconfig_path),
650 base::Bind(&DoNothingWithCallStatus)); 649 base::Bind(&DoNothingWithCallStatus));
651 } 650 }
652 651
653 bool CrosGetWifiAccessPoints(WifiAccessPointVector* result) {
654 scoped_ptr<base::DictionaryValue> manager_properties(
655 DBusThreadManager::Get()->GetShillManagerClient()->
656 CallGetPropertiesAndBlock());
657 if (!manager_properties.get()) {
658 LOG(WARNING) << "Couldn't read managers's properties";
659 return false;
660 }
661
662 base::ListValue* devices = NULL;
663 if (!manager_properties->GetListWithoutPathExpansion(
664 flimflam::kDevicesProperty, &devices)) {
665 LOG(WARNING) << flimflam::kDevicesProperty << " property not found";
666 return false;
667 }
668 const base::Time now = base::Time::Now();
669 bool found_at_least_one_device = false;
670 result->clear();
671 for (size_t i = 0; i < devices->GetSize(); i++) {
672 std::string device_path;
673 if (!devices->GetString(i, &device_path)) {
674 LOG(WARNING) << "Couldn't get devices[" << i << "]";
675 continue;
676 }
677 scoped_ptr<base::DictionaryValue> device_properties(
678 DBusThreadManager::Get()->GetShillDeviceClient()->
679 CallGetPropertiesAndBlock(dbus::ObjectPath(device_path)));
680 if (!device_properties.get()) {
681 LOG(WARNING) << "Couldn't read device's properties " << device_path;
682 continue;
683 }
684
685 base::ListValue* networks = NULL;
686 if (!device_properties->GetListWithoutPathExpansion(
687 flimflam::kNetworksProperty, &networks))
688 continue; // Some devices do not list networks, e.g. ethernet.
689
690 base::Value* device_powered_value = NULL;
691 bool device_powered = false;
692 if (device_properties->GetWithoutPathExpansion(
693 flimflam::kPoweredProperty, &device_powered_value) &&
694 device_powered_value->GetAsBoolean(&device_powered) &&
695 !device_powered)
696 continue; // Skip devices that are not powered up.
697
698 int scan_interval = 0;
699 device_properties->GetIntegerWithoutPathExpansion(
700 flimflam::kScanIntervalProperty, &scan_interval);
701
702 found_at_least_one_device = true;
703 for (size_t j = 0; j < networks->GetSize(); j++) {
704 std::string network_path;
705 if (!networks->GetString(j, &network_path)) {
706 LOG(WARNING) << "Couldn't get networks[" << j << "]";
707 continue;
708 }
709
710 scoped_ptr<base::DictionaryValue> network_properties(
711 DBusThreadManager::Get()->GetShillNetworkClient()->
712 CallGetPropertiesAndBlock(dbus::ObjectPath(network_path)));
713 if (!network_properties.get()) {
714 LOG(WARNING) << "Couldn't read network's properties " << network_path;
715 continue;
716 }
717
718 // Using the scan interval as a proxy for approximate age.
719 // TODO(joth): Replace with actual age, when available from dbus.
720 const int age_seconds = scan_interval;
721 WifiAccessPoint ap;
722 network_properties->GetStringWithoutPathExpansion(
723 flimflam::kAddressProperty, &ap.mac_address);
724 network_properties->GetStringWithoutPathExpansion(
725 flimflam::kNameProperty, &ap.name);
726 ap.timestamp = now - base::TimeDelta::FromSeconds(age_seconds);
727 network_properties->GetIntegerWithoutPathExpansion(
728 flimflam::kSignalStrengthProperty, &ap.signal_strength);
729 network_properties->GetIntegerWithoutPathExpansion(
730 flimflam::kWifiChannelProperty, &ap.channel);
731 result->push_back(ap);
732 }
733 }
734 if (!found_at_least_one_device)
735 return false; // No powered device found that has a 'Networks' array.
736 return true;
737 }
738
739 void CrosConfigureService(const base::DictionaryValue& properties) { 652 void CrosConfigureService(const base::DictionaryValue& properties) {
740 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService( 653 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService(
741 properties, base::Bind(&DoNothing), 654 properties, base::Bind(&DoNothing),
742 base::Bind(&IgnoreErrors)); 655 base::Bind(&IgnoreErrors));
743 } 656 }
744 657
745 // Changes the active cellular carrier. 658 // Changes the active cellular carrier.
746 void CrosSetCarrier(const std::string& device_path, 659 void CrosSetCarrier(const std::string& device_path,
747 const std::string& carrier, 660 const std::string& carrier,
748 const NetworkOperationCallback& callback) { 661 const NetworkOperationCallback& callback) {
749 DBusThreadManager::Get()->GetShillDeviceClient()->SetCarrier( 662 DBusThreadManager::Get()->GetShillDeviceClient()->SetCarrier(
750 dbus::ObjectPath(device_path), carrier, 663 dbus::ObjectPath(device_path), carrier,
751 base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE, 664 base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
752 std::string()), 665 std::string()),
753 base::Bind(&OnNetworkActionError, callback, device_path)); 666 base::Bind(&OnNetworkActionError, callback, device_path));
754 } 667 }
755 668
756 } // namespace chromeos 669 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698