Index: chrome/browser/tabs/tab_strip_model_order_controller.cc |
diff --git a/chrome/browser/tabs/tab_strip_model_order_controller.cc b/chrome/browser/tabs/tab_strip_model_order_controller.cc |
index c7d10f45c19b7cd26d30a70553ecfeaf199aaec7..52730ef3886b8f48e56c2d938b3e1a6fc292e7c5 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; |
} |