Fixing flashing of previous users window upon adding another user to the session
[chromium-blink-merge.git] / components / sessions / session_service_commands.h
blob6bf3be85a84ac9a0c1a7c816631f874ebac3aefd
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);
82 // Searches for a pending command using |base_session_service| that can be
83 // replaced with |command|. If one is found, pending command is removed, the
84 // command is added to the pending commands (taken ownership) and true is
85 // returned.
86 SESSIONS_EXPORT bool ReplacePendingCommand(
87 BaseSessionService* base_session_service,
88 scoped_ptr<SessionCommand>* command);
90 // Returns true if provided |command| either closes a window or a tab.
91 SESSIONS_EXPORT bool IsClosingCommand(SessionCommand* command);
93 // Converts a list of commands into SessionWindows. On return any valid
94 // windows are added to valid_windows. It is up to the caller to delete
95 // the windows added to valid_windows. |active_window_id| will be set with the
96 // id of the last active window, but it's only valid when this id corresponds
97 // to the id of one of the windows in valid_windows.
98 SESSIONS_EXPORT void RestoreSessionFromCommands(
99 const ScopedVector<SessionCommand>& commands,
100 std::vector<SessionWindow*>* valid_windows,
101 SessionID::id_type* active_window_id);
103 } // namespace sessions
105 #endif // COMPONENTS_SESSIONS_SESSION_SERVICE_COMMANDS_H_