Commit e08ba1b9 authored by peria@chromium.org's avatar peria@chromium.org

[TaskManager] Check iterators' availability before manipulating them.

There are some DCHECK() to check iterators, but it checks
nothing in release builds.
We have to check them to avoid crashes in release builds.


BUG=364243

Review URL: https://codereview.chromium.org/338993004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277963 0039d316-1c4b-4281-b951-d872f2087c98
parent e82e2b55
...@@ -994,6 +994,8 @@ void TaskManagerModel::RemoveResource(Resource* resource) { ...@@ -994,6 +994,8 @@ void TaskManagerModel::RemoveResource(Resource* resource) {
// Find the associated group. // Find the associated group.
GroupMap::iterator group_iter = group_map_.find(process); GroupMap::iterator group_iter = group_map_.find(process);
DCHECK(group_iter != group_map_.end()); DCHECK(group_iter != group_map_.end());
if (group_iter == group_map_.end())
return;
ResourceList& group_entries = group_iter->second; ResourceList& group_entries = group_iter->second;
// Remove the entry from the group map. // Remove the entry from the group map.
...@@ -1001,7 +1003,8 @@ void TaskManagerModel::RemoveResource(Resource* resource) { ...@@ -1001,7 +1003,8 @@ void TaskManagerModel::RemoveResource(Resource* resource) {
group_entries.end(), group_entries.end(),
resource); resource);
DCHECK(iter != group_entries.end()); DCHECK(iter != group_entries.end());
group_entries.erase(iter); if (iter != group_entries.end())
group_entries.erase(iter);
// If there are no more entries for that process, do the clean-up. // If there are no more entries for that process, do the clean-up.
if (group_entries.empty()) { if (group_entries.empty()) {
...@@ -1016,27 +1019,26 @@ void TaskManagerModel::RemoveResource(Resource* resource) { ...@@ -1016,27 +1019,26 @@ void TaskManagerModel::RemoveResource(Resource* resource) {
} }
} }
// Prepare to remove the entry from the model list. // Remove the entry from the model list.
iter = std::find(resources_.begin(), resources_.end(), resource); iter = std::find(resources_.begin(), resources_.end(), resource);
DCHECK(iter != resources_.end()); DCHECK(iter != resources_.end());
int index = static_cast<int>(iter - resources_.begin()); if (iter != resources_.end()) {
int index = static_cast<int>(iter - resources_.begin());
// Notify the observers that the contents will change. // Notify the observers that the contents will change.
FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
OnItemsToBeRemoved(index, 1)); OnItemsToBeRemoved(index, 1));
// Now actually remove the entry from the model list.
// Now actually remove the entry from the model list. resources_.erase(iter);
resources_.erase(iter); // Notify the table that the contents have changed.
FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
OnItemsRemoved(index, 1));
}
// Remove the entry from the network maps. // Remove the entry from the network maps.
ResourceValueMap::iterator net_iter = ResourceValueMap::iterator net_iter =
current_byte_count_map_.find(resource); current_byte_count_map_.find(resource);
if (net_iter != current_byte_count_map_.end()) if (net_iter != current_byte_count_map_.end())
current_byte_count_map_.erase(net_iter); current_byte_count_map_.erase(net_iter);
// Notify the table that the contents have changed.
FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
OnItemsRemoved(index, 1));
} }
void TaskManagerModel::StartUpdating() { void TaskManagerModel::StartUpdating() {
......
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