| 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_H_ | 5 #ifndef COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ |
| 6 #define COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ | 6 #define COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // The type of entry. | 48 // The type of entry. |
| 49 enum Type { | 49 enum Type { |
| 50 TAB, | 50 TAB, |
| 51 WINDOW | 51 WINDOW |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 struct SESSIONS_EXPORT Entry { | 54 struct SESSIONS_EXPORT Entry { |
| 55 Entry(); | 55 Entry(); |
| 56 explicit Entry(Type type); | 56 virtual ~Entry() = 0; |
| 57 virtual ~Entry(); | 57 virtual Type type() const = 0; |
| 58 | 58 |
| 59 // Unique id for this entry. The id is guaranteed to be unique for a | 59 // Unique id for this entry. The id is guaranteed to be unique for a |
| 60 // session. | 60 // session. |
| 61 SessionID::id_type id; | 61 SessionID::id_type id; |
| 62 | 62 |
| 63 // The type of the entry. | |
| 64 Type type; | |
| 65 | |
| 66 // The time when the window or tab was closed. | 63 // The time when the window or tab was closed. |
| 67 base::Time timestamp; | 64 base::Time timestamp; |
| 68 | 65 |
| 69 // Is this entry from the last session? This is set to true for entries that | 66 // Is this entry from the last session? This is set to true for entries that |
| 70 // were closed during the last session, and false for entries that were | 67 // were closed during the last session, and false for entries that were |
| 71 // closed during this session. | 68 // closed during this session. |
| 72 bool from_last_session; | 69 bool from_last_session{false}; |
| 70 |
| 71 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(Entry); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 // Represents a previously open tab. | 75 // Represents a previously open tab. |
| 76 struct SESSIONS_EXPORT Tab : public Entry { | 76 struct SESSIONS_EXPORT Tab : public Entry { |
| 77 Tab(); | 77 Tab(); |
| 78 Tab(const Tab& tab); | |
| 79 ~Tab() override; | 78 ~Tab() override; |
| 80 | 79 Type type() const override; |
| 81 Tab& operator=(const Tab& tab); | |
| 82 | |
| 83 bool has_browser() const { return browser_id > 0; } | |
| 84 | 80 |
| 85 // The navigations. | 81 // The navigations. |
| 86 std::vector<SerializedNavigationEntry> navigations; | 82 std::vector<SerializedNavigationEntry> navigations; |
| 87 | 83 |
| 88 // Index of the selected navigation in navigations. | 84 // Index of the selected navigation in navigations. |
| 89 int current_navigation_index; | 85 size_t current_navigation_index{-1}; |
| 90 | 86 |
| 91 // The ID of the browser to which this tab belonged, so it can be restored | 87 // The ID of the browser to which this tab belonged, so it can be restored |
| 92 // there. May be 0 (an invalid SessionID) when restoring an entire session. | 88 // there. May be 0 (an invalid SessionID) when restoring an entire session. |
| 93 SessionID::id_type browser_id; | 89 SessionID::id_type browser_id{0}; |
| 94 | 90 |
| 95 // Index within the tab strip. May be -1 for an unknown index. | 91 // Index within the tab strip. May be -1 for an unknown index. |
| 96 int tabstrip_index; | 92 size_t tabstrip_index{-1}; |
| 97 | 93 |
| 98 // True if the tab was pinned. | 94 // True if the tab was pinned. |
| 99 bool pinned; | 95 bool pinned{false}; |
| 100 | 96 |
| 101 // If non-empty gives the id of the extension for the tab. | 97 // If non-empty gives the id of the extension for the tab. |
| 102 std::string extension_app_id; | 98 std::string extension_app_id; |
| 103 | 99 |
| 104 // The associated client data. | 100 // The associated client data. |
| 105 std::unique_ptr<PlatformSpecificTabData> platform_data; | 101 std::unique_ptr<const PlatformSpecificTabData> platform_data; |
| 106 | 102 |
| 107 // The user agent override used for the tab's navigations (if applicable). | 103 // The user agent override used for the tab's navigations (if applicable). |
| 108 std::string user_agent_override; | 104 std::string user_agent_override; |
| 109 }; | 105 }; |
| 110 | 106 |
| 111 // Represents a previously open window. | 107 // Represents a previously open window. |
| 112 struct SESSIONS_EXPORT Window : public Entry { | 108 struct SESSIONS_EXPORT Window : public Entry { |
| 113 Window(); | 109 Window(); |
| 114 ~Window() override; | 110 ~Window() override; |
| 111 Type type() const override; |
| 115 | 112 |
| 116 // The tabs that comprised the window, in order. | 113 // The tabs that comprised the window, in order. |
| 117 std::vector<Tab> tabs; | 114 std::vector<std::unique_ptr<Tab>> tabs; |
| 118 | 115 |
| 119 // Index of the selected tab. | 116 // Index of the selected tab. |
| 120 int selected_tab_index; | 117 size_t selected_tab_index{-1}; |
| 121 | 118 |
| 122 // If an application window, the name of the app. | 119 // If an application window, the name of the app. |
| 123 std::string app_name; | 120 std::string app_name; |
| 124 }; | 121 }; |
| 125 | 122 |
| 126 typedef std::list<Entry*> Entries; | 123 typedef std::list<std::unique_ptr<Entry>> Entries; |
| 127 | 124 |
| 128 ~TabRestoreService() override; | 125 ~TabRestoreService() override; |
| 129 | 126 |
| 130 // Adds/removes an observer. TabRestoreService does not take ownership of | 127 // Adds/removes an observer. TabRestoreService does not take ownership of |
| 131 // the observer. | 128 // the observer. |
| 132 virtual void AddObserver(TabRestoreServiceObserver* observer) = 0; | 129 virtual void AddObserver(TabRestoreServiceObserver* observer) = 0; |
| 133 virtual void RemoveObserver(TabRestoreServiceObserver* observer) = 0; | 130 virtual void RemoveObserver(TabRestoreServiceObserver* observer) = 0; |
| 134 | 131 |
| 135 // Creates a Tab to represent |live_tab| and notifies observers the list of | 132 // Creates a Tab to represent |live_tab| and notifies observers the list of |
| 136 // entries has changed. | 133 // entries has changed. |
| 137 virtual void CreateHistoricalTab(LiveTab* live_tab, int index) = 0; | 134 virtual void CreateHistoricalTab(LiveTab* live_tab, size_t index) = 0; |
| 138 | 135 |
| 139 // TODO(blundell): Rename and fix comment. | 136 // TODO(blundell): Rename and fix comment. |
| 140 // Invoked when a browser is closing. If |context| is a tabbed browser with | 137 // Invoked when a browser is closing. If |context| is a tabbed browser with |
| 141 // at least one tab, a Window is created, added to entries and observers are | 138 // at least one tab, a Window is created, added to entries and observers are |
| 142 // notified. | 139 // notified. |
| 143 virtual void BrowserClosing(LiveTabContext* context) = 0; | 140 virtual void BrowserClosing(LiveTabContext* context) = 0; |
| 144 | 141 |
| 145 // TODO(blundell): Rename and fix comment. | 142 // TODO(blundell): Rename and fix comment. |
| 146 // Invoked when the browser is done closing. | 143 // Invoked when the browser is done closing. |
| 147 virtual void BrowserClosed(LiveTabContext* context) = 0; | 144 virtual void BrowserClosed(LiveTabContext* context) = 0; |
| 148 | 145 |
| 149 // Removes all entries from the list and notifies observers the list | 146 // Removes all entries from the list and notifies observers the list |
| 150 // of tabs has changed. | 147 // of tabs has changed. |
| 151 virtual void ClearEntries() = 0; | 148 virtual void ClearEntries() = 0; |
| 152 | 149 |
| 153 // Returns the entries, ordered with most recently closed entries at the | 150 // Returns the entries, ordered with most recently closed entries at the |
| 154 // front. | 151 // front. |
| 155 virtual const Entries& entries() const = 0; | 152 virtual const Entries& entries() const = 0; |
| 156 | 153 |
| 157 // Restores the most recently closed entry. Does nothing if there are no | 154 // Restores the most recently closed entry. Does nothing if there are no |
| 158 // entries to restore. If the most recently restored entry is a tab, it is | 155 // entries to restore. If the most recently restored entry is a tab, it is |
| 159 // added to |context|. Returns the LiveTab instances of the restored tab(s). | 156 // added to |context|. Returns the LiveTab instances of the restored tab(s). |
| 160 virtual std::vector<LiveTab*> RestoreMostRecentEntry( | 157 virtual std::vector<LiveTab*> RestoreMostRecentEntry( |
| 161 LiveTabContext* context) = 0; | 158 LiveTabContext* context) = 0; |
| 162 | 159 |
| 163 // Removes the Tab with id |id| from the list and returns it; ownership is | 160 // Removes the Tab with id |id| from the list and returns it. |
| 164 // passed to the caller. | 161 virtual std::unique_ptr<Tab> RemoveTabEntryById(SessionID::id_type id) = 0; |
| 165 virtual Tab* RemoveTabEntryById(SessionID::id_type id) = 0; | |
| 166 | 162 |
| 167 // Restores an entry by id. If there is no entry with an id matching |id|, | 163 // Restores an entry by id. If there is no entry with an id matching |id|, |
| 168 // this does nothing. If |context| is NULL, this creates a new window for the | 164 // this does nothing. If |context| is NULL, this creates a new window for the |
| 169 // entry. |disposition| is respected, but the attributes (tabstrip index, | 165 // entry. |disposition| is respected, but the attributes (tabstrip index, |
| 170 // browser window) of the tab when it was closed will be respected if | 166 // browser window) of the tab when it was closed will be respected if |
| 171 // disposition is UNKNOWN. Returns the LiveTab instances of the restored | 167 // disposition is UNKNOWN. Returns the LiveTab instances of the restored |
| 172 // tab(s). | 168 // tab(s). |
| 173 virtual std::vector<LiveTab*> RestoreEntryById( | 169 virtual std::vector<LiveTab*> RestoreEntryById( |
| 174 LiveTabContext* context, | 170 LiveTabContext* context, |
| 175 SessionID::id_type id, | 171 SessionID::id_type id, |
| 176 WindowOpenDisposition disposition) = 0; | 172 WindowOpenDisposition disposition) = 0; |
| 177 | 173 |
| 178 // Loads the tabs and previous session. This does nothing if the tabs | 174 // Loads the tabs and previous session. This does nothing if the tabs |
| 179 // from the previous session have already been loaded. | 175 // from the previous session have already been loaded. |
| 180 virtual void LoadTabsFromLastSession() = 0; | 176 virtual void LoadTabsFromLastSession() = 0; |
| 181 | 177 |
| 182 // Returns true if the tab entries have been loaded. | 178 // Returns true if the tab entries have been loaded. |
| 183 virtual bool IsLoaded() const = 0; | 179 virtual bool IsLoaded() const = 0; |
| 184 | 180 |
| 185 // Deletes the last session. | 181 // Deletes the last session. |
| 186 virtual void DeleteLastSession() = 0; | 182 virtual void DeleteLastSession() = 0; |
| 187 }; | 183 }; |
| 188 | 184 |
| 189 // A class that is used to associate platform-specific data with | 185 // A class that is used to associate platform-specific data with |
| 190 // TabRestoreService::Tab. See LiveTab::GetPlatformSpecificTabData(). | 186 // TabRestoreService::Tab. See LiveTab::GetPlatformSpecificTabData(). |
| 191 // Subclasses of this class must be copyable by implementing the Clone() method | |
| 192 // for usage by the Tab struct, which is itself copyable and assignable. | |
| 193 class SESSIONS_EXPORT PlatformSpecificTabData { | 187 class SESSIONS_EXPORT PlatformSpecificTabData { |
| 194 public: | 188 public: |
| 195 virtual ~PlatformSpecificTabData(); | 189 virtual ~PlatformSpecificTabData(); |
| 196 | |
| 197 private: | |
| 198 friend TabRestoreService::Tab; | |
| 199 | |
| 200 virtual std::unique_ptr<PlatformSpecificTabData> Clone() = 0; | |
| 201 }; | 190 }; |
| 202 | 191 |
| 203 } // namespace sessions | 192 } // namespace sessions |
| 204 | 193 |
| 205 #endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ | 194 #endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ |
| OLD | NEW |