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

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

Issue 6660028: Decouple TabRestoreService from Browser (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add doc references and fix lint 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
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 |browser| 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* browser);
sky 2011/03/11 17:40:37 rename argument to delegate (comment applies to al
torne_google.com 2011/03/14 15:07:25 Done.
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* browser);
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 |browser|.
151 void RestoreMostRecentEntry(Browser* browser); 151 void RestoreMostRecentEntry(TabRestoreServiceDelegate* browser);
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 |browser|. If
156 // |browser| is NULL, this creates a new window for the entry. 156 // |browser| is NULL, this creates a new window for the entry.
157 void RestoreEntryById(Browser* browser, 157 void RestoreEntryById(TabRestoreServiceDelegate* browser,
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* browser,
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 |browser|. If |browser| is NULL, this creates a new window
263 // for the entry. This returns the Browser into which the tab was restored. 264 // for the entry. This returns the Browser into which the tab was restored.
264 Browser* RestoreTab(const Tab& tab, 265 TabRestoreServiceDelegate* RestoreTab(const Tab& tab,
265 Browser* browser, 266 TabRestoreServiceDelegate* browser,
266 bool replace_existing_tab); 267 bool replace_existing_tab);
267 268
268 // Returns true if |tab| has more than one navigation. If |tab| has more 269 // Returns true if |tab| has more than one navigation. If |tab| has more
269 // than one navigation |tab->current_navigation_index| is constrained based 270 // than one navigation |tab->current_navigation_index| is constrained based
270 // on the number of navigations. 271 // on the number of navigations.
271 bool ValidateTab(Tab* tab); 272 bool ValidateTab(Tab* tab);
272 273
273 // Validates all entries in |entries|, deleting any with no navigations. 274 // Validates all entries in |entries|, deleting any with no navigations.
274 // This also deletes any entries beyond the max number of entries we can 275 // This also deletes any entries beyond the max number of entries we can
275 // hold. 276 // hold.
276 void ValidateAndDeleteEmptyEntries(std::vector<Entry*>* entries); 277 void ValidateAndDeleteEmptyEntries(std::vector<Entry*>* entries);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 bool reached_max_; 314 bool reached_max_;
314 315
315 // The number of entries to write. 316 // The number of entries to write.
316 int entries_to_write_; 317 int entries_to_write_;
317 318
318 // Number of entries we've written. 319 // Number of entries we've written.
319 int entries_written_; 320 int entries_written_;
320 321
321 ObserverList<TabRestoreServiceObserver> observer_list_; 322 ObserverList<TabRestoreServiceObserver> observer_list_;
322 323
323 // Set of tabs that we've received a BrowserClosing method for but no 324 // Set of tabs that we've received a BrowserClosing method for but no
sky 2011/03/11 17:40:37 tabs-> delegates. Field should be renamed to deleg
torne_google.com 2011/03/14 15:07:25 Done.
324 // corresponding BrowserClosed. We cache the set of browsers closing to 325 // corresponding BrowserClosed. We cache the set of browsers closing to
325 // avoid creating historical tabs for them. 326 // avoid creating historical tabs for them.
326 std::set<Browser*> closing_browsers_; 327 std::set<TabRestoreServiceDelegate*> closing_browsers_;
327 328
328 // Used when loading previous tabs/session. 329 // Used when loading previous tabs/session.
329 CancelableRequestConsumer load_consumer_; 330 CancelableRequestConsumer load_consumer_;
330 331
331 // Results from previously closed tabs/sessions is first added here. When 332 // Results from previously closed tabs/sessions is first added here. When
332 // the results from both us and the session restore service have finished 333 // the results from both us and the session restore service have finished
333 // loading LoadStateChanged is invoked, which adds these entries to 334 // loading LoadStateChanged is invoked, which adds these entries to
334 // entries_. 335 // entries_.
335 std::vector<Entry*> staging_entries_; 336 std::vector<Entry*> staging_entries_;
336 337
337 TimeFactory* time_factory_; 338 TimeFactory* time_factory_;
338 339
339 DISALLOW_COPY_AND_ASSIGN(TabRestoreService); 340 DISALLOW_COPY_AND_ASSIGN(TabRestoreService);
340 }; 341 };
341 342
342 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_ 343 #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') | chrome/browser/sessions/tab_restore_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698