Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: chrome/browser/sessions/session_service_commands.h

Issue 672083002: Refactoring of SessionService to get componentized. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_SERVICE_SESSION_COMMANDS_H_
6 #define CHROME_BROWSER_SESSIONS_SERVICE_SESSION_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 BaseSessionServiceDelegate;
21 class SessionCommand;
22
23 // SessionServiceCommands ------------------------------------------------------ ------
24
25 // SessionServiceCommands adds a layer to |BaseSessionService| which offers
26 // command creations and a restoration function. The |GetLastSession| function
27 // will create |SessionWindow| and |SessionTab| data structures.
28 //
29 class SessionServiceCommands : public BaseSessionService {
30 public:
31 // Used to distinguish an application window from a normal one.
32 enum AppType {
33 TYPE_APP,
34 TYPE_NORMAL
35 };
36
37 SessionServiceCommands(BaseSessionService::SessionType type,
38 const base::FilePath& path,
39 scoped_ptr<BaseSessionServiceDelegate> delegate);
40 virtual ~SessionServiceCommands();
41
42 // Callback from GetLastSession.
43 // The second parameter is the id of the window that was last active.
44 typedef base::Callback<void(ScopedVector<SessionWindow>, SessionID::id_type)>
45 SessionCallback;
46
47 // Fetches the contents of the last session, notifying the callback when
48 // done. If the callback is supplied an empty vector of SessionWindows
49 // it means the session could not be restored.
50 base::CancelableTaskTracker::TaskId GetLastSession(
51 const SessionCallback& callback,
52 base::CancelableTaskTracker* tracker);
53
54 // Implemented by the ...TODO: Do not call back into creator?
55 virtual bool ShouldTrackChangesOfWindowType(
56 SessionWindow::WindowType type,
57 SessionServiceCommands::AppType app_type) const = 0;
58 // Schedule to re...TODO: Do not call back into creator?
59 virtual void ScheduleResetCommands() = 0;
60
61 // Methods to create the various commands. It is up to the caller to delete
62 // the returned SessionCommand* object.
63 SessionCommand* CreateSetSelectedTabInWindow(const SessionID& window_id,
64 int index);
65 SessionCommand* CreateSetTabWindow(const SessionID& window_id,
66 const SessionID& tab_id);
67 SessionCommand* CreateSetWindowBounds(const SessionID& window_id,
68 const gfx::Rect& bounds,
69 ui::WindowShowState show_state);
70 SessionCommand* CreateSetTabIndexInWindow(const SessionID& tab_id,
71 int new_index);
72 SessionCommand* CreateTabClosed(SessionID::id_type tab_id);
73 SessionCommand* CreateWindowClosed(SessionID::id_type tab_id);
74 SessionCommand* CreateSetSelectedNavigationIndex(const SessionID& tab_id,
75 int index);
76 SessionCommand* CreateSetWindowType(const SessionID& window_id,
77 SessionWindow::WindowType type);
78 SessionCommand* CreatePinnedState(const SessionID& tab_id, bool is_pinned);
79 SessionCommand* CreateSessionStorageAssociated(
80 const SessionID& tab_id,
81 const std::string& session_storage_persistent_id);
82 SessionCommand* CreateSetActiveWindow(const SessionID& window_id);
83 SessionCommand* CreateTabNavigationPathPrunedFromBack(const SessionID& tab_id,
84 int count);
85 SessionCommand* CreateTabNavigationPathPrunedFromFront(
86 const SessionID& tab_id,
87 int count);
88 SessionCommand* CreateUpdateTabNavigation(
89 const SessionID& tab_id,
90 const sessions::SerializedNavigationEntry& navigation);
91 SessionCommand* CreateSetTabExtensionAppID(const SessionID& tab_id,
92 const std::string& extension_id);
93 SessionCommand* CreateSetTabUserAgentOverride(
94 const SessionID& tab_id,
95 const std::string& user_agent_override);
96 SessionCommand* CreateSetWindowAppName(const SessionID& window_id,
97 const std::string& app_name);
98
99 // BaseSessionService:
100 // Schedules the specified command. This method takes ownership of the
101 // command.
102 void ScheduleCommand(SessionCommand* command) override;
103
104 private:
105 typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab;
106 typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow;
107
108 // Converts |commands| to SessionWindows and notifies the callback.
109 void OnGotSessionServiceCommands(const SessionCallback& callback,
110 ScopedVector<SessionCommand> commands);
111
112 // Converts the commands into SessionWindows. On return any valid
113 // windows are added to valid_windows. It is up to the caller to delete
114 // the windows added to valid_windows. |active_window_id| will be set with the
115 // id of the last active window, but it's only valid when this id corresponds
116 // to the id of one of the windows in valid_windows.
117 void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands,
118 std::vector<SessionWindow*>* valid_windows,
119 SessionID::id_type* active_window_id);
120
121 // Iterates through the vector updating the selected_tab_index of each
122 // SessionWindow based on the actual tabs that were restored.
123 void UpdateSelectedTabIndex(std::vector<SessionWindow*>* windows);
124
125 // Returns the window in windows with the specified id. If a window does
126 // not exist, one is created.
127 SessionWindow* GetWindow(SessionID::id_type window_id,
128 IdToSessionWindow* windows);
129
130 // Returns the tab with the specified id in tabs. If a tab does not exist,
131 // it is created.
132 SessionTab* GetTab(SessionID::id_type tab_id,
133 IdToSessionTab* tabs);
134
135 // Returns an iterator into navigations pointing to the navigation whose
136 // index matches |index|. If no navigation index matches |index|, the first
137 // navigation with an index > |index| is returned.
138 //
139 // This assumes the navigations are ordered by index in ascending order.
140 std::vector<sessions::SerializedNavigationEntry>::iterator
141 FindClosestNavigationWithIndex(
142 std::vector<sessions::SerializedNavigationEntry>* navigations,
143 int index);
144
145 // Does the following:
146 // . Deletes and removes any windows with no tabs or windows with types other
147 // than tabbed_browser or browser. NOTE: constrained windows that have
148 // been dragged out are of type browser. As such, this preserves any dragged
149 // out constrained windows (aka popups that have been dragged out).
150 // . Sorts the tabs in windows with valid tabs based on the tabs
151 // visual order, and adds the valid windows to windows.
152 void SortTabsBasedOnVisualOrderAndPrune(
153 std::map<int, SessionWindow*>* windows,
154 std::vector<SessionWindow*>* valid_windows);
155
156 // Adds tabs to their parent window based on the tab's window_id. This
157 // ignores tabs with no navigations.
158 void AddTabsToWindows(std::map<int, SessionTab*>* tabs,
159 std::map<int, SessionWindow*>* windows);
160
161 // Creates tabs and windows from the commands specified in |data|. The created
162 // tabs and windows are added to |tabs| and |windows| respectively, with the
163 // id of the active window set in |active_window_id|. It is up to the caller
164 // to delete the tabs and windows added to |tabs| and |windows|.
165 //
166 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is
167 // done by AddTabsToWindows.
168 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data,
169 std::map<int, SessionTab*>* tabs,
170 std::map<int, SessionWindow*>* windows,
171 SessionID::id_type* active_window_id);
172
173 // Searches for a pending command that can be replaced with command.
174 // If one is found, pending command is removed, command is added to
175 // the pending commands and true is returned.
176 bool ReplacePendingCommand(SessionCommand* command);
177
178 base::WeakPtrFactory<SessionServiceCommands> weak_factory_;
179
180 DISALLOW_COPY_AND_ASSIGN(SessionServiceCommands);
181 };
182
183 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_COMMANDS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698