diff options
author | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-09 15:15:57 +0000 |
---|---|---|
committer | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-09 15:15:57 +0000 |
commit | 90957658651594ec74ad6db7c369859160256b59 (patch) | |
tree | 33590c5512973fc38a724e87852b85a27d6837cf /chromeos | |
parent | 26923d7369eb43a867b9b43444a8802914f0ae22 (diff) | |
download | chromium_src-90957658651594ec74ad6db7c369859160256b59.zip chromium_src-90957658651594ec74ad6db7c369859160256b59.tar.gz chromium_src-90957658651594ec74ad6db7c369859160256b59.tar.bz2 |
Prevent that uninitialized ManagedState objects are returned from NetworkStateHandler.
This CL
https://codereview.chromium.org/23712002 (Cleanup network type matching.)
uncovered, that some NetworkStateHandler functions returned NetworkState objects that were not fully initialized, namely type() was empty.
BUG=126870
Review URL: https://chromiumcodereview.appspot.com/23681010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/network/network_state_handler.cc | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc index eadc2ca..3b12071 100644 --- a/chromeos/network/network_state_handler.cc +++ b/chromeos/network/network_state_handler.cc @@ -168,7 +168,9 @@ void NetworkStateHandler::SetTechnologyEnabled( const DeviceState* NetworkStateHandler::GetDeviceState( const std::string& device_path) const { - return GetModifiableDeviceState(device_path); + const DeviceState* device = GetModifiableDeviceState(device_path); + DCHECK(!device || device->update_received()); + return device; } const DeviceState* NetworkStateHandler::GetDeviceStateByType( @@ -176,6 +178,8 @@ const DeviceState* NetworkStateHandler::GetDeviceStateByType( for (ManagedStateList::const_iterator iter = device_list_.begin(); iter != device_list_.end(); ++iter) { ManagedState* device = *iter; + if (!device->update_received()) + continue; if (ManagedStateMatchesType(device, type)) return device->AsDeviceState(); } @@ -187,6 +191,8 @@ bool NetworkStateHandler::GetScanningByType(const std::string& type) const { iter != device_list_.end(); ++iter) { const DeviceState* device = (*iter)->AsDeviceState(); DCHECK(device); + if (!device->update_received()) + continue; if (ManagedStateMatchesType(device, type) && device->scanning()) return true; } @@ -195,7 +201,9 @@ bool NetworkStateHandler::GetScanningByType(const std::string& type) const { const NetworkState* NetworkStateHandler::GetNetworkState( const std::string& service_path) const { - return GetModifiableNetworkState(service_path); + const NetworkState* network = GetModifiableNetworkState(service_path); + DCHECK(!network || network->update_received()); + return network; } const NetworkState* NetworkStateHandler::DefaultNetwork() const { @@ -203,7 +211,7 @@ const NetworkState* NetworkStateHandler::DefaultNetwork() const { return NULL; const NetworkState* network = network_list_.front()->AsNetworkState(); DCHECK(network); - if (!network->IsConnectedState()) + if (!network->update_received() || !network->IsConnectedState()) return NULL; return network; } @@ -214,6 +222,8 @@ const NetworkState* NetworkStateHandler::ConnectedNetworkByType( iter != network_list_.end(); ++iter) { const NetworkState* network = (*iter)->AsNetworkState(); DCHECK(network); + if (!network->update_received()) + continue; if (!network->IsConnectedState()) break; // Connected networks are listed first. if (ManagedStateMatchesType(network, type)) @@ -228,7 +238,7 @@ const NetworkState* NetworkStateHandler::ConnectingNetworkByType( iter != network_list_.end(); ++iter) { const NetworkState* network = (*iter)->AsNetworkState(); DCHECK(network); - if (network->IsConnectedState()) + if (!network->update_received() || network->IsConnectedState()) continue; if (!network->IsConnectingState()) break; // Connected and connecting networks are listed first. @@ -244,6 +254,8 @@ const NetworkState* NetworkStateHandler::FirstNetworkByType( iter != network_list_.end(); ++iter) { const NetworkState* network = (*iter)->AsNetworkState(); DCHECK(network); + if (!network->update_received()) + continue; if (ManagedStateMatchesType(network, type)) return network; } @@ -252,13 +264,13 @@ const NetworkState* NetworkStateHandler::FirstNetworkByType( std::string NetworkStateHandler::HardwareAddressForType( const std::string& type) const { - std::string result; const NetworkState* network = ConnectedNetworkByType(type); - if (network) { - const DeviceState* device = GetDeviceState(network->device_path()); - if (device) - result = device->mac_address(); - } + if (!network) + return std::string(); + const DeviceState* device = GetDeviceState(network->device_path()); + if (!device) + return std::string(); + std::string result = device->mac_address(); StringToUpperASCII(&result); return result; } @@ -287,10 +299,10 @@ void NetworkStateHandler::GetNetworkListByType(const std::string& type, list->clear(); for (ManagedStateList::const_iterator iter = network_list_.begin(); iter != network_list_.end(); ++iter) { - if (!(*iter)->update_received()) - continue; const NetworkState* network = (*iter)->AsNetworkState(); DCHECK(network); + if (!network->update_received()) + continue; if (ManagedStateMatchesType(network, type)) list->push_back(network); } @@ -301,10 +313,10 @@ void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { list->clear(); for (ManagedStateList::const_iterator iter = device_list_.begin(); iter != device_list_.end(); ++iter) { - if (!(*iter)->update_received()) - continue; const DeviceState* device = (*iter)->AsDeviceState(); DCHECK(device); + if (!device->update_received()) + continue; list->push_back(device); } } @@ -315,10 +327,10 @@ void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const { list->clear(); for (ManagedStateList::const_iterator iter = favorite_list_.begin(); iter != favorite_list_.end(); ++iter) { - if (!(*iter)->update_received()) - continue; const FavoriteState* favorite = (*iter)->AsFavoriteState(); DCHECK(favorite); + if (!favorite->update_received()) + continue; if (favorite->is_favorite()) list->push_back(favorite); } @@ -330,6 +342,7 @@ const FavoriteState* NetworkStateHandler::GetFavoriteState( GetModifiableManagedState(&favorite_list_, service_path); if (!managed) return NULL; + DCHECK(managed->update_received()); return managed->AsFavoriteState(); } |