0

[ TabRestore ] Use TabRestoreTypes in LiveTabContext

Because of the changes in this cl: https://chromium-review.googlesource.com/c/chromium/src/+/5449978, we are able to use the TabRestoreTypes directly in LiveTabContext. This reduces the parameters we need to pass to functions such as AddRestoredTab and ReplaceRestoredTab.

We also no longer need to independently update the parameters if an addition is made to sessions::tab_restore::Tab.

Change-Id: I46594b45a2dab5e1ac8eacea7b44ea7b5552a209
Bug: 335281443
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5458785
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Commit-Queue: Darryl James <dljames@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1289448}
This commit is contained in:
dljames
2024-04-18 18:04:31 +00:00
committed by Chromium LUCI CQ
parent 3d64257eae
commit 988d7c5218
11 changed files with 88 additions and 239 deletions

@ -30,7 +30,6 @@ class Rect;
namespace sessions {
class LiveTab;
class SerializedNavigationEntry;
// An interface representing the context in which LiveTab instances exist in the
// embedder. As a concrete example, desktop Chrome has an implementation that
@ -68,36 +67,19 @@ class SESSIONS_EXPORT LiveTabContext {
virtual ui::WindowShowState GetRestoredState() const = 0;
virtual std::string GetWorkspace() const = 0;
// Note: |tab_platform_data| may be null (e.g., if restoring from last session
// Note: |tab.platform_data| may be null (e.g., if restoring from last session
// as this data is not persisted, or if the platform does not provide
// platform-specific data).
// |tab_id| is the tab's unique SessionID. Only present if a historical tab
// |tab.id| is the tab's unique SessionID. Only present if a historical tab
// has been created by TabRestoreService.
virtual LiveTab* AddRestoredTab(
const std::vector<SerializedNavigationEntry>& navigations,
int tab_index,
int selected_navigation,
const std::string& extension_app_id,
std::optional<tab_groups::TabGroupId> group,
const tab_groups::TabGroupVisualData& group_visual_data,
bool select,
bool pin,
const tab_restore::PlatformSpecificTabData* tab_platform_data,
const sessions::SerializedUserAgentOverride& user_agent_override,
const std::map<std::string, std::string>& extra_data,
const SessionID* tab_id) = 0;
virtual LiveTab* AddRestoredTab(const tab_restore::Tab& tab,
int tab_index,
bool select) = 0;
// Note: |tab_platform_data| may be null (e.g., if restoring from last session
// Note: |tab.platform_data| may be null (e.g., if restoring from last session
// as this data is not persisted, or if the platform does not provide
// platform-specific data).
virtual LiveTab* ReplaceRestoredTab(
const std::vector<SerializedNavigationEntry>& navigations,
std::optional<tab_groups::TabGroupId> group,
int selected_navigation,
const std::string& extension_app_id,
const tab_restore::PlatformSpecificTabData* tab_platform_data,
const sessions::SerializedUserAgentOverride& user_agent_override,
const std::map<std::string, std::string>& extra_data) = 0;
virtual LiveTab* ReplaceRestoredTab(const tab_restore::Tab& tab) = 0;
virtual void CloseTab() = 0;
protected:

@ -518,7 +518,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
new_group_ids;
for (size_t tab_i = 0; tab_i < window.tabs.size(); ++tab_i) {
const Tab& tab = *window.tabs[tab_i];
Tab& tab = *window.tabs[tab_i];
// Relabel group IDs to prevent duplicating groups, e.g. if the same
// window is restored twice or a tab of the same ID is restored
@ -538,15 +538,13 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
}
new_group = it->second;
tab.group = new_group;
}
LiveTab* restored_tab = context->AddRestoredTab(
tab.navigations, context->GetTabCount(),
tab.current_navigation_index, tab.extension_app_id, new_group,
tab.group_visual_data.value_or(tab_groups::TabGroupVisualData()),
static_cast<int>(tab_i) == window.selected_tab_index, tab.pinned,
tab.platform_data.get(), tab.user_agent_override, tab.extra_data,
nullptr);
tab, /*tab_index=*/context->GetTabCount(),
/*select=*/static_cast<int>(tab_i) == window.selected_tab_index);
if (restored_tab) {
client_->OnTabRestored(
tab.navigations.at(tab.current_navigation_index).virtual_url());
@ -886,23 +884,19 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTab(
LiveTab** live_tab) {
LiveTab* restored_tab;
if (disposition == WindowOpenDisposition::CURRENT_TAB && context) {
restored_tab = context->ReplaceRestoredTab(
tab.navigations, std::nullopt, tab.current_navigation_index,
tab.extension_app_id, tab.platform_data.get(), tab.user_agent_override,
tab.extra_data);
restored_tab = context->ReplaceRestoredTab(tab);
} else {
// We only respect the tab's original browser if there's no disposition.
if (disposition == WindowOpenDisposition::UNKNOWN) {
if (tab.browser_id) {
context = client_->FindLiveTabContextWithID(
SessionID::FromSerializedValue(tab.browser_id));
}
if (disposition == WindowOpenDisposition::UNKNOWN && tab.browser_id) {
context = client_->FindLiveTabContextWithID(
SessionID::FromSerializedValue(tab.browser_id));
}
// Restore a grouped tab into its original group, even if the group has
// since been moved to a different context. If the original group doesn't
// exist any more, fall back to using the tab's original browser.
if (tab.group.has_value()) {
// TODO: This needs to look at the saved id.
LiveTabContext* group_context =
client_->FindLiveTabContextWithGroup(tab.group.value());
if (group_context) {
@ -935,12 +929,8 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTab(
}
restored_tab = context->AddRestoredTab(
tab.navigations, tab_index, tab.current_navigation_index,
tab.extension_app_id, tab.group,
tab.group_visual_data.value_or(tab_groups::TabGroupVisualData()),
disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB, tab.pinned,
tab.platform_data.get(), tab.user_agent_override, tab.extra_data,
&tab.id);
tab, tab_index,
/*select=*/disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB);
}
client_->OnTabRestored(