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

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

Issue 6677042: Decouple TabRestoreService from Browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Created 9 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/sessions/tab_restore_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 #include <set> 10 #include <set>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "chrome/browser/sessions/base_session_service.h" 15 #include "chrome/browser/sessions/base_session_service.h"
16 #include "chrome/browser/sessions/session_id.h" 16 #include "chrome/browser/sessions/session_id.h"
17 #include "chrome/browser/sessions/session_types.h" 17 #include "chrome/browser/sessions/session_types.h"
18 #include "content/browser/in_process_webkit/session_storage_namespace.h" 18 #include "content/browser/in_process_webkit/session_storage_namespace.h"
19 19
20 class Browser;
21 class NavigationController; 20 class NavigationController;
22 class Profile; 21 class Profile;
22 class TabRestoreServiceDelegate;
23 class TabRestoreServiceObserver; 23 class TabRestoreServiceObserver;
24 struct SessionWindow; 24 struct SessionWindow;
25 25
26 // TabRestoreService is responsible for maintaining the most recently closed 26 // TabRestoreService is responsible for maintaining the most recently closed
27 // tabs and windows. When a tab is closed 27 // tabs and windows. When a tab is closed
28 // TabRestoreService::CreateHistoricalTab is invoked and a Tab is created to 28 // TabRestoreService::CreateHistoricalTab is invoked and a Tab is created to
29 // represent the tab. Similarly, when a browser is closed, BrowserClosing is 29 // represent the tab. Similarly, when a browser is closed, BrowserClosing is
30 // invoked and a Window is created to represent the window. 30 // invoked and a Window is created to represent the window.
31 // 31 //
32 // To restore a tab/window from the TabRestoreService invoke RestoreEntryById 32 // To restore a tab/window from the TabRestoreService invoke RestoreEntryById
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 explicit TabRestoreService(Profile* profile, 120 explicit TabRestoreService(Profile* profile,
121 TimeFactory* time_factory_ = NULL); 121 TimeFactory* time_factory_ = NULL);
122 122
123 // Adds/removes an observer. TabRestoreService does not take ownership of 123 // Adds/removes an observer. TabRestoreService does not take ownership of
124 // the observer. 124 // the observer.
125 void AddObserver(TabRestoreServiceObserver* observer); 125 void AddObserver(TabRestoreServiceObserver* observer);
126 void RemoveObserver(TabRestoreServiceObserver* observer); 126 void RemoveObserver(TabRestoreServiceObserver* observer);
127 127
128 // Creates a Tab to represent |tab| and notifies observers the list of 128 // Creates a Tab to represent |tab| and notifies observers the list of
129 // entries has changed. 129 // entries has changed.
130 void CreateHistoricalTab(NavigationController* tab); 130 void CreateHistoricalTab(NavigationController* tab, int index);
131 131
132 // Invoked when a browser is closing. If |browser| is a tabbed browser with 132 // Invoked when a browser is closing. If |delegate| is a tabbed browser with
133 // at least one tab, a Window is created, added to entries and observers are 133 // at least one tab, a Window is created, added to entries and observers are
134 // notified. 134 // notified.
135 void BrowserClosing(Browser* browser); 135 void BrowserClosing(TabRestoreServiceDelegate* delegate);
136 136
137 // Invoked when the browser is done closing. 137 // Invoked when the browser is done closing.
138 void BrowserClosed(Browser* browser); 138 void BrowserClosed(TabRestoreServiceDelegate* delegate);
139 139
140 // Removes all entries from the list and notifies observers the list 140 // Removes all entries from the list and notifies observers the list
141 // of tabs has changed. 141 // of tabs has changed.
142 void ClearEntries(); 142 void ClearEntries();
143 143
144 // Returns the entries, ordered with most recently closed entries at the 144 // Returns the entries, ordered with most recently closed entries at the
145 // front. 145 // front.
146 virtual const Entries& entries() const; 146 virtual const Entries& entries() const;
147 147
148 // Restores the most recently closed entry. Does nothing if there are no 148 // Restores the most recently closed entry. Does nothing if there are no
149 // entries to restore. If the most recently restored entry is a tab, it is 149 // entries to restore. If the most recently restored entry is a tab, it is
150 // added to |browser|. 150 // added to |delegate|.
151 void RestoreMostRecentEntry(Browser* browser); 151 void RestoreMostRecentEntry(TabRestoreServiceDelegate* delegate);
152 152
153 // Restores an entry by id. If there is no entry with an id matching |id|, 153 // Restores an entry by id. If there is no entry with an id matching |id|,
154 // this does nothing. If |replace_existing_tab| is true and id identifies a 154 // this does nothing. If |replace_existing_tab| is true and id identifies a
155 // tab, the newly created tab replaces the selected tab in |browser|. If 155 // tab, the newly created tab replaces the selected tab in |delegate|. If
156 // |browser| is NULL, this creates a new window for the entry. 156 // |delegate| is NULL, this creates a new window for the entry.
157 void RestoreEntryById(Browser* browser, 157 void RestoreEntryById(TabRestoreServiceDelegate* delegate,
158 SessionID::id_type id, 158 SessionID::id_type id,
159 bool replace_existing_tab); 159 bool replace_existing_tab);
160 160
161 // Loads the tabs and previous session. This does nothing if the tabs 161 // Loads the tabs and previous session. This does nothing if the tabs
162 // from the previous session have already been loaded. 162 // from the previous session have already been loaded.
163 void LoadTabsFromLastSession(); 163 void LoadTabsFromLastSession();
164 164
165 // Max number of entries we'll keep around. 165 // Max number of entries we'll keep around.
166 static const size_t kMaxEntries; 166 static const size_t kMaxEntries;
167 167
(...skipping 19 matching lines...) Expand all
187 // Indicates we finished loading the last tabs (but not necessarily the 187 // Indicates we finished loading the last tabs (but not necessarily the
188 // last session). 188 // last session).
189 LOADED_LAST_TABS = 1 << 3, 189 LOADED_LAST_TABS = 1 << 3,
190 190
191 // Indicates we finished loading the last session (but not necessarily the 191 // Indicates we finished loading the last session (but not necessarily the
192 // last tabs). 192 // last tabs).
193 LOADED_LAST_SESSION = 1 << 4 193 LOADED_LAST_SESSION = 1 << 4
194 }; 194 };
195 195
196 // Populates the tab's navigations from the NavigationController, and its 196 // Populates the tab's navigations from the NavigationController, and its
197 // browser_id and tabstrip_index from the browser. 197 // browser_id and pinned state from the browser.
198 void PopulateTab(Tab* tab, 198 void PopulateTab(Tab* tab,
199 Browser* browser, 199 int index,
200 TabRestoreServiceDelegate* delegate,
200 NavigationController* controller); 201 NavigationController* controller);
201 202
202 // Notifies observers the tabs have changed. 203 // Notifies observers the tabs have changed.
203 void NotifyTabsChanged(); 204 void NotifyTabsChanged();
204 205
205 // Adds |entry| to the list of entries and takes ownership. If |prune| is true 206 // Adds |entry| to the list of entries and takes ownership. If |prune| is true
206 // |PruneAndNotify| is invoked. If |to_front| is true the entry is added to 207 // |PruneAndNotify| is invoked. If |to_front| is true the entry is added to
207 // the front, otherwise the back. Normal closes go to the front, but 208 // the front, otherwise the back. Normal closes go to the front, but
208 // tab/window closes from the previous session are added to the back. 209 // tab/window closes from the previous session are added to the back.
209 void AddEntry(Entry* entry, bool prune, bool to_front); 210 void AddEntry(Entry* entry, bool prune, bool to_front);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 Handle handle, 253 Handle handle,
253 scoped_refptr<InternalGetCommandsRequest> request); 254 scoped_refptr<InternalGetCommandsRequest> request);
254 255
255 // Populates |loaded_entries| with Entries from |request|. 256 // Populates |loaded_entries| with Entries from |request|.
256 void CreateEntriesFromCommands( 257 void CreateEntriesFromCommands(
257 scoped_refptr<InternalGetCommandsRequest> request, 258 scoped_refptr<InternalGetCommandsRequest> request,
258 std::vector<Entry*>* loaded_entries); 259 std::vector<Entry*>* loaded_entries);
259 260
260 // This is a helper function for RestoreEntryById() for restoring a single 261 // This is a helper function for RestoreEntryById() for restoring a single
261 // tab. If |replace_existing_tab| is true, the newly created tab replaces the 262 // tab. If |replace_existing_tab| is true, the newly created tab replaces the
262 // selected tab in |browser|. If |browser| is NULL, this creates a new window 263 // selected tab in |delegate|. If |delegate| is NULL, this creates a new
263 // for the entry. This returns the Browser into which the tab was restored. 264 // window for the entry. This returns the TabRestoreServiceDelegate into which
264 Browser* RestoreTab(const Tab& tab, 265 // the tab was restored.
265 Browser* browser, 266 TabRestoreServiceDelegate* RestoreTab(const Tab& tab,
266 bool replace_existing_tab); 267 TabRestoreServiceDelegate* delegate,
268 bool replace_existing_tab);
267 269
268 // Returns true if |tab| has more than one navigation. If |tab| has more 270 // Returns true if |tab| has more than one navigation. If |tab| has more
269 // than one navigation |tab->current_navigation_index| is constrained based 271 // than one navigation |tab->current_navigation_index| is constrained based
270 // on the number of navigations. 272 // on the number of navigations.
271 bool ValidateTab(Tab* tab); 273 bool ValidateTab(Tab* tab);
272 274
273 // Validates all entries in |entries|, deleting any with no navigations. 275 // Validates all entries in |entries|, deleting any with no navigations.
274 // This also deletes any entries beyond the max number of entries we can 276 // This also deletes any entries beyond the max number of entries we can
275 // hold. 277 // hold.
276 void ValidateAndDeleteEmptyEntries(std::vector<Entry*>* entries); 278 void ValidateAndDeleteEmptyEntries(std::vector<Entry*>* entries);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 bool reached_max_; 315 bool reached_max_;
314 316
315 // The number of entries to write. 317 // The number of entries to write.
316 int entries_to_write_; 318 int entries_to_write_;
317 319
318 // Number of entries we've written. 320 // Number of entries we've written.
319 int entries_written_; 321 int entries_written_;
320 322
321 ObserverList<TabRestoreServiceObserver> observer_list_; 323 ObserverList<TabRestoreServiceObserver> observer_list_;
322 324
323 // Set of tabs that we've received a BrowserClosing method for but no 325 // Set of delegates that we've received a BrowserClosing method for but no
324 // corresponding BrowserClosed. We cache the set of browsers closing to 326 // corresponding BrowserClosed. We cache the set of delegates closing to
325 // avoid creating historical tabs for them. 327 // avoid creating historical tabs for them.
326 std::set<Browser*> closing_browsers_; 328 std::set<TabRestoreServiceDelegate*> closing_delegates_;
327 329
328 // Used when loading previous tabs/session. 330 // Used when loading previous tabs/session.
329 CancelableRequestConsumer load_consumer_; 331 CancelableRequestConsumer load_consumer_;
330 332
331 // Results from previously closed tabs/sessions is first added here. When 333 // Results from previously closed tabs/sessions is first added here. When
332 // the results from both us and the session restore service have finished 334 // the results from both us and the session restore service have finished
333 // loading LoadStateChanged is invoked, which adds these entries to 335 // loading LoadStateChanged is invoked, which adds these entries to
334 // entries_. 336 // entries_.
335 std::vector<Entry*> staging_entries_; 337 std::vector<Entry*> staging_entries_;
336 338
337 TimeFactory* time_factory_; 339 TimeFactory* time_factory_;
338 340
339 DISALLOW_COPY_AND_ASSIGN(TabRestoreService); 341 DISALLOW_COPY_AND_ASSIGN(TabRestoreService);
340 }; 342 };
341 343
342 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_ 344 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_
343
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sessions/tab_restore_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698