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

Unified 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: Add back NOTREACHED() and a return for gcc 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 side-by-side diff with in-line comments
Download patch
Index: components/sessions/core/tab_restore_service.h
diff --git a/components/sessions/core/tab_restore_service.h b/components/sessions/core/tab_restore_service.h
index f9eda99c3c0155adddf34530ab4b0d7dcaea2439..bba091a918183d82da7cf7d88e0f0209469f5e2e 100644
--- a/components/sessions/core/tab_restore_service.h
+++ b/components/sessions/core/tab_restore_service.h
@@ -53,56 +53,52 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService {
struct SESSIONS_EXPORT Entry {
Entry();
- explicit Entry(Type type);
- virtual ~Entry();
+ virtual ~Entry() = 0;
+ virtual Type type() const = 0;
sky 2016/08/02 23:12:30 Virtual functions shouldn't use unix_hacker_style.
Sidney San Martín 2016/08/03 14:35:32 Just to confirm, the non-unix_hacker_style would j
Sidney San Martín 2016/08/03 14:35:32 Could you fill me in on why (I'm still new on the
sky 2016/08/03 15:16:07 Expressing the type in the constructor implies the
Sidney San Martín 2016/08/03 15:50:23 OK. Can I make the member const, and the construct
// Unique id for this entry. The id is guaranteed to be unique for a
// session.
SessionID::id_type id;
- // The type of the entry.
- Type type;
-
// The time when the window or tab was closed.
base::Time timestamp;
// Is this entry from the last session? This is set to true for entries that
// were closed during the last session, and false for entries that were
// closed during this session.
- bool from_last_session;
+ bool from_last_session{false};
sky 2016/08/02 23:12:30 Why the {} for many of these? = works just fine.
Sidney San Martín 2016/08/03 14:35:32 I do uniform initialization because it doesn't all
sky 2016/08/03 15:16:07 "Use C++11 "uniform init" syntax ("{}" without '='
Sidney San Martín 2016/08/04 04:24:57 Done. I misread the mailing list thread — I though
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Entry);
};
// Represents a previously open tab.
struct SESSIONS_EXPORT Tab : public Entry {
Tab();
- Tab(const Tab& tab);
~Tab() override;
-
- Tab& operator=(const Tab& tab);
-
- bool has_browser() const { return browser_id > 0; }
+ Type type() const override;
// The navigations.
std::vector<SerializedNavigationEntry> navigations;
// Index of the selected navigation in navigations.
- int current_navigation_index;
+ size_t current_navigation_index{-1};
sky 2016/08/02 23:12:30 Please keep these as ints, I don't want to have to
Sidney San Martín 2016/08/03 14:35:32 Done. For future reference, what issues come up ar
sky 2016/08/03 15:16:07 My concern is around overflow and special casing -
Sidney San Martín 2016/08/04 04:24:57 Done.
// The ID of the browser to which this tab belonged, so it can be restored
// there. May be 0 (an invalid SessionID) when restoring an entire session.
- SessionID::id_type browser_id;
+ SessionID::id_type browser_id{0};
// Index within the tab strip. May be -1 for an unknown index.
- int tabstrip_index;
+ size_t tabstrip_index{-1};
// True if the tab was pinned.
- bool pinned;
+ bool pinned{false};
// If non-empty gives the id of the extension for the tab.
std::string extension_app_id;
// The associated client data.
- std::unique_ptr<PlatformSpecificTabData> platform_data;
+ std::unique_ptr<const PlatformSpecificTabData> platform_data;
// The user agent override used for the tab's navigations (if applicable).
std::string user_agent_override;
@@ -112,18 +108,19 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService {
struct SESSIONS_EXPORT Window : public Entry {
Window();
~Window() override;
+ Type type() const override;
// The tabs that comprised the window, in order.
- std::vector<Tab> tabs;
+ std::vector<std::unique_ptr<Tab>> tabs;
// Index of the selected tab.
- int selected_tab_index;
+ size_t selected_tab_index{-1};
// If an application window, the name of the app.
std::string app_name;
};
- typedef std::list<Entry*> Entries;
+ typedef std::list<std::unique_ptr<Entry>> Entries;
~TabRestoreService() override;
@@ -134,7 +131,7 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService {
// Creates a Tab to represent |live_tab| and notifies observers the list of
// entries has changed.
- virtual void CreateHistoricalTab(LiveTab* live_tab, int index) = 0;
+ virtual void CreateHistoricalTab(LiveTab* live_tab, size_t index) = 0;
// TODO(blundell): Rename and fix comment.
// Invoked when a browser is closing. If |context| is a tabbed browser with
@@ -160,9 +157,8 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService {
virtual std::vector<LiveTab*> RestoreMostRecentEntry(
LiveTabContext* context) = 0;
- // Removes the Tab with id |id| from the list and returns it; ownership is
- // passed to the caller.
- virtual Tab* RemoveTabEntryById(SessionID::id_type id) = 0;
+ // Removes the Tab with id |id| from the list and returns it.
+ virtual std::unique_ptr<Tab> RemoveTabEntryById(SessionID::id_type id) = 0;
// Restores an entry by id. If there is no entry with an id matching |id|,
// this does nothing. If |context| is NULL, this creates a new window for the
@@ -188,16 +184,9 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService {
// A class that is used to associate platform-specific data with
// TabRestoreService::Tab. See LiveTab::GetPlatformSpecificTabData().
-// Subclasses of this class must be copyable by implementing the Clone() method
-// for usage by the Tab struct, which is itself copyable and assignable.
class SESSIONS_EXPORT PlatformSpecificTabData {
public:
virtual ~PlatformSpecificTabData();
-
- private:
- friend TabRestoreService::Tab;
-
- virtual std::unique_ptr<PlatformSpecificTabData> Clone() = 0;
};
} // namespace sessions

Powered by Google App Engine
This is Rietveld 408576698