| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_HELPER_H_ | 5 #ifndef CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_HELPER_H_ |
| 6 #define CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_HELPER_H_ | 6 #define CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_HELPER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/sessions/tab_restore_service.h" | 14 #include "chrome/browser/sessions/tab_restore_service.h" |
| 15 #include "chrome/browser/ui/host_desktop.h" | |
| 16 #include "components/sessions/session_id.h" | 15 #include "components/sessions/session_id.h" |
| 17 #include "components/sessions/session_types.h" | 16 #include "components/sessions/session_types.h" |
| 18 | 17 |
| 19 class Profile; | |
| 20 class TabRestoreService; | 18 class TabRestoreService; |
| 21 class TabRestoreServiceDelegate; | 19 class TabRestoreServiceDelegate; |
| 22 class TabRestoreServiceObserver; | 20 class TabRestoreServiceObserver; |
| 23 class TimeFactory; | 21 class TimeFactory; |
| 24 | 22 |
| 25 namespace content { | 23 namespace content { |
| 26 class NavigationController; | 24 class NavigationController; |
| 27 class WebContents; | 25 class WebContents; |
| 28 } | 26 } |
| 29 | 27 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 enum { | 62 enum { |
| 65 // Max number of entries we'll keep around. | 63 // Max number of entries we'll keep around. |
| 66 kMaxEntries = 25, | 64 kMaxEntries = 25, |
| 67 }; | 65 }; |
| 68 | 66 |
| 69 // Creates a new TabRestoreServiceHelper and provides an object that provides | 67 // Creates a new TabRestoreServiceHelper and provides an object that provides |
| 70 // the current time. The TabRestoreServiceHelper does not take ownership of | 68 // the current time. The TabRestoreServiceHelper does not take ownership of |
| 71 // |time_factory| and |observer|. Note that |observer| can also be NULL. | 69 // |time_factory| and |observer|. Note that |observer| can also be NULL. |
| 72 TabRestoreServiceHelper(TabRestoreService* tab_restore_service, | 70 TabRestoreServiceHelper(TabRestoreService* tab_restore_service, |
| 73 Observer* observer, | 71 Observer* observer, |
| 74 Profile* profile, | |
| 75 sessions::TabRestoreServiceClient* client, | 72 sessions::TabRestoreServiceClient* client, |
| 76 TimeFactory* time_factory); | 73 TimeFactory* time_factory); |
| 77 | 74 |
| 78 ~TabRestoreServiceHelper(); | 75 ~TabRestoreServiceHelper(); |
| 79 | 76 |
| 80 // Helper methods used to implement TabRestoreService. | 77 // Helper methods used to implement TabRestoreService. |
| 81 void AddObserver(TabRestoreServiceObserver* observer); | 78 void AddObserver(TabRestoreServiceObserver* observer); |
| 82 void RemoveObserver(TabRestoreServiceObserver* observer); | 79 void RemoveObserver(TabRestoreServiceObserver* observer); |
| 83 void CreateHistoricalTab(content::WebContents* contents, int index); | 80 void CreateHistoricalTab(content::WebContents* contents, int index); |
| 84 void BrowserClosing(TabRestoreServiceDelegate* delegate); | 81 void BrowserClosing(TabRestoreServiceDelegate* delegate); |
| 85 void BrowserClosed(TabRestoreServiceDelegate* delegate); | 82 void BrowserClosed(TabRestoreServiceDelegate* delegate); |
| 86 void ClearEntries(); | 83 void ClearEntries(); |
| 87 const Entries& entries() const; | 84 const Entries& entries() const; |
| 88 std::vector<content::WebContents*> RestoreMostRecentEntry( | 85 std::vector<content::WebContents*> RestoreMostRecentEntry( |
| 89 TabRestoreServiceDelegate* delegate, | 86 TabRestoreServiceDelegate* delegate, |
| 90 chrome::HostDesktopType host_desktop_type); | 87 int host_desktop_type); |
| 91 Tab* RemoveTabEntryById(SessionID::id_type id); | 88 Tab* RemoveTabEntryById(SessionID::id_type id); |
| 92 std::vector<content::WebContents*> RestoreEntryById( | 89 std::vector<content::WebContents*> RestoreEntryById( |
| 93 TabRestoreServiceDelegate* delegate, | 90 TabRestoreServiceDelegate* delegate, |
| 94 SessionID::id_type id, | 91 SessionID::id_type id, |
| 95 chrome::HostDesktopType host_desktop_type, | 92 int host_desktop_type, |
| 96 WindowOpenDisposition disposition); | 93 WindowOpenDisposition disposition); |
| 97 | 94 |
| 98 // Notifies observers the tabs have changed. | 95 // Notifies observers the tabs have changed. |
| 99 void NotifyTabsChanged(); | 96 void NotifyTabsChanged(); |
| 100 | 97 |
| 101 // Notifies observers the service has loaded. | 98 // Notifies observers the service has loaded. |
| 102 void NotifyLoaded(); | 99 void NotifyLoaded(); |
| 103 | 100 |
| 104 // Adds |entry| to the list of entries and takes ownership. If |prune| is true | 101 // Adds |entry| to the list of entries and takes ownership. If |prune| is true |
| 105 // |PruneAndNotify| is invoked. If |to_front| is true the entry is added to | 102 // |PruneAndNotify| is invoked. If |to_front| is true the entry is added to |
| (...skipping 21 matching lines...) Expand all Loading... |
| 127 // browser_id and pinned state from the browser. | 124 // browser_id and pinned state from the browser. |
| 128 void PopulateTab(Tab* tab, | 125 void PopulateTab(Tab* tab, |
| 129 int index, | 126 int index, |
| 130 TabRestoreServiceDelegate* delegate, | 127 TabRestoreServiceDelegate* delegate, |
| 131 content::NavigationController* controller); | 128 content::NavigationController* controller); |
| 132 | 129 |
| 133 // This is a helper function for RestoreEntryById() for restoring a single | 130 // This is a helper function for RestoreEntryById() for restoring a single |
| 134 // tab. If |delegate| is NULL, this creates a new window for the entry. This | 131 // tab. If |delegate| is NULL, this creates a new window for the entry. This |
| 135 // returns the TabRestoreServiceDelegate into which the tab was restored. | 132 // returns the TabRestoreServiceDelegate into which the tab was restored. |
| 136 // |disposition| will be respected, but if it is UNKNOWN then the tab's | 133 // |disposition| will be respected, but if it is UNKNOWN then the tab's |
| 137 // original attributes will be respected instead. If a new browser needs to be | 134 // original attributes will be respected instead. If a new |
| 138 // created for this tab, it will be created on the desktop specified by | 135 // TabRestoreServiceDelegate needs to be created for this tab, |
| 139 // |host_desktop_type|. If present, |contents| will be populated with the | 136 // |host_desktop_type| will be passed to |
| 140 // WebContents of the restored tab. | 137 // TabRestoreServiceClient::CreateTabRestoreServiceDelegate(). If present, |
| 141 TabRestoreServiceDelegate* RestoreTab( | 138 // |contents| will be populated with the WebContents of the restored tab. |
| 142 const Tab& tab, | 139 TabRestoreServiceDelegate* RestoreTab(const Tab& tab, |
| 143 TabRestoreServiceDelegate* delegate, | 140 TabRestoreServiceDelegate* delegate, |
| 144 chrome::HostDesktopType host_desktop_type, | 141 int host_desktop_type, |
| 145 WindowOpenDisposition disposition, | 142 WindowOpenDisposition disposition, |
| 146 content::WebContents** contents); | 143 content::WebContents** contents); |
| 147 | 144 |
| 148 // Returns true if |tab| has more than one navigation. If |tab| has more | 145 // Returns true if |tab| has more than one navigation. If |tab| has more |
| 149 // than one navigation |tab->current_navigation_index| is constrained based | 146 // than one navigation |tab->current_navigation_index| is constrained based |
| 150 // on the number of navigations. | 147 // on the number of navigations. |
| 151 static bool ValidateTab(Tab* tab); | 148 static bool ValidateTab(Tab* tab); |
| 152 | 149 |
| 153 // Validates all the tabs in a window, plus the window's active tab index. | 150 // Validates all the tabs in a window, plus the window's active tab index. |
| 154 static bool ValidateWindow(Window* window); | 151 static bool ValidateWindow(Window* window); |
| 155 | 152 |
| 156 // Returns true if |tab| is one we care about restoring. | 153 // Returns true if |tab| is one we care about restoring. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 167 void UpdateTabBrowserIDs(SessionID::id_type old_id, | 164 void UpdateTabBrowserIDs(SessionID::id_type old_id, |
| 168 SessionID::id_type new_id); | 165 SessionID::id_type new_id); |
| 169 | 166 |
| 170 // Gets the current time. This uses the time_factory_ if there is one. | 167 // Gets the current time. This uses the time_factory_ if there is one. |
| 171 base::Time TimeNow() const; | 168 base::Time TimeNow() const; |
| 172 | 169 |
| 173 TabRestoreService* const tab_restore_service_; | 170 TabRestoreService* const tab_restore_service_; |
| 174 | 171 |
| 175 Observer* const observer_; | 172 Observer* const observer_; |
| 176 | 173 |
| 177 Profile* const profile_; | |
| 178 | |
| 179 sessions::TabRestoreServiceClient* client_; | 174 sessions::TabRestoreServiceClient* client_; |
| 180 | 175 |
| 181 // Set of entries. They are ordered from most to least recent. | 176 // Set of entries. They are ordered from most to least recent. |
| 182 Entries entries_; | 177 Entries entries_; |
| 183 | 178 |
| 184 // Are we restoring a tab? If this is true we ignore requests to create a | 179 // Are we restoring a tab? If this is true we ignore requests to create a |
| 185 // historical tab. | 180 // historical tab. |
| 186 bool restoring_; | 181 bool restoring_; |
| 187 | 182 |
| 188 base::ObserverList<TabRestoreServiceObserver> observer_list_; | 183 base::ObserverList<TabRestoreServiceObserver> observer_list_; |
| 189 | 184 |
| 190 // Set of delegates that we've received a BrowserClosing method for but no | 185 // Set of delegates that we've received a BrowserClosing method for but no |
| 191 // corresponding BrowserClosed. We cache the set of delegates closing to | 186 // corresponding BrowserClosed. We cache the set of delegates closing to |
| 192 // avoid creating historical tabs for them. | 187 // avoid creating historical tabs for them. |
| 193 std::set<TabRestoreServiceDelegate*> closing_delegates_; | 188 std::set<TabRestoreServiceDelegate*> closing_delegates_; |
| 194 | 189 |
| 195 TimeFactory* const time_factory_; | 190 TimeFactory* const time_factory_; |
| 196 | 191 |
| 197 DISALLOW_COPY_AND_ASSIGN(TabRestoreServiceHelper); | 192 DISALLOW_COPY_AND_ASSIGN(TabRestoreServiceHelper); |
| 198 }; | 193 }; |
| 199 | 194 |
| 200 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_HELPER_H_ | 195 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_HELPER_H_ |
| OLD | NEW |