0

[TabRestore] Update AddRestoreTab parameter name

Updates the boolean parameter restored_from_group_or_window_context to
is_restoring_group_or_window which better reflects what it is capturing.

Adds an additional comment TabRestoreServiceHelper::RestoreTab which
describes what is_restoring_group_or_window does. This comment is
similar to the one that can be found in live_tab_context.h already.

Includes other small comment updates for clarity.

Change-Id: I7a048671e3d91f315b9fc60062367d687beedc10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6409453
Reviewed-by: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Commit-Queue: Darryl James <dljames@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1440476}
This commit is contained in:
dljames
2025-03-31 12:27:50 -07:00
committed by Chromium LUCI CQ
parent 916a2da9e2
commit f5b1ac6d9a
11 changed files with 30 additions and 27 deletions

@ -75,13 +75,13 @@ class SESSIONS_EXPORT LiveTabContext {
// has been created by TabRestoreService.
// |original_session_type| indicates the type of session entry the tab
// belongs to.
// |restored_from_group_or_window_context| when true indicates if the tab we
// |is_restoring_group_or_window| when true indicates if the tab we
// are restoring is part of a window or group which is trying to restore all
// of its tabs.
virtual LiveTab* AddRestoredTab(const tab_restore::Tab& tab,
int tab_index,
bool select,
bool restored_from_group_or_window_context,
bool is_restoring_group_or_window,
tab_restore::Type original_session_type) = 0;
// Note: |tab.platform_data| may be null (e.g., if restoring from last session

@ -460,8 +460,7 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTabOrGroupFromWindow(
LiveTabContext* context,
WindowOpenDisposition disposition,
std::vector<LiveTab*>* live_tabs) {
// Restore a single tab from the window. Find the tab that matches the
// ID in the window and restore it.
// 1. Determine if `id` corresponds to a tab. If so, restore the tab.
bool found_tab_to_delete = false;
SessionID::id_type restored_tab_browser_id;
for (size_t tab_i = 0; tab_i < window.tabs.size() && !found_tab_to_delete;
@ -476,9 +475,10 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTabOrGroupFromWindow(
LiveTab* restored_tab = nullptr;
context = RestoreTab(tab, context, disposition,
sessions::tab_restore::WINDOW, &restored_tab,
/*restored_from_group_or_window_context=*/false);
/*is_restoring_group_or_window=*/false);
live_tabs->push_back(restored_tab);
// Cleanup.
std::optional<tab_groups::TabGroupId> group_id = tab.group;
window.tabs.erase(window.tabs.begin() + tab_i);
@ -503,7 +503,8 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTabOrGroupFromWindow(
found_tab_to_delete = true;
}
// Check the groups for the id if we didn't find the tab.
// 2. Determine if `id` corresponds to a group if we haven't restored a tab
// yet. If so, restore the group.
if (!found_tab_to_delete) {
for (auto& group_pair : window.tab_groups) {
auto& group = group_pair.second;
@ -514,7 +515,7 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTabOrGroupFromWindow(
restored_tab_browser_id = group->browser_id;
tab_groups::TabGroupId group_id = group->group_id;
// Restore tabs in the window that belong to `group_id`.
// Restore the grouped tabs that belong to `group_id`.
for (size_t tab_i = 0; tab_i < window.tabs.size();) {
const Tab& tab = *window.tabs[tab_i];
if (!tab.group.has_value() || tab.group.value() != group_id) {
@ -523,11 +524,11 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTabOrGroupFromWindow(
continue;
}
// Restore the tab.
// Restore the grouped tab.
LiveTab* restored_tab = nullptr;
LiveTabContext* new_context = RestoreTab(
tab, context, disposition, sessions::tab_restore::WINDOW,
&restored_tab, /*restored_from_group_or_window_context=*/true);
LiveTabContext* new_context =
RestoreTab(tab, context, disposition, sessions::tab_restore::WINDOW,
&restored_tab, /*is_restoring_group_or_window=*/true);
if (tab_i != 0) {
// CHECK that the context should be the same except for the first tab.
DCHECK_EQ(new_context, context);
@ -538,7 +539,7 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTabOrGroupFromWindow(
window.tabs.erase(window.tabs.begin() + tab_i);
}
// Clear group from mapping.
// Clean up.
window.tab_groups.erase(group_id);
if (!window.tabs.empty()) {
@ -628,7 +629,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
LiveTab* restored_tab = nullptr;
context = RestoreTab(tab, context, disposition, entry.type, &restored_tab,
/*restored_from_group_or_window_context=*/false);
/*is_restoring_group_or_window=*/false);
live_tabs.push_back(restored_tab);
context->ShowBrowserWindow();
break;
@ -747,7 +748,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
LiveTab* restored_tab = nullptr;
context =
RestoreTab(tab, context, disposition, entry.type, &restored_tab,
/*restored_from_group_or_window_context=*/false);
/*is_restoring_group_or_window=*/false);
live_tabs.push_back(restored_tab);
CHECK(ValidateGroup(group));
group.tabs.erase(group.tabs.begin() + i);
@ -1002,7 +1003,7 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTab(
WindowOpenDisposition disposition,
sessions::tab_restore::Type session_restore_type,
LiveTab** live_tab,
bool restored_from_group_or_window_context) {
bool is_restoring_group_or_window) {
LiveTab* restored_tab;
if (disposition == WindowOpenDisposition::CURRENT_TAB && context) {
restored_tab = context->ReplaceRestoredTab(tab);
@ -1052,7 +1053,7 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTab(
restored_tab = context->AddRestoredTab(
tab, tab_index,
/*select=*/disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB,
restored_from_group_or_window_context, session_restore_type);
is_restoring_group_or_window, session_restore_type);
}
client_->OnTabRestored(

@ -169,12 +169,14 @@ class SESSIONS_EXPORT TabRestoreServiceHelper
// restored tab.
// |original_session_type| indicates the type of session entry the tab
// belongs to.
// |is_restoring_group_or_window| indicates if the tab is being restored
// alongside other tabs inside the same group or window.
LiveTabContext* RestoreTab(const Tab& tab,
LiveTabContext* context,
WindowOpenDisposition disposition,
sessions::tab_restore::Type session_restore_type,
LiveTab** live_tab,
bool restored_from_group_or_window_context);
bool is_restoring_group_or_window);
// This is a helper function for RestoreEntryById(). Restores a single entry
// from the `window`. The entry to restore is denoted by `id` and can either