#include "components/sessions/core/session_service_commands.h"
#include <stdint.h>
#include <string.h>
#include <map>
#include <tuple>
#include <utility>
#include <vector>
#include "base/containers/flat_set.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/pickle.h"
#include "base/token.h"
#include "base/uuid.h"
#include "base/values.h"
#include "components/sessions/core/base_session_service_commands.h"
#include "components/tab_groups/tab_group_color.h"
namespace sessions {
static const SessionCommand::id_type kCommandSetTabWindow = …;
static const SessionCommand::id_type kCommandSetTabIndexInWindow = …;
static const SessionCommand::id_type
kCommandTabNavigationPathPrunedFromBack = …;
static const SessionCommand::id_type kCommandUpdateTabNavigation = …;
static const SessionCommand::id_type kCommandSetSelectedNavigationIndex = …;
static const SessionCommand::id_type kCommandSetSelectedTabInIndex = …;
static const SessionCommand::id_type kCommandSetWindowType = …;
static const SessionCommand::id_type
kCommandTabNavigationPathPrunedFromFront = …;
static const SessionCommand::id_type kCommandSetPinnedState = …;
static const SessionCommand::id_type kCommandSetExtensionAppID = …;
static const SessionCommand::id_type kCommandSetWindowBounds3 = …;
static const SessionCommand::id_type kCommandSetWindowAppName = …;
static const SessionCommand::id_type kCommandTabClosed = …;
static const SessionCommand::id_type kCommandWindowClosed = …;
static const SessionCommand::id_type kCommandSetTabUserAgentOverride = …;
static const SessionCommand::id_type kCommandSessionStorageAssociated = …;
static const SessionCommand::id_type kCommandSetActiveWindow = …;
static const SessionCommand::id_type kCommandLastActiveTime = …;
static const SessionCommand::id_type kCommandSetWindowWorkspace2 = …;
static const SessionCommand::id_type kCommandTabNavigationPathPruned = …;
static const SessionCommand::id_type kCommandSetTabGroup = …;
static const SessionCommand::id_type kCommandSetTabGroupMetadata2 = …;
static const SessionCommand::id_type kCommandSetTabGuid = …;
static const SessionCommand::id_type kCommandSetTabUserAgentOverride2 = …;
static const SessionCommand::id_type kCommandSetTabData = …;
static const SessionCommand::id_type kCommandSetWindowUserTitle = …;
static const SessionCommand::id_type kCommandSetWindowVisibleOnAllWorkspaces = …;
static const SessionCommand::id_type kCommandAddTabExtraData = …;
static const SessionCommand::id_type kCommandAddWindowExtraData = …;
namespace {
struct ClosedPayload { … };
struct WindowBoundsPayload2 { … };
struct WindowBoundsPayload3 { … };
ActiveWindowPayload;
struct IDAndIndexPayload { … };
TabIndexInWindowPayload;
TabNavigationPathPrunedFromBackPayload;
SelectedNavigationIndexPayload;
SelectedTabInIndexPayload;
WindowTypePayload;
TabNavigationPathPrunedFromFrontPayload;
struct TabNavigationPathPrunedPayload { … };
struct SerializedToken { … };
struct TabGroupPayload { … };
struct PinnedStatePayload { … };
struct LastActiveTimePayload { … };
struct VisibleOnAllWorkspacesPayload { … };
enum PersistedWindowShowState { … };
const base::TimeDelta kLastActiveWorkaroundThreshold = …;
static_assert …;
PersistedWindowShowState ShowStateToPersistedShowState(
ui::WindowShowState state) { … }
ui::WindowShowState PersistedShowStateToShowState(int state) { … }
void UpdateSelectedTabIndex(
std::vector<std::unique_ptr<SessionWindow>>* windows) { … }
IdToSessionTab;
IdToSessionWindow;
GroupIdToSessionTabGroup;
SessionWindow* GetWindow(SessionID window_id, IdToSessionWindow* windows) { … }
SessionTab* GetTab(SessionID tab_id, IdToSessionTab* tabs) { … }
SessionTabGroup* GetTabGroup(tab_groups::TabGroupId group_id,
GroupIdToSessionTabGroup* groups) { … }
std::vector<sessions::SerializedNavigationEntry>::iterator
FindClosestNavigationWithIndex(
std::vector<sessions::SerializedNavigationEntry>* navigations,
int index) { … }
static bool WindowOrderSortFunction(const std::unique_ptr<SessionWindow>& w1,
const std::unique_ptr<SessionWindow>& w2) { … }
static bool TabVisualIndexSortFunction(const std::unique_ptr<SessionTab>& t1,
const std::unique_ptr<SessionTab>& t2) { … }
void SortTabsBasedOnVisualOrderAndClear(
IdToSessionWindow* windows,
std::vector<std::unique_ptr<SessionWindow>>* valid_windows) { … }
void AddTabsToWindows(IdToSessionTab* tabs,
GroupIdToSessionTabGroup* tab_groups,
IdToSessionWindow* windows) { … }
void ProcessTabNavigationPathPrunedCommand(
TabNavigationPathPrunedPayload& payload,
SessionTab* tab) { … }
void CreateTabsAndWindows(
const std::vector<std::unique_ptr<SessionCommand>>& data,
IdToSessionTab* tabs,
GroupIdToSessionTabGroup* tab_groups,
IdToSessionWindow* windows,
SessionID* active_window_id) { … }
template <typename Payload>
std::unique_ptr<SessionCommand> CreateSessionCommandForPayload(
SessionCommand::id_type id,
const Payload& payload) { … }
}
std::unique_ptr<SessionCommand> CreateSetSelectedTabInWindowCommand(
SessionID window_id,
int index) { … }
std::unique_ptr<SessionCommand> CreateSetTabWindowCommand(SessionID window_id,
SessionID tab_id) { … }
std::unique_ptr<SessionCommand> CreateSetWindowBoundsCommand(
SessionID window_id,
const gfx::Rect& bounds,
ui::WindowShowState show_state) { … }
std::unique_ptr<SessionCommand> CreateSetTabIndexInWindowCommand(
SessionID tab_id,
int new_index) { … }
std::unique_ptr<SessionCommand> CreateTabClosedCommand(const SessionID tab_id) { … }
std::unique_ptr<SessionCommand> CreateWindowClosedCommand(
const SessionID window_id) { … }
std::unique_ptr<SessionCommand> CreateSetSelectedNavigationIndexCommand(
SessionID tab_id,
int index) { … }
std::unique_ptr<SessionCommand> CreateSetWindowTypeCommand(
SessionID window_id,
SessionWindow::WindowType type) { … }
std::unique_ptr<SessionCommand> CreateTabGroupCommand(
SessionID tab_id,
std::optional<tab_groups::TabGroupId> group) { … }
std::unique_ptr<SessionCommand> CreateTabGroupMetadataUpdateCommand(
const tab_groups::TabGroupId group,
const tab_groups::TabGroupVisualData* visual_data,
const std::optional<std::string> saved_guid) { … }
std::unique_ptr<SessionCommand> CreatePinnedStateCommand(SessionID tab_id,
bool is_pinned) { … }
std::unique_ptr<SessionCommand> CreateSessionStorageAssociatedCommand(
SessionID tab_id,
const std::string& session_storage_persistent_id) { … }
std::unique_ptr<SessionCommand> CreateSetActiveWindowCommand(
SessionID window_id) { … }
std::unique_ptr<SessionCommand> CreateLastActiveTimeCommand(
SessionID tab_id,
base::Time last_active_time) { … }
std::unique_ptr<SessionCommand> CreateSetWindowWorkspaceCommand(
SessionID window_id,
const std::string& workspace) { … }
std::unique_ptr<SessionCommand> CreateSetWindowVisibleOnAllWorkspacesCommand(
SessionID window_id,
bool visible_on_all_workspaces) { … }
std::unique_ptr<SessionCommand>
CreateTabNavigationPathPrunedCommand(SessionID tab_id, int index, int count) { … }
std::unique_ptr<SessionCommand> CreateUpdateTabNavigationCommand(
SessionID tab_id,
const sessions::SerializedNavigationEntry& navigation) { … }
std::unique_ptr<SessionCommand> CreateSetTabExtensionAppIDCommand(
SessionID tab_id,
const std::string& extension_id) { … }
std::unique_ptr<SessionCommand> CreateSetTabUserAgentOverrideCommand(
SessionID tab_id,
const SerializedUserAgentOverride& user_agent_override) { … }
std::unique_ptr<SessionCommand> CreateSetWindowAppNameCommand(
SessionID window_id,
const std::string& app_name) { … }
std::unique_ptr<SessionCommand> CreateSetWindowUserTitleCommand(
SessionID window_id,
const std::string& user_title) { … }
std::unique_ptr<SessionCommand> CreateSetTabGuidCommand(
SessionID tab_id,
const std::string& guid) { … }
std::unique_ptr<SessionCommand> CreateSetTabDataCommand(
SessionID tab_id,
const std::map<std::string, std::string>& data) { … }
std::unique_ptr<SessionCommand> CreateAddTabExtraDataCommand(
SessionID tab_id,
const std::string& key,
const std::string& data) { … }
std::unique_ptr<SessionCommand> CreateAddWindowExtraDataCommand(
SessionID window_id,
const std::string& key,
const std::string& data) { … }
bool ReplacePendingCommand(CommandStorageManager* command_storage_manager,
std::unique_ptr<SessionCommand>* command) { … }
bool IsClosingCommand(SessionCommand* command) { … }
void RestoreSessionFromCommands(
const std::vector<std::unique_ptr<SessionCommand>>& commands,
std::vector<std::unique_ptr<SessionWindow>>* valid_windows,
SessionID* active_window_id) { … }
}