Roll src/third_party/WebKit b4168eb:6c137a7 (svn 202006:202008)
[chromium-blink-merge.git] / components / sessions / session_service_commands.h
blobe1cca36902da7b57fc74b33a22b3e2c635303024
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SESSIONS_SESSION_SERVICE_COMMANDS_H_
6 #define COMPONENTS_SESSIONS_SESSION_SERVICE_COMMANDS_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/task/cancelable_task_tracker.h"
16 #include "components/sessions/base_session_service.h"
17 #include "components/sessions/session_types.h"
18 #include "components/sessions/sessions_export.h"
19 #include "ui/base/ui_base_types.h"
21 namespace sessions {
23 class SessionCommand;
25 // The following functions create sequentialized change commands which are
26 // used to reconstruct the current/previous session state.
27 // It is up to the caller to delete the returned SessionCommand* object.
28 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateSetSelectedTabInWindowCommand(
29 const SessionID& window_id,
30 int index);
31 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateSetTabWindowCommand(
32 const SessionID& window_id,
33 const SessionID& tab_id);
34 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateSetWindowBoundsCommand(
35 const SessionID& window_id,
36 const gfx::Rect& bounds,
37 ui::WindowShowState show_state);
38 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateSetTabIndexInWindowCommand(
39 const SessionID& tab_id,
40 int new_index);
41 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateTabClosedCommand(
42 SessionID::id_type tab_id);
43 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateWindowClosedCommand(
44 SessionID::id_type tab_id);
45 SESSIONS_EXPORT scoped_ptr<SessionCommand>
46 CreateSetSelectedNavigationIndexCommand(
47 const SessionID& tab_id,
48 int index);
49 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateSetWindowTypeCommand(
50 const SessionID& window_id,
51 SessionWindow::WindowType type);
52 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreatePinnedStateCommand(
53 const SessionID& tab_id,
54 bool is_pinned);
55 SESSIONS_EXPORT scoped_ptr<SessionCommand>
56 CreateSessionStorageAssociatedCommand(
57 const SessionID& tab_id,
58 const std::string& session_storage_persistent_id);
59 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateSetActiveWindowCommand(
60 const SessionID& window_id);
61 SESSIONS_EXPORT scoped_ptr<SessionCommand>
62 CreateTabNavigationPathPrunedFromBackCommand(
63 const SessionID& tab_id,
64 int count);
65 SESSIONS_EXPORT scoped_ptr<SessionCommand>
66 CreateTabNavigationPathPrunedFromFrontCommand(
67 const SessionID& tab_id,
68 int count);
69 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateUpdateTabNavigationCommand(
70 const SessionID& tab_id,
71 const sessions::SerializedNavigationEntry& navigation);
72 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateSetTabExtensionAppIDCommand(
73 const SessionID& tab_id,
74 const std::string& extension_id);
75 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateSetTabUserAgentOverrideCommand(
76 const SessionID& tab_id,
77 const std::string& user_agent_override);
78 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateSetWindowAppNameCommand(
79 const SessionID& window_id,
80 const std::string& app_name);
81 SESSIONS_EXPORT scoped_ptr<SessionCommand> CreateLastActiveTimeCommand(
82 const SessionID& tab_id,
83 base::TimeTicks last_active_time);
85 // Searches for a pending command using |base_session_service| that can be
86 // replaced with |command|. If one is found, pending command is removed, the
87 // command is added to the pending commands (taken ownership) and true is
88 // returned.
89 SESSIONS_EXPORT bool ReplacePendingCommand(
90 BaseSessionService* base_session_service,
91 scoped_ptr<SessionCommand>* command);
93 // Returns true if provided |command| either closes a window or a tab.
94 SESSIONS_EXPORT bool IsClosingCommand(SessionCommand* command);
96 // Converts a list of commands into SessionWindows. On return any valid
97 // windows are added to valid_windows. It is up to the caller to delete
98 // the windows added to valid_windows. |active_window_id| will be set with the
99 // id of the last active window, but it's only valid when this id corresponds
100 // to the id of one of the windows in valid_windows.
101 SESSIONS_EXPORT void RestoreSessionFromCommands(
102 const ScopedVector<SessionCommand>& commands,
103 std::vector<SessionWindow*>* valid_windows,
104 SessionID::id_type* active_window_id);
106 } // namespace sessions
108 #endif // COMPONENTS_SESSIONS_SESSION_SERVICE_COMMANDS_H_