diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-07 08:14:46 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-07 08:14:46 +0000 |
commit | b16d79d79bfef59f829d61909c05f795627b3f95 (patch) | |
tree | 2b74f0267347f8a6fa0a6dae6350e669ed1215c6 /chromeos | |
parent | 84646839c323715f3e9c9b9d792c7c386bbebc33 (diff) | |
download | chromium_src-b16d79d79bfef59f829d61909c05f795627b3f95.zip chromium_src-b16d79d79bfef59f829d61909c05f795627b3f95.tar.gz chromium_src-b16d79d79bfef59f829d61909c05f795627b3f95.tar.bz2 |
Observe devices in NetworkStateHandler
This includes a bit of cleanup to NetworkStateHandler and ShillPropertyHandler.
I made ShillServicePropertyObserver support devices, renamed it
ShillPropertyObserver, and moved it into ShillPropertyHandler since:
a) naming it would be challenging without context
b) It doesn't really do much, so if we want something similar (e.g. in NetworkConfigurationHandler) it will be easier just to copy/paste the code we need
BUG=161869
Review URL: https://chromiumcodereview.appspot.com/12211051
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181254 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/chromeos.gyp | 2 | ||||
-rw-r--r-- | chromeos/dbus/shill_service_client.cc | 12 | ||||
-rw-r--r-- | chromeos/network/device_state.cc | 5 | ||||
-rw-r--r-- | chromeos/network/device_state.h | 2 | ||||
-rw-r--r-- | chromeos/network/network_state_handler.cc | 234 | ||||
-rw-r--r-- | chromeos/network/network_state_handler.h | 70 | ||||
-rw-r--r-- | chromeos/network/network_state_handler_observer.cc | 3 | ||||
-rw-r--r-- | chromeos/network/network_state_handler_observer.h | 5 | ||||
-rw-r--r-- | chromeos/network/network_state_handler_unittest.cc | 5 | ||||
-rw-r--r-- | chromeos/network/shill_property_handler.cc | 231 | ||||
-rw-r--r-- | chromeos/network/shill_property_handler.h | 60 | ||||
-rw-r--r-- | chromeos/network/shill_property_handler_unittest.cc | 52 | ||||
-rw-r--r-- | chromeos/network/shill_service_observer.cc | 33 | ||||
-rw-r--r-- | chromeos/network/shill_service_observer.h | 44 |
14 files changed, 458 insertions, 300 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 9d35c08..2139970 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -182,8 +182,6 @@ 'network/onc/onc_validator.h', 'network/shill_property_handler.cc', 'network/shill_property_handler.h', - 'network/shill_service_observer.cc', - 'network/shill_service_observer.h', 'network/sms_watcher.cc', 'network/sms_watcher.h', 'power/power_state_override.cc', diff --git a/chromeos/dbus/shill_service_client.cc b/chromeos/dbus/shill_service_client.cc index f0ed08f..efc9243 100644 --- a/chromeos/dbus/shill_service_client.cc +++ b/chromeos/dbus/shill_service_client.cc @@ -332,8 +332,10 @@ class ShillServiceClientStubImpl : public ShillServiceClient, service_path, flimflam::kStateProperty, online_value, - callback, error_callback), + base::Bind(&base::DoNothing), + error_callback), base::TimeDelta::FromSeconds(kConnectDelaySeconds)); + callback.Run(); } virtual void Disconnect(const dbus::ObjectPath& service_path, @@ -349,8 +351,10 @@ class ShillServiceClientStubImpl : public ShillServiceClient, service_path, flimflam::kStateProperty, idle_value, - callback, error_callback), + base::Bind(&base::DoNothing), + error_callback), base::TimeDelta::FromSeconds(kConnectDelaySeconds)); + callback.Run(); } virtual void Remove(const dbus::ObjectPath& service_path, @@ -438,6 +442,10 @@ class ShillServiceClientStubImpl : public ShillServiceClient, SetServiceProperty("stub_wifi2", flimflam::kSecurityProperty, psk_value); + base::FundamentalValue strength_value(80); + SetServiceProperty("stub_wifi2", + flimflam::kSignalStrengthProperty, + strength_value); AddService("stub_cellular1", "cellular1", flimflam::kTypeCellular, diff --git a/chromeos/network/device_state.cc b/chromeos/network/device_state.cc index 3ba9c87..78a8674 100644 --- a/chromeos/network/device_state.cc +++ b/chromeos/network/device_state.cc @@ -14,7 +14,8 @@ namespace chromeos { DeviceState::DeviceState(const std::string& path) : ManagedState(MANAGED_TYPE_DEVICE, path), provider_requires_roaming_(false), - support_network_scan_(false) { + support_network_scan_(false), + scanning_(false) { } DeviceState::~DeviceState() { @@ -26,6 +27,8 @@ bool DeviceState::PropertyChanged(const std::string& key, return true; if (key == flimflam::kAddressProperty) { return GetStringValue(key, value, &mac_address_); + } else if (key == flimflam::kScanningProperty) { + return GetBooleanValue(key, value, &scanning_); } else if (key == flimflam::kSupportNetworkScanProperty) { return GetBooleanValue(key, value, &support_network_scan_); } else if (key == shill::kProviderRequiresRoamingProperty) { diff --git a/chromeos/network/device_state.h b/chromeos/network/device_state.h index 3545b45..2547017 100644 --- a/chromeos/network/device_state.h +++ b/chromeos/network/device_state.h @@ -24,6 +24,7 @@ class CHROMEOS_EXPORT DeviceState : public ManagedState { const std::string& mac_address() const { return mac_address_; } bool provider_requires_roaming() const { return provider_requires_roaming_; } bool support_network_scan() const { return support_network_scan_; } + bool scanning() const { return scanning_; } private: // Common Device Properties @@ -32,6 +33,7 @@ class CHROMEOS_EXPORT DeviceState : public ManagedState { std::string home_provider_id_; bool provider_requires_roaming_; bool support_network_scan_; + bool scanning_; DISALLOW_COPY_AND_ASSIGN(DeviceState); }; diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc index 0698c3b..9b5bb46 100644 --- a/chromeos/network/network_state_handler.cc +++ b/chromeos/network/network_state_handler.cc @@ -26,15 +26,48 @@ const char kLogModule[] = "NetworkPropertyHandler"; // * kMatchTypeDefault matches any network (i.e. the first instance) // * kMatchTypeNonVirtual matches non virtual networks // * kMatchTypeWireless matches wireless networks -bool NetworkStateMatchesType(const chromeos::NetworkState* network, +// * kMatchTypeMobile matches cellular or wimax networks +bool ManagedStateMatchesType(const chromeos::ManagedState* managed, const std::string& match_type) { - const std::string& type = network->type(); - return ((match_type == chromeos::NetworkStateHandler::kMatchTypeDefault) || - (match_type == type) || - (match_type == chromeos::NetworkStateHandler::kMatchTypeNonVirtual && - type != flimflam::kTypeVPN) || - (match_type == chromeos::NetworkStateHandler::kMatchTypeWireless && - type != flimflam::kTypeEthernet && type != flimflam::kTypeVPN)); + const std::string& type = managed->type(); + if (match_type == chromeos::NetworkStateHandler::kMatchTypeDefault) + return true; + if (match_type == type) + return true; + if (match_type == chromeos::NetworkStateHandler::kMatchTypeNonVirtual && + type != flimflam::kTypeVPN) { + return true; + } + if (match_type == chromeos::NetworkStateHandler::kMatchTypeWireless && + type != flimflam::kTypeEthernet && type != flimflam::kTypeVPN) { + return true; + } + if (match_type == chromeos::NetworkStateHandler::kMatchTypeMobile && + (type == flimflam::kTypeCellular || type == flimflam::kTypeWimax)) { + return true; + } + return false; +} + +std::string ValueAsString(const base::Value& value) { + if (value.GetType() == base::Value::TYPE_BOOLEAN) { + bool bval = false; + value.GetAsBoolean(&bval); + return bval ? "true" : "false"; + } else if (value.GetType() == base::Value::TYPE_INTEGER) { + int intval = 0; + value.GetAsInteger(&intval); + return StringPrintf("%d", intval); + } else if (value.GetType() == base::Value::TYPE_DOUBLE) { + double dval = 0; + value.GetAsDouble(&dval); + return StringPrintf("%g", dval); + } else if (value.GetType() == base::Value::TYPE_STRING) { + std::string vstr; + value.GetAsString(&vstr); + return vstr; + } + return ""; } } // namespace @@ -43,6 +76,7 @@ namespace chromeos { const char NetworkStateHandler::kMatchTypeDefault[] = "default"; const char NetworkStateHandler::kMatchTypeWireless[] = "wireless"; +const char NetworkStateHandler::kMatchTypeMobile[] = "mobile"; const char NetworkStateHandler::kMatchTypeNonVirtual[] = "non-virtual"; static NetworkStateHandler* g_network_state_handler = NULL; @@ -90,23 +124,48 @@ void NetworkStateHandler::RemoveObserver( observers_.RemoveObserver(observer); } -bool NetworkStateHandler::TechnologyAvailable( - const std::string& technology) const { - return available_technologies_.find(technology) != - available_technologies_.end(); +bool NetworkStateHandler::TechnologyAvailable(const std::string& type) const { + if (type == kMatchTypeMobile) { + return shill_property_handler_->TechnologyAvailable(flimflam::kTypeWimax) || + shill_property_handler_->TechnologyAvailable(flimflam::kTypeCellular); + } + return shill_property_handler_->TechnologyAvailable(type); } -bool NetworkStateHandler::TechnologyEnabled( - const std::string& technology) const { - return enabled_technologies_.find(technology) != enabled_technologies_.end(); +bool NetworkStateHandler::TechnologyEnabled(const std::string& type) const { + if (type == kMatchTypeMobile) { + return shill_property_handler_->TechnologyEnabled(flimflam::kTypeWimax) || + shill_property_handler_->TechnologyEnabled(flimflam::kTypeCellular); + } + return shill_property_handler_->TechnologyEnabled(type); } +bool NetworkStateHandler::TechnologyUninitialized( + const std::string& type) const { + if (type == kMatchTypeMobile) { + return + shill_property_handler_->TechnologyUninitialized( + flimflam::kTypeWimax) || + shill_property_handler_->TechnologyUninitialized( + flimflam::kTypeCellular); + } + return shill_property_handler_->TechnologyUninitialized(type); +} + + void NetworkStateHandler::SetTechnologyEnabled( - const std::string& technology, + const std::string& type, bool enabled, const network_handler::ErrorCallback& error_callback) { - shill_property_handler_->SetTechnologyEnabled( - technology, enabled, error_callback); + if (type == kMatchTypeMobile) { + shill_property_handler_->SetTechnologyEnabled( + flimflam::kTypeCellular, enabled, error_callback); + shill_property_handler_->SetTechnologyEnabled( + flimflam::kTypeWimax, enabled, error_callback); + } else { + shill_property_handler_->SetTechnologyEnabled( + type, enabled, error_callback); + } } const DeviceState* NetworkStateHandler::GetDeviceState( @@ -119,12 +178,23 @@ const DeviceState* NetworkStateHandler::GetDeviceStateByType( for (ManagedStateList::const_iterator iter = device_list_.begin(); iter != device_list_.end(); ++iter) { ManagedState* device = *iter; - if (device->type() == type) + if (ManagedStateMatchesType(device, type)) return device->AsDeviceState(); } return NULL; } +bool NetworkStateHandler::GetScanningByType(const std::string& type) const { + for (ManagedStateList::const_iterator iter = device_list_.begin(); + iter != device_list_.end(); ++iter) { + const DeviceState* device = (*iter)->AsDeviceState(); + DCHECK(device); + if (ManagedStateMatchesType(device, type) && device->scanning()) + return true; + } + return false; +} + const NetworkState* NetworkStateHandler::GetNetworkState( const std::string& service_path) const { return GetModifiableNetworkState(service_path); @@ -148,7 +218,7 @@ const NetworkState* NetworkStateHandler::ConnectedNetworkByType( DCHECK(network); if (!network->IsConnectedState()) break; // Connected networks are listed first. - if (NetworkStateMatchesType(network, type)) + if (ManagedStateMatchesType(network, type)) return network; } return NULL; @@ -164,7 +234,19 @@ const NetworkState* NetworkStateHandler::ConnectingNetworkByType( continue; if (!network->IsConnectingState()) break; // Connected and connecting networks are listed first. - if (NetworkStateMatchesType(network, type)) + if (ManagedStateMatchesType(network, type)) + return network; + } + return NULL; +} + +const NetworkState* NetworkStateHandler::FirstNetworkByType( + const std::string& type) const { + for (ManagedStateList::const_iterator iter = network_list_.begin(); + iter != network_list_.end(); ++iter) { + const NetworkState* network = (*iter)->AsNetworkState(); + DCHECK(network); + if (ManagedStateMatchesType(network, type)) return network; } return NULL; @@ -209,11 +291,8 @@ void NetworkStateHandler::GetNetworkList(NetworkStateList* list) const { } } -bool NetworkStateHandler::RequestWifiScan() const { - if (!TechnologyEnabled(flimflam::kTypeWifi)) - return false; +void NetworkStateHandler::RequestScan() const { shill_property_handler_->RequestScan(); - return true; } //------------------------------------------------------------------------------ @@ -263,39 +342,6 @@ void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); } -void NetworkStateHandler::UpdateAvailableTechnologies( - const base::ListValue& technologies) { - available_technologies_.clear(); - network_event_log::AddEntry( - kLogModule, "AvailableTechnologiesChanged", - StringPrintf("Size: %"PRIuS, technologies.GetSize())); - for (base::ListValue::const_iterator iter = technologies.begin(); - iter != technologies.end(); ++iter) { - std::string technology; - (*iter)->GetAsString(&technology); - DCHECK(!technology.empty()); - available_technologies_.insert(technology); - } -} - -void NetworkStateHandler::UpdateEnabledTechnologies( - const base::ListValue& technologies) { - bool wifi_was_enabled = TechnologyEnabled(flimflam::kTypeWifi); - enabled_technologies_.clear(); - network_event_log::AddEntry( - kLogModule, "EnabledTechnologiesChanged", - StringPrintf("Size: %"PRIuS, technologies.GetSize())); - for (base::ListValue::const_iterator iter = technologies.begin(); - iter != technologies.end(); ++iter) { - std::string technology; - (*iter)->GetAsString(&technology); - DCHECK(!technology.empty()); - enabled_technologies_.insert(technology); - } - if (!wifi_was_enabled && TechnologyEnabled(flimflam::kTypeWifi)) - RequestWifiScan(); -} - void NetworkStateHandler::UpdateManagedStateProperties( ManagedState::ManagedType type, const std::string& path, @@ -306,13 +352,14 @@ void NetworkStateHandler::UpdateManagedStateProperties( return; } bool network_property_updated = false; + std::string prev_connection_state; + if (type == ManagedState::MANAGED_TYPE_NETWORK) + prev_connection_state = managed->AsNetworkState()->connection_state(); for (base::DictionaryValue::Iterator iter(properties); iter.HasNext(); iter.Advance()) { if (type == ManagedState::MANAGED_TYPE_NETWORK) { - if (ParseNetworkServiceProperty( - managed->AsNetworkState(), iter.key(), iter.value())) { + if (managed->PropertyChanged(iter.key(), iter.value())) network_property_updated = true; - } } else { managed->PropertyChanged(iter.key(), iter.value()); } @@ -321,6 +368,9 @@ void NetworkStateHandler::UpdateManagedStateProperties( if (network_property_updated) { NetworkState* network = managed->AsNetworkState(); DCHECK(network); + // Signal connection state changed after all properties have been updated. + if (network->connection_state() != prev_connection_state) + OnNetworkConnectionStateChanged(network); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, NetworkPropertiesUpdated(network)); } @@ -336,15 +386,20 @@ void NetworkStateHandler::UpdateNetworkServiceProperty( NetworkState* network = GetModifiableNetworkState(service_path); if (!network) return; - if (!ParseNetworkServiceProperty(network, key, value)) + std::string prev_connection_state = network->connection_state(); + if (!network->PropertyChanged(key, value)) return; - std::string detail = network->name() + "." + key; - std::string vstr; - if (value.GetAsString(&vstr)) - detail += " = " + vstr; - network_event_log::AddEntry(kLogModule, "NetworkPropertiesUpdated", detail); + if (network->connection_state() != prev_connection_state) + OnNetworkConnectionStateChanged(network); + FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, NetworkPropertiesUpdated(network)); + + std::string detail = network->name() + "." + key; + std::string vstr = ValueAsString(value); + if (!vstr.empty()) + detail += " = " + vstr; + network_event_log::AddEntry(kLogModule, "NetworkPropertyUpdated", detail); } void NetworkStateHandler::UpdateNetworkServiceIPAddress( @@ -361,6 +416,25 @@ void NetworkStateHandler::UpdateNetworkServiceIPAddress( NetworkPropertiesUpdated(network)); } +void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, + const std::string& key, + const base::Value& value) { + DeviceState* device = GetModifiableDeviceState(device_path); + if (!device) + return; + if (!device->PropertyChanged(key, value)) + return; + + FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, + DeviceListChanged()); + + std::string detail = device->name() + "." + key; + std::string vstr = ValueAsString(value); + if (!vstr.empty()) + detail += " = " + vstr; + network_event_log::AddEntry(kLogModule, "DevicePropertyUpdated", detail); +} + void NetworkStateHandler::ManagerPropertyChanged() { FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, NetworkManagerChanged()); @@ -370,13 +444,11 @@ void NetworkStateHandler::ManagedStateListChanged( ManagedState::ManagedType type) { if (type == ManagedState::MANAGED_TYPE_NETWORK) { // Notify observers that the list of networks has changed. - NetworkStateList network_list; - GetNetworkList(&network_list); network_event_log::AddEntry( kLogModule, "NetworkListChanged", StringPrintf("Size: %"PRIuS, network_list_.size())); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, - NetworkListChanged(network_list)); + NetworkListChanged()); // The list order may have changed, so check if the default network changed. if (CheckDefaultNetworkChanged()) OnDefaultNetworkChanged(); @@ -435,33 +507,17 @@ NetworkStateHandler::ManagedStateList* NetworkStateHandler::GetManagedList( return NULL; } -bool NetworkStateHandler::ParseNetworkServiceProperty( - NetworkState* network, - const std::string& key, - const base::Value& value) { - DCHECK(network); - std::string prev_connection_state = network->connection_state(); - if (!network->PropertyChanged(key, value)) - return false; - if (key == flimflam::kStateProperty && - network->connection_state() != prev_connection_state) { - OnNetworkConnectionStateChanged(network); - } - return true; -} - void NetworkStateHandler::OnNetworkConnectionStateChanged( NetworkState* network) { + DCHECK(network); std::string desc = StringPrintf( "%s: %s", network->path().c_str(), network->connection_state().c_str()); network_event_log::AddEntry( kLogModule, "NetworkConnectionStateChanged", desc); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, NetworkConnectionStateChanged(network)); - if (CheckDefaultNetworkChanged() || - network->path() == default_network_path_) { + if (CheckDefaultNetworkChanged() || network->path() == default_network_path_) OnDefaultNetworkChanged(); - } } bool NetworkStateHandler::CheckDefaultNetworkChanged() { @@ -479,7 +535,7 @@ void NetworkStateHandler::OnDefaultNetworkChanged() { const NetworkState* default_network = DefaultNetwork(); network_event_log::AddEntry( kLogModule, "DefaultNetworkChanged", - default_network ? default_network->path() : "Null"); + default_network ? default_network->path() : "None"); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, DefaultNetworkChanged(default_network)); } diff --git a/chromeos/network/network_state_handler.h b/chromeos/network/network_state_handler.h index 68f48a7..1eab61c 100644 --- a/chromeos/network/network_state_handler.h +++ b/chromeos/network/network_state_handler.h @@ -41,6 +41,15 @@ class NetworkStateHandlerTest; // keep properties up to date by managing the appropriate Shill observers. // It will invoke its own more specific observer methods when the specified // changes occur. +// +// Most *ByType or *ForType methods will accept any of the following for +// |type|. See individual methods for specific notes. +// * Any type defined in service_constants.h (e.g. flimflam::kTypeWifi) +// * kMatchTypeDefault returns the default (active) network +// * kMatchTypeNonVirtual returns the primary non virtual network +// * kMatchTypeWireless returns the primary wireless network +// * kMatchTypeMobile returns the primary cellular or wimax network + class CHROMEOS_EXPORT NetworkStateHandler : public internal::ShillPropertyHandler::Listener { public: @@ -62,14 +71,17 @@ class CHROMEOS_EXPORT NetworkStateHandler void AddObserver(NetworkStateHandlerObserver* observer); void RemoveObserver(NetworkStateHandlerObserver* observer); - // Returns true if |technology| is enabled / available. - bool TechnologyAvailable(const std::string& technology) const; - bool TechnologyEnabled(const std::string& technology) const; + // Returns true if technology for |type| is available/ enabled/uninitialized. + // kMatchTypeMobile (only) is also supported. + bool TechnologyAvailable(const std::string& type) const; + bool TechnologyEnabled(const std::string& type) const; + bool TechnologyUninitialized(const std::string& type) const; - // Asynchronously sets the enabled property for |technology|. + // Asynchronously sets the technology enabled property for |type|. + // kMatchTypeMobile (only) is also supported. // Note: Modifies Manager state. Calls |error_callback| on failure. void SetTechnologyEnabled( - const std::string& technology, + const std::string& type, bool enabled, const network_handler::ErrorCallback& error_callback); @@ -77,8 +89,13 @@ class CHROMEOS_EXPORT NetworkStateHandler const DeviceState* GetDeviceState(const std::string& device_path) const; // Finds and returns a device state by |type|. Returns NULL if not found. + // See note above for valid types. const DeviceState* GetDeviceStateByType(const std::string& type) const; + // Returns true if any device of |type| is scanning. + // See note above for valid types. + bool GetScanningByType(const std::string& type) const; + // Finds and returns a network state by |service_path| or NULL if not found. // Note: NetworkState is frequently updated asynchronously, i.e. properties // are not always updated all at once. This will contain the most recent @@ -91,18 +108,20 @@ class CHROMEOS_EXPORT NetworkStateHandler const NetworkState* DefaultNetwork() const; // Returns the primary connected network of matching |type|, otherwise NULL. - // |type| can be a type defined in service_constants.h, or one of the - // following special constants: - // * kMatchTypeDefault returns the default (active) network - // * kMatchTypeNonVirtual returns the primary connected non virtual network - // * kMatchTypeWireless returns the primary connected wireless network + // See note above for valid types. const NetworkState* ConnectedNetworkByType(const std::string& type) const; // Like ConnectedNetworkByType() but returns a connecting network or NULL. const NetworkState* ConnectingNetworkByType(const std::string& type) const; + // Like ConnectedNetworkByType() but returns any matching network or NULL. + // Mostly useful for mobile networks where there is generally only one + // netowrk. Note: O(N). + const NetworkState* FirstNetworkByType(const std::string& type) const; + // Returns the hardware (MAC) address for the first connected network // matching |type|, or an empty string if none. + // See note above for valid types. std::string HardwareAddressForType(const std::string& type) const; // Same as above but in aa:bb format. std::string FormattedHardwareAddressForType(const std::string& type) const; @@ -113,13 +132,13 @@ class CHROMEOS_EXPORT NetworkStateHandler // only on the UI thread). void GetNetworkList(NetworkStateList* list) const; - // Requests a scan of wifi networks. This may trigger updates to the network + // Requests a network scan. This may trigger updates to the network // list, which will trigger the appropriate observer calls. - // Returns true if a scan was requested. - bool RequestWifiScan() const; + void RequestScan() const; static const char kMatchTypeDefault[]; static const char kMatchTypeWireless[]; + static const char kMatchTypeMobile[]; static const char kMatchTypeNonVirtual[]; protected: @@ -132,14 +151,6 @@ class CHROMEOS_EXPORT NetworkStateHandler virtual void UpdateManagedList(ManagedState::ManagedType type, const base::ListValue& entries) OVERRIDE; - // Sets |available_technologies_| to contain only entries in |technologies|. - virtual void UpdateAvailableTechnologies( - const base::ListValue& technologies) OVERRIDE; - - // Sets |enabled_technologies_| to contain only entries in |technologies|. - virtual void UpdateEnabledTechnologies( - const base::ListValue& technologies) OVERRIDE; - // Parses the properties for the network service or device. Mostly calls // managed->PropertyChanged(key, value) for each dictionary entry. virtual void UpdateManagedStateProperties( @@ -148,7 +159,6 @@ class CHROMEOS_EXPORT NetworkStateHandler const base::DictionaryValue& properties) OVERRIDE; // Called by ShillPropertyHandler when a watched service property changes. - // Calls ParseNetworkServiceProperty() and signals observers. virtual void UpdateNetworkServiceProperty( const std::string& service_path, const std::string& key, @@ -159,6 +169,12 @@ class CHROMEOS_EXPORT NetworkStateHandler const std::string& service_path, const std::string& ip_address) OVERRIDE; + // Called by ShillPropertyHandler when a watched device property changes. + virtual void UpdateDeviceProperty( + const std::string& device_path, + const std::string& key, + const base::Value& value) OVERRIDE; + // Sends NetworkManagerChanged() to observers. virtual void ManagerPropertyChanged() OVERRIDE; @@ -189,12 +205,6 @@ class CHROMEOS_EXPORT NetworkStateHandler // Gets the list specified by |type|. ManagedStateList* GetManagedList(ManagedState::ManagedType type); - // Helper function called to parse |network| properties. Also calls - // OnNetworkConnectionStateChanged() if the connection_state property changes. - bool ParseNetworkServiceProperty(NetworkState* network, - const std::string& key, - const base::Value& value); - // Helper function to notify observers. Calls CheckDefaultNetworkChanged(). void OnNetworkConnectionStateChanged(NetworkState* network); @@ -215,10 +225,6 @@ class CHROMEOS_EXPORT NetworkStateHandler ManagedStateList network_list_; ManagedStateList device_list_; - // Lists of available / enabled technologies - std::set<std::string> available_technologies_; - std::set<std::string> enabled_technologies_; - // Keeps track of the default network for notifying observers when it changes. std::string default_network_path_; diff --git a/chromeos/network/network_state_handler_observer.cc b/chromeos/network/network_state_handler_observer.cc index 08ee3e8..1aa1042 100644 --- a/chromeos/network/network_state_handler_observer.cc +++ b/chromeos/network/network_state_handler_observer.cc @@ -15,8 +15,7 @@ NetworkStateHandlerObserver::~NetworkStateHandlerObserver() { void NetworkStateHandlerObserver::NetworkManagerChanged() { } -void NetworkStateHandlerObserver::NetworkListChanged( - const NetworkStateList& networks) { +void NetworkStateHandlerObserver::NetworkListChanged() { } void NetworkStateHandlerObserver::DeviceListChanged() { diff --git a/chromeos/network/network_state_handler_observer.h b/chromeos/network/network_state_handler_observer.h index 96f25ce..a23076c 100644 --- a/chromeos/network/network_state_handler_observer.h +++ b/chromeos/network/network_state_handler_observer.h @@ -28,10 +28,9 @@ class CHROMEOS_EXPORT NetworkStateHandlerObserver { virtual void NetworkManagerChanged(); // The list of networks changed. - virtual void NetworkListChanged(const NetworkStateList& networks); + virtual void NetworkListChanged(); - // The list of devices changed. Typically we don't care about the list - // of devices, so they are not passed in the method. + // The list of devices changed, or a property changed (e.g. scanning). virtual void DeviceListChanged(); // The default network changed (includes VPNs) or its connection state diff --git a/chromeos/network/network_state_handler_unittest.cc b/chromeos/network/network_state_handler_unittest.cc index 20522eb..1ee88a7 100644 --- a/chromeos/network/network_state_handler_unittest.cc +++ b/chromeos/network/network_state_handler_unittest.cc @@ -46,8 +46,9 @@ class TestObserver : public chromeos::NetworkStateHandlerObserver { ++manager_changed_count_; } - virtual void NetworkListChanged( - const NetworkStateHandler::NetworkStateList& networks) OVERRIDE { + virtual void NetworkListChanged() OVERRIDE { + NetworkStateHandler::NetworkStateList networks; + handler_->GetNetworkList(&networks); network_count_ = networks.size(); if (network_count_ == 0) { default_network_ = ""; diff --git a/chromeos/network/shill_property_handler.cc b/chromeos/network/shill_property_handler.cc index 7781367..fa01cc9 100644 --- a/chromeos/network/shill_property_handler.cc +++ b/chromeos/network/shill_property_handler.cc @@ -16,7 +16,6 @@ #include "chromeos/dbus/shill_manager_client.h" #include "chromeos/dbus/shill_service_client.h" #include "chromeos/network/network_event_log.h" -#include "chromeos/network/shill_service_observer.h" #include "dbus/object_path.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -24,9 +23,9 @@ namespace { const char kLogModule[] = "ShillPropertyHandler"; -// Limit the number of services we observe. Since they are listed in priority -// order, it should be reasonable to ignore services past this. -const size_t kMaxObservedServices = 100; +// Limit the number of services or devices we observe. Since they are listed in +// priority order, it should be reasonable to ignore services past this. +const size_t kMaxObserved = 100; const base::ListValue* GetListValue(const std::string& key, const base::Value& value) { @@ -43,6 +42,62 @@ const base::ListValue* GetListValue(const std::string& key, namespace chromeos { namespace internal { +// Class to manage Shill service property changed observers. Observers are +// added on construction and removed on destruction. Runs the handler when +// OnPropertyChanged is called. +class ShillPropertyObserver : public ShillPropertyChangedObserver { + public: + typedef base::Callback<void(ManagedState::ManagedType type, + const std::string& service, + const std::string& name, + const base::Value& value)> Handler; + + ShillPropertyObserver(ManagedState::ManagedType type, + const std::string& path, + const Handler& handler) + : type_(type), + path_(path), + handler_(handler) { + if (type_ == ManagedState::MANAGED_TYPE_NETWORK) { + DBusThreadManager::Get()->GetShillServiceClient()-> + AddPropertyChangedObserver(dbus::ObjectPath(path_), this); + } else if (type_ == ManagedState::MANAGED_TYPE_DEVICE) { + DBusThreadManager::Get()->GetShillDeviceClient()-> + AddPropertyChangedObserver(dbus::ObjectPath(path_), this); + } else { + NOTREACHED(); + } + } + + virtual ~ShillPropertyObserver() { + if (type_ == ManagedState::MANAGED_TYPE_NETWORK) { + DBusThreadManager::Get()->GetShillServiceClient()-> + RemovePropertyChangedObserver(dbus::ObjectPath(path_), this); + } else if (type_ == ManagedState::MANAGED_TYPE_DEVICE) { + DBusThreadManager::Get()->GetShillDeviceClient()-> + RemovePropertyChangedObserver(dbus::ObjectPath(path_), this); + } else { + NOTREACHED(); + } + } + + // ShillPropertyChangedObserver overrides. + virtual void OnPropertyChanged(const std::string& key, + const base::Value& value) OVERRIDE { + handler_.Run(type_, path_, key, value); + } + + private: + ManagedState::ManagedType type_; + std::string path_; + Handler handler_; + + DISALLOW_COPY_AND_ASSIGN(ShillPropertyObserver); +}; + +//------------------------------------------------------------------------------ +// ShillPropertyHandler + ShillPropertyHandler::ShillPropertyHandler(Listener* listener) : listener_(listener), shill_manager_(DBusThreadManager::Get()->GetShillManagerClient()), @@ -53,6 +108,8 @@ ShillPropertyHandler::~ShillPropertyHandler() { // Delete network service observers. STLDeleteContainerPairSecondPointers( observed_networks_.begin(), observed_networks_.end()); + STLDeleteContainerPairSecondPointers( + observed_devices_.begin(), observed_devices_.end()); CHECK(shill_manager_ == DBusThreadManager::Get()->GetShillManagerClient()); shill_manager_->RemovePropertyChangedObserver(this); } @@ -64,6 +121,21 @@ void ShillPropertyHandler::Init() { shill_manager_->AddPropertyChangedObserver(this); } +bool ShillPropertyHandler::TechnologyAvailable( + const std::string& technology) const { + return available_technologies_.count(technology) != 0; +} + +bool ShillPropertyHandler::TechnologyEnabled( + const std::string& technology) const { + return enabled_technologies_.count(technology) != 0; +} + +bool ShillPropertyHandler::TechnologyUninitialized( + const std::string& technology) const { + return uninitialized_technologies_.count(technology) != 0; +} + void ShillPropertyHandler::SetTechnologyEnabled( const std::string& technology, bool enabled, @@ -116,6 +188,16 @@ void ShillPropertyHandler::OnPropertyChanged(const std::string& key, const base::Value& value) { if (ManagerPropertyChanged(key, value)) listener_->ManagerPropertyChanged(); + // If the service watch or device list changed and there are no pending + // updates, signal the state list changed callback. + if ((key == flimflam::kServiceWatchListProperty) && + pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0) { + listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_NETWORK); + } + if (key == flimflam::kDevicesProperty && + pending_updates_[ManagedState::MANAGED_TYPE_DEVICE].size() == 0) { + listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_DEVICE); + } } //------------------------------------------------------------------------------ @@ -147,6 +229,11 @@ void ShillPropertyHandler::ManagerPropertiesCallback( } if (notify) listener_->ManagerPropertyChanged(); + // If there are no pending updates, signal the state list changed callbacks. + if (pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0) + listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_NETWORK); + if (pending_updates_[ManagedState::MANAGED_TYPE_DEVICE].size() == 0) + listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_DEVICE); } bool ShillPropertyHandler::ManagerPropertyChanged(const std::string& key, @@ -155,78 +242,122 @@ bool ShillPropertyHandler::ManagerPropertyChanged(const std::string& key, if (key == flimflam::kServicesProperty) { const base::ListValue* vlist = GetListValue(key, value); if (vlist) - UpdateManagedList(ManagedState::MANAGED_TYPE_NETWORK, *vlist); + listener_->UpdateManagedList(ManagedState::MANAGED_TYPE_NETWORK, *vlist); } else if (key == flimflam::kServiceWatchListProperty) { const base::ListValue* vlist = GetListValue(key, value); - if (vlist) - UpdateObservedNetworkServices(*vlist); + if (vlist) { + UpdateObserved(ManagedState::MANAGED_TYPE_NETWORK, *vlist); + } } else if (key == flimflam::kDevicesProperty) { const ListValue* vlist = GetListValue(key, value); - if (vlist) - UpdateManagedList(ManagedState::MANAGED_TYPE_DEVICE, *vlist); + if (vlist) { + listener_->UpdateManagedList(ManagedState::MANAGED_TYPE_DEVICE, *vlist); + UpdateObserved(ManagedState::MANAGED_TYPE_DEVICE, *vlist); + } } else if (key == flimflam::kAvailableTechnologiesProperty) { const base::ListValue* vlist = GetListValue(key, value); if (vlist) { - listener_->UpdateAvailableTechnologies(*vlist); + UpdateAvailableTechnologies(*vlist); notify_manager_changed = true; } } else if (key == flimflam::kEnabledTechnologiesProperty) { const base::ListValue* vlist = GetListValue(key, value); if (vlist) { - listener_->UpdateEnabledTechnologies(*vlist); + UpdateEnabledTechnologies(*vlist); + notify_manager_changed = true; + } + } else if (key == shill::kUninitializedTechnologiesProperty) { + const base::ListValue* vlist = GetListValue(key, value); + if (vlist) { + UpdateUninitializedTechnologies(*vlist); notify_manager_changed = true; } } return notify_manager_changed; } -void ShillPropertyHandler::UpdateManagedList(ManagedState::ManagedType type, - const base::ListValue& entries) { - listener_->UpdateManagedList(type, entries); - // Do not send a ManagerPropertyChanged notification to the Listener if - // RequestProperties has been called (ManagedStateListChanged will be - // called when the update requests have completed). If no requests - // have been made, call ManagedStateListChanged to indicate that the - // order of the list has changed. - if (pending_updates_[type].size() == 0) - listener_->ManagedStateListChanged(type); -} - -void ShillPropertyHandler::UpdateObservedNetworkServices( - const base::ListValue& entries) { - // Watch all networks in the watch list. - ShillServiceObserverMap new_observed; +void ShillPropertyHandler::UpdateObserved(ManagedState::ManagedType type, + const base::ListValue& entries) { + ShillPropertyObserverMap& observer_map = + (type == ManagedState::MANAGED_TYPE_NETWORK) + ? observed_networks_ : observed_devices_; + ShillPropertyObserverMap new_observed; for (base::ListValue::const_iterator iter1 = entries.begin(); iter1 != entries.end(); ++iter1) { std::string path; (*iter1)->GetAsString(&path); if (path.empty()) continue; - ShillServiceObserverMap::iterator iter2 = observed_networks_.find(path); - if (iter2 != observed_networks_.end()) { + ShillPropertyObserverMap::iterator iter2 = observer_map.find(path); + if (iter2 != observer_map.end()) { new_observed[path] = iter2->second; } else { - // Request an update for the network. - RequestProperties(ManagedState::MANAGED_TYPE_NETWORK, path); + // Request an update. + RequestProperties(type, path); // Create an observer for future updates. - new_observed[path] = new ShillServiceObserver( - path, base::Bind( - &ShillPropertyHandler::NetworkServicePropertyChangedCallback, + new_observed[path] = new ShillPropertyObserver( + type, path, base::Bind( + &ShillPropertyHandler::PropertyChangedCallback, weak_ptr_factory_.GetWeakPtr())); network_event_log::AddEntry(kLogModule, "StartObserving", path); } - observed_networks_.erase(path); + observer_map.erase(path); // Limit the number of observed services. - if (new_observed.size() >= kMaxObservedServices) + if (new_observed.size() >= kMaxObserved) break; } - // Delete network service observers still in observed_networks_. - for (ShillServiceObserverMap::iterator iter = observed_networks_.begin(); - iter != observed_networks_.end(); ++iter) { + // Delete network service observers still in observer_map. + for (ShillPropertyObserverMap::iterator iter = observer_map.begin(); + iter != observer_map.end(); ++iter) { network_event_log::AddEntry(kLogModule, "StopObserving", iter->first); delete iter->second; } - observed_networks_.swap(new_observed); + observer_map.swap(new_observed); +} + +void ShillPropertyHandler::UpdateAvailableTechnologies( + const base::ListValue& technologies) { + available_technologies_.clear(); + network_event_log::AddEntry( + kLogModule, "AvailableTechnologiesChanged", + StringPrintf("Size: %"PRIuS, technologies.GetSize())); + for (base::ListValue::const_iterator iter = technologies.begin(); + iter != technologies.end(); ++iter) { + std::string technology; + (*iter)->GetAsString(&technology); + DCHECK(!technology.empty()); + available_technologies_.insert(technology); + } +} + +void ShillPropertyHandler::UpdateEnabledTechnologies( + const base::ListValue& technologies) { + enabled_technologies_.clear(); + network_event_log::AddEntry( + kLogModule, "EnabledTechnologiesChanged", + StringPrintf("Size: %"PRIuS, technologies.GetSize())); + for (base::ListValue::const_iterator iter = technologies.begin(); + iter != technologies.end(); ++iter) { + std::string technology; + (*iter)->GetAsString(&technology); + DCHECK(!technology.empty()); + enabled_technologies_.insert(technology); + } +} + +void ShillPropertyHandler::UpdateUninitializedTechnologies( + const base::ListValue& technologies) { + uninitialized_technologies_.clear(); + network_event_log::AddEntry( + kLogModule, "UninitializedTechnologiesChanged", + StringPrintf("Size: %"PRIuS, technologies.GetSize())); + for (base::ListValue::const_iterator iter = technologies.begin(); + iter != technologies.end(); ++iter) { + std::string technology; + (*iter)->GetAsString(&technology); + DCHECK(!technology.empty()); + uninitialized_technologies_.insert(technology); + } } void ShillPropertyHandler::GetPropertiesCallback( @@ -247,6 +378,19 @@ void ShillPropertyHandler::GetPropertiesCallback( listener_->ManagedStateListChanged(type); } +void ShillPropertyHandler::PropertyChangedCallback( + ManagedState::ManagedType type, + const std::string& path, + const std::string& key, + const base::Value& value) { + if (type == ManagedState::MANAGED_TYPE_NETWORK) + NetworkServicePropertyChangedCallback(path, key, value); + else if (type == ManagedState::MANAGED_TYPE_DEVICE) + NetworkDevicePropertyChangedCallback(path, key, value); + else + NOTREACHED(); +} + void ShillPropertyHandler::NetworkServicePropertyChangedCallback( const std::string& path, const std::string& key, @@ -283,5 +427,12 @@ void ShillPropertyHandler::GetIPConfigCallback( listener_->UpdateNetworkServiceIPAddress(service_path, ip_address); } +void ShillPropertyHandler::NetworkDevicePropertyChangedCallback( + const std::string& path, + const std::string& key, + const base::Value& value) { + listener_->UpdateDeviceProperty(path, key, value); +} + } // namespace internal } // namespace chromeos diff --git a/chromeos/network/shill_property_handler.h b/chromeos/network/shill_property_handler.h index f90584c..66678ac 100644 --- a/chromeos/network/shill_property_handler.h +++ b/chromeos/network/shill_property_handler.h @@ -28,7 +28,7 @@ class ShillManagerClient; namespace internal { -class ShillServiceObserver; +class ShillPropertyObserver; // This class handles Shill calls and observers to reflect the state of the // Shill Manager and its services and devices. It observes Shill.Manager and @@ -40,7 +40,8 @@ class ShillServiceObserver; class CHROMEOS_EXPORT ShillPropertyHandler : public ShillPropertyChangedObserver { public: - typedef std::map<std::string, ShillServiceObserver*> ShillServiceObserverMap; + typedef std::map<std::string, ShillPropertyObserver*> + ShillPropertyObserverMap; class CHROMEOS_EXPORT Listener { public: @@ -48,14 +49,6 @@ class CHROMEOS_EXPORT ShillPropertyHandler virtual void UpdateManagedList(ManagedState::ManagedType type, const base::ListValue& entries) = 0; - // Called when the available technologies are set or have changed. - virtual void UpdateAvailableTechnologies( - const base::ListValue& technologies) = 0; - - // Called when the enabled technologies are set or have changed. - virtual void UpdateEnabledTechnologies( - const base::ListValue& technologies) = 0; - // Called when the properties for a managed state have changed. virtual void UpdateManagedStateProperties( ManagedState::ManagedType type, @@ -68,6 +61,12 @@ class CHROMEOS_EXPORT ShillPropertyHandler const std::string& key, const base::Value& value) = 0; + // Called when a property for a watched device has changed. + virtual void UpdateDeviceProperty( + const std::string& device_path, + const std::string& key, + const base::Value& value) = 0; + // Called when one or more manager properties (e.g. a technology list) // changes. virtual void ManagerPropertyChanged() = 0; @@ -93,6 +92,11 @@ class CHROMEOS_EXPORT ShillPropertyHandler // Sends an initial property request and sets up the observer. void Init(); + // Returns true if |technology| is available / enabled / uninitialized. + bool TechnologyAvailable(const std::string& technology) const; + bool TechnologyEnabled(const std::string& technology) const; + bool TechnologyUninitialized(const std::string& technology) const; + // Asynchronously sets the enabled state for |technology|. // Note: Modifes Manager state. Calls |error_callback| on failure. void SetTechnologyEnabled( @@ -124,14 +128,15 @@ class CHROMEOS_EXPORT ShillPropertyHandler // Returns true if observers should be notified. bool ManagerPropertyChanged(const std::string& key, const base::Value& value); - // Calls listener_->UpdateManagedList and triggers ManagedStateListChanged if - // no new property requests have been made. - void UpdateManagedList(ManagedState::ManagedType type, - const base::ListValue& entries); + // Updates the Shill property observers to observe any entries for |type|. + void UpdateObserved(ManagedState::ManagedType type, + const base::ListValue& entries); + - // Updates the Shill service property observers to observe any entries - // in the service watch list. - void UpdateObservedNetworkServices(const base::ListValue& entries); + // Sets |*_technologies_| to contain only entries in |technologies|. + void UpdateAvailableTechnologies(const base::ListValue& technologies); + void UpdateEnabledTechnologies(const base::ListValue& technologies); + void UpdateUninitializedTechnologies(const base::ListValue& technologies); // Called when Shill returns the properties for a service or device. void GetPropertiesCallback(ManagedState::ManagedType type, @@ -139,11 +144,18 @@ class CHROMEOS_EXPORT ShillPropertyHandler DBusMethodCallStatus call_status, const base::DictionaryValue& properties); - // Callback invoked when a watched service property changes. Calls - // network->PropertyChanged(key, value) and signals observers. + // Callback invoked when a watched property changes. Calls appropriate + // handlers and signals observers. + void PropertyChangedCallback(ManagedState::ManagedType type, + const std::string& path, + const std::string& key, + const base::Value& value); void NetworkServicePropertyChangedCallback(const std::string& path, const std::string& key, const base::Value& value); + void NetworkDevicePropertyChangedCallback(const std::string& path, + const std::string& key, + const base::Value& value); // Callback for getting the IPConfig property of a Network. Handled here // instead of in NetworkState so that all asynchronous requests are done @@ -162,7 +174,15 @@ class CHROMEOS_EXPORT ShillPropertyHandler std::map<ManagedState::ManagedType, std::set<std::string> > pending_updates_; // List of network services with Shill property changed observers - ShillServiceObserverMap observed_networks_; + ShillPropertyObserverMap observed_networks_; + + // List of network devices with Shill property changed observers + ShillPropertyObserverMap observed_devices_; + + // Lists of available / enabled / uninitialized technologies + std::set<std::string> available_technologies_; + std::set<std::string> enabled_technologies_; + std::set<std::string> uninitialized_technologies_; // For Shill client callbacks base::WeakPtrFactory<ShillPropertyHandler> weak_ptr_factory_; diff --git a/chromeos/network/shill_property_handler_unittest.cc b/chromeos/network/shill_property_handler_unittest.cc index 9f6e609..d660d00 100644 --- a/chromeos/network/shill_property_handler_unittest.cc +++ b/chromeos/network/shill_property_handler_unittest.cc @@ -39,16 +39,6 @@ class TestListener : public internal::ShillPropertyHandler::Listener { UpdateEntries(GetTypeString(type), entries); } - virtual void UpdateAvailableTechnologies( - const base::ListValue& technologies) OVERRIDE { - UpdateEntries(flimflam::kAvailableTechnologiesProperty, technologies); - } - - virtual void UpdateEnabledTechnologies( - const base::ListValue& technologies) OVERRIDE { - UpdateEntries(flimflam::kEnabledTechnologiesProperty, technologies); - } - virtual void UpdateManagedStateProperties( ManagedState::ManagedType type, const std::string& path, @@ -63,6 +53,13 @@ class TestListener : public internal::ShillPropertyHandler::Listener { AddPropertyUpdate(flimflam::kServicesProperty, service_path); } + virtual void UpdateDeviceProperty( + const std::string& device_path, + const std::string& key, + const base::Value& value) OVERRIDE { + AddPropertyUpdate(flimflam::kDevicesProperty, device_path); + } + virtual void ManagerPropertyChanged() OVERRIDE { ++manager_updates_; } @@ -228,13 +225,10 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { EXPECT_EQ(1, listener_->manager_updates()); // ShillManagerClient default stub entries are in shill_manager_client.cc. // TODO(stevenjb): Eliminate default stub entries and add them explicitly. - const size_t kNumShillManagerClientStubImplTechnologies = 3; - EXPECT_EQ(kNumShillManagerClientStubImplTechnologies, - listener_->entries( - flimflam::kAvailableTechnologiesProperty).size()); - EXPECT_EQ(kNumShillManagerClientStubImplTechnologies, - listener_->entries( - flimflam::kEnabledTechnologiesProperty).size()); + EXPECT_TRUE(shill_property_handler_->TechnologyAvailable( + flimflam::kTypeWifi)); + EXPECT_TRUE(shill_property_handler_->TechnologyEnabled( + flimflam::kTypeWifi)); const size_t kNumShillManagerClientStubImplDevices = 2; EXPECT_EQ(kNumShillManagerClientStubImplDevices, listener_->entries(flimflam::kDevicesProperty).size()); @@ -254,22 +248,19 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { manager_test_->AddTechnology(flimflam::kTypeWimax, false); message_loop_.RunUntilIdle(); EXPECT_EQ(2, listener_->manager_updates()); - const size_t kNumShillManagerClientStubImplTechnologies = 3; - EXPECT_EQ(kNumShillManagerClientStubImplTechnologies + 1, - listener_->entries( - flimflam::kAvailableTechnologiesProperty).size()); - EXPECT_EQ(kNumShillManagerClientStubImplTechnologies, - listener_->entries( - flimflam::kEnabledTechnologiesProperty).size()); + EXPECT_TRUE(shill_property_handler_->TechnologyAvailable( + flimflam::kTypeWimax)); + EXPECT_FALSE(shill_property_handler_->TechnologyEnabled( + flimflam::kTypeWimax)); + // Enable the technology. DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( flimflam::kTypeWimax, base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); message_loop_.RunUntilIdle(); EXPECT_EQ(3, listener_->manager_updates()); - EXPECT_EQ(kNumShillManagerClientStubImplTechnologies + 1, - listener_->entries( - flimflam::kEnabledTechnologiesProperty).size()); + EXPECT_TRUE(shill_property_handler_->TechnologyEnabled( + flimflam::kTypeWimax)); EXPECT_EQ(0, listener_->errors()); } @@ -318,7 +309,8 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { flimflam::kStateIdle, false); message_loop_.RunUntilIdle(); EXPECT_EQ(1, listener_->manager_updates()); // No new manager updates. - EXPECT_EQ(2, listener_->list_updates(flimflam::kServicesProperty)); + // Only watched services trigger a service list update. + EXPECT_EQ(1, listener_->list_updates(flimflam::kServicesProperty)); EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, listener_->entries(flimflam::kServicesProperty).size()); // Change a property. @@ -338,7 +330,7 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { flimflam::kStateIdle, true); message_loop_.RunUntilIdle(); // Service list update should be received when watch list changes. - EXPECT_EQ(3, listener_->list_updates(flimflam::kServicesProperty)); + EXPECT_EQ(2, listener_->list_updates(flimflam::kServicesProperty)); // Number of services shouldn't change. EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, listener_->entries(flimflam::kServicesProperty).size()); @@ -360,7 +352,7 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { // Remove a service RemoveService(kTestServicePath); message_loop_.RunUntilIdle(); - EXPECT_EQ(4, listener_->list_updates(flimflam::kServicesProperty)); + EXPECT_EQ(3, listener_->list_updates(flimflam::kServicesProperty)); EXPECT_EQ(kNumShillManagerClientStubImplServices, listener_->entries(flimflam::kServicesProperty).size()); diff --git a/chromeos/network/shill_service_observer.cc b/chromeos/network/shill_service_observer.cc deleted file mode 100644 index ae42690..0000000 --- a/chromeos/network/shill_service_observer.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chromeos/network/shill_service_observer.h" - -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/shill_service_client.h" -#include "dbus/object_path.h" - -namespace chromeos { -namespace internal { - -ShillServiceObserver::ShillServiceObserver(const std::string& service_path, - const Handler& handler) - : service_path_(service_path), - handler_(handler) { - DBusThreadManager::Get()->GetShillServiceClient()-> - AddPropertyChangedObserver(dbus::ObjectPath(service_path), this); -} - -ShillServiceObserver::~ShillServiceObserver() { - DBusThreadManager::Get()->GetShillServiceClient()-> - RemovePropertyChangedObserver(dbus::ObjectPath(service_path_), this); -} - -void ShillServiceObserver::OnPropertyChanged(const std::string& key, - const base::Value& value) { - handler_.Run(service_path_, key, value); -} - -} // namespace internal -} // namespace chromeos diff --git a/chromeos/network/shill_service_observer.h b/chromeos/network/shill_service_observer.h deleted file mode 100644 index 1365f0e..0000000 --- a/chromeos/network/shill_service_observer.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROMEOS_NETWORK_SHILL_SERVICE_OBSERVER_H_ -#define CHROMEOS_NETWORK_SHILL_SERVICE_OBSERVER_H_ - -#include <string> - -#include "base/callback.h" -#include "chromeos/dbus/shill_property_changed_observer.h" - -namespace chromeos { -namespace internal { - -// Class to manage Shill service property changed observers. Observers are -// added on construction and removed on destruction. Runs the handler when -// OnPropertyChanged is called. -class ShillServiceObserver : public ShillPropertyChangedObserver { - public: - typedef base::Callback<void(const std::string& service, - const std::string& name, - const base::Value& value)> Handler; - - ShillServiceObserver(const std::string& service_path, - const Handler& handler); - - virtual ~ShillServiceObserver(); - - // ShillPropertyChangedObserver overrides. - virtual void OnPropertyChanged(const std::string& key, - const base::Value& value) OVERRIDE; - - private: - std::string service_path_; - Handler handler_; - - DISALLOW_COPY_AND_ASSIGN(ShillServiceObserver); -}; - -} // namespace internal -} // namespace chromeos - -#endif // CHROMEOS_NETWORK_SHILL_SERVICE_OBSERVER_H_ |