| 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" | 15 #include "chrome/browser/ui/host_desktop.h" |
| 16 #include "components/sessions/session_id.h" | 16 #include "components/sessions/session_id.h" |
| 17 #include "components/sessions/session_types.h" | 17 #include "components/sessions/session_types.h" |
| 18 | 18 |
| 19 class Profile; | 19 class Profile; |
| 20 class TabRestoreService; | 20 class TabRestoreService; |
| 21 class TabRestoreServiceDelegate; | 21 class TabRestoreServiceDelegate; |
| 22 class TabRestoreServiceObserver; | 22 class TabRestoreServiceObserver; |
| 23 class TimeFactory; | 23 class TimeFactory; |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 class NavigationController; | 26 class NavigationController; |
| 27 class WebContents; | 27 class WebContents; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace sessions { |
| 31 class TabRestoreServiceClient; |
| 32 } |
| 33 |
| 30 // Helper class used to implement InMemoryTabRestoreService and | 34 // Helper class used to implement InMemoryTabRestoreService and |
| 31 // PersistentTabRestoreService. See tab_restore_service.h for method-level | 35 // PersistentTabRestoreService. See tab_restore_service.h for method-level |
| 32 // comments. | 36 // comments. |
| 33 class TabRestoreServiceHelper { | 37 class TabRestoreServiceHelper { |
| 34 public: | 38 public: |
| 35 typedef TabRestoreService::Entries Entries; | 39 typedef TabRestoreService::Entries Entries; |
| 36 typedef TabRestoreService::Entry Entry; | 40 typedef TabRestoreService::Entry Entry; |
| 37 typedef TabRestoreService::Tab Tab; | 41 typedef TabRestoreService::Tab Tab; |
| 38 typedef TabRestoreService::TimeFactory TimeFactory; | 42 typedef TabRestoreService::TimeFactory TimeFactory; |
| 39 typedef TabRestoreService::Window Window; | 43 typedef TabRestoreService::Window Window; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 61 // Max number of entries we'll keep around. | 65 // Max number of entries we'll keep around. |
| 62 kMaxEntries = 25, | 66 kMaxEntries = 25, |
| 63 }; | 67 }; |
| 64 | 68 |
| 65 // Creates a new TabRestoreServiceHelper and provides an object that provides | 69 // Creates a new TabRestoreServiceHelper and provides an object that provides |
| 66 // the current time. The TabRestoreServiceHelper does not take ownership of | 70 // the current time. The TabRestoreServiceHelper does not take ownership of |
| 67 // |time_factory| and |observer|. Note that |observer| can also be NULL. | 71 // |time_factory| and |observer|. Note that |observer| can also be NULL. |
| 68 TabRestoreServiceHelper(TabRestoreService* tab_restore_service, | 72 TabRestoreServiceHelper(TabRestoreService* tab_restore_service, |
| 69 Observer* observer, | 73 Observer* observer, |
| 70 Profile* profile, | 74 Profile* profile, |
| 75 sessions::TabRestoreServiceClient* client, |
| 71 TimeFactory* time_factory); | 76 TimeFactory* time_factory); |
| 72 | 77 |
| 73 ~TabRestoreServiceHelper(); | 78 ~TabRestoreServiceHelper(); |
| 74 | 79 |
| 75 // Helper methods used to implement TabRestoreService. | 80 // Helper methods used to implement TabRestoreService. |
| 76 void AddObserver(TabRestoreServiceObserver* observer); | 81 void AddObserver(TabRestoreServiceObserver* observer); |
| 77 void RemoveObserver(TabRestoreServiceObserver* observer); | 82 void RemoveObserver(TabRestoreServiceObserver* observer); |
| 78 void CreateHistoricalTab(content::WebContents* contents, int index); | 83 void CreateHistoricalTab(content::WebContents* contents, int index); |
| 79 void BrowserClosing(TabRestoreServiceDelegate* delegate); | 84 void BrowserClosing(TabRestoreServiceDelegate* delegate); |
| 80 void BrowserClosed(TabRestoreServiceDelegate* delegate); | 85 void BrowserClosed(TabRestoreServiceDelegate* delegate); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 147 |
| 143 // Returns true if |tab| has more than one navigation. If |tab| has more | 148 // Returns true if |tab| has more than one navigation. If |tab| has more |
| 144 // than one navigation |tab->current_navigation_index| is constrained based | 149 // than one navigation |tab->current_navigation_index| is constrained based |
| 145 // on the number of navigations. | 150 // on the number of navigations. |
| 146 static bool ValidateTab(Tab* tab); | 151 static bool ValidateTab(Tab* tab); |
| 147 | 152 |
| 148 // Validates all the tabs in a window, plus the window's active tab index. | 153 // Validates all the tabs in a window, plus the window's active tab index. |
| 149 static bool ValidateWindow(Window* window); | 154 static bool ValidateWindow(Window* window); |
| 150 | 155 |
| 151 // Returns true if |tab| is one we care about restoring. | 156 // Returns true if |tab| is one we care about restoring. |
| 152 static bool IsTabInteresting(const Tab* tab); | 157 bool IsTabInteresting(const Tab* tab); |
| 153 | 158 |
| 154 // Checks whether |window| is interesting --- if it only contains a single, | 159 // Checks whether |window| is interesting --- if it only contains a single, |
| 155 // uninteresting tab, it's not interesting. | 160 // uninteresting tab, it's not interesting. |
| 156 static bool IsWindowInteresting(const Window* window); | 161 bool IsWindowInteresting(const Window* window); |
| 157 | 162 |
| 158 // Validates and checks |entry| for interesting. | 163 // Validates and checks |entry| for interesting. |
| 159 static bool FilterEntry(Entry* entry); | 164 bool FilterEntry(Entry* entry); |
| 160 | 165 |
| 161 // Finds tab entries with the old browser_id and sets it to the new one. | 166 // Finds tab entries with the old browser_id and sets it to the new one. |
| 162 void UpdateTabBrowserIDs(SessionID::id_type old_id, | 167 void UpdateTabBrowserIDs(SessionID::id_type old_id, |
| 163 SessionID::id_type new_id); | 168 SessionID::id_type new_id); |
| 164 | 169 |
| 165 // Gets the current time. This uses the time_factory_ if there is one. | 170 // Gets the current time. This uses the time_factory_ if there is one. |
| 166 base::Time TimeNow() const; | 171 base::Time TimeNow() const; |
| 167 | 172 |
| 168 TabRestoreService* const tab_restore_service_; | 173 TabRestoreService* const tab_restore_service_; |
| 169 | 174 |
| 170 Observer* const observer_; | 175 Observer* const observer_; |
| 171 | 176 |
| 172 Profile* const profile_; | 177 Profile* const profile_; |
| 173 | 178 |
| 179 sessions::TabRestoreServiceClient* client_; |
| 180 |
| 174 // Set of entries. They are ordered from most to least recent. | 181 // Set of entries. They are ordered from most to least recent. |
| 175 Entries entries_; | 182 Entries entries_; |
| 176 | 183 |
| 177 // Are we restoring a tab? If this is true we ignore requests to create a | 184 // Are we restoring a tab? If this is true we ignore requests to create a |
| 178 // historical tab. | 185 // historical tab. |
| 179 bool restoring_; | 186 bool restoring_; |
| 180 | 187 |
| 181 base::ObserverList<TabRestoreServiceObserver> observer_list_; | 188 base::ObserverList<TabRestoreServiceObserver> observer_list_; |
| 182 | 189 |
| 183 // Set of delegates that we've received a BrowserClosing method for but no | 190 // Set of delegates that we've received a BrowserClosing method for but no |
| 184 // corresponding BrowserClosed. We cache the set of delegates closing to | 191 // corresponding BrowserClosed. We cache the set of delegates closing to |
| 185 // avoid creating historical tabs for them. | 192 // avoid creating historical tabs for them. |
| 186 std::set<TabRestoreServiceDelegate*> closing_delegates_; | 193 std::set<TabRestoreServiceDelegate*> closing_delegates_; |
| 187 | 194 |
| 188 TimeFactory* const time_factory_; | 195 TimeFactory* const time_factory_; |
| 189 | 196 |
| 190 DISALLOW_COPY_AND_ASSIGN(TabRestoreServiceHelper); | 197 DISALLOW_COPY_AND_ASSIGN(TabRestoreServiceHelper); |
| 191 }; | 198 }; |
| 192 | 199 |
| 193 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_HELPER_H_ | 200 #endif // CHROME_BROWSER_SESSIONS_TAB_RESTORE_SERVICE_HELPER_H_ |
| OLD | NEW |