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

Unified Diff: chrome/browser/tabs/tab_strip_model.cc

Issue 4687009: Fixes possible crash in TabStripModel. If during close all a tab was (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 10 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/tabs/tab_strip_model_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tabs/tab_strip_model.cc
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index 5862727575e9e1659613ecd79a4a299b46fa0c0d..a03c8e21d2ad332fc44c463321e9e75baca08896 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -789,8 +789,17 @@ bool TabStripModel::IsNewTabAtEndOfTabStrip(TabContents* contents) const {
bool TabStripModel::InternalCloseTabs(const std::vector<int>& indices,
uint32 close_types) {
+ if (indices.empty())
+ return true;
+
bool retval = true;
+ // Map the indices to TabContents, that way if deleting a tab deletes other
+ // tabs we're ok.
Ben Goodger (Google) 2010/11/11 22:20:28 Can you mention what situations would cause one ta
+ std::vector<TabContents*> tabs;
+ for (size_t i = 0; i < indices.size(); ++i)
+ tabs.push_back(GetContentsAt(indices[i]));
+
// We only try the fast shutdown path if the whole browser process is *not*
// shutting down. Fast shutdown during browser termination is handled in
// BrowserShutdown.
@@ -824,11 +833,16 @@ bool TabStripModel::InternalCloseTabs(const std::vector<int>& indices,
}
// We now return to our regularly scheduled shutdown procedure.
- for (size_t i = 0; i < indices.size(); ++i) {
- TabContents* detached_contents = GetContentsAt(indices[i]);
+ for (size_t i = 0; i < tabs.size(); ++i) {
+ TabContents* detached_contents = tabs[i];
+ int index = GetIndexOfTabContents(detached_contents);
+ // Make sure we still contain the tab.
+ if (index == kNoTab)
+ continue;
+
detached_contents->OnCloseStarted();
- if (!delegate_->CanCloseContentsAt(indices[i])) {
+ if (!delegate_->CanCloseContentsAt(index)) {
retval = false;
continue;
}
@@ -847,7 +861,7 @@ bool TabStripModel::InternalCloseTabs(const std::vector<int>& indices,
continue;
}
- InternalCloseTab(detached_contents, indices[i],
+ InternalCloseTab(detached_contents, index,
(close_types & CLOSE_CREATE_HISTORICAL_TAB) != 0);
}
« no previous file with comments | « no previous file | chrome/browser/tabs/tab_strip_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698