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 #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 | 18 |
19 class Browser; | 19 class Browser; |
20 class NavigationController; | 20 class NavigationController; |
21 class Profile; | 21 class Profile; |
22 struct SessionWindow; | 22 struct SessionWindow; |
23 class TabRestoreServiceObserver; | |
24 | 23 |
25 // TabRestoreService is responsible for maintaining the most recently closed | 24 // TabRestoreService is responsible for maintaining the most recently closed |
26 // tabs and windows. When a tab is closed | 25 // tabs and windows. When a tab is closed |
27 // TabRestoreService::CreateHistoricalTab is invoked and a Tab is created to | 26 // TabRestoreService::CreateHistoricalTab is invoked and a Tab is created to |
28 // represent the tab. Similarly, when a browser is closed, BrowserClosing is | 27 // represent the tab. Similarly, when a browser is closed, BrowserClosing is |
29 // invoked and a Window is created to represent the window. | 28 // invoked and a Window is created to represent the window. |
30 // | 29 // |
31 // To restore a tab/window from the TabRestoreService invoke RestoreEntryById | 30 // To restore a tab/window from the TabRestoreService invoke RestoreEntryById |
32 // or RestoreMostRecentEntry. | 31 // or RestoreMostRecentEntry. |
33 // | 32 // |
34 // To listen for changes to the set of entries managed by the TabRestoreService | 33 // To listen for changes to the set of entries managed by the TabRestoreService |
35 // add an observer. | 34 // add an observer. |
36 class TabRestoreService : public BaseSessionService { | 35 class TabRestoreService : public BaseSessionService { |
37 public: | 36 public: |
| 37 // Observer is notified when the set of entries managed by TabRestoreService |
| 38 // changes in some way. |
| 39 class Observer { |
| 40 public: |
| 41 // Sent when the set of entries changes in some way. |
| 42 virtual void TabRestoreServiceChanged(TabRestoreService* service) = 0; |
| 43 |
| 44 // Sent to all remaining Observers when TabRestoreService's |
| 45 // destructor is run. |
| 46 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) = 0; |
| 47 |
| 48 protected: |
| 49 virtual ~Observer() {} |
| 50 }; |
| 51 |
38 // Interface used to allow the test to provide a custom time. | 52 // Interface used to allow the test to provide a custom time. |
39 class TimeFactory { | 53 class TimeFactory { |
40 public: | 54 public: |
41 virtual ~TimeFactory(); | 55 virtual ~TimeFactory(); |
42 virtual base::Time TimeNow() = 0; | 56 virtual base::Time TimeNow() = 0; |
43 }; | 57 }; |
44 | 58 |
45 // The type of entry. | 59 // The type of entry. |
46 enum Type { | 60 enum Type { |
47 TAB, | 61 TAB, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 typedef std::list<Entry*> Entries; | 125 typedef std::list<Entry*> Entries; |
112 | 126 |
113 // Creates a new TabRestoreService and provides an object that provides the | 127 // Creates a new TabRestoreService and provides an object that provides the |
114 // current time. The TabRestoreService does not take ownership of the | 128 // current time. The TabRestoreService does not take ownership of the |
115 // |time_factory_|. | 129 // |time_factory_|. |
116 explicit TabRestoreService(Profile* profile, | 130 explicit TabRestoreService(Profile* profile, |
117 TimeFactory* time_factory_ = NULL); | 131 TimeFactory* time_factory_ = NULL); |
118 | 132 |
119 // Adds/removes an observer. TabRestoreService does not take ownership of | 133 // Adds/removes an observer. TabRestoreService does not take ownership of |
120 // the observer. | 134 // the observer. |
121 void AddObserver(TabRestoreServiceObserver* observer); | 135 void AddObserver(Observer* observer); |
122 void RemoveObserver(TabRestoreServiceObserver* observer); | 136 void RemoveObserver(Observer* observer); |
123 | 137 |
124 // Creates a Tab to represent |tab| and notifies observers the list of | 138 // Creates a Tab to represent |tab| and notifies observers the list of |
125 // entries has changed. | 139 // entries has changed. |
126 void CreateHistoricalTab(NavigationController* tab); | 140 void CreateHistoricalTab(NavigationController* tab); |
127 | 141 |
128 // Invoked when a browser is closing. If |browser| is a tabbed browser with | 142 // Invoked when a browser is closing. If |browser| is a tabbed browser with |
129 // at least one tab, a Window is created, added to entries and observers are | 143 // at least one tab, a Window is created, added to entries and observers are |
130 // notified. | 144 // notified. |
131 void BrowserClosing(Browser* browser); | 145 void BrowserClosing(Browser* browser); |
132 | 146 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 321 |
308 // Have the max number of entries ever been created? | 322 // Have the max number of entries ever been created? |
309 bool reached_max_; | 323 bool reached_max_; |
310 | 324 |
311 // The number of entries to write. | 325 // The number of entries to write. |
312 int entries_to_write_; | 326 int entries_to_write_; |
313 | 327 |
314 // Number of entries we've written. | 328 // Number of entries we've written. |
315 int entries_written_; | 329 int entries_written_; |
316 | 330 |
317 ObserverList<TabRestoreServiceObserver> observer_list_; | 331 ObserverList<Observer> observer_list_; |
318 | 332 |
319 // Set of tabs that we've received a BrowserClosing method for but no | 333 // Set of tabs that we've received a BrowserClosing method for but no |
320 // corresponding BrowserClosed. We cache the set of browsers closing to | 334 // corresponding BrowserClosed. We cache the set of browsers closing to |
321 // avoid creating historical tabs for them. | 335 // avoid creating historical tabs for them. |
322 std::set<Browser*> closing_browsers_; | 336 std::set<Browser*> closing_browsers_; |
323 | 337 |
324 // Used when loading previous tabs/session. | 338 // Used when loading previous tabs/session. |
325 CancelableRequestConsumer load_consumer_; | 339 CancelableRequestConsumer load_consumer_; |
326 | 340 |
327 // Results from previously closed tabs/sessions is first added here. When | 341 // Results from previously closed tabs/sessions is first added here. When |
328 // the results from both us and the session restore service have finished | 342 // the results from both us and the session restore service have finished |
329 // loading LoadStateChanged is invoked, which adds these entries to | 343 // loading LoadStateChanged is invoked, which adds these entries to |
330 // entries_. | 344 // entries_. |
331 std::vector<Entry*> staging_entries_; | 345 std::vector<Entry*> staging_entries_; |
332 | 346 |
333 TimeFactory* time_factory_; | 347 TimeFactory* time_factory_; |
334 | 348 |
335 DISALLOW_COPY_AND_ASSIGN(TabRestoreService); | 349 DISALLOW_COPY_AND_ASSIGN(TabRestoreService); |
336 }; | 350 }; |
337 | 351 |
338 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_ | 352 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_H_ |
339 | 353 |
OLD | NEW |