[ TabRestore ] Move restore types out of TabRestoreService
Moves the tab restore structs Entry, Tab, Group, and Window out of the TabRestoreService and into its own file. The goal of this CL is to decouple LiveTabContext from TabRestoreService, which includes LiveTabContext. Doing this will allow us to pass the Tab, Group, and Window types as parameters to functions such as LiveTabContext::AddRestoredTab instead of passing all the fields of the objects individually. Change-Id: I2f30bb25f934806112333d67ed3586dade09fe46 Bug: 334170377 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5449978 Commit-Queue: Darryl James <dljames@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: Gauthier Ambard <gambard@chromium.org> Cr-Commit-Position: refs/heads/main@{#1288110}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
b9179c71e6
commit
71303418b7
chrome/browser
android
app_controller_mac.hbrowsing_data
extensions
api
sessions
sessions
session_restore_browsertest.cctab_restore_browsertest.cctab_restore_service_browsertest.cctab_restore_service_unittest.cc
ui
android
tab_model
cocoa
tabs
views
web_applications
webui
win
components/sessions
docs/ui/learn/bestpractices
ios/chrome/browser
external_files
sessions
tabs_search
ui
@ -120,7 +120,6 @@ source_set("shared") {
|
||||
"core/session_service_commands.h",
|
||||
"core/session_types.cc",
|
||||
"core/session_types.h",
|
||||
"core/tab_restore_service.cc",
|
||||
"core/tab_restore_service.h",
|
||||
"core/tab_restore_service_client.cc",
|
||||
"core/tab_restore_service_client.h",
|
||||
@ -129,6 +128,8 @@ source_set("shared") {
|
||||
"core/tab_restore_service_impl.cc",
|
||||
"core/tab_restore_service_impl.h",
|
||||
"core/tab_restore_service_observer.h",
|
||||
"core/tab_restore_types.cc",
|
||||
"core/tab_restore_types.h",
|
||||
]
|
||||
|
||||
configs += [ ":implementation" ]
|
||||
|
@ -59,7 +59,7 @@ int ContentLiveTab::GetEntryCount() {
|
||||
return navigation_controller().GetEntryCount();
|
||||
}
|
||||
|
||||
std::unique_ptr<sessions::PlatformSpecificTabData>
|
||||
std::unique_ptr<tab_restore::PlatformSpecificTabData>
|
||||
ContentLiveTab::GetPlatformSpecificTabData() {
|
||||
return std::make_unique<sessions::ContentPlatformSpecificTabData>(
|
||||
web_contents());
|
||||
|
@ -42,8 +42,8 @@ class SESSIONS_EXPORT ContentLiveTab
|
||||
sessions::SerializedNavigationEntry GetEntryAtIndex(int index) override;
|
||||
sessions::SerializedNavigationEntry GetPendingEntry() override;
|
||||
int GetEntryCount() override;
|
||||
std::unique_ptr<PlatformSpecificTabData> GetPlatformSpecificTabData()
|
||||
override;
|
||||
std::unique_ptr<tab_restore::PlatformSpecificTabData>
|
||||
GetPlatformSpecificTabData() override;
|
||||
SerializedUserAgentOverride GetUserAgentOverride() override;
|
||||
|
||||
content::WebContents* web_contents() { return web_contents_; }
|
||||
|
@ -17,11 +17,11 @@ class WebContents;
|
||||
namespace sessions {
|
||||
|
||||
// A //content-specific subclass of PlatformSpecificTabData that is used to
|
||||
// associate TabRestoreService::Tab instances with the
|
||||
// associate tab_restore::Tab instances with the
|
||||
// content::SessionStorageNamespace of the WebContents from which they were
|
||||
// created.
|
||||
class SESSIONS_EXPORT ContentPlatformSpecificTabData
|
||||
: public PlatformSpecificTabData {
|
||||
: public tab_restore::PlatformSpecificTabData {
|
||||
public:
|
||||
explicit ContentPlatformSpecificTabData(content::WebContents* web_contents);
|
||||
ContentPlatformSpecificTabData();
|
||||
|
@ -8,7 +8,8 @@ namespace sessions {
|
||||
|
||||
LiveTab::~LiveTab() {}
|
||||
|
||||
std::unique_ptr<PlatformSpecificTabData> LiveTab::GetPlatformSpecificTabData() {
|
||||
std::unique_ptr<tab_restore::PlatformSpecificTabData>
|
||||
LiveTab::GetPlatformSpecificTabData() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,10 @@ class SESSIONS_EXPORT LiveTab {
|
||||
virtual int GetEntryCount() = 0;
|
||||
|
||||
// Returns any platform-specific data that should be associated with the
|
||||
// TabRestoreService::Tab corresponding to this instance. The default
|
||||
// tab_restore::Tab corresponding to this instance. The default
|
||||
// implementation returns null.
|
||||
virtual std::unique_ptr<PlatformSpecificTabData> GetPlatformSpecificTabData();
|
||||
virtual std::unique_ptr<tab_restore::PlatformSpecificTabData>
|
||||
GetPlatformSpecificTabData();
|
||||
|
||||
// Returns the user agent override, if any.
|
||||
virtual SerializedUserAgentOverride GetUserAgentOverride() = 0;
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "components/sessions/core/session_id.h"
|
||||
#include "components/sessions/core/session_types.h"
|
||||
#include "components/sessions/core/sessions_export.h"
|
||||
#include "components/sessions/core/tab_restore_types.h"
|
||||
#include "components/tab_groups/tab_group_id.h"
|
||||
#include "components/tab_groups/tab_group_visual_data.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
@ -30,7 +31,6 @@ namespace sessions {
|
||||
|
||||
class LiveTab;
|
||||
class SerializedNavigationEntry;
|
||||
class PlatformSpecificTabData;
|
||||
|
||||
// An interface representing the context in which LiveTab instances exist in the
|
||||
// embedder. As a concrete example, desktop Chrome has an implementation that
|
||||
@ -82,7 +82,7 @@ class SESSIONS_EXPORT LiveTabContext {
|
||||
const tab_groups::TabGroupVisualData& group_visual_data,
|
||||
bool select,
|
||||
bool pin,
|
||||
const PlatformSpecificTabData* tab_platform_data,
|
||||
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;
|
||||
@ -95,7 +95,7 @@ class SESSIONS_EXPORT LiveTabContext {
|
||||
std::optional<tab_groups::TabGroupId> group,
|
||||
int selected_navigation,
|
||||
const std::string& extension_app_id,
|
||||
const PlatformSpecificTabData* tab_platform_data,
|
||||
const tab_restore::PlatformSpecificTabData* tab_platform_data,
|
||||
const sessions::SerializedUserAgentOverride& user_agent_override,
|
||||
const std::map<std::string, std::string>& extra_data) = 0;
|
||||
virtual void CloseTab() = 0;
|
||||
|
@ -1,66 +0,0 @@
|
||||
// Copyright 2012 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "components/sessions/core/tab_restore_service.h"
|
||||
|
||||
#include "base/trace_event/memory_usage_estimator.h"
|
||||
#include "components/tab_groups/tab_group_id.h"
|
||||
#include "components/tab_groups/tab_group_visual_data.h"
|
||||
|
||||
namespace sessions {
|
||||
|
||||
// TimeFactory-----------------------------------------------------------------
|
||||
|
||||
TabRestoreService::TimeFactory::~TimeFactory() {}
|
||||
|
||||
// Entry ----------------------------------------------------------------------
|
||||
|
||||
TabRestoreService::Entry::~Entry() = default;
|
||||
|
||||
TabRestoreService::Entry::Entry(Type type)
|
||||
: id(SessionID::NewUnique()),
|
||||
original_id(SessionID::InvalidValue()),
|
||||
type(type) {}
|
||||
|
||||
size_t TabRestoreService::Entry::EstimateMemoryUsage() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
TabRestoreService::Tab::Tab() : Entry(TAB) {}
|
||||
TabRestoreService::Tab::~Tab() = default;
|
||||
|
||||
size_t TabRestoreService::Tab::EstimateMemoryUsage() const {
|
||||
using base::trace_event::EstimateMemoryUsage;
|
||||
return EstimateMemoryUsage(navigations) +
|
||||
EstimateMemoryUsage(extension_app_id) +
|
||||
user_agent_override.EstimateMemoryUsage();
|
||||
}
|
||||
|
||||
TabRestoreService::Window::Window() : Entry(WINDOW) {}
|
||||
TabRestoreService::Window::~Window() = default;
|
||||
|
||||
size_t TabRestoreService::Window::EstimateMemoryUsage() const {
|
||||
using base::trace_event::EstimateMemoryUsage;
|
||||
return EstimateMemoryUsage(tabs) + EstimateMemoryUsage(app_name);
|
||||
}
|
||||
|
||||
TabRestoreService::Group::Group() : Entry(GROUP) {}
|
||||
TabRestoreService::Group::~Group() = default;
|
||||
|
||||
size_t TabRestoreService::Group::EstimateMemoryUsage() const {
|
||||
using base::trace_event::EstimateMemoryUsage;
|
||||
return EstimateMemoryUsage(tabs) + EstimateMemoryUsage(visual_data.title());
|
||||
}
|
||||
|
||||
// TabRestoreService ----------------------------------------------------------
|
||||
|
||||
TabRestoreService::~TabRestoreService() {
|
||||
}
|
||||
|
||||
// PlatformSpecificTabData
|
||||
// ------------------------------------------------------
|
||||
|
||||
PlatformSpecificTabData::~PlatformSpecificTabData() {}
|
||||
|
||||
} // namespace sessions
|
@ -22,6 +22,7 @@
|
||||
#include "components/sessions/core/session_id.h"
|
||||
#include "components/sessions/core/session_types.h"
|
||||
#include "components/sessions/core/sessions_export.h"
|
||||
#include "components/sessions/core/tab_restore_types.h"
|
||||
#include "components/tab_groups/tab_group_id.h"
|
||||
#include "components/tab_groups/tab_group_visual_data.h"
|
||||
#include "ui/base/ui_base_types.h"
|
||||
@ -31,7 +32,6 @@
|
||||
namespace sessions {
|
||||
|
||||
class LiveTab;
|
||||
class PlatformSpecificTabData;
|
||||
class TabRestoreServiceObserver;
|
||||
|
||||
// TabRestoreService is responsible for maintaining the most recently closed
|
||||
@ -49,180 +49,11 @@ class TabRestoreServiceObserver;
|
||||
// add an observer.
|
||||
class SESSIONS_EXPORT TabRestoreService : public KeyedService {
|
||||
public:
|
||||
struct Tab;
|
||||
struct Window;
|
||||
struct Group;
|
||||
|
||||
// Interface used to allow the test to provide a custom time.
|
||||
class SESSIONS_EXPORT TimeFactory {
|
||||
public:
|
||||
virtual ~TimeFactory();
|
||||
virtual base::Time TimeNow() = 0;
|
||||
};
|
||||
|
||||
// The type of entry.
|
||||
enum Type {
|
||||
TAB,
|
||||
WINDOW,
|
||||
GROUP,
|
||||
};
|
||||
|
||||
struct SESSIONS_EXPORT Entry {
|
||||
Entry(const Entry&) = delete;
|
||||
Entry& operator=(const Entry&) = delete;
|
||||
|
||||
virtual ~Entry();
|
||||
|
||||
// Unique id for this entry. The id is guaranteed to be unique for a
|
||||
// session.
|
||||
SessionID id;
|
||||
|
||||
// The original id of the entry when it was saved.
|
||||
SessionID original_id;
|
||||
|
||||
// The type of the entry.
|
||||
const Type type;
|
||||
|
||||
// The time when the window, tab, or group was closed. Not always set - can
|
||||
// be nullptr or 0 in cases where a timestamp isn't available at entry
|
||||
// creation.
|
||||
base::Time timestamp;
|
||||
|
||||
// Used for storing arbitrary key/value pairs.
|
||||
std::map<std::string, std::string> extra_data;
|
||||
|
||||
// Estimates memory usage. By default returns 0.
|
||||
virtual size_t EstimateMemoryUsage() const;
|
||||
|
||||
protected:
|
||||
explicit Entry(Type type);
|
||||
};
|
||||
|
||||
// Represents a previously open tab.
|
||||
// If you add a new field that can allocate memory, please also add
|
||||
// it to the EstimatedMemoryUsage() implementation.
|
||||
struct SESSIONS_EXPORT Tab : public Entry {
|
||||
Tab();
|
||||
~Tab() override;
|
||||
|
||||
// Entry:
|
||||
size_t EstimateMemoryUsage() const override;
|
||||
|
||||
// Since the current_navigation_index can be larger than the index for
|
||||
// number of navigations in the current sessions (chrome://newtab is not
|
||||
// stored), we must perform bounds checking. Returns a normalized
|
||||
// bounds-checked navigation_index.
|
||||
int normalized_navigation_index() const {
|
||||
return std::max(0, std::min(current_navigation_index,
|
||||
static_cast<int>(navigations.size() - 1)));
|
||||
}
|
||||
|
||||
// The navigations.
|
||||
std::vector<SerializedNavigationEntry> navigations;
|
||||
|
||||
// Index of the selected navigation in navigations.
|
||||
int current_navigation_index = -1;
|
||||
|
||||
// The ID of the browser to which this tab belonged, so it can be restored
|
||||
// there. May be 0 (an invalid SessionID) when restoring an entire session.
|
||||
SessionID::id_type browser_id = 0;
|
||||
|
||||
// Index within the tab strip. May be -1 for an unknown index.
|
||||
int tabstrip_index = -1;
|
||||
|
||||
// True if the tab was pinned.
|
||||
bool pinned = false;
|
||||
|
||||
// If non-empty gives the id of the extension for the tab.
|
||||
std::string extension_app_id;
|
||||
|
||||
// The associated client data.
|
||||
std::unique_ptr<PlatformSpecificTabData> platform_data;
|
||||
|
||||
// The user agent override used for the tab's navigations (if applicable).
|
||||
SerializedUserAgentOverride user_agent_override;
|
||||
|
||||
// The group the tab belonged to, if any.
|
||||
std::optional<tab_groups::TabGroupId> group;
|
||||
|
||||
// The saved group id the tab belong to, if any.
|
||||
std::optional<base::Uuid> saved_group_id = std::nullopt;
|
||||
|
||||
// The group metadata for the tab, if any.
|
||||
std::optional<tab_groups::TabGroupVisualData> group_visual_data;
|
||||
};
|
||||
|
||||
// Represents a previously open window.
|
||||
// If you add a new field that can allocate memory, please also add
|
||||
// it to the EstimatedMemoryUsage() implementation.
|
||||
struct SESSIONS_EXPORT Window : public Entry {
|
||||
Window();
|
||||
~Window() override;
|
||||
|
||||
// Entry:
|
||||
size_t EstimateMemoryUsage() const override;
|
||||
|
||||
// Type of window.
|
||||
SessionWindow::WindowType type;
|
||||
|
||||
// TODO(crbug.com/333425400): `tabs`, `groups`, and `tab_groups` contain
|
||||
// duplicated data. To prevent duplication of data consider changing `tabs`
|
||||
// to std::vector<std::unique_ptr<Entries>> so all data can be stored
|
||||
// together in one object. This should prevent data duplication.
|
||||
// The tabs that comprised the window, in order.
|
||||
std::vector<std::unique_ptr<Tab>> tabs;
|
||||
|
||||
// Tab groups in this window including their tabs.
|
||||
std::map<tab_groups::TabGroupId, std::unique_ptr<Group>> groups;
|
||||
|
||||
// Tab group data.
|
||||
std::map<tab_groups::TabGroupId, tab_groups::TabGroupVisualData> tab_groups;
|
||||
|
||||
// Index of the selected tab.
|
||||
int selected_tab_index = -1;
|
||||
|
||||
// If an application window, the name of the app.
|
||||
std::string app_name;
|
||||
|
||||
// User-set title of the window, if there is one.
|
||||
std::string user_title;
|
||||
|
||||
// Where and how the window is displayed.
|
||||
gfx::Rect bounds;
|
||||
ui::WindowShowState show_state;
|
||||
std::string workspace;
|
||||
};
|
||||
|
||||
// Represents a previously open group.
|
||||
// If you add a new field that can allocate memory, please also add
|
||||
// it to the EstimatedMemoryUsage() implementation.
|
||||
struct SESSIONS_EXPORT Group : public Entry {
|
||||
Group();
|
||||
~Group() override;
|
||||
|
||||
// Entry:
|
||||
size_t EstimateMemoryUsage() const override;
|
||||
|
||||
// The tabs that comprised the group, in order.
|
||||
std::vector<std::unique_ptr<Tab>> tabs;
|
||||
|
||||
// Group metadata.
|
||||
tab_groups::TabGroupId group_id = tab_groups::TabGroupId::CreateEmpty();
|
||||
tab_groups::TabGroupVisualData visual_data;
|
||||
|
||||
// The saved group id of this group, if any.
|
||||
std::optional<base::Uuid> saved_group_id = std::nullopt;
|
||||
|
||||
// The ID of the browser to which this group belonged, so it can be restored
|
||||
// there.
|
||||
SessionID::id_type browser_id = 0;
|
||||
};
|
||||
|
||||
typedef std::list<std::unique_ptr<Entry>> Entries;
|
||||
typedef std::list<std::unique_ptr<tab_restore::Entry>> Entries;
|
||||
typedef base::RepeatingCallback<bool(const SerializedNavigationEntry& entry)>
|
||||
DeletionPredicate;
|
||||
|
||||
~TabRestoreService() override;
|
||||
~TabRestoreService() override = default;
|
||||
|
||||
// Adds/removes an observer. TabRestoreService does not take ownership of
|
||||
// the observer.
|
||||
@ -303,13 +134,6 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService {
|
||||
virtual bool IsRestoring() const = 0;
|
||||
};
|
||||
|
||||
// A class that is used to associate platform-specific data with
|
||||
// TabRestoreService::Tab. See LiveTab::GetPlatformSpecificTabData().
|
||||
class SESSIONS_EXPORT PlatformSpecificTabData {
|
||||
public:
|
||||
virtual ~PlatformSpecificTabData();
|
||||
};
|
||||
|
||||
} // namespace sessions
|
||||
|
||||
#endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_
|
||||
|
@ -38,9 +38,9 @@
|
||||
#include "components/sessions/core/tab_restore_service.h"
|
||||
#include "components/sessions/core/tab_restore_service_client.h"
|
||||
#include "components/sessions/core/tab_restore_service_observer.h"
|
||||
#include "components/sessions/core/tab_restore_types.h"
|
||||
#include "components/tab_groups/tab_group_id.h"
|
||||
#include "components/tab_groups/tab_group_visual_data.h"
|
||||
|
||||
namespace sessions {
|
||||
namespace {
|
||||
|
||||
@ -126,7 +126,7 @@ void TabRestoreServiceHelper::Observer::OnAddEntry() {}
|
||||
TabRestoreServiceHelper::TabRestoreServiceHelper(
|
||||
TabRestoreService* tab_restore_service,
|
||||
TabRestoreServiceClient* client,
|
||||
TabRestoreService::TimeFactory* time_factory)
|
||||
tab_restore::TimeFactory* time_factory)
|
||||
: tab_restore_service_(tab_restore_service),
|
||||
observer_(nullptr),
|
||||
client_(client),
|
||||
@ -249,7 +249,7 @@ void TabRestoreServiceHelper::BrowserClosed(LiveTabContext* context) {
|
||||
closing_contexts_.erase(context);
|
||||
}
|
||||
|
||||
std::unique_ptr<TabRestoreService::Group>
|
||||
std::unique_ptr<tab_restore::Group>
|
||||
TabRestoreServiceHelper::CreateHistoricalGroupImpl(
|
||||
LiveTabContext* context,
|
||||
const tab_groups::TabGroupId& id) {
|
||||
@ -394,14 +394,14 @@ void TabRestoreServiceHelper::DeleteNavigationEntries(
|
||||
Entries new_entries;
|
||||
for (std::unique_ptr<Entry>& entry : entries_) {
|
||||
switch (entry->type) {
|
||||
case TabRestoreService::TAB: {
|
||||
case tab_restore::Type::TAB: {
|
||||
Tab* tab = static_cast<Tab*>(entry.get());
|
||||
if (!DeleteFromTab(predicate, tab)) {
|
||||
new_entries.push_back(std::move(entry));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TabRestoreService::WINDOW: {
|
||||
case tab_restore::Type::WINDOW: {
|
||||
Window* window = static_cast<Window*>(entry.get());
|
||||
if (!DeleteFromWindow(predicate, window)) {
|
||||
// If only a single tab is left, just keep the tab.
|
||||
@ -413,7 +413,7 @@ void TabRestoreServiceHelper::DeleteNavigationEntries(
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TabRestoreService::GROUP: {
|
||||
case tab_restore::Type::GROUP: {
|
||||
Group* group = static_cast<Group*>(entry.get());
|
||||
if (!DeleteFromGroup(predicate, group)) {
|
||||
new_entries.push_back(std::move(entry));
|
||||
@ -478,7 +478,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
|
||||
// new browser into which we restore the tabs.
|
||||
std::vector<LiveTab*> live_tabs;
|
||||
switch (entry.type) {
|
||||
case TabRestoreService::TAB: {
|
||||
case tab_restore::Type::TAB: {
|
||||
auto& tab = static_cast<const Tab&>(entry);
|
||||
|
||||
if (tab.timestamp != base::Time() &&
|
||||
@ -493,7 +493,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
|
||||
context->ShowBrowserWindow();
|
||||
break;
|
||||
}
|
||||
case TabRestoreService::WINDOW: {
|
||||
case tab_restore::Type::WINDOW: {
|
||||
LiveTabContext* current_context = context;
|
||||
auto& window = static_cast<Window&>(entry);
|
||||
|
||||
@ -624,7 +624,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TabRestoreService::GROUP: {
|
||||
case tab_restore::Type::GROUP: {
|
||||
auto& group = static_cast<Group&>(entry);
|
||||
|
||||
if (group.timestamp != base::Time() &&
|
||||
@ -749,14 +749,14 @@ TabRestoreServiceHelper::GetEntryIteratorById(SessionID id) {
|
||||
|
||||
// For Window and Group entries, see if the ID matches a tab. If so, report
|
||||
// the window or group as the Entry.
|
||||
if ((*i)->type == TabRestoreService::WINDOW) {
|
||||
if ((*i)->type == tab_restore::Type::WINDOW) {
|
||||
const auto& window = static_cast<const Window&>(**i);
|
||||
for (const auto& tab : window.tabs) {
|
||||
if (tab->id == id || tab->original_id == id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else if ((*i)->type == TabRestoreService::GROUP) {
|
||||
} else if ((*i)->type == tab_restore::Type::GROUP) {
|
||||
const auto& group = static_cast<const Group&>(**i);
|
||||
for (const auto& tab : group.tabs) {
|
||||
if (tab->id == id || tab->original_id == id) {
|
||||
@ -793,13 +793,13 @@ bool TabRestoreServiceHelper::OnMemoryDump(
|
||||
for (const auto& entry : entries_) {
|
||||
const char* type_string = "";
|
||||
switch (entry->type) {
|
||||
case TabRestoreService::WINDOW:
|
||||
case tab_restore::Type::WINDOW:
|
||||
type_string = "window";
|
||||
break;
|
||||
case TabRestoreService::TAB:
|
||||
case tab_restore::Type::TAB:
|
||||
type_string = "tab";
|
||||
break;
|
||||
case TabRestoreService::GROUP:
|
||||
case tab_restore::Type::GROUP:
|
||||
type_string = "group";
|
||||
break;
|
||||
}
|
||||
@ -828,11 +828,11 @@ bool TabRestoreServiceHelper::OnMemoryDump(
|
||||
// static
|
||||
bool TabRestoreServiceHelper::ValidateEntry(const Entry& entry) {
|
||||
switch (entry.type) {
|
||||
case TabRestoreService::TAB:
|
||||
case tab_restore::Type::TAB:
|
||||
return ValidateTab(static_cast<const Tab&>(entry));
|
||||
case TabRestoreService::WINDOW:
|
||||
case tab_restore::Type::WINDOW:
|
||||
return ValidateWindow(static_cast<const Window&>(entry));
|
||||
case TabRestoreService::GROUP:
|
||||
case tab_restore::Type::GROUP:
|
||||
return ValidateGroup(static_cast<const Group&>(entry));
|
||||
}
|
||||
NOTREACHED();
|
||||
@ -1017,11 +1017,11 @@ bool TabRestoreServiceHelper::FilterEntry(const Entry& entry) {
|
||||
}
|
||||
|
||||
switch (entry.type) {
|
||||
case TabRestoreService::TAB:
|
||||
case tab_restore::Type::TAB:
|
||||
return IsTabInteresting(static_cast<const Tab&>(entry));
|
||||
case TabRestoreService::WINDOW:
|
||||
case tab_restore::Type::WINDOW:
|
||||
return IsWindowInteresting(static_cast<const Window&>(entry));
|
||||
case TabRestoreService::GROUP:
|
||||
case tab_restore::Type::GROUP:
|
||||
return IsGroupInteresting(static_cast<const Group&>(entry));
|
||||
}
|
||||
NOTREACHED();
|
||||
@ -1031,7 +1031,7 @@ bool TabRestoreServiceHelper::FilterEntry(const Entry& entry) {
|
||||
void TabRestoreServiceHelper::UpdateTabBrowserIDs(SessionID::id_type old_id,
|
||||
SessionID new_id) {
|
||||
for (const auto& entry : entries_) {
|
||||
if (entry->type == TabRestoreService::TAB) {
|
||||
if (entry->type == tab_restore::Type::TAB) {
|
||||
auto& tab = static_cast<Tab&>(*entry);
|
||||
if (tab.browser_id == old_id) {
|
||||
tab.browser_id = new_id.id();
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "components/sessions/core/session_types.h"
|
||||
#include "components/sessions/core/sessions_export.h"
|
||||
#include "components/sessions/core/tab_restore_service.h"
|
||||
#include "components/sessions/core/tab_restore_types.h"
|
||||
|
||||
namespace sessions {
|
||||
|
||||
@ -34,11 +35,11 @@ class SESSIONS_EXPORT TabRestoreServiceHelper
|
||||
public:
|
||||
typedef TabRestoreService::DeletionPredicate DeletionPredicate;
|
||||
typedef TabRestoreService::Entries Entries;
|
||||
typedef TabRestoreService::Entry Entry;
|
||||
typedef TabRestoreService::Tab Tab;
|
||||
typedef TabRestoreService::TimeFactory TimeFactory;
|
||||
typedef TabRestoreService::Window Window;
|
||||
typedef TabRestoreService::Group Group;
|
||||
typedef tab_restore::Entry Entry;
|
||||
typedef tab_restore::Tab Tab;
|
||||
typedef tab_restore::TimeFactory TimeFactory;
|
||||
typedef tab_restore::Window Window;
|
||||
typedef tab_restore::Group Group;
|
||||
|
||||
// Provides a way for the client to add behavior to the tab restore service
|
||||
// helper (e.g. implementing tabs persistence).
|
||||
|
@ -129,24 +129,24 @@ const size_t kMaxEntries = TabRestoreServiceHelper::kMaxEntries;
|
||||
|
||||
void RemoveEntryByID(
|
||||
SessionID id,
|
||||
std::vector<std::unique_ptr<TabRestoreService::Entry>>* entries) {
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>>* entries) {
|
||||
// If the id is invalid, return.
|
||||
if (id == SessionID::InvalidValue()) {
|
||||
return;
|
||||
} // Look for the entry in the top-level collection.
|
||||
for (auto entry_it = entries->begin(); entry_it != entries->end();
|
||||
++entry_it) {
|
||||
TabRestoreService::Entry& entry = **entry_it;
|
||||
tab_restore::Entry& entry = **entry_it;
|
||||
// Erase it if it's our target.
|
||||
if (entry.id == id || entry.original_id == id) {
|
||||
entries->erase(entry_it);
|
||||
return;
|
||||
}
|
||||
// If this entry is a window, look through its tabs.
|
||||
if (entry.type == TabRestoreService::WINDOW) {
|
||||
auto& window = static_cast<TabRestoreService::Window&>(entry);
|
||||
if (entry.type == tab_restore::Type::WINDOW) {
|
||||
auto& window = static_cast<tab_restore::Window&>(entry);
|
||||
for (auto it = window.tabs.begin(); it != window.tabs.end(); ++it) {
|
||||
const TabRestoreService::Tab& tab = **it;
|
||||
const tab_restore::Tab& tab = **it;
|
||||
// Erase it if it's our target.
|
||||
if (tab.id == id) {
|
||||
window.tabs.erase(it);
|
||||
@ -155,10 +155,10 @@ void RemoveEntryByID(
|
||||
}
|
||||
}
|
||||
// If this entry is a group, look through its tabs.
|
||||
if (entry.type == TabRestoreService::GROUP) {
|
||||
auto& group = static_cast<TabRestoreService::Group&>(entry);
|
||||
if (entry.type == tab_restore::Type::GROUP) {
|
||||
auto& group = static_cast<tab_restore::Group&>(entry);
|
||||
for (auto it = group.tabs.begin(); it != group.tabs.end(); ++it) {
|
||||
const TabRestoreService::Tab& tab = **it;
|
||||
const tab_restore::Tab& tab = **it;
|
||||
// Erase it if it's our target.
|
||||
if (tab.id == id) {
|
||||
group.tabs.erase(it);
|
||||
@ -281,10 +281,10 @@ struct WindowCommandFields {
|
||||
int type = 0;
|
||||
};
|
||||
|
||||
std::unique_ptr<sessions::TabRestoreService::Window>
|
||||
CreateWindowEntryFromCommand(const SessionCommand* command,
|
||||
SessionID* window_id,
|
||||
int32_t* num_tabs) {
|
||||
std::unique_ptr<sessions::tab_restore::Window> CreateWindowEntryFromCommand(
|
||||
const SessionCommand* command,
|
||||
SessionID* window_id,
|
||||
int32_t* num_tabs) {
|
||||
WindowCommandFields fields;
|
||||
ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT;
|
||||
auto type = sessions::SessionWindow::TYPE_NORMAL;
|
||||
@ -375,8 +375,8 @@ CreateWindowEntryFromCommand(const SessionCommand* command,
|
||||
}
|
||||
|
||||
// Create the Window entry.
|
||||
std::unique_ptr<sessions::TabRestoreService::Window> window =
|
||||
std::make_unique<sessions::TabRestoreService::Window>();
|
||||
std::unique_ptr<sessions::tab_restore::Window> window =
|
||||
std::make_unique<sessions::tab_restore::Window>();
|
||||
window->type = type;
|
||||
window->selected_tab_index = fields.selected_tab_index;
|
||||
window->timestamp = base::Time::FromDeltaSinceWindowsEpoch(
|
||||
@ -410,7 +410,7 @@ struct GroupCommandFields {
|
||||
uint32_t color = 0;
|
||||
};
|
||||
|
||||
std::unique_ptr<sessions::TabRestoreService::Group> CreateGroupEntryFromCommand(
|
||||
std::unique_ptr<sessions::tab_restore::Group> CreateGroupEntryFromCommand(
|
||||
const SessionCommand* command,
|
||||
SessionID* session_id,
|
||||
int32_t* num_tabs) {
|
||||
@ -436,8 +436,8 @@ std::unique_ptr<sessions::TabRestoreService::Group> CreateGroupEntryFromCommand(
|
||||
GroupCommandFields fields = parsed_fields;
|
||||
|
||||
// Create the Group entry.
|
||||
std::unique_ptr<sessions::TabRestoreService::Group> group =
|
||||
std::make_unique<sessions::TabRestoreService::Group>();
|
||||
std::unique_ptr<sessions::tab_restore::Group> group =
|
||||
std::make_unique<sessions::tab_restore::Group>();
|
||||
group->group_id =
|
||||
tab_groups::TabGroupId::FromRawToken(fields.tab_group_token.value());
|
||||
group->browser_id = fields.browser_id;
|
||||
@ -495,22 +495,23 @@ class TabRestoreServiceImpl::PersistenceDelegate
|
||||
// Creates and add entries to |entries| for each of the windows in |windows|.
|
||||
static void CreateEntriesFromWindows(
|
||||
std::vector<std::unique_ptr<sessions::SessionWindow>>* windows,
|
||||
std::vector<std::unique_ptr<Entry>>* entries);
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>>* entries);
|
||||
|
||||
void Shutdown();
|
||||
|
||||
// Schedules the commands for a window close.
|
||||
void ScheduleCommandsForWindow(const Window& window);
|
||||
void ScheduleCommandsForWindow(const tab_restore::Window& window);
|
||||
|
||||
// Schedules the commands for a group close.
|
||||
void ScheduleCommandsForGroup(const Group& group);
|
||||
void ScheduleCommandsForGroup(const tab_restore::Group& group);
|
||||
|
||||
// Schedules the commands for a list of tabs (from a window or group).
|
||||
void ScheduleCommandsForTabs(const std::vector<std::unique_ptr<Tab>>& tabs);
|
||||
void ScheduleCommandsForTabs(
|
||||
const std::vector<std::unique_ptr<tab_restore::Tab>>& tabs);
|
||||
|
||||
// Schedules the commands for a tab close. |selected_index| gives the index of
|
||||
// the selected navigation.
|
||||
void ScheduleCommandsForTab(const Tab& tab, int selected_index);
|
||||
void ScheduleCommandsForTab(const tab_restore::Tab& tab, int selected_index);
|
||||
|
||||
void ScheduleRestoredEntryCommandsForTest(SessionID id);
|
||||
|
||||
@ -547,7 +548,7 @@ class TabRestoreServiceImpl::PersistenceDelegate
|
||||
// |tab.current_navigation_index| unless the entry at
|
||||
// |tab.current_navigation_index| shouldn't be persisted. Returns -1 if no
|
||||
// valid navigation to persist.
|
||||
int GetSelectedNavigationIndexToPersist(const Tab& tab);
|
||||
int GetSelectedNavigationIndexToPersist(const tab_restore::Tab& tab);
|
||||
|
||||
// Invoked when we've loaded the session commands that identify the previously
|
||||
// closed tabs. This creates entries, adds them to staging_entries_, and
|
||||
@ -559,12 +560,12 @@ class TabRestoreServiceImpl::PersistenceDelegate
|
||||
// Populates |loaded_entries| with Entries from |commands|.
|
||||
void CreateEntriesFromCommands(
|
||||
const std::vector<std::unique_ptr<SessionCommand>>& commands,
|
||||
std::vector<std::unique_ptr<Entry>>* loaded_entries);
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>>* loaded_entries);
|
||||
|
||||
// Validates all entries in |entries|, deleting any with no navigations. This
|
||||
// also deletes any entries beyond the max number of entries we can hold.
|
||||
static void ValidateAndDeleteEmptyEntries(
|
||||
std::vector<std::unique_ptr<Entry>>* entries);
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>>* entries);
|
||||
|
||||
// Callback from CommandStorageManager when we've received the windows from
|
||||
// the previous session. This creates and add entries to |staging_entries_|
|
||||
@ -577,7 +578,7 @@ class TabRestoreServiceImpl::PersistenceDelegate
|
||||
// Converts a SessionWindow into a Window, returning true on success. We use 0
|
||||
// as the timestamp here since we do not know when the window/tab was closed.
|
||||
static bool ConvertSessionWindowToWindow(SessionWindow* session_window,
|
||||
Window* window);
|
||||
tab_restore::Window* window);
|
||||
|
||||
// Invoked when previous tabs or session is loaded. If both have finished
|
||||
// loading the entries in |staging_entries_| are added to entries and
|
||||
@ -604,7 +605,7 @@ class TabRestoreServiceImpl::PersistenceDelegate
|
||||
// Results from previously closed tabs/sessions is first added here. When the
|
||||
// results from both us and the session restore service have finished loading
|
||||
// LoadStateChanged is invoked, which adds these entries to entries_.
|
||||
std::vector<std::unique_ptr<Entry>> staging_entries_;
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>> staging_entries_;
|
||||
|
||||
// Used when loading previous tabs/session and open tabs/session.
|
||||
base::WeakPtrFactory<PersistenceDelegate> weak_factory_{this};
|
||||
@ -646,21 +647,21 @@ void TabRestoreServiceImpl::PersistenceDelegate::OnWillSaveCommands() {
|
||||
DCHECK(static_cast<size_t>(to_write_count) <= entries.size());
|
||||
std::advance(i, entries.size() - static_cast<int>(to_write_count));
|
||||
for (; i != entries.rend(); ++i) {
|
||||
Entry& entry = **i;
|
||||
tab_restore::Entry& entry = **i;
|
||||
switch (entry.type) {
|
||||
case TAB: {
|
||||
Tab& tab = static_cast<Tab&>(entry);
|
||||
case tab_restore::Type::TAB: {
|
||||
tab_restore::Tab& tab = static_cast<tab_restore::Tab&>(entry);
|
||||
int selected_index = GetSelectedNavigationIndexToPersist(tab);
|
||||
if (selected_index != -1) {
|
||||
ScheduleCommandsForTab(tab, selected_index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WINDOW:
|
||||
ScheduleCommandsForWindow(static_cast<Window&>(entry));
|
||||
case tab_restore::Type::WINDOW:
|
||||
ScheduleCommandsForWindow(static_cast<tab_restore::Window&>(entry));
|
||||
break;
|
||||
case GROUP:
|
||||
ScheduleCommandsForGroup(static_cast<Group&>(entry));
|
||||
case tab_restore::Type::GROUP:
|
||||
ScheduleCommandsForGroup(static_cast<tab_restore::Group&>(entry));
|
||||
break;
|
||||
}
|
||||
entries_written_++;
|
||||
@ -767,9 +768,10 @@ bool TabRestoreServiceImpl::PersistenceDelegate::IsLoaded() const {
|
||||
// static
|
||||
void TabRestoreServiceImpl::PersistenceDelegate::CreateEntriesFromWindows(
|
||||
std::vector<std::unique_ptr<sessions::SessionWindow>>* windows,
|
||||
std::vector<std::unique_ptr<Entry>>* entries) {
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>>* entries) {
|
||||
for (const auto& session_window : *windows) {
|
||||
std::unique_ptr<Window> window = std::make_unique<Window>();
|
||||
std::unique_ptr<tab_restore::Window> window =
|
||||
std::make_unique<tab_restore::Window>();
|
||||
if (ConvertSessionWindowToWindow(session_window.get(), window.get())) {
|
||||
entries->push_back(std::move(window));
|
||||
}
|
||||
@ -781,7 +783,7 @@ void TabRestoreServiceImpl::PersistenceDelegate::Shutdown() {
|
||||
}
|
||||
|
||||
void TabRestoreServiceImpl::PersistenceDelegate::ScheduleCommandsForWindow(
|
||||
const Window& window) {
|
||||
const tab_restore::Window& window) {
|
||||
DCHECK(!window.tabs.empty());
|
||||
int selected_tab = window.selected_tab_index;
|
||||
int valid_tab_count = 0;
|
||||
@ -815,7 +817,7 @@ void TabRestoreServiceImpl::PersistenceDelegate::ScheduleCommandsForWindow(
|
||||
}
|
||||
|
||||
void TabRestoreServiceImpl::PersistenceDelegate::ScheduleCommandsForGroup(
|
||||
const Group& group) {
|
||||
const tab_restore::Group& group) {
|
||||
DCHECK(!group.tabs.empty());
|
||||
|
||||
command_storage_manager_->ScheduleCommand(
|
||||
@ -825,8 +827,8 @@ void TabRestoreServiceImpl::PersistenceDelegate::ScheduleCommandsForGroup(
|
||||
}
|
||||
|
||||
void TabRestoreServiceImpl::PersistenceDelegate::ScheduleCommandsForTabs(
|
||||
const std::vector<std::unique_ptr<Tab>>& tabs) {
|
||||
for (const std::unique_ptr<Tab>& tab : tabs) {
|
||||
const std::vector<std::unique_ptr<tab_restore::Tab>>& tabs) {
|
||||
for (const std::unique_ptr<tab_restore::Tab>& tab : tabs) {
|
||||
int selected_index = GetSelectedNavigationIndexToPersist(*tab);
|
||||
if (selected_index != -1) {
|
||||
ScheduleCommandsForTab(*tab, selected_index);
|
||||
@ -835,7 +837,7 @@ void TabRestoreServiceImpl::PersistenceDelegate::ScheduleCommandsForTabs(
|
||||
}
|
||||
|
||||
void TabRestoreServiceImpl::PersistenceDelegate::ScheduleCommandsForTab(
|
||||
const Tab& tab,
|
||||
const tab_restore::Tab& tab,
|
||||
int selected_index) {
|
||||
const std::vector<SerializedNavigationEntry>& navigations = tab.navigations;
|
||||
int max_index = static_cast<int>(navigations.size());
|
||||
@ -996,7 +998,7 @@ TabRestoreServiceImpl::PersistenceDelegate::CreateRestoredEntryCommand(
|
||||
}
|
||||
|
||||
int TabRestoreServiceImpl::PersistenceDelegate::
|
||||
GetSelectedNavigationIndexToPersist(const Tab& tab) {
|
||||
GetSelectedNavigationIndexToPersist(const tab_restore::Tab& tab) {
|
||||
const std::vector<SerializedNavigationEntry>& navigations = tab.navigations;
|
||||
int selected_index = tab.current_navigation_index;
|
||||
int max_index = static_cast<int>(navigations.size());
|
||||
@ -1026,7 +1028,7 @@ int TabRestoreServiceImpl::PersistenceDelegate::
|
||||
void TabRestoreServiceImpl::PersistenceDelegate::OnGotLastSessionCommands(
|
||||
std::vector<std::unique_ptr<SessionCommand>> commands,
|
||||
bool read_error) {
|
||||
std::vector<std::unique_ptr<TabRestoreService::Entry>> entries;
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>> entries;
|
||||
CreateEntriesFromCommands(commands, &entries);
|
||||
// Closed tabs always go to the end.
|
||||
staging_entries_.insert(staging_entries_.end(),
|
||||
@ -1038,20 +1040,20 @@ void TabRestoreServiceImpl::PersistenceDelegate::OnGotLastSessionCommands(
|
||||
|
||||
void TabRestoreServiceImpl::PersistenceDelegate::CreateEntriesFromCommands(
|
||||
const std::vector<std::unique_ptr<SessionCommand>>& commands,
|
||||
std::vector<std::unique_ptr<Entry>>* loaded_entries) {
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>>* loaded_entries) {
|
||||
if (tab_restore_service_helper_->entries().size() == kMaxEntries) {
|
||||
return;
|
||||
}
|
||||
// Iterate through the commands, populating |entries|.
|
||||
std::vector<std::unique_ptr<Entry>> entries;
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>> entries;
|
||||
// If non-null we're processing the navigations of this tab.
|
||||
Tab* current_tab = nullptr;
|
||||
tab_restore::Tab* current_tab = nullptr;
|
||||
// If non-null we're processing the tabs of this window. The int represents
|
||||
// the number of tabs left to process within the window.
|
||||
std::optional<std::pair<Window*, int>> current_window;
|
||||
std::optional<std::pair<tab_restore::Window*, int>> current_window;
|
||||
// If non-null we're processing the tabs of this group. The int represents
|
||||
// the number of tabs left to process within the group.
|
||||
std::optional<std::pair<Group*, int>> current_group;
|
||||
std::optional<std::pair<tab_restore::Group*, int>> current_group;
|
||||
for (const auto& i : commands) {
|
||||
const SessionCommand& command = *i;
|
||||
switch (command.id()) {
|
||||
@ -1084,7 +1086,7 @@ void TabRestoreServiceImpl::PersistenceDelegate::CreateEntriesFromCommands(
|
||||
|
||||
int32_t num_tabs = 0;
|
||||
SessionID window_id = SessionID::InvalidValue();
|
||||
std::unique_ptr<Window> window =
|
||||
std::unique_ptr<tab_restore::Window> window =
|
||||
CreateWindowEntryFromCommand(&command, &window_id, &num_tabs);
|
||||
if (!window) {
|
||||
return;
|
||||
@ -1111,7 +1113,7 @@ void TabRestoreServiceImpl::PersistenceDelegate::CreateEntriesFromCommands(
|
||||
|
||||
int32_t num_tabs = 0;
|
||||
SessionID group_id = SessionID::InvalidValue();
|
||||
std::unique_ptr<Group> group =
|
||||
std::unique_ptr<tab_restore::Group> group =
|
||||
CreateGroupEntryFromCommand(&command, &group_id, &num_tabs);
|
||||
if (!group) {
|
||||
return;
|
||||
@ -1150,7 +1152,8 @@ void TabRestoreServiceImpl::PersistenceDelegate::CreateEntriesFromCommands(
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
current_window->first->tabs.push_back(std::make_unique<Tab>());
|
||||
current_window->first->tabs.push_back(
|
||||
std::make_unique<tab_restore::Tab>());
|
||||
current_tab = current_window->first->tabs.back().get();
|
||||
if (--current_window->second == 0) {
|
||||
current_window = std::nullopt;
|
||||
@ -1161,15 +1164,16 @@ void TabRestoreServiceImpl::PersistenceDelegate::CreateEntriesFromCommands(
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
current_group->first->tabs.push_back(std::make_unique<Tab>());
|
||||
current_group->first->tabs.push_back(
|
||||
std::make_unique<tab_restore::Tab>());
|
||||
current_tab = current_group->first->tabs.back().get();
|
||||
if (--current_group->second == 0) {
|
||||
current_group = std::nullopt;
|
||||
}
|
||||
} else {
|
||||
RemoveEntryByID(SessionID::FromSerializedValue(payload.id), &entries);
|
||||
entries.push_back(std::make_unique<Tab>());
|
||||
current_tab = static_cast<Tab*>(entries.back().get());
|
||||
entries.push_back(std::make_unique<tab_restore::Tab>());
|
||||
current_tab = static_cast<tab_restore::Tab*>(entries.back().get());
|
||||
current_tab->timestamp = base::Time::FromDeltaSinceWindowsEpoch(
|
||||
base::Microseconds(payload.timestamp));
|
||||
}
|
||||
@ -1346,11 +1350,11 @@ void TabRestoreServiceImpl::PersistenceDelegate::CreateEntriesFromCommands(
|
||||
|
||||
// static
|
||||
void TabRestoreServiceImpl::PersistenceDelegate::ValidateAndDeleteEmptyEntries(
|
||||
std::vector<std::unique_ptr<Entry>>* entries) {
|
||||
std::vector<std::unique_ptr<Entry>> valid_entries;
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>>* entries) {
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>> valid_entries;
|
||||
|
||||
// Iterate from the back so that we keep the most recently closed entries.
|
||||
for (std::unique_ptr<Entry>& entry : base::Reversed(*entries)) {
|
||||
for (std::unique_ptr<tab_restore::Entry>& entry : base::Reversed(*entries)) {
|
||||
if (TabRestoreServiceHelper::ValidateEntry(*entry)) {
|
||||
valid_entries.push_back(std::move(entry));
|
||||
}
|
||||
@ -1363,7 +1367,7 @@ void TabRestoreServiceImpl::PersistenceDelegate::OnGotPreviousSession(
|
||||
std::vector<std::unique_ptr<SessionWindow>> windows,
|
||||
SessionID ignored_active_window,
|
||||
bool error_reading) {
|
||||
std::vector<std::unique_ptr<Entry>> entries;
|
||||
std::vector<std::unique_ptr<tab_restore::Entry>> entries;
|
||||
CreateEntriesFromWindows(&windows, &entries);
|
||||
// Previous session tabs go first.
|
||||
staging_entries_.insert(staging_entries_.begin(),
|
||||
@ -1375,7 +1379,7 @@ void TabRestoreServiceImpl::PersistenceDelegate::OnGotPreviousSession(
|
||||
|
||||
bool TabRestoreServiceImpl::PersistenceDelegate::ConvertSessionWindowToWindow(
|
||||
SessionWindow* session_window,
|
||||
Window* window) {
|
||||
tab_restore::Window* window) {
|
||||
window->type = session_window->type;
|
||||
|
||||
// The group visual datas must be stored in both |window| and each
|
||||
@ -1391,8 +1395,8 @@ bool TabRestoreServiceImpl::PersistenceDelegate::ConvertSessionWindowToWindow(
|
||||
if (i->navigations.empty()) {
|
||||
continue;
|
||||
}
|
||||
window->tabs.push_back(std::make_unique<Tab>());
|
||||
Tab& tab = *window->tabs.back();
|
||||
window->tabs.push_back(std::make_unique<tab_restore::Tab>());
|
||||
tab_restore::Tab& tab = *window->tabs.back();
|
||||
|
||||
auto group_id = i->group;
|
||||
if (group_id.has_value()) {
|
||||
@ -1480,7 +1484,7 @@ void TabRestoreServiceImpl::PersistenceDelegate::
|
||||
TabRestoreServiceImpl::TabRestoreServiceImpl(
|
||||
std::unique_ptr<TabRestoreServiceClient> client,
|
||||
PrefService* pref_service,
|
||||
TimeFactory* time_factory)
|
||||
tab_restore::TimeFactory* time_factory)
|
||||
: client_(std::move(client)), helper_(this, client_.get(), time_factory) {
|
||||
if (pref_service) {
|
||||
pref_change_registrar_.Init(pref_service);
|
||||
|
@ -27,7 +27,7 @@ class SESSIONS_EXPORT TabRestoreServiceImpl : public TabRestoreService {
|
||||
// Does not take ownership of |time_factory|.
|
||||
TabRestoreServiceImpl(std::unique_ptr<TabRestoreServiceClient> client,
|
||||
PrefService* pref_service,
|
||||
TimeFactory* time_factory);
|
||||
tab_restore::TimeFactory* time_factory);
|
||||
|
||||
TabRestoreServiceImpl(const TabRestoreServiceImpl&) = delete;
|
||||
TabRestoreServiceImpl& operator=(const TabRestoreServiceImpl&) = delete;
|
||||
|
51
components/sessions/core/tab_restore_types.cc
Normal file
51
components/sessions/core/tab_restore_types.cc
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "components/sessions/core/tab_restore_types.h"
|
||||
|
||||
#include "base/trace_event/memory_usage_estimator.h"
|
||||
|
||||
namespace sessions::tab_restore {
|
||||
|
||||
TimeFactory::~TimeFactory() = default;
|
||||
|
||||
Entry::Entry(Type type)
|
||||
: id(SessionID::NewUnique()),
|
||||
original_id(SessionID::InvalidValue()),
|
||||
type(type) {}
|
||||
Entry::~Entry() = default;
|
||||
|
||||
size_t Entry::EstimateMemoryUsage() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Tab::Tab() : Entry(TAB) {}
|
||||
Tab::~Tab() = default;
|
||||
|
||||
size_t Tab::EstimateMemoryUsage() const {
|
||||
using base::trace_event::EstimateMemoryUsage;
|
||||
return EstimateMemoryUsage(navigations) +
|
||||
EstimateMemoryUsage(extension_app_id) +
|
||||
user_agent_override.EstimateMemoryUsage();
|
||||
}
|
||||
|
||||
Window::Window() : Entry(WINDOW) {}
|
||||
Window::~Window() = default;
|
||||
|
||||
size_t Window::EstimateMemoryUsage() const {
|
||||
using base::trace_event::EstimateMemoryUsage;
|
||||
return EstimateMemoryUsage(tabs) + EstimateMemoryUsage(app_name);
|
||||
}
|
||||
|
||||
Group::Group() : Entry(GROUP) {}
|
||||
Group::~Group() = default;
|
||||
|
||||
size_t Group::EstimateMemoryUsage() const {
|
||||
using base::trace_event::EstimateMemoryUsage;
|
||||
return EstimateMemoryUsage(tabs) + EstimateMemoryUsage(visual_data.title());
|
||||
}
|
||||
|
||||
PlatformSpecificTabData::~PlatformSpecificTabData() = default;
|
||||
|
||||
} // namespace sessions::tab_restore
|
203
components/sessions/core/tab_restore_types.h
Normal file
203
components/sessions/core/tab_restore_types.h
Normal file
@ -0,0 +1,203 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef COMPONENTS_SESSIONS_CORE_TAB_RESTORE_TYPES_H_
|
||||
#define COMPONENTS_SESSIONS_CORE_TAB_RESTORE_TYPES_H_
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/time/time.h"
|
||||
#include "base/uuid.h"
|
||||
#include "components/sessions/core/serialized_navigation_entry.h"
|
||||
#include "components/sessions/core/serialized_user_agent_override.h"
|
||||
#include "components/sessions/core/session_id.h"
|
||||
#include "components/sessions/core/session_types.h"
|
||||
#include "components/sessions/core/sessions_export.h"
|
||||
#include "components/tab_groups/tab_group_id.h"
|
||||
#include "components/tab_groups/tab_group_visual_data.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
||||
namespace sessions::tab_restore {
|
||||
|
||||
// Interface used to allow the test to provide a custom time.
|
||||
class SESSIONS_EXPORT TimeFactory {
|
||||
public:
|
||||
virtual ~TimeFactory();
|
||||
virtual base::Time TimeNow() = 0;
|
||||
};
|
||||
|
||||
// A class that is used to associate platform-specific data with
|
||||
// TabRestoreTab. See LiveTab::GetPlatformSpecificTabData().
|
||||
class SESSIONS_EXPORT PlatformSpecificTabData {
|
||||
public:
|
||||
virtual ~PlatformSpecificTabData();
|
||||
};
|
||||
|
||||
// The type of entry.
|
||||
enum Type {
|
||||
TAB,
|
||||
GROUP,
|
||||
WINDOW,
|
||||
};
|
||||
|
||||
// Represent a previously open object (a memento) that is stored in memory
|
||||
// allowing us to identify and restore specific entries using their `id` to a
|
||||
// previous state.
|
||||
struct SESSIONS_EXPORT Entry {
|
||||
Entry(const Entry&) = delete;
|
||||
Entry& operator=(const Entry&) = delete;
|
||||
|
||||
virtual ~Entry();
|
||||
|
||||
// Unique id for this entry. The id is guaranteed to be unique for a
|
||||
// session.
|
||||
SessionID id;
|
||||
|
||||
// The original id of the entry when it was saved.
|
||||
SessionID original_id;
|
||||
|
||||
// The type of the entry.
|
||||
const Type type;
|
||||
|
||||
// The time when the window, tab, or group was closed. Not always set - can
|
||||
// be nullptr or 0 in cases where a timestamp isn't available at entry
|
||||
// creation.
|
||||
base::Time timestamp;
|
||||
|
||||
// Used for storing arbitrary key/value pairs.
|
||||
std::map<std::string, std::string> extra_data;
|
||||
|
||||
// Estimates memory usage. By default returns 0.
|
||||
virtual size_t EstimateMemoryUsage() const;
|
||||
|
||||
protected:
|
||||
explicit Entry(Type type);
|
||||
};
|
||||
|
||||
// Represents a previously open tab.
|
||||
// If you add a new field that can allocate memory also add
|
||||
// it to the EstimatedMemoryUsage() implementation.
|
||||
struct SESSIONS_EXPORT Tab : public Entry {
|
||||
Tab();
|
||||
~Tab() override;
|
||||
|
||||
// Entry:
|
||||
size_t EstimateMemoryUsage() const override;
|
||||
|
||||
// Since the current_navigation_index can be larger than the index for
|
||||
// number of navigations in the current sessions (chrome://newtab is not
|
||||
// stored), we must perform bounds checking. Returns a normalized
|
||||
// bounds-checked navigation_index.
|
||||
int normalized_navigation_index() const {
|
||||
return std::max(0, std::min(current_navigation_index,
|
||||
static_cast<int>(navigations.size() - 1)));
|
||||
}
|
||||
|
||||
// The navigations.
|
||||
std::vector<sessions::SerializedNavigationEntry> navigations;
|
||||
|
||||
// Index of the selected navigation in navigations.
|
||||
int current_navigation_index = -1;
|
||||
|
||||
// The ID of the browser to which this tab belonged, so it can be restored
|
||||
// there. May be 0 (an invalid SessionID) when restoring an entire session.
|
||||
SessionID::id_type browser_id = 0;
|
||||
|
||||
// Index within the tab strip. May be -1 for an unknown index.
|
||||
int tabstrip_index = -1;
|
||||
|
||||
// True if the tab was pinned.
|
||||
bool pinned = false;
|
||||
|
||||
// If non-empty gives the id of the extension for the tab.
|
||||
std::string extension_app_id;
|
||||
|
||||
// The associated client data.
|
||||
std::unique_ptr<PlatformSpecificTabData> platform_data;
|
||||
|
||||
// The user agent override used for the tab's navigations (if applicable).
|
||||
sessions::SerializedUserAgentOverride user_agent_override;
|
||||
|
||||
// The group the tab belonged to, if any.
|
||||
std::optional<tab_groups::TabGroupId> group;
|
||||
|
||||
// The saved group id the tab belong to, if any.
|
||||
std::optional<base::Uuid> saved_group_id = std::nullopt;
|
||||
|
||||
// The group metadata for the tab, if any.
|
||||
std::optional<tab_groups::TabGroupVisualData> group_visual_data;
|
||||
};
|
||||
|
||||
// Represents a previously open group.
|
||||
// If you add a new field that can allocate memory also add
|
||||
// it to the EstimatedMemoryUsage() implementation.
|
||||
struct SESSIONS_EXPORT Group : public Entry {
|
||||
Group();
|
||||
~Group() override;
|
||||
|
||||
// Entry:
|
||||
size_t EstimateMemoryUsage() const override;
|
||||
|
||||
// The tabs that comprised the group, in order.
|
||||
std::vector<std::unique_ptr<Tab>> tabs;
|
||||
|
||||
// Group metadata.
|
||||
tab_groups::TabGroupId group_id = tab_groups::TabGroupId::CreateEmpty();
|
||||
tab_groups::TabGroupVisualData visual_data;
|
||||
|
||||
// The saved group id of this group, if any.
|
||||
std::optional<base::Uuid> saved_group_id = std::nullopt;
|
||||
|
||||
// The ID of the browser to which this group belonged, so it can be restored
|
||||
// there.
|
||||
SessionID::id_type browser_id = 0;
|
||||
};
|
||||
|
||||
// Represents a previously open window.
|
||||
// If you add a new field that can allocate memory, please also add
|
||||
// it to the EstimatedMemoryUsage() implementation.
|
||||
struct SESSIONS_EXPORT Window : public Entry {
|
||||
Window();
|
||||
~Window() override;
|
||||
|
||||
// Entry:
|
||||
size_t EstimateMemoryUsage() const override;
|
||||
|
||||
// Type of window.
|
||||
sessions::SessionWindow::WindowType type;
|
||||
|
||||
// TODO(crbug.com/333425400): `tabs`, `groups`, and `tab_groups` contain
|
||||
// duplicated data. To prevent duplication of data consider changing `tabs`
|
||||
// to std::vector<std::unique_ptr<Entries>> so all data can be stored
|
||||
// together in one object. This should prevent data duplication.
|
||||
// The tabs that comprised the window, in order.
|
||||
std::vector<std::unique_ptr<Tab>> tabs;
|
||||
|
||||
// Tab groups in this window including their tabs.
|
||||
std::map<tab_groups::TabGroupId, std::unique_ptr<Group>> groups;
|
||||
|
||||
// Tab group data.
|
||||
std::map<tab_groups::TabGroupId, tab_groups::TabGroupVisualData> tab_groups;
|
||||
|
||||
// Index of the selected tab.
|
||||
int selected_tab_index = -1;
|
||||
|
||||
// If an application window, the name of the app.
|
||||
std::string app_name;
|
||||
|
||||
// User-set title of the window, if there is one.
|
||||
std::string user_title;
|
||||
|
||||
// Where and how the window is displayed.
|
||||
gfx::Rect bounds;
|
||||
ui::WindowShowState show_state;
|
||||
std::string workspace;
|
||||
};
|
||||
|
||||
} // namespace sessions::tab_restore
|
||||
|
||||
#endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_TYPES_H_
|
Reference in New Issue
Block a user