diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-17 20:46:16 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-17 20:46:16 +0000 |
commit | 44bcec48e565403ed83a6f5030ad468a9f9c7a7c (patch) | |
tree | fb7a0158fe4ece22b40b9a97667e8f26538341a6 /chromeos/network | |
parent | 63c74fe87a6b631f53a17109e10e8011f74f99aa (diff) | |
download | chromium_src-44bcec48e565403ed83a6f5030ad468a9f9c7a7c.zip chromium_src-44bcec48e565403ed83a6f5030ad468a9f9c7a7c.tar.gz chromium_src-44bcec48e565403ed83a6f5030ad468a9f9c7a7c.tar.bz2 |
Add DevicePropertiesUpdated to NetworkStateHandlerObserver
We will need this for networkingPrivate so that we can notify observers
when Device properties of a Cellular network change.
BUG=none
Review URL: https://codereview.chromium.org/395523004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283863 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/network')
-rw-r--r-- | chromeos/network/network_state_handler.cc | 9 | ||||
-rw-r--r-- | chromeos/network/network_state_handler.h | 5 | ||||
-rw-r--r-- | chromeos/network/network_state_handler_observer.cc | 4 | ||||
-rw-r--r-- | chromeos/network/network_state_handler_observer.h | 4 | ||||
-rw-r--r-- | chromeos/network/network_state_handler_unittest.cc | 83 |
5 files changed, 96 insertions, 9 deletions
diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc index d19bd7d..a78b6ee 100644 --- a/chromeos/network/network_state_handler.cc +++ b/chromeos/network/network_state_handler.cc @@ -611,6 +611,7 @@ void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, NET_LOG_EVENT("DevicePropertyUpdated", detail); NotifyDeviceListChanged(); + NotifyDevicePropertiesUpdated(device); if (key == shill::kScanningProperty && device->scanning() == false) ScanCompleted(device->type()); @@ -652,6 +653,7 @@ void NetworkStateHandler::UpdateIPConfigProperties( if (!device) return; device->IPConfigPropertiesChanged(ip_config_path, properties); + NotifyDevicePropertiesUpdated(device); if (!default_network_path_.empty()) { const NetworkState* default_network = GetNetworkState(default_network_path_); @@ -897,6 +899,13 @@ void NetworkStateHandler::NotifyNetworkPropertiesUpdated( NetworkPropertiesUpdated(network)); } +void NetworkStateHandler::NotifyDevicePropertiesUpdated( + const DeviceState* device) { + NET_LOG_DEBUG("NOTIFY:DevicePropertiesUpdated", GetLogName(device)); + FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, + DevicePropertiesUpdated(device)); +} + void NetworkStateHandler::ScanCompleted(const std::string& type) { size_t num_callbacks = scan_complete_callbacks_.count(type); NET_LOG_EVENT("ScanCompleted", diff --git a/chromeos/network/network_state_handler.h b/chromeos/network/network_state_handler.h index a4f16f5..20f0577 100644 --- a/chromeos/network/network_state_handler.h +++ b/chromeos/network/network_state_handler.h @@ -348,9 +348,12 @@ class CHROMEOS_EXPORT NetworkStateHandler // Notifies observers when the default network or its properties change. void NotifyDefaultNetworkChanged(const NetworkState* default_network); - // Notifies observers about changes to |network|. + // Notifies observers about changes to |network|, including IPConfg. void NotifyNetworkPropertiesUpdated(const NetworkState* network); + // Notifies observers about changes to |device|, including IPConfigs. + void NotifyDevicePropertiesUpdated(const DeviceState* device); + // Called whenever Device.Scanning state transitions to false. void ScanCompleted(const std::string& type); diff --git a/chromeos/network/network_state_handler_observer.cc b/chromeos/network/network_state_handler_observer.cc index 0914e6b..3cbde4c 100644 --- a/chromeos/network/network_state_handler_observer.cc +++ b/chromeos/network/network_state_handler_observer.cc @@ -30,6 +30,10 @@ void NetworkStateHandlerObserver::NetworkPropertiesUpdated( const NetworkState* network) { } +void NetworkStateHandlerObserver::DevicePropertiesUpdated( + const chromeos::DeviceState* device) { +} + void NetworkStateHandlerObserver::IsShuttingDown() { } diff --git a/chromeos/network/network_state_handler_observer.h b/chromeos/network/network_state_handler_observer.h index 63910c4..bcf3275 100644 --- a/chromeos/network/network_state_handler_observer.h +++ b/chromeos/network/network_state_handler_observer.h @@ -13,6 +13,7 @@ namespace chromeos { +class DeviceState; class NetworkState; // Observer class for all network state changes, including changes to @@ -44,6 +45,9 @@ class CHROMEOS_EXPORT NetworkStateHandlerObserver { // wifi strength. virtual void NetworkPropertiesUpdated(const NetworkState* network); + // One or more properties of |device| have been updated. + virtual void DevicePropertiesUpdated(const DeviceState* device); + // Called just before NetworkStateHandler is destroyed so that observers // can safely stop observing. virtual void IsShuttingDown(); diff --git a/chromeos/network/network_state_handler_unittest.cc b/chromeos/network/network_state_handler_unittest.cc index 619a284..74c9b6d 100644 --- a/chromeos/network/network_state_handler_unittest.cc +++ b/chromeos/network/network_state_handler_unittest.cc @@ -14,9 +14,11 @@ #include "base/values.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/shill_device_client.h" +#include "chromeos/dbus/shill_ipconfig_client.h" #include "chromeos/dbus/shill_manager_client.h" #include "chromeos/dbus/shill_profile_client.h" #include "chromeos/dbus/shill_service_client.h" +#include "chromeos/network/device_state.h" #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler_observer.h" @@ -31,11 +33,16 @@ void ErrorCallbackFunction(const std::string& error_name, LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; } +const std::string kShillManagerClientStubWifiDevice = + "/device/stub_wifi_device1"; +const std::string kShillManagerClientStubCellularDevice = + "/device/stub_cellular_device1"; const std::string kShillManagerClientStubDefaultService = "/service/eth1"; const std::string kShillManagerClientStubDefaultWifi = "/service/wifi1"; const std::string kShillManagerClientStubWifi2 = "/service/wifi2"; const std::string kShillManagerClientStubCellular = "/service/cellular1"; +using chromeos::DeviceState; using chromeos::NetworkState; using chromeos::NetworkStateHandler; @@ -95,6 +102,11 @@ class TestObserver : public chromeos::NetworkStateHandlerObserver { property_updates_[network->path()]++; } + virtual void DevicePropertiesUpdated(const DeviceState* device) OVERRIDE { + DCHECK(device); + device_property_updates_[device->path()]++; + } + size_t device_list_changed_count() { return device_list_changed_count_; } size_t device_count() { return device_count_; } size_t network_list_changed_count() { return network_list_changed_count_; } @@ -107,6 +119,11 @@ class TestObserver : public chromeos::NetworkStateHandlerObserver { default_network_change_count_ = 0; device_list_changed_count_ = 0; network_list_changed_count_ = 0; + connection_state_changes_.clear(); + } + void reset_updates() { + property_updates_.clear(); + device_property_updates_.clear(); } std::string default_network() { return default_network_; } std::string default_network_connection_state() { @@ -117,6 +134,10 @@ class TestObserver : public chromeos::NetworkStateHandlerObserver { return property_updates_[service_path]; } + int PropertyUpdatesForDevice(const std::string& device_path) { + return device_property_updates_[device_path]; + } + int ConnectionStateChangesForService(const std::string& service_path) { return connection_state_changes_[service_path]; } @@ -136,6 +157,7 @@ class TestObserver : public chromeos::NetworkStateHandlerObserver { std::string default_network_; std::string default_network_connection_state_; std::map<std::string, int> property_updates_; + std::map<std::string, int> device_property_updates_; std::map<std::string, int> connection_state_changes_; std::map<std::string, std::string> network_connection_state_; @@ -190,11 +212,10 @@ class NetworkStateHandlerTest : public testing::Test { DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); ASSERT_TRUE(device_test_); device_test_->ClearDevices(); - device_test_->AddDevice( - "/device/stub_wifi_device1", shill::kTypeWifi, "stub_wifi_device1"); - device_test_->AddDevice("/device/stub_cellular_device1", - shill::kTypeCellular, - "stub_cellular_device1"); + device_test_->AddDevice(kShillManagerClientStubWifiDevice, + shill::kTypeWifi, "stub_wifi_device1"); + device_test_->AddDevice(kShillManagerClientStubCellularDevice, + shill::kTypeCellular, "stub_cellular_device1"); manager_test_ = DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); @@ -521,21 +542,23 @@ TEST_F(NetworkStateHandlerTest, GetState) { } TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { - // Change a network state. const std::string eth1 = kShillManagerClientStubDefaultService; + EXPECT_EQ(0, test_observer_->ConnectionStateChangesForService(eth1)); + + // Change a network state. base::StringValue connection_state_idle_value(shill::kStateIdle); service_test_->SetServiceProperty(eth1, shill::kStateProperty, connection_state_idle_value); message_loop_.RunUntilIdle(); EXPECT_EQ(shill::kStateIdle, test_observer_->NetworkConnectionStateForService(eth1)); - EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); + EXPECT_EQ(1, test_observer_->ConnectionStateChangesForService(eth1)); // Confirm that changing the connection state to the same value does *not* // signal the observer. service_test_->SetServiceProperty(eth1, shill::kStateProperty, connection_state_idle_value); message_loop_.RunUntilIdle(); - EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); + EXPECT_EQ(1, test_observer_->ConnectionStateChangesForService(eth1)); } TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) { @@ -713,4 +736,48 @@ TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) { EXPECT_EQ(wifi_guid, network->guid()); } +TEST_F(NetworkStateHandlerTest, DeviceListChanged) { + size_t stub_device_count = test_observer_->device_count(); + // Add an additional device. + const std::string wifi_device = "/service/stub_wifi_device2"; + device_test_->AddDevice(wifi_device, shill::kTypeWifi, "stub_wifi_device2"); + UpdateManagerProperties(); + // Expect a device list update. + EXPECT_EQ(stub_device_count + 1, test_observer_->device_count()); + EXPECT_EQ(0, test_observer_->PropertyUpdatesForDevice(wifi_device)); + // Change a device property. + device_test_->SetDeviceProperty( + wifi_device, shill::kScanningProperty, base::FundamentalValue(true)); + UpdateManagerProperties(); + EXPECT_EQ(1, test_observer_->PropertyUpdatesForDevice(wifi_device)); +} + +TEST_F(NetworkStateHandlerTest, IPConfigChanged) { + test_observer_->reset_updates(); + EXPECT_EQ(0, test_observer_->PropertyUpdatesForDevice( + kShillManagerClientStubWifiDevice)); + EXPECT_EQ(0, test_observer_->PropertyUpdatesForService( + kShillManagerClientStubDefaultWifi)); + + // Change IPConfigs property. + ShillIPConfigClient::TestInterface* ip_config_test = + DBusThreadManager::Get()->GetShillIPConfigClient()->GetTestInterface(); + const std::string kIPConfigPath = "test_ip_config"; + base::DictionaryValue ip_config_properties; + ip_config_test->AddIPConfig(kIPConfigPath, ip_config_properties); + base::ListValue device_ip_configs; + device_ip_configs.Append(new base::StringValue(kIPConfigPath)); + device_test_->SetDeviceProperty( + kShillManagerClientStubWifiDevice, shill::kIPConfigsProperty, + device_ip_configs); + service_test_->SetServiceProperty( + kShillManagerClientStubDefaultWifi, shill::kIPConfigProperty, + base::StringValue(kIPConfigPath)); + UpdateManagerProperties(); + EXPECT_EQ(1, test_observer_->PropertyUpdatesForDevice( + kShillManagerClientStubWifiDevice)); + EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( + kShillManagerClientStubDefaultWifi)); +} + } // namespace chromeos |