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

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

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

Powered by Google App Engine
This is Rietveld 408576698