Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(562)

Side by Side Diff: chrome/browser/task_manager/task_manager.cc

Issue 338993004: [TaskManager] Check iterators' availabilities before manipulating them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/task_manager/task_manager.h" 5 #include "chrome/browser/task_manager/task_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/i18n/number_formatting.h" 8 #include "base/i18n/number_formatting.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, 987 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
988 OnItemsAdded(new_entry_index, 1)); 988 OnItemsAdded(new_entry_index, 1));
989 } 989 }
990 990
991 void TaskManagerModel::RemoveResource(Resource* resource) { 991 void TaskManagerModel::RemoveResource(Resource* resource) {
992 base::ProcessHandle process = resource->GetProcess(); 992 base::ProcessHandle process = resource->GetProcess();
993 993
994 // Find the associated group. 994 // Find the associated group.
995 GroupMap::iterator group_iter = group_map_.find(process); 995 GroupMap::iterator group_iter = group_map_.find(process);
996 DCHECK(group_iter != group_map_.end()); 996 DCHECK(group_iter != group_map_.end());
997 if (group_iter == group_map_.end())
998 return;
997 ResourceList& group_entries = group_iter->second; 999 ResourceList& group_entries = group_iter->second;
998 1000
999 // Remove the entry from the group map. 1001 // Remove the entry from the group map.
1000 ResourceList::iterator iter = std::find(group_entries.begin(), 1002 ResourceList::iterator iter = std::find(group_entries.begin(),
1001 group_entries.end(), 1003 group_entries.end(),
1002 resource); 1004 resource);
1003 DCHECK(iter != group_entries.end()); 1005 DCHECK(iter != group_entries.end());
1004 group_entries.erase(iter); 1006 if (iter != group_entries.end())
1007 group_entries.erase(iter);
1005 1008
1006 // If there are no more entries for that process, do the clean-up. 1009 // If there are no more entries for that process, do the clean-up.
1007 if (group_entries.empty()) { 1010 if (group_entries.empty()) {
1008 group_map_.erase(group_iter); 1011 group_map_.erase(group_iter);
1009 1012
1010 // Nobody is using this process, we don't need the process metrics anymore. 1013 // Nobody is using this process, we don't need the process metrics anymore.
1011 MetricsMap::iterator pm_iter = metrics_map_.find(process); 1014 MetricsMap::iterator pm_iter = metrics_map_.find(process);
1012 DCHECK(pm_iter != metrics_map_.end()); 1015 DCHECK(pm_iter != metrics_map_.end());
1013 if (pm_iter != metrics_map_.end()) { 1016 if (pm_iter != metrics_map_.end()) {
1014 delete pm_iter->second; 1017 delete pm_iter->second;
1015 metrics_map_.erase(process); 1018 metrics_map_.erase(process);
1016 } 1019 }
1017 } 1020 }
1018 1021
1019 // Prepare to remove the entry from the model list. 1022 // Remove the entry from the model list.
1020 iter = std::find(resources_.begin(), resources_.end(), resource); 1023 iter = std::find(resources_.begin(), resources_.end(), resource);
1021 DCHECK(iter != resources_.end()); 1024 DCHECK(iter != resources_.end());
1022 int index = static_cast<int>(iter - resources_.begin()); 1025 if (iter != resources_.end()) {
1023 1026 int index = static_cast<int>(iter - resources_.begin());
1024 // Notify the observers that the contents will change. 1027 // Notify the observers that the contents will change.
1025 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, 1028 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
1026 OnItemsToBeRemoved(index, 1)); 1029 OnItemsToBeRemoved(index, 1));
1027 1030 // Now actually remove the entry from the model list.
1028 // Now actually remove the entry from the model list. 1031 resources_.erase(iter);
1029 resources_.erase(iter); 1032 // Notify the table that the contents have changed.
1033 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
1034 OnItemsRemoved(index, 1));
1035 }
1030 1036
1031 // Remove the entry from the network maps. 1037 // Remove the entry from the network maps.
1032 ResourceValueMap::iterator net_iter = 1038 ResourceValueMap::iterator net_iter =
1033 current_byte_count_map_.find(resource); 1039 current_byte_count_map_.find(resource);
1034 if (net_iter != current_byte_count_map_.end()) 1040 if (net_iter != current_byte_count_map_.end())
1035 current_byte_count_map_.erase(net_iter); 1041 current_byte_count_map_.erase(net_iter);
1036
1037 // Notify the table that the contents have changed.
1038 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
1039 OnItemsRemoved(index, 1));
1040 } 1042 }
1041 1043
1042 void TaskManagerModel::StartUpdating() { 1044 void TaskManagerModel::StartUpdating() {
1043 // Multiple StartUpdating requests may come in, and we only need to take 1045 // Multiple StartUpdating requests may come in, and we only need to take
1044 // action the first time. 1046 // action the first time.
1045 update_requests_++; 1047 update_requests_++;
1046 if (update_requests_ > 1) 1048 if (update_requests_ > 1)
1047 return; 1049 return;
1048 DCHECK_EQ(1, update_requests_); 1050 DCHECK_EQ(1, update_requests_);
1049 DCHECK_NE(TASK_PENDING, update_state_); 1051 DCHECK_NE(TASK_PENDING, update_state_);
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 params.host_desktop_type = desktop_type; 1555 params.host_desktop_type = desktop_type;
1554 chrome::Navigate(&params); 1556 chrome::Navigate(&params);
1555 } 1557 }
1556 1558
1557 TaskManager::TaskManager() 1559 TaskManager::TaskManager()
1558 : model_(new TaskManagerModel(this)) { 1560 : model_(new TaskManagerModel(this)) {
1559 } 1561 }
1560 1562
1561 TaskManager::~TaskManager() { 1563 TaskManager::~TaskManager() {
1562 } 1564 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698