| Index: chromeos/network/network_device_handler.cc
|
| diff --git a/chromeos/network/network_device_handler.cc b/chromeos/network/network_device_handler.cc
|
| index 6524459b6587a8208e6f86c28f93144f5f4e4294..4bff925ee9bdeaff6bf3e4a584ec65c49f752998 100644
|
| --- a/chromeos/network/network_device_handler.cc
|
| +++ b/chromeos/network/network_device_handler.cc
|
| @@ -9,35 +9,27 @@
|
| #include "chromeos/dbus/dbus_thread_manager.h"
|
| #include "chromeos/dbus/shill_device_client.h"
|
| #include "chromeos/dbus/shill_manager_client.h"
|
| -#include "chromeos/dbus/shill_network_client.h"
|
| #include "chromeos/network/network_event_log.h"
|
| +#include "chromeos/network/network_handler_callbacks.h"
|
| #include "dbus/object_path.h"
|
| #include "third_party/cros_system_api/dbus/service_constants.h"
|
|
|
| +namespace {
|
| +const char kLogModule[] = "NetworkDeviceHandler";
|
| +}
|
| +
|
| namespace chromeos {
|
|
|
| +static NetworkDeviceHandler* g_network_device_handler = NULL;
|
| +
|
| //------------------------------------------------------------------------------
|
| // NetworkDeviceHandler public methods
|
|
|
| -NetworkDeviceHandler::NetworkDeviceHandler()
|
| - : devices_ready_(false),
|
| - weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
|
| -}
|
| -
|
| NetworkDeviceHandler::~NetworkDeviceHandler() {
|
| DBusThreadManager::Get()->GetShillManagerClient()->
|
| RemovePropertyChangedObserver(this);
|
| }
|
|
|
| -void NetworkDeviceHandler::Init() {
|
| - ShillManagerClient* shill_manager =
|
| - DBusThreadManager::Get()->GetShillManagerClient();
|
| - shill_manager->GetProperties(
|
| - base::Bind(&NetworkDeviceHandler::ManagerPropertiesCallback,
|
| - weak_ptr_factory_.GetWeakPtr()));
|
| - shill_manager->AddPropertyChangedObserver(this);
|
| -}
|
| -
|
| void NetworkDeviceHandler::AddObserver(Observer* observer) {
|
| observers_.AddObserver(observer);
|
| }
|
| @@ -46,6 +38,27 @@ void NetworkDeviceHandler::RemoveObserver(Observer* observer) {
|
| observers_.RemoveObserver(observer);
|
| }
|
|
|
| +// static
|
| +void NetworkDeviceHandler::Initialize() {
|
| + CHECK(!g_network_device_handler);
|
| + g_network_device_handler = new NetworkDeviceHandler();
|
| + g_network_device_handler->Init();
|
| +}
|
| +
|
| +// static
|
| +void NetworkDeviceHandler::Shutdown() {
|
| + CHECK(g_network_device_handler);
|
| + delete g_network_device_handler;
|
| + g_network_device_handler = NULL;
|
| +}
|
| +
|
| +// static
|
| +NetworkDeviceHandler* NetworkDeviceHandler::Get() {
|
| + CHECK(g_network_device_handler)
|
| + << "NetworkDeviceHandler::Get() called before Initialize()";
|
| + return g_network_device_handler;
|
| +}
|
| +
|
| //------------------------------------------------------------------------------
|
| // ShillPropertyChangedObserver overrides
|
|
|
| @@ -64,6 +77,20 @@ void NetworkDeviceHandler::OnPropertyChanged(const std::string& key,
|
| //------------------------------------------------------------------------------
|
| // Private methods
|
|
|
| +NetworkDeviceHandler::NetworkDeviceHandler()
|
| + : devices_ready_(false),
|
| + weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
|
| +}
|
| +
|
| +void NetworkDeviceHandler::Init() {
|
| + ShillManagerClient* shill_manager =
|
| + DBusThreadManager::Get()->GetShillManagerClient();
|
| + shill_manager->GetProperties(
|
| + base::Bind(&NetworkDeviceHandler::ManagerPropertiesCallback,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| + shill_manager->AddPropertyChangedObserver(this);
|
| +}
|
| +
|
| void NetworkDeviceHandler::ManagerPropertiesCallback(
|
| DBusMethodCallStatus call_status,
|
| const base::DictionaryValue& properties) {
|
| @@ -108,14 +135,23 @@ void NetworkDeviceHandler::DevicePropertiesCallback(
|
| if (call_status != DBUS_METHOD_CALL_SUCCESS) {
|
| LOG(ERROR) << "Failed to get Device properties for " << device_path
|
| << ": " << call_status;
|
| - DeviceReady(device_path);
|
| - return;
|
| + } else {
|
| + GetDeviceProperties(device_path, properties);
|
| }
|
| + pending_device_paths_.erase(device_path);
|
| + if (pending_device_paths_.empty()) {
|
| + devices_ready_ = true;
|
| + FOR_EACH_OBSERVER(Observer, observers_, NetworkDevicesUpdated(devices_));
|
| + }
|
| +}
|
| +
|
| +void NetworkDeviceHandler::GetDeviceProperties(
|
| + const std::string& device_path,
|
| + const base::DictionaryValue& properties) {
|
| std::string type;
|
| if (!properties.GetStringWithoutPathExpansion(
|
| flimflam::kTypeProperty, &type)) {
|
| LOG(WARNING) << "Failed to parse Type property for " << device_path;
|
| - DeviceReady(device_path);
|
| return;
|
| }
|
| Device& device = devices_[device_path];
|
| @@ -126,82 +162,6 @@ void NetworkDeviceHandler::DevicePropertiesCallback(
|
| flimflam::kScanningProperty, &device.scanning);
|
| properties.GetIntegerWithoutPathExpansion(
|
| flimflam::kScanIntervalProperty, &device.scan_interval);
|
| -
|
| - if (!device.powered ||
|
| - (type != flimflam::kTypeWifi && type != flimflam::kTypeWimax)) {
|
| - DeviceReady(device_path);
|
| - return;
|
| - }
|
| -
|
| - // Get WifiAccessPoint data for each Network property (only for powered
|
| - // wifi or wimax devices).
|
| - const base::ListValue* networks = NULL;
|
| - if (!properties.GetListWithoutPathExpansion(
|
| - flimflam::kNetworksProperty, &networks)) {
|
| - LOG(WARNING) << "Failed to parse Networks property for " << device_path;
|
| - DeviceReady(device_path);
|
| - return;
|
| - }
|
| -
|
| - for (size_t i = 0; i < networks->GetSize(); ++i) {
|
| - std::string network_path;
|
| - if (!networks->GetString(i, &network_path)) {
|
| - LOG(WARNING) << "Failed tp parse Networks[" << i << "]"
|
| - << " for device: " << device_path;
|
| - continue;
|
| - }
|
| - pending_network_paths_[device_path].insert(network_path);
|
| - DBusThreadManager::Get()->GetShillNetworkClient()->GetProperties(
|
| - dbus::ObjectPath(device_path),
|
| - base::Bind(&NetworkDeviceHandler::NetworkPropertiesCallback,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - device_path,
|
| - network_path));
|
| - }
|
| -}
|
| -
|
| -void NetworkDeviceHandler::NetworkPropertiesCallback(
|
| - const std::string& device_path,
|
| - const std::string& network_path,
|
| - DBusMethodCallStatus call_status,
|
| - const base::DictionaryValue& properties) {
|
| - if (call_status != DBUS_METHOD_CALL_SUCCESS) {
|
| - LOG(ERROR) << "Failed to get Network properties for " << network_path
|
| - << ", for device: " << device_path << ": " << call_status;
|
| - DeviceNetworkReady(device_path, network_path);
|
| - return;
|
| - }
|
| -
|
| - // Using the scan interval as a proxy for approximate age.
|
| - // TODO(joth): Replace with actual age, when available from dbus.
|
| - Device& device = devices_[device_path];
|
| - WifiAccessPoint& wap = device.wifi_access_points[network_path];
|
| - properties.GetStringWithoutPathExpansion(
|
| - flimflam::kAddressProperty, &wap.mac_address);
|
| - properties.GetStringWithoutPathExpansion(
|
| - flimflam::kNameProperty, &wap.name);
|
| - int age_seconds = device.scan_interval;
|
| - wap.timestamp = base::Time::Now() - base::TimeDelta::FromSeconds(age_seconds);
|
| - properties.GetIntegerWithoutPathExpansion(
|
| - flimflam::kSignalStrengthProperty, &wap.signal_strength);
|
| - properties.GetIntegerWithoutPathExpansion(
|
| - flimflam::kWifiChannelProperty, &wap.channel);
|
| - DeviceNetworkReady(device_path, network_path);
|
| -}
|
| -
|
| -void NetworkDeviceHandler::DeviceNetworkReady(const std::string& device_path,
|
| - const std::string& network_path) {
|
| - pending_network_paths_[device_path].erase(network_path);
|
| - if (pending_network_paths_[device_path].empty())
|
| - DeviceReady(device_path);
|
| -}
|
| -
|
| -void NetworkDeviceHandler::DeviceReady(const std::string& device_path) {
|
| - pending_device_paths_.erase(device_path);
|
| - if (pending_device_paths_.empty()) {
|
| - devices_ready_ = true;
|
| - FOR_EACH_OBSERVER(Observer, observers_, NetworkDevicesUpdated(devices_));
|
| - }
|
| }
|
|
|
| //------------------------------------------------------------------------------
|
|
|