Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_COMMANDS_H_ | |
| 6 #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_COMMANDS_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 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 "chrome/browser/sessions/base_session_service.h" | |
| 17 #include "chrome/browser/sessions/session_types.h" | |
| 18 #include "ui/base/ui_base_types.h" | |
| 19 | |
| 20 class SessionCommand; | |
| 21 | |
| 22 // SessionServiceCommands ------------------------------------------------------ | |
| 23 | |
| 24 // SessionServiceCommands supplies functions to create sequentialized change | |
| 25 // commands which are required to reconstruct the current session state. It | |
| 26 // furthermore offers a |RestoreSessionFromCommands| function which will create | |
| 27 // |SessionWindow| and |SessionTab| data structures from a list of commands. | |
| 28 // | |
| 29 class SessionServiceCommands { | |
| 30 public: | |
| 31 // Used to distinguish an application from a ordinary content window. | |
| 32 enum AppType { | |
|
sky
2014/10/28 22:52:38
Move to session_types.
Mr4D (OOO till 08-26)
2014/10/29 02:04:13
It is not stored by any structure in session_types
| |
| 33 TYPE_APP, | |
| 34 TYPE_NORMAL | |
| 35 }; | |
| 36 | |
| 37 SessionServiceCommands(); | |
| 38 virtual ~SessionServiceCommands(); | |
| 39 | |
| 40 // Callback from GetLastSession. | |
| 41 // The second parameter is the id of the window that was last active. | |
| 42 typedef base::Callback<void(ScopedVector<SessionWindow>, SessionID::id_type)> | |
| 43 SessionCallback; | |
| 44 | |
| 45 // Fetches the contents of the last session, notifying the callback when | |
| 46 // done. If the callback is supplied an empty vector of SessionWindows | |
| 47 // it means the session could not be restored. | |
| 48 base::CancelableTaskTracker::TaskId GetLastSession( | |
| 49 const SessionCallback& callback, | |
| 50 base::CancelableTaskTracker* tracker); | |
| 51 | |
| 52 // Returns true if a window of given |window_type| and |app_type| should get | |
| 53 // restored upon session restore. | |
| 54 virtual bool ShouldRestoreWindowOfType( | |
| 55 SessionWindow::WindowType type, | |
| 56 SessionServiceCommands::AppType app_type) const = 0; | |
| 57 | |
| 58 // Methods to create the various commands. It is up to the caller to delete | |
| 59 // the returned SessionCommand* object. | |
| 60 SessionCommand* CreateSetSelectedTabInWindowCommand( | |
| 61 const SessionID& window_id, | |
| 62 int index); | |
| 63 SessionCommand* CreateSetTabWindowCommand(const SessionID& window_id, | |
|
sky
2014/10/28 22:52:38
None of these functions have any state. Move them
Mr4D (OOO till 08-26)
2014/10/29 02:04:13
Understood. But please see the previous patch set.
sky
2014/10/29 15:44:20
I don't understand this, can you elaborate?
Mr4D (OOO till 08-26)
2014/10/29 19:35:30
As discussed offline. Changed.
It is good to see
sky
2014/10/29 20:49:15
In theory these headers should only be included by
| |
| 64 const SessionID& tab_id); | |
| 65 SessionCommand* CreateSetWindowBoundsCommand(const SessionID& window_id, | |
| 66 const gfx::Rect& bounds, | |
| 67 ui::WindowShowState show_state); | |
| 68 SessionCommand* CreateSetTabIndexInWindowCommand(const SessionID& tab_id, | |
| 69 int new_index); | |
| 70 SessionCommand* CreateTabClosedCommand(SessionID::id_type tab_id); | |
| 71 SessionCommand* CreateWindowClosedCommand(SessionID::id_type tab_id); | |
| 72 SessionCommand* CreateSetSelectedNavigationIndexCommand( | |
| 73 const SessionID& tab_id, | |
| 74 int index); | |
| 75 SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id, | |
| 76 SessionWindow::WindowType type); | |
| 77 SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id, | |
| 78 bool is_pinned); | |
| 79 SessionCommand* CreateSessionStorageAssociatedCommand( | |
| 80 const SessionID& tab_id, | |
| 81 const std::string& session_storage_persistent_id); | |
| 82 SessionCommand* CreateSetActiveWindowCommand(const SessionID& window_id); | |
| 83 SessionCommand* CreateTabNavigationPathPrunedFromBackCommand( | |
| 84 const SessionID& tab_id, | |
| 85 int count); | |
| 86 SessionCommand* CreateTabNavigationPathPrunedFromFrontCommand( | |
| 87 const SessionID& tab_id, | |
| 88 int count); | |
| 89 SessionCommand* CreateUpdateTabNavigationCommand( | |
| 90 const SessionID& tab_id, | |
| 91 const sessions::SerializedNavigationEntry& navigation); | |
| 92 SessionCommand* CreateSetTabExtensionAppIDCommand( | |
| 93 const SessionID& tab_id, | |
| 94 const std::string& extension_id); | |
| 95 SessionCommand* CreateSetTabUserAgentOverrideCommand( | |
| 96 const SessionID& tab_id, | |
| 97 const std::string& user_agent_override); | |
| 98 SessionCommand* CreateSetWindowAppNameCommand(const SessionID& window_id, | |
| 99 const std::string& app_name); | |
| 100 | |
| 101 // Searches for a pending command in |pending_commands| that can be replaced | |
| 102 // with |command|. If one is found, pending command is removed, command is | |
| 103 // added to the pending commands and true is returned. | |
| 104 bool ReplacePendingCommand(SessionCommand* command, | |
| 105 std::vector<SessionCommand*>& pending_commands); | |
| 106 | |
| 107 // Returns true if provided |command| either closes a window or a tab. | |
| 108 bool IsClosingCommand(SessionCommand* command) const; | |
| 109 | |
| 110 // Converts the commands into SessionWindows. On return any valid | |
| 111 // windows are added to valid_windows. It is up to the caller to delete | |
| 112 // the windows added to valid_windows. |active_window_id| will be set with the | |
| 113 // id of the last active window, but it's only valid when this id corresponds | |
| 114 // to the id of one of the windows in valid_windows. | |
| 115 void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands, | |
| 116 std::vector<SessionWindow*>* valid_windows, | |
| 117 SessionID::id_type* active_window_id); | |
| 118 | |
| 119 private: | |
| 120 typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab; | |
| 121 typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow; | |
| 122 | |
| 123 // Iterates through the vector updating the selected_tab_index of each | |
| 124 // SessionWindow based on the actual tabs that were restored. | |
| 125 void UpdateSelectedTabIndex(std::vector<SessionWindow*>* windows); | |
| 126 | |
| 127 // Returns the window in windows with the specified id. If a window does | |
| 128 // not exist, one is created. | |
| 129 SessionWindow* GetWindow(SessionID::id_type window_id, | |
| 130 IdToSessionWindow* windows); | |
| 131 | |
| 132 // Returns the tab with the specified id in tabs. If a tab does not exist, | |
| 133 // it is created. | |
| 134 SessionTab* GetTab(SessionID::id_type tab_id, | |
| 135 IdToSessionTab* tabs); | |
| 136 | |
| 137 // Returns an iterator into navigations pointing to the navigation whose | |
| 138 // index matches |index|. If no navigation index matches |index|, the first | |
| 139 // navigation with an index > |index| is returned. | |
| 140 // | |
| 141 // This assumes the navigations are ordered by index in ascending order. | |
| 142 std::vector<sessions::SerializedNavigationEntry>::iterator | |
| 143 FindClosestNavigationWithIndex( | |
| 144 std::vector<sessions::SerializedNavigationEntry>* navigations, | |
| 145 int index); | |
| 146 | |
| 147 // Does the following: | |
| 148 // . Deletes and removes any windows with no tabs or windows with types other | |
| 149 // than tabbed_browser or browser. NOTE: constrained windows that have | |
| 150 // been dragged out are of type browser. As such, this preserves any dragged | |
| 151 // out constrained windows (aka popups that have been dragged out). | |
| 152 // . Sorts the tabs in windows with valid tabs based on the tabs | |
| 153 // visual order, and adds the valid windows to windows. | |
| 154 void SortTabsBasedOnVisualOrderAndPrune( | |
| 155 std::map<int, SessionWindow*>* windows, | |
| 156 std::vector<SessionWindow*>* valid_windows); | |
| 157 | |
| 158 // Adds tabs to their parent window based on the tab's window_id. This | |
| 159 // ignores tabs with no navigations. | |
| 160 void AddTabsToWindows(std::map<int, SessionTab*>* tabs, | |
| 161 std::map<int, SessionWindow*>* windows); | |
| 162 | |
| 163 // Creates tabs and windows from the commands specified in |data|. The created | |
| 164 // tabs and windows are added to |tabs| and |windows| respectively, with the | |
| 165 // id of the active window set in |active_window_id|. It is up to the caller | |
| 166 // to delete the tabs and windows added to |tabs| and |windows|. | |
| 167 // | |
| 168 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is | |
| 169 // done by AddTabsToWindows. | |
| 170 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data, | |
| 171 std::map<int, SessionTab*>* tabs, | |
| 172 std::map<int, SessionWindow*>* windows, | |
| 173 SessionID::id_type* active_window_id); | |
| 174 | |
| 175 DISALLOW_COPY_AND_ASSIGN(SessionServiceCommands); | |
| 176 }; | |
| 177 | |
| 178 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_COMMANDS_H_ | |
| OLD | NEW |