OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ | 5 #ifndef COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ |
6 #define COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ | 6 #define COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
15 #include "components/sessions/core/tab_restore_service_client.h" | 15 #include "components/sessions/core/tab_restore_service_client.h" |
16 #include "components/sessions/serialized_navigation_entry.h" | 16 #include "components/sessions/serialized_navigation_entry.h" |
17 #include "components/sessions/session_id.h" | 17 #include "components/sessions/session_id.h" |
18 #include "components/sessions/session_types.h" | 18 #include "components/sessions/session_types.h" |
19 #include "components/sessions/sessions_export.h" | 19 #include "components/sessions/sessions_export.h" |
20 #include "ui/base/window_open_disposition.h" | 20 #include "ui/base/window_open_disposition.h" |
21 | 21 |
| 22 namespace sessions { |
| 23 |
| 24 class LiveTab; |
22 class TabRestoreServiceDelegate; | 25 class TabRestoreServiceDelegate; |
23 class TabRestoreServiceObserver; | 26 class TabRestoreServiceObserver; |
24 | 27 |
25 namespace sessions { | |
26 class LiveTab; | |
27 } | |
28 | |
29 // TabRestoreService is responsible for maintaining the most recently closed | 28 // TabRestoreService is responsible for maintaining the most recently closed |
30 // tabs and windows. When a tab is closed | 29 // tabs and windows. When a tab is closed |
31 // TabRestoreService::CreateHistoricalTab is invoked and a Tab is created to | 30 // TabRestoreService::CreateHistoricalTab is invoked and a Tab is created to |
32 // represent the tab. Similarly, when a browser is closed, BrowserClosing is | 31 // represent the tab. Similarly, when a browser is closed, BrowserClosing is |
33 // invoked and a Window is created to represent the window. | 32 // invoked and a Window is created to represent the window. |
34 // | 33 // |
35 // To restore a tab/window from the TabRestoreService invoke RestoreEntryById | 34 // To restore a tab/window from the TabRestoreService invoke RestoreEntryById |
36 // or RestoreMostRecentEntry. | 35 // or RestoreMostRecentEntry. |
37 // | 36 // |
38 // To listen for changes to the set of entries managed by the TabRestoreService | 37 // To listen for changes to the set of entries managed by the TabRestoreService |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 struct SESSIONS_EXPORT Tab : public Entry { | 76 struct SESSIONS_EXPORT Tab : public Entry { |
78 Tab(); | 77 Tab(); |
79 Tab(const Tab& tab); | 78 Tab(const Tab& tab); |
80 ~Tab() override; | 79 ~Tab() override; |
81 | 80 |
82 Tab& operator=(const Tab& tab); | 81 Tab& operator=(const Tab& tab); |
83 | 82 |
84 bool has_browser() const { return browser_id > 0; } | 83 bool has_browser() const { return browser_id > 0; } |
85 | 84 |
86 // The navigations. | 85 // The navigations. |
87 std::vector<sessions::SerializedNavigationEntry> navigations; | 86 std::vector<SerializedNavigationEntry> navigations; |
88 | 87 |
89 // Index of the selected navigation in navigations. | 88 // Index of the selected navigation in navigations. |
90 int current_navigation_index; | 89 int current_navigation_index; |
91 | 90 |
92 // The ID of the browser to which this tab belonged, so it can be restored | 91 // The ID of the browser to which this tab belonged, so it can be restored |
93 // there. May be 0 (an invalid SessionID) when restoring an entire session. | 92 // there. May be 0 (an invalid SessionID) when restoring an entire session. |
94 SessionID::id_type browser_id; | 93 SessionID::id_type browser_id; |
95 | 94 |
96 // Index within the tab strip. May be -1 for an unknown index. | 95 // Index within the tab strip. May be -1 for an unknown index. |
97 int tabstrip_index; | 96 int tabstrip_index; |
98 | 97 |
99 // True if the tab was pinned. | 98 // True if the tab was pinned. |
100 bool pinned; | 99 bool pinned; |
101 | 100 |
102 // If non-empty gives the id of the extension for the tab. | 101 // If non-empty gives the id of the extension for the tab. |
103 std::string extension_app_id; | 102 std::string extension_app_id; |
104 | 103 |
105 // The associated client data. | 104 // The associated client data. |
106 scoped_ptr<sessions::TabClientData> client_data; | 105 scoped_ptr<TabClientData> client_data; |
107 | 106 |
108 // The user agent override used for the tab's navigations (if applicable). | 107 // The user agent override used for the tab's navigations (if applicable). |
109 std::string user_agent_override; | 108 std::string user_agent_override; |
110 }; | 109 }; |
111 | 110 |
112 // Represents a previously open window. | 111 // Represents a previously open window. |
113 struct SESSIONS_EXPORT Window : public Entry { | 112 struct SESSIONS_EXPORT Window : public Entry { |
114 Window(); | 113 Window(); |
115 ~Window() override; | 114 ~Window() override; |
116 | 115 |
(...skipping 11 matching lines...) Expand all Loading... |
128 | 127 |
129 ~TabRestoreService() override; | 128 ~TabRestoreService() override; |
130 | 129 |
131 // Adds/removes an observer. TabRestoreService does not take ownership of | 130 // Adds/removes an observer. TabRestoreService does not take ownership of |
132 // the observer. | 131 // the observer. |
133 virtual void AddObserver(TabRestoreServiceObserver* observer) = 0; | 132 virtual void AddObserver(TabRestoreServiceObserver* observer) = 0; |
134 virtual void RemoveObserver(TabRestoreServiceObserver* observer) = 0; | 133 virtual void RemoveObserver(TabRestoreServiceObserver* observer) = 0; |
135 | 134 |
136 // Creates a Tab to represent |live_tab| and notifies observers the list of | 135 // Creates a Tab to represent |live_tab| and notifies observers the list of |
137 // entries has changed. | 136 // entries has changed. |
138 virtual void CreateHistoricalTab(sessions::LiveTab* live_tab, int index) = 0; | 137 virtual void CreateHistoricalTab(LiveTab* live_tab, int index) = 0; |
139 | 138 |
140 // Invoked when a browser is closing. If |delegate| is a tabbed browser with | 139 // Invoked when a browser is closing. If |delegate| is a tabbed browser with |
141 // at least one tab, a Window is created, added to entries and observers are | 140 // at least one tab, a Window is created, added to entries and observers are |
142 // notified. | 141 // notified. |
143 virtual void BrowserClosing(TabRestoreServiceDelegate* delegate) = 0; | 142 virtual void BrowserClosing(TabRestoreServiceDelegate* delegate) = 0; |
144 | 143 |
145 // Invoked when the browser is done closing. | 144 // Invoked when the browser is done closing. |
146 virtual void BrowserClosed(TabRestoreServiceDelegate* delegate) = 0; | 145 virtual void BrowserClosed(TabRestoreServiceDelegate* delegate) = 0; |
147 | 146 |
148 // Removes all entries from the list and notifies observers the list | 147 // Removes all entries from the list and notifies observers the list |
149 // of tabs has changed. | 148 // of tabs has changed. |
150 virtual void ClearEntries() = 0; | 149 virtual void ClearEntries() = 0; |
151 | 150 |
152 // Returns the entries, ordered with most recently closed entries at the | 151 // Returns the entries, ordered with most recently closed entries at the |
153 // front. | 152 // front. |
154 virtual const Entries& entries() const = 0; | 153 virtual const Entries& entries() const = 0; |
155 | 154 |
156 // Restores the most recently closed entry. Does nothing if there are no | 155 // Restores the most recently closed entry. Does nothing if there are no |
157 // entries to restore. If the most recently restored entry is a tab, it is | 156 // entries to restore. If the most recently restored entry is a tab, it is |
158 // added to |delegate|. |host_desktop_type| is a value that is opaque to this | 157 // added to |delegate|. |host_desktop_type| is a value that is opaque to this |
159 // class and will be used only to pass back to the embedder via | 158 // class and will be used only to pass back to the embedder via |
160 // TabRestoreServiceClient if necessary. Returns the LiveTab instances of the | 159 // TabRestoreServiceClient if necessary. Returns the LiveTab instances of the |
161 // restored tab(s). | 160 // restored tab(s). |
162 virtual std::vector<sessions::LiveTab*> RestoreMostRecentEntry( | 161 virtual std::vector<LiveTab*> RestoreMostRecentEntry( |
163 TabRestoreServiceDelegate* delegate, | 162 TabRestoreServiceDelegate* delegate, |
164 int host_desktop_type) = 0; | 163 int host_desktop_type) = 0; |
165 | 164 |
166 // Removes the Tab with id |id| from the list and returns it; ownership is | 165 // Removes the Tab with id |id| from the list and returns it; ownership is |
167 // passed to the caller. | 166 // passed to the caller. |
168 virtual Tab* RemoveTabEntryById(SessionID::id_type id) = 0; | 167 virtual Tab* RemoveTabEntryById(SessionID::id_type id) = 0; |
169 | 168 |
170 // Restores an entry by id. If there is no entry with an id matching |id|, | 169 // Restores an entry by id. If there is no entry with an id matching |id|, |
171 // this does nothing. If |delegate| is NULL, this creates a new window for the | 170 // this does nothing. If |delegate| is NULL, this creates a new window for the |
172 // entry. |disposition| is respected, but the attributes (tabstrip index, | 171 // entry. |disposition| is respected, but the attributes (tabstrip index, |
173 // browser window) of the tab when it was closed will be respected if | 172 // browser window) of the tab when it was closed will be respected if |
174 // disposition is UNKNOWN. |host_desktop_type| is a value that is opaque to | 173 // disposition is UNKNOWN. |host_desktop_type| is a value that is opaque to |
175 // this class and will be used only to pass back to the embedder via | 174 // this class and will be used only to pass back to the embedder via |
176 // TabRestoreServiceClient if necessary. Returns the LiveTab instances of the | 175 // TabRestoreServiceClient if necessary. Returns the LiveTab instances of the |
177 // restored tab(s). | 176 // restored tab(s). |
178 virtual std::vector<sessions::LiveTab*> RestoreEntryById( | 177 virtual std::vector<LiveTab*> RestoreEntryById( |
179 TabRestoreServiceDelegate* delegate, | 178 TabRestoreServiceDelegate* delegate, |
180 SessionID::id_type id, | 179 SessionID::id_type id, |
181 int host_desktop_type, | 180 int host_desktop_type, |
182 WindowOpenDisposition disposition) = 0; | 181 WindowOpenDisposition disposition) = 0; |
183 | 182 |
184 // Loads the tabs and previous session. This does nothing if the tabs | 183 // Loads the tabs and previous session. This does nothing if the tabs |
185 // from the previous session have already been loaded. | 184 // from the previous session have already been loaded. |
186 virtual void LoadTabsFromLastSession() = 0; | 185 virtual void LoadTabsFromLastSession() = 0; |
187 | 186 |
188 // Returns true if the tab entries have been loaded. | 187 // Returns true if the tab entries have been loaded. |
189 virtual bool IsLoaded() const = 0; | 188 virtual bool IsLoaded() const = 0; |
190 | 189 |
191 // Deletes the last session. | 190 // Deletes the last session. |
192 virtual void DeleteLastSession() = 0; | 191 virtual void DeleteLastSession() = 0; |
193 }; | 192 }; |
194 | 193 |
| 194 } // namespace sessions |
| 195 |
195 #endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ | 196 #endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ |
OLD | NEW |