summaryrefslogtreecommitdiff
path: root/chromium/components/sessions/core/tab_restore_service_helper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/sessions/core/tab_restore_service_helper.cc')
-rw-r--r--chromium/components/sessions/core/tab_restore_service_helper.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/chromium/components/sessions/core/tab_restore_service_helper.cc b/chromium/components/sessions/core/tab_restore_service_helper.cc
index d7e3a9543d4..3a142b4dfcd 100644
--- a/chromium/components/sessions/core/tab_restore_service_helper.cc
+++ b/chromium/components/sessions/core/tab_restore_service_helper.cc
@@ -319,11 +319,10 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
} else {
// Restore a single tab from the window. Find the tab that matches the
// ID in the window and restore it.
- for (auto tab_i = window.tabs.begin(); tab_i != window.tabs.end();
- ++tab_i) {
+ for (size_t tab_i = 0; tab_i < window.tabs.size(); tab_i++) {
SessionID::id_type restored_tab_browser_id;
{
- const Tab& tab = **tab_i;
+ const Tab& tab = *window.tabs[tab_i];
if (tab.id != id)
continue;
@@ -331,13 +330,20 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
LiveTab* restored_tab = nullptr;
context = RestoreTab(tab, context, disposition, &restored_tab);
live_tabs.push_back(restored_tab);
- window.tabs.erase(tab_i);
+ DCHECK(ValidateWindow(window));
+ window.tabs.erase(window.tabs.begin() + tab_i);
}
// If restoring the tab leaves the window with nothing else, delete it
// as well.
if (window.tabs.empty()) {
entries_.erase(entry_iterator);
} else {
+ // Adjust |selected_tab index| to keep the window in a valid state.
+ if (static_cast<int>(tab_i) <= window.selected_tab_index) {
+ window.selected_tab_index =
+ std::max(0, window.selected_tab_index - 1);
+ }
+ DCHECK(ValidateWindow(window));
// Update the browser ID of the rest of the tabs in the window so if
// any one is restored, it goes into the same window as the tab
// being restored now.