Commit 90957658 authored by pneubeck@chromium.org's avatar pneubeck@chromium.org

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
parent 26923d73
...@@ -168,7 +168,9 @@ void NetworkStateHandler::SetTechnologyEnabled( ...@@ -168,7 +168,9 @@ void NetworkStateHandler::SetTechnologyEnabled(
const DeviceState* NetworkStateHandler::GetDeviceState( const DeviceState* NetworkStateHandler::GetDeviceState(
const std::string& device_path) const { 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( const DeviceState* NetworkStateHandler::GetDeviceStateByType(
...@@ -176,6 +178,8 @@ const DeviceState* NetworkStateHandler::GetDeviceStateByType( ...@@ -176,6 +178,8 @@ const DeviceState* NetworkStateHandler::GetDeviceStateByType(
for (ManagedStateList::const_iterator iter = device_list_.begin(); for (ManagedStateList::const_iterator iter = device_list_.begin();
iter != device_list_.end(); ++iter) { iter != device_list_.end(); ++iter) {
ManagedState* device = *iter; ManagedState* device = *iter;
if (!device->update_received())
continue;
if (ManagedStateMatchesType(device, type)) if (ManagedStateMatchesType(device, type))
return device->AsDeviceState(); return device->AsDeviceState();
} }
...@@ -187,6 +191,8 @@ bool NetworkStateHandler::GetScanningByType(const std::string& type) const { ...@@ -187,6 +191,8 @@ bool NetworkStateHandler::GetScanningByType(const std::string& type) const {
iter != device_list_.end(); ++iter) { iter != device_list_.end(); ++iter) {
const DeviceState* device = (*iter)->AsDeviceState(); const DeviceState* device = (*iter)->AsDeviceState();
DCHECK(device); DCHECK(device);
if (!device->update_received())
continue;
if (ManagedStateMatchesType(device, type) && device->scanning()) if (ManagedStateMatchesType(device, type) && device->scanning())
return true; return true;
} }
...@@ -195,7 +201,9 @@ bool NetworkStateHandler::GetScanningByType(const std::string& type) const { ...@@ -195,7 +201,9 @@ bool NetworkStateHandler::GetScanningByType(const std::string& type) const {
const NetworkState* NetworkStateHandler::GetNetworkState( const NetworkState* NetworkStateHandler::GetNetworkState(
const std::string& service_path) const { 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 { const NetworkState* NetworkStateHandler::DefaultNetwork() const {
...@@ -203,7 +211,7 @@ const NetworkState* NetworkStateHandler::DefaultNetwork() const { ...@@ -203,7 +211,7 @@ const NetworkState* NetworkStateHandler::DefaultNetwork() const {
return NULL; return NULL;
const NetworkState* network = network_list_.front()->AsNetworkState(); const NetworkState* network = network_list_.front()->AsNetworkState();
DCHECK(network); DCHECK(network);
if (!network->IsConnectedState()) if (!network->update_received() || !network->IsConnectedState())
return NULL; return NULL;
return network; return network;
} }
...@@ -214,6 +222,8 @@ const NetworkState* NetworkStateHandler::ConnectedNetworkByType( ...@@ -214,6 +222,8 @@ const NetworkState* NetworkStateHandler::ConnectedNetworkByType(
iter != network_list_.end(); ++iter) { iter != network_list_.end(); ++iter) {
const NetworkState* network = (*iter)->AsNetworkState(); const NetworkState* network = (*iter)->AsNetworkState();
DCHECK(network); DCHECK(network);
if (!network->update_received())
continue;
if (!network->IsConnectedState()) if (!network->IsConnectedState())
break; // Connected networks are listed first. break; // Connected networks are listed first.
if (ManagedStateMatchesType(network, type)) if (ManagedStateMatchesType(network, type))
...@@ -228,7 +238,7 @@ const NetworkState* NetworkStateHandler::ConnectingNetworkByType( ...@@ -228,7 +238,7 @@ const NetworkState* NetworkStateHandler::ConnectingNetworkByType(
iter != network_list_.end(); ++iter) { iter != network_list_.end(); ++iter) {
const NetworkState* network = (*iter)->AsNetworkState(); const NetworkState* network = (*iter)->AsNetworkState();
DCHECK(network); DCHECK(network);
if (network->IsConnectedState()) if (!network->update_received() || network->IsConnectedState())
continue; continue;
if (!network->IsConnectingState()) if (!network->IsConnectingState())
break; // Connected and connecting networks are listed first. break; // Connected and connecting networks are listed first.
...@@ -244,6 +254,8 @@ const NetworkState* NetworkStateHandler::FirstNetworkByType( ...@@ -244,6 +254,8 @@ const NetworkState* NetworkStateHandler::FirstNetworkByType(
iter != network_list_.end(); ++iter) { iter != network_list_.end(); ++iter) {
const NetworkState* network = (*iter)->AsNetworkState(); const NetworkState* network = (*iter)->AsNetworkState();
DCHECK(network); DCHECK(network);
if (!network->update_received())
continue;
if (ManagedStateMatchesType(network, type)) if (ManagedStateMatchesType(network, type))
return network; return network;
} }
...@@ -252,13 +264,13 @@ const NetworkState* NetworkStateHandler::FirstNetworkByType( ...@@ -252,13 +264,13 @@ const NetworkState* NetworkStateHandler::FirstNetworkByType(
std::string NetworkStateHandler::HardwareAddressForType( std::string NetworkStateHandler::HardwareAddressForType(
const std::string& type) const { const std::string& type) const {
std::string result;
const NetworkState* network = ConnectedNetworkByType(type); const NetworkState* network = ConnectedNetworkByType(type);
if (network) { if (!network)
const DeviceState* device = GetDeviceState(network->device_path()); return std::string();
if (device) const DeviceState* device = GetDeviceState(network->device_path());
result = device->mac_address(); if (!device)
} return std::string();
std::string result = device->mac_address();
StringToUpperASCII(&result); StringToUpperASCII(&result);
return result; return result;
} }
...@@ -287,10 +299,10 @@ void NetworkStateHandler::GetNetworkListByType(const std::string& type, ...@@ -287,10 +299,10 @@ void NetworkStateHandler::GetNetworkListByType(const std::string& type,
list->clear(); list->clear();
for (ManagedStateList::const_iterator iter = network_list_.begin(); for (ManagedStateList::const_iterator iter = network_list_.begin();
iter != network_list_.end(); ++iter) { iter != network_list_.end(); ++iter) {
if (!(*iter)->update_received())
continue;
const NetworkState* network = (*iter)->AsNetworkState(); const NetworkState* network = (*iter)->AsNetworkState();
DCHECK(network); DCHECK(network);
if (!network->update_received())
continue;
if (ManagedStateMatchesType(network, type)) if (ManagedStateMatchesType(network, type))
list->push_back(network); list->push_back(network);
} }
...@@ -301,10 +313,10 @@ void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { ...@@ -301,10 +313,10 @@ void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const {
list->clear(); list->clear();
for (ManagedStateList::const_iterator iter = device_list_.begin(); for (ManagedStateList::const_iterator iter = device_list_.begin();
iter != device_list_.end(); ++iter) { iter != device_list_.end(); ++iter) {
if (!(*iter)->update_received())
continue;
const DeviceState* device = (*iter)->AsDeviceState(); const DeviceState* device = (*iter)->AsDeviceState();
DCHECK(device); DCHECK(device);
if (!device->update_received())
continue;
list->push_back(device); list->push_back(device);
} }
} }
...@@ -315,10 +327,10 @@ void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const { ...@@ -315,10 +327,10 @@ void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const {
list->clear(); list->clear();
for (ManagedStateList::const_iterator iter = favorite_list_.begin(); for (ManagedStateList::const_iterator iter = favorite_list_.begin();
iter != favorite_list_.end(); ++iter) { iter != favorite_list_.end(); ++iter) {
if (!(*iter)->update_received())
continue;
const FavoriteState* favorite = (*iter)->AsFavoriteState(); const FavoriteState* favorite = (*iter)->AsFavoriteState();
DCHECK(favorite); DCHECK(favorite);
if (!favorite->update_received())
continue;
if (favorite->is_favorite()) if (favorite->is_favorite())
list->push_back(favorite); list->push_back(favorite);
} }
...@@ -330,6 +342,7 @@ const FavoriteState* NetworkStateHandler::GetFavoriteState( ...@@ -330,6 +342,7 @@ const FavoriteState* NetworkStateHandler::GetFavoriteState(
GetModifiableManagedState(&favorite_list_, service_path); GetModifiableManagedState(&favorite_list_, service_path);
if (!managed) if (!managed)
return NULL; return NULL;
DCHECK(managed->update_received());
return managed->AsFavoriteState(); return managed->AsFavoriteState();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment