From 5b94218ebe61b11e24798536c5a6d13695006e8b Mon Sep 17 00:00:00 2001 From: "sky@chromium.org" <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> Date: Wed, 12 Jan 2011 00:29:03 +0000 Subject: [PATCH] Adds some debugging code in hopes of figuring out why we're crashing. I can only see this crash happening if the opener ends up equal to contents, but that doesn't seem possible in code. BUG=34135 TEST=none Review URL: http://codereview.chromium.org/6124009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71116 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/tabs/tab_strip_model.cc | 7 ++++++- .../tabs/tab_strip_model_order_controller.cc | 21 ++++++++++++++----- .../tabs/tab_strip_model_order_controller.h | 3 ++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc index c127254aa290e..5e877c13a6153 100644 --- a/chrome/browser/tabs/tab_strip_model.cc +++ b/chrome/browser/tabs/tab_strip_model.cc @@ -209,7 +209,12 @@ TabContentsWrapper* TabStripModel::DetachTabContentsAt(int index) { DCHECK(ContainsIndex(index)); TabContentsWrapper* removed_contents = GetContentsAt(index); - int next_selected_index = order_controller_->DetermineNewSelectedIndex(index); + // TODO(sky): nuke reason and old_data when we figure out what is causing + // 34135. + volatile int reason = 0; + int next_selected_index = + order_controller_->DetermineNewSelectedIndex(index, &reason); + volatile TabContentsData old_data = *contents_data_.at(index); delete contents_data_.at(index); contents_data_.erase(contents_data_.begin() + index); if (empty()) diff --git a/chrome/browser/tabs/tab_strip_model_order_controller.cc b/chrome/browser/tabs/tab_strip_model_order_controller.cc index c7d10f45c19b7..52730ef3886b8 100644 --- a/chrome/browser/tabs/tab_strip_model_order_controller.cc +++ b/chrome/browser/tabs/tab_strip_model_order_controller.cc @@ -64,7 +64,7 @@ int TabStripModelOrderController::DetermineInsertionIndexForAppending() { } int TabStripModelOrderController::DetermineNewSelectedIndex( - int removing_index) const { + int removing_index, volatile int* reason) const { int tab_count = tabstrip_->count(); DCHECK(removing_index >= 0 && removing_index < tab_count); NavigationController* parent_opener = @@ -74,33 +74,44 @@ int TabStripModelOrderController::DetermineNewSelectedIndex( // group of the removed tab. NavigationController* removed_controller = &tabstrip_->GetTabContentsAt(removing_index)->controller(); + // The parent opener should never be the same as the controller being removed. + CHECK(parent_opener != removed_controller); int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(removed_controller, removing_index, false); - if (index != TabStripModel::kNoTab) + if (index != TabStripModel::kNoTab) { + *reason = 1; return GetValidIndex(index, removing_index); + } if (parent_opener) { // If the tab was in a group, shift selection to the next tab in the group. int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(parent_opener, removing_index, false); - if (index != TabStripModel::kNoTab) + if (index != TabStripModel::kNoTab) { + *reason = 2; return GetValidIndex(index, removing_index); + } // If we can't find a subsequent group member, just fall back to the // parent_opener itself. Note that we use "group" here since opener is // reset by select operations.. index = tabstrip_->GetIndexOfController(parent_opener); - if (index != TabStripModel::kNoTab) + if (index != TabStripModel::kNoTab) { + *reason = 3; return GetValidIndex(index, removing_index); + } } // No opener set, fall through to the default handler... int selected_index = tabstrip_->selected_index(); - if (selected_index >= (tab_count - 1)) + if (selected_index >= (tab_count - 1)) { + *reason = 4; return selected_index - 1; + } + *reason = 5; return selected_index; } diff --git a/chrome/browser/tabs/tab_strip_model_order_controller.h b/chrome/browser/tabs/tab_strip_model_order_controller.h index 5ecaa2c948b65..2f3629128fd62 100644 --- a/chrome/browser/tabs/tab_strip_model_order_controller.h +++ b/chrome/browser/tabs/tab_strip_model_order_controller.h @@ -40,7 +40,8 @@ class TabStripModelOrderController : public TabStripModelObserver { int DetermineInsertionIndexForAppending(); // Determine where to shift selection after a tab is closed. - int DetermineNewSelectedIndex(int removed_index) const; + // TODO(sky): nuke reason when we figure out what is causing 34135. + int DetermineNewSelectedIndex(int removed_index, volatile int* reason) const; // Overridden from TabStripModelObserver: virtual void TabSelectedAt(TabContentsWrapper* old_contents, -- GitLab