| 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 COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ | 5 #ifndef COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ |
| 6 #define COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ | 6 #define COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 // Helper methods used to implement TabRestoreService. | 72 // Helper methods used to implement TabRestoreService. |
| 73 void AddObserver(TabRestoreServiceObserver* observer); | 73 void AddObserver(TabRestoreServiceObserver* observer); |
| 74 void RemoveObserver(TabRestoreServiceObserver* observer); | 74 void RemoveObserver(TabRestoreServiceObserver* observer); |
| 75 void CreateHistoricalTab(LiveTab* live_tab, int index); | 75 void CreateHistoricalTab(LiveTab* live_tab, int index); |
| 76 void BrowserClosing(LiveTabContext* context); | 76 void BrowserClosing(LiveTabContext* context); |
| 77 void BrowserClosed(LiveTabContext* context); | 77 void BrowserClosed(LiveTabContext* context); |
| 78 void ClearEntries(); | 78 void ClearEntries(); |
| 79 const Entries& entries() const; | 79 const Entries& entries() const; |
| 80 std::vector<LiveTab*> RestoreMostRecentEntry(LiveTabContext* context); | 80 std::vector<LiveTab*> RestoreMostRecentEntry(LiveTabContext* context); |
| 81 Tab* RemoveTabEntryById(SessionID::id_type id); | 81 std::unique_ptr<Tab> RemoveTabEntryById(SessionID::id_type id); |
| 82 std::vector<LiveTab*> RestoreEntryById(LiveTabContext* context, | 82 std::vector<LiveTab*> RestoreEntryById(LiveTabContext* context, |
| 83 SessionID::id_type id, | 83 SessionID::id_type id, |
| 84 WindowOpenDisposition disposition); | 84 WindowOpenDisposition disposition); |
| 85 | 85 |
| 86 // Notifies observers the tabs have changed. | 86 // Notifies observers the tabs have changed. |
| 87 void NotifyTabsChanged(); | 87 void NotifyTabsChanged(); |
| 88 | 88 |
| 89 // Notifies observers the service has loaded. | 89 // Notifies observers the service has loaded. |
| 90 void NotifyLoaded(); | 90 void NotifyLoaded(); |
| 91 | 91 |
| 92 // Adds |entry| to the list of entries and takes ownership. If |prune| is true | 92 // Adds |entry| to the list of entries. If |prune| is true |PruneAndNotify| is |
| 93 // |PruneAndNotify| is invoked. If |to_front| is true the entry is added to | 93 // invoked. If |to_front| is true the entry is added to the front, otherwise |
| 94 // the front, otherwise the back. Normal closes go to the front, but | 94 // the back. Normal closes go to the front, but tab/window closes from the |
| 95 // tab/window closes from the previous session are added to the back. | 95 // previous session are added to the back. |
| 96 void AddEntry(Entry* entry, bool prune, bool to_front); | 96 void AddEntry(std::unique_ptr<Entry> entry, bool prune, bool to_front); |
| 97 | 97 |
| 98 // Prunes |entries_| to contain only kMaxEntries, and removes uninteresting | 98 // Prunes |entries_| to contain only kMaxEntries, and removes uninteresting |
| 99 // entries. | 99 // entries. |
| 100 void PruneEntries(); | 100 void PruneEntries(); |
| 101 | 101 |
| 102 // Returns an iterator into |entries_| whose id matches |id|. If |id| | 102 // Returns an iterator into |entries_| whose id matches |id|. If |id| |
| 103 // identifies a Window, then its iterator position will be returned. If it | 103 // identifies a Window, then its iterator position will be returned. If it |
| 104 // identifies a tab, then the iterator position of the Window in which the Tab | 104 // identifies a tab, then the iterator position of the Window in which the Tab |
| 105 // resides is returned. | 105 // resides is returned. |
| 106 Entries::iterator GetEntryIteratorById(SessionID::id_type id); | 106 Entries::iterator GetEntryIteratorById(SessionID::id_type id); |
| 107 | 107 |
| 108 // Calls either ValidateTab or ValidateWindow as appropriate. | 108 // Calls either ValidateTab or ValidateWindow as appropriate. |
| 109 static bool ValidateEntry(Entry* entry); | 109 static bool ValidateEntry(const Entry& entry); |
| 110 | 110 |
| 111 private: | 111 private: |
| 112 friend class PersistentTabRestoreService; | 112 friend class PersistentTabRestoreService; |
| 113 | 113 |
| 114 // Populates the tab's navigations from the LiveTab, and its browser_id and | 114 // Populates the tab's navigations from the LiveTab, and its browser_id and |
| 115 // pinned state from the context. | 115 // pinned state from the context. |
| 116 void PopulateTab(Tab* tab, | 116 void PopulateTab(Tab* tab, |
| 117 int index, | 117 int index, |
| 118 LiveTabContext* context, | 118 LiveTabContext* context, |
| 119 LiveTab* live_tab); | 119 LiveTab* live_tab); |
| 120 | 120 |
| 121 // This is a helper function for RestoreEntryById() for restoring a single | 121 // This is a helper function for RestoreEntryById() for restoring a single |
| 122 // tab. If |context| is NULL, this creates a new window for the entry. This | 122 // tab. If |context| is NULL, this creates a new window for the entry. This |
| 123 // returns the LiveTabContext into which the tab was restored. |disposition| | 123 // returns the LiveTabContext into which the tab was restored. |disposition| |
| 124 // will be respected, but if it is UNKNOWN then the tab's original attributes | 124 // will be respected, but if it is UNKNOWN then the tab's original attributes |
| 125 // will be respected instead. If a new LiveTabContext needs to be created for | 125 // will be respected instead. If a new LiveTabContext needs to be created for |
| 126 // this tab, If present, |live_tab| will be populated with the LiveTab of the | 126 // this tab, If present, |live_tab| will be populated with the LiveTab of the |
| 127 // restored tab. | 127 // restored tab. |
| 128 LiveTabContext* RestoreTab(const Tab& tab, | 128 LiveTabContext* RestoreTab(const Tab& tab, |
| 129 LiveTabContext* context, | 129 LiveTabContext* context, |
| 130 WindowOpenDisposition disposition, | 130 WindowOpenDisposition disposition, |
| 131 LiveTab** live_tab); | 131 LiveTab** live_tab); |
| 132 | 132 |
| 133 // Returns true if |tab| has more than one navigation. If |tab| has more | 133 // Returns true if |tab| has at least one navigation and |
| 134 // than one navigation |tab->current_navigation_index| is constrained based | 134 // |tab->current_navigation_index| is in bounds. |
| 135 // on the number of navigations. | 135 static bool ValidateTab(const Tab& tab); |
| 136 static bool ValidateTab(Tab* tab); | |
| 137 | 136 |
| 138 // Validates all the tabs in a window, plus the window's active tab index. | 137 // Validates all the tabs in a window, plus the window's active tab index. |
| 139 static bool ValidateWindow(Window* window); | 138 static bool ValidateWindow(const Window& window); |
| 140 | 139 |
| 141 // Returns true if |tab| is one we care about restoring. | 140 // Returns true if |tab| is one we care about restoring. |
| 142 bool IsTabInteresting(const Tab* tab); | 141 bool IsTabInteresting(const Tab& tab); |
| 143 | 142 |
| 144 // Checks whether |window| is interesting --- if it only contains a single, | 143 // Checks whether |window| is interesting --- if it only contains a single, |
| 145 // uninteresting tab, it's not interesting. | 144 // uninteresting tab, it's not interesting. |
| 146 bool IsWindowInteresting(const Window* window); | 145 bool IsWindowInteresting(const Window& window); |
| 147 | 146 |
| 148 // Validates and checks |entry| for interesting. | 147 // Validates and checks |entry| for interesting. |
| 149 bool FilterEntry(Entry* entry); | 148 bool FilterEntry(const Entry& entry); |
| 150 | 149 |
| 151 // Finds tab entries with the old browser_id and sets it to the new one. | 150 // Finds tab entries with the old browser_id and sets it to the new one. |
| 152 void UpdateTabBrowserIDs(SessionID::id_type old_id, | 151 void UpdateTabBrowserIDs(SessionID::id_type old_id, |
| 153 SessionID::id_type new_id); | 152 SessionID::id_type new_id); |
| 154 | 153 |
| 155 // Gets the current time. This uses the time_factory_ if there is one. | 154 // Gets the current time. This uses the time_factory_ if there is one. |
| 156 base::Time TimeNow() const; | 155 base::Time TimeNow() const; |
| 157 | 156 |
| 158 TabRestoreService* const tab_restore_service_; | 157 TabRestoreService* const tab_restore_service_; |
| 159 | 158 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 176 std::set<LiveTabContext*> closing_contexts_; | 175 std::set<LiveTabContext*> closing_contexts_; |
| 177 | 176 |
| 178 TimeFactory* const time_factory_; | 177 TimeFactory* const time_factory_; |
| 179 | 178 |
| 180 DISALLOW_COPY_AND_ASSIGN(TabRestoreServiceHelper); | 179 DISALLOW_COPY_AND_ASSIGN(TabRestoreServiceHelper); |
| 181 }; | 180 }; |
| 182 | 181 |
| 183 } // namespace sessions | 182 } // namespace sessions |
| 184 | 183 |
| 185 #endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ | 184 #endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ |
| OLD | NEW |