chromium/chrome/browser/sessions/session_service.cc

// 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 "chrome/browser/sessions/session_service.h"

#include <stddef.h>

#include <set>
#include <string>
#include <utility>
#include <vector>

#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/debug/alias.h"
#include "base/debug/dump_without_crashing.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/apps/app_service/launch_utils.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/buildflags.h"
#include "chrome/browser/lifetime/application_lifetime_desktop.h"
#include "chrome/browser/lifetime/browser_shutdown.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/sessions/exit_type_service.h"
#include "chrome/browser/sessions/session_common_utils.h"
#include "chrome/browser/sessions/session_data_deleter.h"
#include "chrome/browser/sessions/session_restore.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_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/session_crashed_bubble.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/startup/startup_tab.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/common/chrome_switches.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 "components/sessions/core/tab_restore_service.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/session_storage_namespace.h"
#include "content/public/browser/web_contents.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/components/kiosk/kiosk_utils.h"
#endif  // BUILDFLAG(IS_CHROMEOS)

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/crostini/crostini_util.h"
#endif

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chrome/browser/lacros/browser_launcher.h"
#endif

#if BUILDFLAG(IS_MAC)
#include "chrome/browser/app_controller_mac.h"
#endif

#if defined(TOOLKIT_VIEWS)
#include "chrome/browser/ui/side_search/side_search_utils.h"
#endif  // defined(TOOLKIT_VIEWS)

NavigationEntry;
WebContents;
ContentSerializedNavigationBuilder;
SerializedNavigationEntry;

namespace {

const void* const kInstanceTrackerKey =;

// An instance of this class is created pre-profile. It is used to track how
// many SessionServices have been created.
class InstanceTracker : public base::SupportsUserData::Data {};

}  // namespace

SessionService::SessionService(Profile* profile)
    :{}

SessionService::~SessionService() {}

// static
bool SessionService::IsRelevantWindowType(
    sessions::SessionWindow::WindowType window_type) {}

bool SessionService::ShouldRestore(Browser* browser) {}

bool SessionService::RestoreIfNecessary(const StartupTabs& startup_tabs,
                                        bool restore_apps) {}

void SessionService::MoveCurrentSessionToLastSession() {}

void SessionService::DeleteLastSession() {}

void SessionService::SetTabGroup(SessionID window_id,
                                 SessionID tab_id,
                                 std::optional<tab_groups::TabGroupId> group) {}

void SessionService::SetTabGroupMetadata(
    SessionID window_id,
    const tab_groups::TabGroupId& group_id,
    const tab_groups::TabGroupVisualData* visual_data,
    const std::optional<std::string> saved_guid) {}

void SessionService::AddTabExtraData(SessionID window_id,
                                     SessionID tab_id,
                                     const char* key,
                                     const std::string data) {}

void SessionService::AddWindowExtraData(SessionID window_id,
                                        const char* key,
                                        const std::string data) {}

void SessionService::TabClosed(SessionID window_id, SessionID tab_id) {}

void SessionService::WindowOpened(Browser* browser) {}

void SessionService::WindowClosing(SessionID window_id) {}

void SessionService::WindowClosed(SessionID window_id) {}

void SessionService::SetWindowType(SessionID window_id, Browser::Type type) {}

void SessionService::SetWindowUserTitle(SessionID window_id,
                                        const std::string& user_title) {}

void SessionService::OnErrorWritingSessionCommands() {}

void SessionService::SetTabUserAgentOverride(
    SessionID window_id,
    SessionID tab_id,
    const sessions::SerializedUserAgentOverride& user_agent_override) {}

Browser::Type SessionService::GetDesiredBrowserTypeForWebContents() {}

void SessionService::DidScheduleCommand() {}

bool SessionService::ShouldRestoreWindowOfType(
    sessions::SessionWindow::WindowType window_type) const {}

bool SessionService::RestoreIfNecessary(const StartupTabs& startup_tabs,
                                        Browser* browser,
                                        bool restore_apps) {}

void SessionService::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 SessionService::ScheduleResetCommands() {}

void SessionService::CommitPendingCloses() {}

bool SessionService::IsOnlyOneTabLeft() const {}

bool SessionService::HasOpenTrackableBrowsers(SessionID window_id) const {}

void SessionService::RebuildCommandsIfRequired() {}

void SessionService::OnClosingAllBrowsersChanged(bool closing) {}

void SessionService::LogExitEvent() {}

void SessionService::RemoveExitEvent() {}