| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_ | 6 #define CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 11 #include "base/time.h" | 12 #include "base/time.h" |
| 12 #include "chrome/browser/sessions/base_session_service.h" | 13 #include "chrome/browser/sessions/base_session_service.h" |
| 13 #include "chrome/browser/sessions/session_id.h" | 14 #include "chrome/browser/sessions/session_id.h" |
| 14 #include "chrome/browser/sessions/session_types.h" | 15 #include "chrome/browser/sessions/session_types.h" |
| 15 | 16 |
| 16 class Browser; | 17 class Browser; |
| 17 class NavigationController; | 18 class NavigationController; |
| 18 class Profile; | 19 class Profile; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // added to |browser|. | 120 // added to |browser|. |
| 120 void RestoreMostRecentEntry(Browser* browser); | 121 void RestoreMostRecentEntry(Browser* browser); |
| 121 | 122 |
| 122 // Restores an entry by id. If there is no entry with an id matching |id|, | 123 // Restores an entry by id. If there is no entry with an id matching |id|, |
| 123 // this does nothing. If |replace_existing_tab| is true and id identifies a | 124 // this does nothing. If |replace_existing_tab| is true and id identifies a |
| 124 // tab, the newly created tab replaces the selected tab in |browser|. | 125 // tab, the newly created tab replaces the selected tab in |browser|. |
| 125 void RestoreEntryById(Browser* browser, | 126 void RestoreEntryById(Browser* browser, |
| 126 SessionID::id_type id, | 127 SessionID::id_type id, |
| 127 bool replace_existing_tab); | 128 bool replace_existing_tab); |
| 128 | 129 |
| 129 // Loads the tabs from the previous session. This does nothing if the tabs | 130 // Loads the tabs and previous session. This does nothing if the tabs |
| 130 // from the previous session have already been loaded. | 131 // from the previous session have already been loaded. |
| 131 void LoadTabsFromLastSession(); | 132 void LoadTabsFromLastSession(); |
| 132 | 133 |
| 134 // Max number of entries we'll keep around. |
| 135 static const size_t kMaxEntries; |
| 136 |
| 133 protected: | 137 protected: |
| 134 virtual void Save(); | 138 virtual void Save(); |
| 135 | 139 |
| 136 private: | 140 private: |
| 141 // Used to indicate what has loaded. |
| 142 enum LoadState { |
| 143 // Indicates we haven't loaded anything. |
| 144 NOT_LOADED = 1 << 0, |
| 145 |
| 146 // Indicates we've asked for the last sessions and tabs but haven't gotten |
| 147 // the result back yet. |
| 148 LOADING = 1 << 2, |
| 149 |
| 150 // Indicates we finished loading the last tabs (but not necessarily the |
| 151 // last session). |
| 152 LOADED_LAST_TABS = 1 << 3, |
| 153 |
| 154 // Indicates we finished loading the last session (but not necessarily the |
| 155 // last tabs). |
| 156 LOADED_LAST_SESSION = 1 << 4 |
| 157 }; |
| 158 |
| 137 // Populates tabs->navigations from the NavigationController. | 159 // Populates tabs->navigations from the NavigationController. |
| 138 void PopulateTabFromController(NavigationController* controller, | 160 void PopulateTabFromController(NavigationController* controller, |
| 139 Tab* tab); | 161 Tab* tab); |
| 140 | 162 |
| 141 // Notifies observers the tabs have changed. | 163 // Notifies observers the tabs have changed. |
| 142 void NotifyTabsChanged(); | 164 void NotifyTabsChanged(); |
| 143 | 165 |
| 144 // Adds |entry| to the list of entries. If |prune| is true |PruneAndNotify| | 166 // Adds |entry| to the list of entries. If |prune| is true |PruneAndNotify| |
| 145 // is invoked. If |to_front| is true the entry is added to the front, | 167 // is invoked. If |to_front| is true the entry is added to the front, |
| 146 // otherwise the back. Normal closes go to the front, but tab/window closes | 168 // otherwise the back. Normal closes go to the front, but tab/window closes |
| (...skipping 25 matching lines...) Expand all Loading... |
| 172 | 194 |
| 173 // Creates a restore command. | 195 // Creates a restore command. |
| 174 SessionCommand* CreateRestoredEntryCommand(SessionID::id_type entry_id); | 196 SessionCommand* CreateRestoredEntryCommand(SessionID::id_type entry_id); |
| 175 | 197 |
| 176 // Returns the index to persist as the selected index. This is the same | 198 // Returns the index to persist as the selected index. This is the same |
| 177 // as |tab.current_navigation_index| unless the entry at | 199 // as |tab.current_navigation_index| unless the entry at |
| 178 // |tab.current_navigation_index| shouldn't be persisted. Returns -1 if | 200 // |tab.current_navigation_index| shouldn't be persisted. Returns -1 if |
| 179 // no valid navigation to persist. | 201 // no valid navigation to persist. |
| 180 int GetSelectedNavigationIndexToPersist(const Tab& tab); | 202 int GetSelectedNavigationIndexToPersist(const Tab& tab); |
| 181 | 203 |
| 182 // Invoked when we've loaded the session commands from the previous run. | 204 // Invoked when we've loaded the session commands that identify the |
| 183 // This creates entries and adds them to entries_, notifying the observer. | 205 // previously closed tabs. This creates entries, adds them to |
| 206 // staging_entries_, and invokes LoadState. |
| 184 void OnGotLastSessionCommands( | 207 void OnGotLastSessionCommands( |
| 185 Handle handle, | 208 Handle handle, |
| 186 scoped_refptr<InternalGetCommandsRequest> request); | 209 scoped_refptr<InternalGetCommandsRequest> request); |
| 187 | 210 |
| 211 // Populates |loaded_entries| with Entries from |request|. |
| 212 void CreateEntriesFromCommands( |
| 213 scoped_refptr<InternalGetCommandsRequest> request, |
| 214 std::vector<Entry*>* loaded_entries); |
| 215 |
| 188 // Returns true if |tab| has more than one navigation. If |tab| has more | 216 // Returns true if |tab| has more than one navigation. If |tab| has more |
| 189 // than one navigation |tab->current_navigation_index| is constrained based | 217 // than one navigation |tab->current_navigation_index| is constrained based |
| 190 // on the number of navigations. | 218 // on the number of navigations. |
| 191 bool ValidateTab(Tab* tab); | 219 bool ValidateTab(Tab* tab); |
| 192 | 220 |
| 193 // Validates all entries in |entries|, deleting any with no navigations. | 221 // Validates all entries in |entries|, deleting any with no navigations. |
| 194 // This also deletes any entries beyond the max number of entries we can | 222 // This also deletes any entries beyond the max number of entries we can |
| 195 // hold. | 223 // hold. |
| 196 void ValidateAndDeleteEmptyEntries(std::vector<Entry*>* entries); | 224 void ValidateAndDeleteEmptyEntries(std::vector<Entry*>* entries); |
| 197 | 225 |
| 226 // Callback from SessionService when we've received the windows from the |
| 227 // previous session. This creates and add entries to |staging_entries_| |
| 228 // and invokes LoadStateChanged. |
| 229 void OnGotPreviousSession(Handle handle, |
| 230 std::vector<SessionWindow*>* windows); |
| 231 |
| 232 // Creates and add entries to |entries| for each of the windows in |windows|. |
| 233 void CreateEntriesFromWindows( |
| 234 std::vector<SessionWindow*>* windows, |
| 235 std::vector<Entry*>* entries); |
| 236 |
| 237 // Converts a SessionWindow into a Window, returning true on success. |
| 238 bool ConvertSessionWindowToWindow( |
| 239 SessionWindow* session_window, |
| 240 Window* window); |
| 241 |
| 242 // Invoked when previous tabs or session is loaded. If both have finished |
| 243 // loading the entries in staging_entries_ are added to entries_ and |
| 244 // observers are notified. |
| 245 void LoadStateChanged(); |
| 246 |
| 198 // Set of entries. | 247 // Set of entries. |
| 199 Entries entries_; | 248 Entries entries_; |
| 200 | 249 |
| 201 // Whether we've loaded the last session. | 250 // Whether we've loaded the last session. |
| 202 bool loaded_last_session_; | 251 int load_state_; |
| 203 | 252 |
| 204 // Are we restoring a tab? If this is true we ignore requests to create a | 253 // Are we restoring a tab? If this is true we ignore requests to create a |
| 205 // historical tab. | 254 // historical tab. |
| 206 bool restoring_; | 255 bool restoring_; |
| 207 | 256 |
| 208 // Have the max number of entries ever been created? | 257 // Have the max number of entries ever been created? |
| 209 bool reached_max_; | 258 bool reached_max_; |
| 210 | 259 |
| 211 // The number of entries to write. | 260 // The number of entries to write. |
| 212 int entries_to_write_; | 261 int entries_to_write_; |
| 213 | 262 |
| 214 // Number of entries we've written. | 263 // Number of entries we've written. |
| 215 int entries_written_; | 264 int entries_written_; |
| 216 | 265 |
| 217 ObserverList<Observer> observer_list_; | 266 ObserverList<Observer> observer_list_; |
| 218 | 267 |
| 219 // Set of tabs that we've received a BrowserClosing method for but no | 268 // Set of tabs that we've received a BrowserClosing method for but no |
| 220 // corresponding BrowserClosed. We cache the set of browsers closing to | 269 // corresponding BrowserClosed. We cache the set of browsers closing to |
| 221 // avoid creating historical tabs for them. | 270 // avoid creating historical tabs for them. |
| 222 std::set<Browser*> closing_browsers_; | 271 std::set<Browser*> closing_browsers_; |
| 223 | 272 |
| 224 // Used when loading commands from the previous session. | 273 // Used when loading previous tabs/session. |
| 225 CancelableRequestConsumer load_tabs_consumer_; | 274 CancelableRequestConsumer load_consumer_; |
| 275 |
| 276 // Results from previously closed tabs/sessions is first added here. When |
| 277 // the results from both us and the session restore service have finished |
| 278 // loading LoadStateChanged is invoked, which adds these entries to |
| 279 // entries_. |
| 280 std::vector<Entry*> staging_entries_; |
| 226 | 281 |
| 227 DISALLOW_COPY_AND_ASSIGN(TabRestoreService); | 282 DISALLOW_COPY_AND_ASSIGN(TabRestoreService); |
| 228 }; | 283 }; |
| 229 | 284 |
| 230 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_ | 285 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_ |
| OLD | NEW |