#include "chrome/browser/sessions/session_service_base.h"
#include <stddef.h>
#include <set>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/apps/app_service/web_contents_app_id_utils.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_service_log.h"
#include "chrome/browser/sessions/session_service_utils.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_utils.h"
#include "chrome/browser/ui/tabs/tab_group.h"
#include "chrome/browser/ui/tabs/tab_group_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "components/sessions/content/content_serialized_navigation_builder.h"
#include "components/sessions/content/session_tab_helper.h"
#include "components/sessions/core/command_storage_manager.h"
#include "components/sessions/core/session_command.h"
#include "components/sessions/core/session_constants.h"
#include "components/sessions/core/session_types.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/session_storage_namespace.h"
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/app_controller_mac.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#endif
Time;
NavigationEntry;
WebContents;
ContentSerializedNavigationBuilder;
SerializedNavigationEntry;
namespace {
const int kWritesPerReset = …;
const void* const kSessionServiceBaseUserDataKey = …;
const void* const kProfileTaskRunnerKey = …;
const void* const kProfileTaskRunnerKeyForApps = …;
class TaskRunnerData : public base::SupportsUserData::Data { … };
class SessionServiceBaseUserData : public base::SupportsUserData::Data { … };
}
SessionServiceBase::SessionServiceBase(Profile* profile,
SessionServiceType type)
: … { … }
SessionServiceBase::~SessionServiceBase() { … }
Browser::Type SessionServiceBase::GetBrowserTypeFromWebContents(
content::WebContents* web_contents) { … }
void SessionServiceBase::SetWindowVisibleOnAllWorkspaces(
SessionID window_id,
bool visible_on_all_workspaces) { … }
void SessionServiceBase::ResetFromCurrentBrowsers() { … }
void SessionServiceBase::SetTabWindow(SessionID window_id, SessionID tab_id) { … }
void SessionServiceBase::SetWindowBounds(SessionID window_id,
const gfx::Rect& bounds,
ui::WindowShowState show_state) { … }
void SessionServiceBase::SetWindowWorkspace(SessionID window_id,
const std::string& workspace) { … }
void SessionServiceBase::SetTabIndexInWindow(SessionID window_id,
SessionID tab_id,
int new_index) { … }
void SessionServiceBase::TabInserted(WebContents* contents) { … }
void SessionServiceBase::TabClosing(WebContents* contents) { … }
void SessionServiceBase::TabRestored(WebContents* tab, bool pinned) { … }
void SessionServiceBase::SetSelectedTabInWindow(SessionID window_id,
int index) { … }
void SessionServiceBase::SetTabExtensionAppID(
SessionID window_id,
SessionID tab_id,
const std::string& extension_app_id) { … }
void SessionServiceBase::SetLastActiveTime(SessionID window_id,
SessionID tab_id,
base::Time last_active_time) { … }
void SessionServiceBase::GetLastSession(
sessions::GetLastSessionCallback callback) { … }
void SessionServiceBase::SetWindowAppName(SessionID window_id,
const std::string& app_name) { … }
void SessionServiceBase::SetPinnedState(SessionID window_id,
SessionID tab_id,
bool is_pinned) { … }
bool SessionServiceBase::ShouldUseDelayedSave() { … }
void SessionServiceBase::OnWillSaveCommands() { … }
void SessionServiceBase::OnErrorWritingSessionCommands() { … }
void SessionServiceBase::SetTabUserAgentOverride(
SessionID window_id,
SessionID tab_id,
const sessions::SerializedUserAgentOverride& user_agent_override) { … }
void SessionServiceBase::SetSelectedNavigationIndex(SessionID window_id,
SessionID tab_id,
int index) { … }
void SessionServiceBase::UpdateTabNavigation(
SessionID window_id,
SessionID tab_id,
const SerializedNavigationEntry& navigation) { … }
void SessionServiceBase::TabNavigationPathPruned(SessionID window_id,
SessionID tab_id,
int index,
int count) { … }
void SessionServiceBase::TabNavigationPathEntriesDeleted(SessionID window_id,
SessionID tab_id) { … }
void SessionServiceBase::DestroyCommandStorageManager() { … }
void SessionServiceBase::RemoveUnusedRestoreWindows(
std::vector<std::unique_ptr<sessions::SessionWindow>>* window_list) { … }
void SessionServiceBase::OnBrowserSetLastActive(Browser* browser) { … }
void SessionServiceBase::OnGotSessionCommands(
sessions::GetLastSessionCallback callback,
std::vector<std::unique_ptr<sessions::SessionCommand>> commands,
bool read_error) { … }
void SessionServiceBase::BuildCommandsForTab(
SessionID window_id,
WebContents* tab,
int index_in_window,
std::optional<tab_groups::TabGroupId> group,
bool is_pinned,
IdToRange* tab_to_available_range) { … }
void SessionServiceBase::BuildCommandsForBrowser(
Browser* browser,
IdToRange* tab_to_available_range,
std::set<SessionID>* windows_to_track) { … }
void SessionServiceBase::BuildCommandsFromBrowsers(
IdToRange* tab_to_available_range,
std::set<SessionID>* windows_to_track) { … }
void SessionServiceBase::ScheduleCommand(
std::unique_ptr<sessions::SessionCommand> command) { … }
bool SessionServiceBase::ShouldTrackChangesToWindow(SessionID window_id) const { … }
bool SessionServiceBase::ShouldTrackBrowser(Browser* browser) const { … }
sessions::CommandStorageManager*
SessionServiceBase::GetCommandStorageManagerForTest() { … }
void SessionServiceBase::SetAvailableRangeForTest(
SessionID tab_id,
const std::pair<int, int>& range) { … }
bool SessionServiceBase::GetAvailableRangeForTest(SessionID tab_id,
std::pair<int, int>* range) { … }
void SessionServiceBase::SetSavingEnabled(bool enabled) { … }