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

Side by Side Diff: components/sessions/core/tab_restore_service.h

Issue 2200993004: Make TabRestoreService::Entry noncopyable and fix up surrounding code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab-test-cleanup
Patch Set: Get session ID from entries, take tabs' active status directly instead of an index Created 4 years, 4 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 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 virtual base::Time TimeNow() = 0; 45 virtual base::Time TimeNow() = 0;
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();
56 explicit Entry(Type type);
57 virtual ~Entry(); 55 virtual ~Entry();
58 56
59 // Unique id for this entry. The id is guaranteed to be unique for a 57 // Unique id for this entry. The id is guaranteed to be unique for a
60 // session. 58 // session.
61 SessionID::id_type id; 59 SessionID::id_type id;
62 60
63 // The type of the entry. 61 // The type of the entry.
64 Type type; 62 const Type type;
65 63
66 // The time when the window or tab was closed. 64 // The time when the window or tab was closed.
67 base::Time timestamp; 65 base::Time timestamp;
68 66
69 // Is this entry from the last session? This is set to true for entries that 67 // 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 68 // were closed during the last session, and false for entries that were
71 // closed during this session. 69 // closed during this session.
72 bool from_last_session; 70 bool from_last_session = false;
71
72 protected:
73 explicit Entry(Type type);
74
75 private:
76 DISALLOW_COPY_AND_ASSIGN(Entry);
73 }; 77 };
74 78
75 // Represents a previously open tab. 79 // Represents a previously open tab.
76 struct SESSIONS_EXPORT Tab : public Entry { 80 struct SESSIONS_EXPORT Tab : public Entry {
77 Tab(); 81 Tab();
78 Tab(const Tab& tab);
79 ~Tab() override; 82 ~Tab() override;
80 83
81 Tab& operator=(const Tab& tab);
82
83 bool has_browser() const { return browser_id > 0; }
84
85 // The navigations. 84 // The navigations.
86 std::vector<SerializedNavigationEntry> navigations; 85 std::vector<SerializedNavigationEntry> navigations;
87 86
88 // Index of the selected navigation in navigations. 87 // Index of the selected navigation in navigations.
89 int current_navigation_index; 88 int current_navigation_index = -1;
90 89
91 // The ID of the browser to which this tab belonged, so it can be restored 90 // 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. 91 // there. May be 0 (an invalid SessionID) when restoring an entire session.
93 SessionID::id_type browser_id; 92 SessionID::id_type browser_id = 0;
94 93
95 // Index within the tab strip. May be -1 for an unknown index. 94 // Index within the tab strip. May be -1 for an unknown index.
96 int tabstrip_index; 95 int tabstrip_index = -1;
97 96
98 // True if the tab was pinned. 97 // True if the tab was pinned.
99 bool pinned; 98 bool pinned = false;
100 99
101 // If non-empty gives the id of the extension for the tab. 100 // If non-empty gives the id of the extension for the tab.
102 std::string extension_app_id; 101 std::string extension_app_id;
103 102
104 // The associated client data. 103 // The associated client data.
105 std::unique_ptr<PlatformSpecificTabData> platform_data; 104 std::unique_ptr<PlatformSpecificTabData> platform_data;
106 105
107 // The user agent override used for the tab's navigations (if applicable). 106 // The user agent override used for the tab's navigations (if applicable).
108 std::string user_agent_override; 107 std::string user_agent_override;
109 }; 108 };
110 109
111 // Represents a previously open window. 110 // Represents a previously open window.
112 struct SESSIONS_EXPORT Window : public Entry { 111 struct SESSIONS_EXPORT Window : public Entry {
113 Window(); 112 Window();
114 ~Window() override; 113 ~Window() override;
115 114
116 // The tabs that comprised the window, in order. 115 // The tabs that comprised the window, in order.
117 std::vector<Tab> tabs; 116 std::vector<std::unique_ptr<Tab>> tabs;
118 117
119 // Index of the selected tab. 118 // Index of the selected tab.
120 int selected_tab_index; 119 int selected_tab_index = -1;
121 120
122 // If an application window, the name of the app. 121 // If an application window, the name of the app.
123 std::string app_name; 122 std::string app_name;
124 }; 123 };
125 124
126 typedef std::list<Entry*> Entries; 125 typedef std::list<std::unique_ptr<Entry>> Entries;
127 126
128 ~TabRestoreService() override; 127 ~TabRestoreService() override;
129 128
130 // Adds/removes an observer. TabRestoreService does not take ownership of 129 // Adds/removes an observer. TabRestoreService does not take ownership of
131 // the observer. 130 // the observer.
132 virtual void AddObserver(TabRestoreServiceObserver* observer) = 0; 131 virtual void AddObserver(TabRestoreServiceObserver* observer) = 0;
133 virtual void RemoveObserver(TabRestoreServiceObserver* observer) = 0; 132 virtual void RemoveObserver(TabRestoreServiceObserver* observer) = 0;
134 133
135 // Creates a Tab to represent |live_tab| and notifies observers the list of 134 // Creates a Tab to represent |live_tab| and notifies observers the list of
136 // entries has changed. 135 // entries has changed.
(...skipping 16 matching lines...) Expand all
153 // Returns the entries, ordered with most recently closed entries at the 152 // Returns the entries, ordered with most recently closed entries at the
154 // front. 153 // front.
155 virtual const Entries& entries() const = 0; 154 virtual const Entries& entries() const = 0;
156 155
157 // Restores the most recently closed entry. Does nothing if there are no 156 // 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 157 // 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). 158 // added to |context|. Returns the LiveTab instances of the restored tab(s).
160 virtual std::vector<LiveTab*> RestoreMostRecentEntry( 159 virtual std::vector<LiveTab*> RestoreMostRecentEntry(
161 LiveTabContext* context) = 0; 160 LiveTabContext* context) = 0;
162 161
163 // Removes the Tab with id |id| from the list and returns it; ownership is 162 // Removes the Tab with id |id| from the list and returns it.
164 // passed to the caller. 163 virtual std::unique_ptr<Tab> RemoveTabEntryById(SessionID::id_type id) = 0;
165 virtual Tab* RemoveTabEntryById(SessionID::id_type id) = 0;
166 164
167 // Restores an entry by id. If there is no entry with an id matching |id|, 165 // 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 166 // this does nothing. If |context| is NULL, this creates a new window for the
169 // entry. |disposition| is respected, but the attributes (tabstrip index, 167 // entry. |disposition| is respected, but the attributes (tabstrip index,
170 // browser window) of the tab when it was closed will be respected if 168 // browser window) of the tab when it was closed will be respected if
171 // disposition is UNKNOWN. Returns the LiveTab instances of the restored 169 // disposition is UNKNOWN. Returns the LiveTab instances of the restored
172 // tab(s). 170 // tab(s).
173 virtual std::vector<LiveTab*> RestoreEntryById( 171 virtual std::vector<LiveTab*> RestoreEntryById(
174 LiveTabContext* context, 172 LiveTabContext* context,
175 SessionID::id_type id, 173 SessionID::id_type id,
176 WindowOpenDisposition disposition) = 0; 174 WindowOpenDisposition disposition) = 0;
177 175
178 // Loads the tabs and previous session. This does nothing if the tabs 176 // Loads the tabs and previous session. This does nothing if the tabs
179 // from the previous session have already been loaded. 177 // from the previous session have already been loaded.
180 virtual void LoadTabsFromLastSession() = 0; 178 virtual void LoadTabsFromLastSession() = 0;
181 179
182 // Returns true if the tab entries have been loaded. 180 // Returns true if the tab entries have been loaded.
183 virtual bool IsLoaded() const = 0; 181 virtual bool IsLoaded() const = 0;
184 182
185 // Deletes the last session. 183 // Deletes the last session.
186 virtual void DeleteLastSession() = 0; 184 virtual void DeleteLastSession() = 0;
187 }; 185 };
188 186
189 // A class that is used to associate platform-specific data with 187 // A class that is used to associate platform-specific data with
190 // TabRestoreService::Tab. See LiveTab::GetPlatformSpecificTabData(). 188 // 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 { 189 class SESSIONS_EXPORT PlatformSpecificTabData {
194 public: 190 public:
195 virtual ~PlatformSpecificTabData(); 191 virtual ~PlatformSpecificTabData();
196
197 private:
198 friend TabRestoreService::Tab;
199
200 virtual std::unique_ptr<PlatformSpecificTabData> Clone() = 0;
201 }; 192 };
202 193
203 } // namespace sessions 194 } // namespace sessions
204 195
205 #endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_ 196 #endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_H_
OLDNEW
« no previous file with comments | « components/sessions/core/persistent_tab_restore_service.cc ('k') | components/sessions/core/tab_restore_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698