summaryrefslogtreecommitdiff
path: root/chromium/components/sessions
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-05-15 10:20:33 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-05-15 10:28:57 +0000
commitd17ea114e5ef69ad5d5d7413280a13e6428098aa (patch)
tree2c01a75df69f30d27b1432467cfe7c1467a498da /chromium/components/sessions
parent8c5c43c7b138c9b4b0bf56d946e61d3bbc111bec (diff)
downloadqtwebengine-chromium-d17ea114e5ef69ad5d5d7413280a13e6428098aa.tar.gz
BASELINE: Update Chromium to 67.0.3396.47
Change-Id: Idcb1341782e417561a2473eeecc82642dafda5b7 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'chromium/components/sessions')
-rw-r--r--chromium/components/sessions/content/DEPS2
-rw-r--r--chromium/components/sessions/content/content_platform_specific_tab_data.cc1
-rw-r--r--chromium/components/sessions/content/content_serialized_navigation_driver.cc2
-rw-r--r--chromium/components/sessions/core/base_session_service_commands.cc53
-rw-r--r--chromium/components/sessions/core/base_session_service_commands.h55
-rw-r--r--chromium/components/sessions/core/in_memory_tab_restore_service.cc4
-rw-r--r--chromium/components/sessions/core/in_memory_tab_restore_service.h4
-rw-r--r--chromium/components/sessions/core/live_tab_context.h2
-rw-r--r--chromium/components/sessions/core/persistent_tab_restore_service.cc60
-rw-r--r--chromium/components/sessions/core/persistent_tab_restore_service.h4
-rw-r--r--chromium/components/sessions/core/serialized_navigation_entry.cc2
-rw-r--r--chromium/components/sessions/core/serialized_navigation_entry_unittest.cc2
-rw-r--r--chromium/components/sessions/core/session_id.cc12
-rw-r--r--chromium/components/sessions/core/session_id.h48
-rw-r--r--chromium/components/sessions/core/session_service_commands.cc123
-rw-r--r--chromium/components/sessions/core/session_service_commands.h6
-rw-r--r--chromium/components/sessions/core/session_types.cc14
-rw-r--r--chromium/components/sessions/core/session_types_unittest.cc8
-rw-r--r--chromium/components/sessions/core/tab_restore_service.cc7
-rw-r--r--chromium/components/sessions/core/tab_restore_service.h6
-rw-r--r--chromium/components/sessions/core/tab_restore_service_client.h5
-rw-r--r--chromium/components/sessions/core/tab_restore_service_helper.cc71
-rw-r--r--chromium/components/sessions/core/tab_restore_service_helper.h11
23 files changed, 288 insertions, 214 deletions
diff --git a/chromium/components/sessions/content/DEPS b/chromium/components/sessions/content/DEPS
index 1187a87bb73..06ba743d0fa 100644
--- a/chromium/components/sessions/content/DEPS
+++ b/chromium/components/sessions/content/DEPS
@@ -1,5 +1,5 @@
include_rules = [
"+content/public/browser",
"+content/public/common",
- "+third_party/WebKit/public/platform",
+ "+third_party/blink/public/platform",
]
diff --git a/chromium/components/sessions/content/content_platform_specific_tab_data.cc b/chromium/components/sessions/content/content_platform_specific_tab_data.cc
index bca42b8dea8..20d40df5174 100644
--- a/chromium/components/sessions/content/content_platform_specific_tab_data.cc
+++ b/chromium/components/sessions/content/content_platform_specific_tab_data.cc
@@ -4,7 +4,6 @@
#include "components/sessions/content/content_platform_specific_tab_data.h"
-#include "base/memory/ptr_util.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents.h"
diff --git a/chromium/components/sessions/content/content_serialized_navigation_driver.cc b/chromium/components/sessions/content/content_serialized_navigation_driver.cc
index abf02b4862e..4e37fe884d5 100644
--- a/chromium/components/sessions/content/content_serialized_navigation_driver.cc
+++ b/chromium/components/sessions/content/content_serialized_navigation_driver.cc
@@ -9,7 +9,7 @@
#include "base/memory/singleton.h"
#include "components/sessions/core/serialized_navigation_entry.h"
#include "content/public/common/page_state.h"
-#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
+#include "third_party/blink/public/platform/web_referrer_policy.h"
namespace sessions {
diff --git a/chromium/components/sessions/core/base_session_service_commands.cc b/chromium/components/sessions/core/base_session_service_commands.cc
index 934f13d6596..b6029a7f941 100644
--- a/chromium/components/sessions/core/base_session_service_commands.cc
+++ b/chromium/components/sessions/core/base_session_service_commands.cc
@@ -29,15 +29,24 @@ void WriteStringToPickle(base::Pickle& pickle,
}
}
+bool ReadSessionIdFromPickle(base::PickleIterator* iterator, SessionID* id) {
+ SessionID::id_type value;
+ if (!iterator->ReadInt(&value)) {
+ return false;
+ }
+ *id = SessionID::FromSerializedValue(value);
+ return true;
+}
+
} // namespace
std::unique_ptr<SessionCommand> CreateUpdateTabNavigationCommand(
- SessionID::id_type command_id,
- SessionID::id_type tab_id,
+ SessionCommand::id_type command_id,
+ SessionID tab_id,
const sessions::SerializedNavigationEntry& navigation) {
// Use pickle to handle marshalling.
base::Pickle pickle;
- pickle.WriteInt(tab_id);
+ pickle.WriteInt(tab_id.id());
// We only allow navigations up to 63k (which should be completely
// reasonable).
static const size_t max_state_size =
@@ -48,12 +57,12 @@ std::unique_ptr<SessionCommand> CreateUpdateTabNavigationCommand(
}
std::unique_ptr<SessionCommand> CreateSetTabExtensionAppIDCommand(
- SessionID::id_type command_id,
- SessionID::id_type tab_id,
+ SessionCommand::id_type command_id,
+ SessionID tab_id,
const std::string& extension_id) {
// Use pickle to handle marshalling.
base::Pickle pickle;
- pickle.WriteInt(tab_id);
+ pickle.WriteInt(tab_id.id());
// Enforce a max for ids. They should never be anywhere near this size.
static const SessionCommand::size_type max_id_size =
@@ -68,12 +77,12 @@ std::unique_ptr<SessionCommand> CreateSetTabExtensionAppIDCommand(
}
std::unique_ptr<SessionCommand> CreateSetTabUserAgentOverrideCommand(
- SessionID::id_type command_id,
- SessionID::id_type tab_id,
+ SessionCommand::id_type command_id,
+ SessionID tab_id,
const std::string& user_agent_override) {
// Use pickle to handle marshalling.
base::Pickle pickle;
- pickle.WriteInt(tab_id);
+ pickle.WriteInt(tab_id.id());
// Enforce a max for the user agent length. They should never be anywhere
// near this size.
@@ -90,12 +99,12 @@ std::unique_ptr<SessionCommand> CreateSetTabUserAgentOverrideCommand(
}
std::unique_ptr<SessionCommand> CreateSetWindowAppNameCommand(
- SessionID::id_type command_id,
- SessionID::id_type window_id,
+ SessionCommand::id_type command_id,
+ SessionID window_id,
const std::string& app_name) {
// Use pickle to handle marshalling.
base::Pickle pickle;
- pickle.WriteInt(window_id);
+ pickle.WriteInt(window_id.id());
// Enforce a max for ids. They should never be anywhere near this size.
static const SessionCommand::size_type max_id_size =
@@ -112,45 +121,49 @@ std::unique_ptr<SessionCommand> CreateSetWindowAppNameCommand(
bool RestoreUpdateTabNavigationCommand(
const SessionCommand& command,
sessions::SerializedNavigationEntry* navigation,
- SessionID::id_type* tab_id) {
+ SessionID* tab_id) {
std::unique_ptr<base::Pickle> pickle(command.PayloadAsPickle());
if (!pickle.get())
return false;
base::PickleIterator iterator(*pickle);
- return iterator.ReadInt(tab_id) && navigation->ReadFromPickle(&iterator);
+ return ReadSessionIdFromPickle(&iterator, tab_id) &&
+ navigation->ReadFromPickle(&iterator);
}
bool RestoreSetTabExtensionAppIDCommand(const SessionCommand& command,
- SessionID::id_type* tab_id,
+ SessionID* tab_id,
std::string* extension_app_id) {
std::unique_ptr<base::Pickle> pickle(command.PayloadAsPickle());
if (!pickle.get())
return false;
base::PickleIterator iterator(*pickle);
- return iterator.ReadInt(tab_id) && iterator.ReadString(extension_app_id);
+ return ReadSessionIdFromPickle(&iterator, tab_id) &&
+ iterator.ReadString(extension_app_id);
}
bool RestoreSetTabUserAgentOverrideCommand(const SessionCommand& command,
- SessionID::id_type* tab_id,
+ SessionID* tab_id,
std::string* user_agent_override) {
std::unique_ptr<base::Pickle> pickle(command.PayloadAsPickle());
if (!pickle.get())
return false;
base::PickleIterator iterator(*pickle);
- return iterator.ReadInt(tab_id) && iterator.ReadString(user_agent_override);
+ return ReadSessionIdFromPickle(&iterator, tab_id) &&
+ iterator.ReadString(user_agent_override);
}
bool RestoreSetWindowAppNameCommand(const SessionCommand& command,
- SessionID::id_type* window_id,
+ SessionID* window_id,
std::string* app_name) {
std::unique_ptr<base::Pickle> pickle(command.PayloadAsPickle());
if (!pickle.get())
return false;
base::PickleIterator iterator(*pickle);
- return iterator.ReadInt(window_id) && iterator.ReadString(app_name);
+ return ReadSessionIdFromPickle(&iterator, window_id) &&
+ iterator.ReadString(app_name);
}
} // namespace sessions
diff --git a/chromium/components/sessions/core/base_session_service_commands.h b/chromium/components/sessions/core/base_session_service_commands.h
index 05fd51fdb5a..3fa305353bb 100644
--- a/chromium/components/sessions/core/base_session_service_commands.h
+++ b/chromium/components/sessions/core/base_session_service_commands.h
@@ -8,6 +8,7 @@
#include <memory>
#include <string>
+#include "components/sessions/core/session_command.h"
#include "components/sessions/core/session_id.h"
#include "components/sessions/core/sessions_export.h"
@@ -19,61 +20,57 @@ class SerializedNavigationEntry;
// PersistentTabRestoreService.
// Creates a SessionCommand that represents a navigation.
-SESSIONS_EXPORT std::unique_ptr<SessionCommand>
-CreateUpdateTabNavigationCommand(
- SessionID::id_type command_id,
- SessionID::id_type tab_id,
+std::unique_ptr<SessionCommand> CreateUpdateTabNavigationCommand(
+ SessionCommand::id_type command_id,
+ SessionID tab_id,
const sessions::SerializedNavigationEntry& navigation);
// Creates a SessionCommand that represents marking a tab as an application.
-SESSIONS_EXPORT std::unique_ptr<SessionCommand>
-CreateSetTabExtensionAppIDCommand(SessionID::id_type command_id,
- SessionID::id_type tab_id,
- const std::string& extension_id);
+std::unique_ptr<SessionCommand> CreateSetTabExtensionAppIDCommand(
+ SessionCommand::id_type command_id,
+ SessionID tab_id,
+ const std::string& extension_id);
// Creates a SessionCommand that containing user agent override used by a
// tab's navigations.
-SESSIONS_EXPORT std::unique_ptr<SessionCommand>
-CreateSetTabUserAgentOverrideCommand(SessionID::id_type command_id,
- SessionID::id_type tab_id,
- const std::string& user_agent_override);
+std::unique_ptr<SessionCommand> CreateSetTabUserAgentOverrideCommand(
+ SessionCommand::id_type command_id,
+ SessionID tab_id,
+ const std::string& user_agent_override);
// Creates a SessionCommand stores a browser window's app name.
-SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateSetWindowAppNameCommand(
- SessionID::id_type command_id,
- SessionID::id_type window_id,
+std::unique_ptr<SessionCommand> CreateSetWindowAppNameCommand(
+ SessionCommand::id_type command_id,
+ SessionID window_id,
const std::string& app_name);
// Converts a SessionCommand previously created by
// CreateUpdateTabNavigationCommand into a
// SerializedNavigationEntry. Returns true on success. If
// successful |tab_id| is set to the id of the restored tab.
-SESSIONS_EXPORT bool RestoreUpdateTabNavigationCommand(
+bool RestoreUpdateTabNavigationCommand(
const SessionCommand& command,
sessions::SerializedNavigationEntry* navigation,
- SessionID::id_type* tab_id);
+ SessionID* tab_id);
// Extracts a SessionCommand as previously created by
// CreateSetTabExtensionAppIDCommand into the tab id and application
// extension id.
-SESSIONS_EXPORT bool RestoreSetTabExtensionAppIDCommand(
- const SessionCommand& command,
- SessionID::id_type* tab_id,
- std::string* extension_app_id);
+bool RestoreSetTabExtensionAppIDCommand(const SessionCommand& command,
+ SessionID* tab_id,
+ std::string* extension_app_id);
// Extracts a SessionCommand as previously created by
// CreateSetTabUserAgentOverrideCommand into the tab id and user agent.
-SESSIONS_EXPORT bool RestoreSetTabUserAgentOverrideCommand(
- const SessionCommand& command,
- SessionID::id_type* tab_id,
- std::string* user_agent_override);
+bool RestoreSetTabUserAgentOverrideCommand(const SessionCommand& command,
+ SessionID* tab_id,
+ std::string* user_agent_override);
// Extracts a SessionCommand as previously created by
// CreateSetWindowAppNameCommand into the window id and application name.
-SESSIONS_EXPORT bool RestoreSetWindowAppNameCommand(
- const SessionCommand& command,
- SessionID::id_type* window_id,
- std::string* app_name);
+bool RestoreSetWindowAppNameCommand(const SessionCommand& command,
+ SessionID* window_id,
+ std::string* app_name);
} // namespace sessions
diff --git a/chromium/components/sessions/core/in_memory_tab_restore_service.cc b/chromium/components/sessions/core/in_memory_tab_restore_service.cc
index bfbf7ae9bfb..7ad73e70de9 100644
--- a/chromium/components/sessions/core/in_memory_tab_restore_service.cc
+++ b/chromium/components/sessions/core/in_memory_tab_restore_service.cc
@@ -61,13 +61,13 @@ std::vector<LiveTab*> InMemoryTabRestoreService::RestoreMostRecentEntry(
}
std::unique_ptr<TabRestoreService::Tab>
-InMemoryTabRestoreService::RemoveTabEntryById(SessionID::id_type id) {
+InMemoryTabRestoreService::RemoveTabEntryById(SessionID id) {
return helper_.RemoveTabEntryById(id);
}
std::vector<LiveTab*> InMemoryTabRestoreService::RestoreEntryById(
LiveTabContext* context,
- SessionID::id_type id,
+ SessionID id,
WindowOpenDisposition disposition) {
return helper_.RestoreEntryById(context, id, disposition);
}
diff --git a/chromium/components/sessions/core/in_memory_tab_restore_service.h b/chromium/components/sessions/core/in_memory_tab_restore_service.h
index b2ca707aad1..07a4ab3a439 100644
--- a/chromium/components/sessions/core/in_memory_tab_restore_service.h
+++ b/chromium/components/sessions/core/in_memory_tab_restore_service.h
@@ -43,10 +43,10 @@ class SESSIONS_EXPORT InMemoryTabRestoreService : public TabRestoreService {
const Entries& entries() const override;
std::vector<LiveTab*> RestoreMostRecentEntry(
LiveTabContext* context) override;
- std::unique_ptr<Tab> RemoveTabEntryById(SessionID::id_type id) override;
+ std::unique_ptr<Tab> RemoveTabEntryById(SessionID id) override;
std::vector<LiveTab*> RestoreEntryById(
LiveTabContext* context,
- SessionID::id_type id,
+ SessionID id,
WindowOpenDisposition disposition) override;
void LoadTabsFromLastSession() override;
bool IsLoaded() const override;
diff --git a/chromium/components/sessions/core/live_tab_context.h b/chromium/components/sessions/core/live_tab_context.h
index 0efb779e20c..9ba4f1c7b1e 100644
--- a/chromium/components/sessions/core/live_tab_context.h
+++ b/chromium/components/sessions/core/live_tab_context.h
@@ -29,7 +29,7 @@ class SESSIONS_EXPORT LiveTabContext {
public:
// TODO(blundell): Rename.
virtual void ShowBrowserWindow() = 0;
- virtual const SessionID& GetSessionID() const = 0;
+ virtual SessionID GetSessionID() const = 0;
virtual int GetTabCount() const = 0;
virtual int GetSelectedIndex() const = 0;
virtual std::string GetAppName() const = 0;
diff --git a/chromium/components/sessions/core/persistent_tab_restore_service.cc b/chromium/components/sessions/core/persistent_tab_restore_service.cc
index a8dd9e47a50..f46f5878adb 100644
--- a/chromium/components/sessions/core/persistent_tab_restore_service.cc
+++ b/chromium/components/sessions/core/persistent_tab_restore_service.cc
@@ -111,7 +111,7 @@ const int kEntriesPerReset = 40;
const size_t kMaxEntries = TabRestoreServiceHelper::kMaxEntries;
void RemoveEntryByID(
- SessionID::id_type id,
+ SessionID id,
std::vector<std::unique_ptr<TabRestoreService::Entry>>* entries) {
// Look for the entry in the top-level collection.
for (auto it = entries->begin(); it != entries->end(); ++it) {
@@ -230,7 +230,7 @@ struct WindowCommandFields {
std::unique_ptr<sessions::TabRestoreService::Window>
CreateWindowEntryFromCommand(const SessionCommand* command,
- SessionID::id_type* window_id,
+ SessionID* window_id,
int32_t* num_tabs) {
WindowCommandFields fields;
ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT;
@@ -315,7 +315,7 @@ CreateWindowEntryFromCommand(const SessionCommand* command,
std::make_unique<sessions::TabRestoreService::Window>();
window->selected_tab_index = fields.selected_tab_index;
window->timestamp = base::Time::FromInternalValue(fields.timestamp);
- *window_id = static_cast<SessionID::id_type>(fields.window_id);
+ *window_id = SessionID::FromSerializedValue(fields.window_id);
*num_tabs = fields.num_tabs;
// Set the bounds, show state and workspace if valid ones have been provided.
@@ -353,7 +353,7 @@ class PersistentTabRestoreService::Delegate
// TabRestoreServiceHelper::Observer:
void OnClearEntries() override;
void OnNavigationEntriesDeleted() override;
- void OnRestoreEntryById(SessionID::id_type id,
+ void OnRestoreEntryById(SessionID id,
Entries::const_iterator entry_iterator) override;
void OnAddEntry() override;
@@ -384,7 +384,7 @@ class PersistentTabRestoreService::Delegate
// Creates a window close command.
static std::unique_ptr<SessionCommand> CreateWindowCommand(
- SessionID::id_type window_id,
+ SessionID window_id,
int selected_tab_index,
int num_tabs,
const gfx::Rect& bounds,
@@ -394,13 +394,13 @@ class PersistentTabRestoreService::Delegate
// Creates a tab close command.
static std::unique_ptr<SessionCommand> CreateSelectedNavigationInTabCommand(
- SessionID::id_type tab_id,
+ SessionID tab_id,
int32_t index,
base::Time timestamp);
// Creates a restore command.
static std::unique_ptr<SessionCommand> CreateRestoredEntryCommand(
- SessionID::id_type entry_id);
+ SessionID entry_id);
// Returns the index to persist as the selected index. This is the same as
// |tab.current_navigation_index| unless the entry at
@@ -429,7 +429,7 @@ class PersistentTabRestoreService::Delegate
// invokes LoadStateChanged. |ignored_active_window| is ignored because we
// don't need to restore activation.
void OnGotPreviousSession(std::vector<std::unique_ptr<SessionWindow>> windows,
- SessionID::id_type ignored_active_window);
+ SessionID ignored_active_window);
// Converts a SessionWindow into a Window, returning true on success. We use 0
// as the timestamp here since we do not know when the window/tab was closed.
@@ -536,7 +536,8 @@ void PersistentTabRestoreService::Delegate::OnClearEntries() {
base_session_service_->set_pending_reset(true);
// Schedule a command, otherwise if there are no pending commands Save does
// nothing.
- base_session_service_->ScheduleCommand(CreateRestoredEntryCommand(1));
+ base_session_service_->ScheduleCommand(
+ CreateRestoredEntryCommand(SessionID::InvalidValue()));
}
void PersistentTabRestoreService::Delegate::OnNavigationEntriesDeleted() {
@@ -547,11 +548,12 @@ void PersistentTabRestoreService::Delegate::OnNavigationEntriesDeleted() {
base_session_service_->set_pending_reset(true);
// Schedule a command, otherwise if there are no pending commands Save does
// nothing.
- base_session_service_->ScheduleCommand(CreateRestoredEntryCommand(1));
+ base_session_service_->ScheduleCommand(
+ CreateRestoredEntryCommand(SessionID::InvalidValue()));
}
void PersistentTabRestoreService::Delegate::OnRestoreEntryById(
- SessionID::id_type id,
+ SessionID id,
Entries::const_iterator entry_iterator) {
size_t index = 0;
const Entries& entries = tab_restore_service_helper_->entries();
@@ -710,7 +712,7 @@ void PersistentTabRestoreService::Delegate::ScheduleCommandsForTab(
// static
std::unique_ptr<SessionCommand>
PersistentTabRestoreService::Delegate::CreateWindowCommand(
- SessionID::id_type window_id,
+ SessionID window_id,
int selected_tab_index,
int num_tabs,
const gfx::Rect& bounds,
@@ -723,7 +725,7 @@ PersistentTabRestoreService::Delegate::CreateWindowCommand(
// Use a pickle to handle marshaling as this command contains variable-length
// content.
base::Pickle pickle;
- pickle.WriteInt(static_cast<int>(window_id));
+ pickle.WriteInt(static_cast<int>(window_id.id()));
pickle.WriteInt(selected_tab_index);
pickle.WriteInt(num_tabs);
pickle.WriteInt64(timestamp.ToInternalValue());
@@ -748,11 +750,11 @@ PersistentTabRestoreService::Delegate::CreateWindowCommand(
// static
std::unique_ptr<SessionCommand>
PersistentTabRestoreService::Delegate::CreateSelectedNavigationInTabCommand(
- SessionID::id_type tab_id,
+ SessionID tab_id,
int32_t index,
base::Time timestamp) {
SelectedNavigationInTabPayload2 payload;
- payload.id = tab_id;
+ payload.id = tab_id.id();
payload.index = index;
payload.timestamp = timestamp.ToInternalValue();
std::unique_ptr<SessionCommand> command(
@@ -764,8 +766,8 @@ PersistentTabRestoreService::Delegate::CreateSelectedNavigationInTabCommand(
// static
std::unique_ptr<SessionCommand>
PersistentTabRestoreService::Delegate::CreateRestoredEntryCommand(
- SessionID::id_type entry_id) {
- RestoredEntryPayload payload = entry_id;
+ SessionID entry_id) {
+ RestoredEntryPayload payload = entry_id.id();
std::unique_ptr<SessionCommand> command(
new SessionCommand(kCommandRestoredEntry, sizeof(payload)));
memcpy(command->contents(), &payload, sizeof(payload));
@@ -842,7 +844,7 @@ void PersistentTabRestoreService::Delegate::CreateEntriesFromCommands(
RestoredEntryPayload payload;
if (!command.GetPayload(&payload, sizeof(payload)))
return;
- RemoveEntryByID(payload, &entries);
+ RemoveEntryByID(SessionID::FromSerializedValue(payload), &entries);
break;
}
@@ -855,7 +857,7 @@ void PersistentTabRestoreService::Delegate::CreateEntriesFromCommands(
// Try to parse the command, and silently skip if it fails.
int32_t num_tabs = 0;
- SessionID::id_type window_id = 0;
+ SessionID window_id = SessionID::InvalidValue();
std::unique_ptr<Window> window =
CreateWindowEntryFromCommand(&command, &window_id, &num_tabs);
if (!window)
@@ -896,7 +898,7 @@ void PersistentTabRestoreService::Delegate::CreateEntriesFromCommands(
if (--pending_window_tabs == 0)
current_window = nullptr;
} else {
- RemoveEntryByID(payload.id, &entries);
+ RemoveEntryByID(SessionID::FromSerializedValue(payload.id), &entries);
entries.push_back(std::make_unique<Tab>());
current_tab = static_cast<Tab*>(entries.back().get());
current_tab->timestamp =
@@ -912,12 +914,16 @@ void PersistentTabRestoreService::Delegate::CreateEntriesFromCommands(
return;
}
current_tab->navigations.resize(current_tab->navigations.size() + 1);
- SessionID::id_type tab_id;
+ SessionID tab_id = SessionID::InvalidValue();
if (!RestoreUpdateTabNavigationCommand(command,
&current_tab->navigations.back(),
&tab_id)) {
return;
}
+ // When navigations are serialized, only gMaxPersistNavigationCount
+ // navigations are written. This leads to inconsistent indices.
+ current_tab->navigations.back().set_index(
+ current_tab->navigations.size() - 1);
break;
}
@@ -939,7 +945,7 @@ void PersistentTabRestoreService::Delegate::CreateEntriesFromCommands(
return;
}
- SessionID::id_type window_id;
+ SessionID window_id = SessionID::InvalidValue();
std::string app_name;
if (!RestoreSetWindowAppNameCommand(command, &window_id, &app_name))
return;
@@ -953,7 +959,7 @@ void PersistentTabRestoreService::Delegate::CreateEntriesFromCommands(
// Should be in a tab when we get this.
return;
}
- SessionID::id_type tab_id;
+ SessionID tab_id = SessionID::InvalidValue();
std::string extension_app_id;
if (!RestoreSetTabExtensionAppIDCommand(command,
&tab_id,
@@ -969,7 +975,7 @@ void PersistentTabRestoreService::Delegate::CreateEntriesFromCommands(
// Should be in a tab when we get this.
return;
}
- SessionID::id_type tab_id;
+ SessionID tab_id = SessionID::InvalidValue();
std::string user_agent_override;
if (!RestoreSetTabUserAgentOverrideCommand(command,
&tab_id,
@@ -1007,7 +1013,7 @@ void PersistentTabRestoreService::Delegate::ValidateAndDeleteEmptyEntries(
void PersistentTabRestoreService::Delegate::OnGotPreviousSession(
std::vector<std::unique_ptr<SessionWindow>> windows,
- SessionID::id_type ignored_active_window) {
+ SessionID ignored_active_window) {
std::vector<std::unique_ptr<Entry>> entries;
CreateEntriesFromWindows(&windows, &entries);
// Previous session tabs go first.
@@ -1147,13 +1153,13 @@ std::vector<LiveTab*> PersistentTabRestoreService::RestoreMostRecentEntry(
}
std::unique_ptr<TabRestoreService::Tab>
-PersistentTabRestoreService::RemoveTabEntryById(SessionID::id_type id) {
+PersistentTabRestoreService::RemoveTabEntryById(SessionID id) {
return helper_.RemoveTabEntryById(id);
}
std::vector<LiveTab*> PersistentTabRestoreService::RestoreEntryById(
LiveTabContext* context,
- SessionID::id_type id,
+ SessionID id,
WindowOpenDisposition disposition) {
return helper_.RestoreEntryById(context, id, disposition);
}
diff --git a/chromium/components/sessions/core/persistent_tab_restore_service.h b/chromium/components/sessions/core/persistent_tab_restore_service.h
index 206ca4aec7d..1ac2659187d 100644
--- a/chromium/components/sessions/core/persistent_tab_restore_service.h
+++ b/chromium/components/sessions/core/persistent_tab_restore_service.h
@@ -39,10 +39,10 @@ class SESSIONS_EXPORT PersistentTabRestoreService : public TabRestoreService {
const Entries& entries() const override;
std::vector<LiveTab*> RestoreMostRecentEntry(
LiveTabContext* context) override;
- std::unique_ptr<Tab> RemoveTabEntryById(SessionID::id_type id) override;
+ std::unique_ptr<Tab> RemoveTabEntryById(SessionID id) override;
std::vector<LiveTab*> RestoreEntryById(
LiveTabContext* context,
- SessionID::id_type id,
+ SessionID id,
WindowOpenDisposition disposition) override;
void LoadTabsFromLastSession() override;
bool IsLoaded() const override;
diff --git a/chromium/components/sessions/core/serialized_navigation_entry.cc b/chromium/components/sessions/core/serialized_navigation_entry.cc
index b89cff1ca32..c18183e5283 100644
--- a/chromium/components/sessions/core/serialized_navigation_entry.cc
+++ b/chromium/components/sessions/core/serialized_navigation_entry.cc
@@ -188,7 +188,7 @@ SerializedNavigationEntry SerializedNavigationEntry::FromSyncData(
navigation.transition_type_ = static_cast<ui::PageTransition>(transition);
- navigation.timestamp_ = base::Time();
+ navigation.timestamp_ = syncer::ProtoTimeToTime(sync_data.timestamp_msec());
if (sync_data.has_favicon_url())
navigation.favicon_url_ = GURL(sync_data.favicon_url());
diff --git a/chromium/components/sessions/core/serialized_navigation_entry_unittest.cc b/chromium/components/sessions/core/serialized_navigation_entry_unittest.cc
index 72592872095..72dcbe1e36c 100644
--- a/chromium/components/sessions/core/serialized_navigation_entry_unittest.cc
+++ b/chromium/components/sessions/core/serialized_navigation_entry_unittest.cc
@@ -92,7 +92,7 @@ TEST(SerializedNavigationEntryTest, FromSyncData) {
EXPECT_EQ(-1, navigation.post_id());
EXPECT_EQ(GURL(), navigation.original_request_url());
EXPECT_FALSE(navigation.is_overriding_user_agent());
- EXPECT_TRUE(navigation.timestamp().is_null());
+ EXPECT_EQ(test_data::kTimestamp, navigation.timestamp());
EXPECT_EQ(test_data::kFaviconURL, navigation.favicon_url());
EXPECT_EQ(test_data::kHttpStatusCode, navigation.http_status_code());
// The redirect chain only syncs one way.
diff --git a/chromium/components/sessions/core/session_id.cc b/chromium/components/sessions/core/session_id.cc
index 1ab9753a83d..dcd49218731 100644
--- a/chromium/components/sessions/core/session_id.cc
+++ b/chromium/components/sessions/core/session_id.cc
@@ -4,8 +4,16 @@
#include "components/sessions/core/session_id.h"
+#include <ostream>
+
static SessionID::id_type next_id = 1;
-SessionID::SessionID() {
- id_ = next_id++;
+// static
+SessionID SessionID::NewUnique() {
+ return SessionID(next_id++);
+}
+
+std::ostream& operator<<(std::ostream& out, SessionID id) {
+ out << id.id();
+ return out;
}
diff --git a/chromium/components/sessions/core/session_id.h b/chromium/components/sessions/core/session_id.h
index d4c2645f1e6..0941baed0f4 100644
--- a/chromium/components/sessions/core/session_id.h
+++ b/chromium/components/sessions/core/session_id.h
@@ -6,23 +6,63 @@
#define COMPONENTS_SESSIONS_CORE_SESSION_ID_H_
#include <stdint.h>
+#include <functional>
+#include <iosfwd>
#include "components/sessions/core/sessions_export.h"
-// Uniquely identifies a tab or window for the duration of a session.
+// Uniquely identifies a tab or window for the duration of a session. Pass by
+// value.
class SESSIONS_EXPORT SessionID {
public:
typedef int32_t id_type;
- SessionID();
- ~SessionID() {}
+ // Creates a new instance representing an ID that has never been used in the
+ // current session. The same value may be instantiated in future sessions.
+ static SessionID NewUnique();
+
+ // Special value representing a null-like, invalid ID. It's the only value
+ // that returns false for is_valid().
+ static constexpr SessionID InvalidValue() { return SessionID(-1); }
+
+ // Should be used rarely because it can lead to collisions.
+ static constexpr SessionID FromSerializedValue(id_type value) {
+ return IsValidValue(value) ? SessionID(value) : InvalidValue();
+ }
+
+ // Returns whether a certain underlying ID value would represent a valid
+ // SessionID instance. Note that zero is also considered invalid.
+ static constexpr bool IsValidValue(id_type value) { return value > 0; }
+
+ // All IDs are valid except InvalidValue() above.
+ bool is_valid() const { return IsValidValue(id_); }
// Returns the underlying id.
- void set_id(id_type id) { id_ = id; }
id_type id() const { return id_; }
+ struct Hasher {
+ inline std::size_t operator()(SessionID id) const { return id.id(); }
+ };
+
private:
+ explicit constexpr SessionID(id_type id) : id_(id) {}
+
id_type id_;
};
+inline bool operator==(SessionID lhs, SessionID rhs) {
+ return lhs.id() == rhs.id();
+}
+
+inline bool operator!=(SessionID lhs, SessionID rhs) {
+ return lhs.id() != rhs.id();
+}
+
+inline bool operator<(SessionID lhs, SessionID rhs) {
+ return lhs.id() < rhs.id();
+}
+
+// For use in gtest-based unit tests.
+SESSIONS_EXPORT std::ostream& operator<<(std::ostream& out, SessionID id);
+
#endif // COMPONENTS_SESSIONS_CORE_SESSION_ID_H_
diff --git a/chromium/components/sessions/core/session_service_commands.cc b/chromium/components/sessions/core/session_service_commands.cc
index e78449f01fb..5d40ee29561 100644
--- a/chromium/components/sessions/core/session_service_commands.cc
+++ b/chromium/components/sessions/core/session_service_commands.cc
@@ -117,10 +117,8 @@ enum PersistedWindowShowState {
PERSISTED_SHOW_STATE_END = 8,
};
-using IdToSessionTab =
- std::map<SessionID::id_type, std::unique_ptr<SessionTab>>;
-using IdToSessionWindow =
- std::map<SessionID::id_type, std::unique_ptr<SessionWindow>>;
+using IdToSessionTab = std::map<SessionID, std::unique_ptr<SessionTab>>;
+using IdToSessionWindow = std::map<SessionID, std::unique_ptr<SessionWindow>>;
// Assert to ensure PersistedWindowShowState is updated if ui::WindowShowState
// is changed.
@@ -190,12 +188,11 @@ void UpdateSelectedTabIndex(
// Returns the window in windows with the specified id. If a window does
// not exist, one is created.
-SessionWindow* GetWindow(SessionID::id_type window_id,
- IdToSessionWindow* windows) {
+SessionWindow* GetWindow(SessionID window_id, IdToSessionWindow* windows) {
auto i = windows->find(window_id);
if (i == windows->end()) {
SessionWindow* window = new SessionWindow();
- window->window_id.set_id(window_id);
+ window->window_id = window_id;
(*windows)[window_id] = base::WrapUnique(window);
return window;
}
@@ -204,12 +201,12 @@ SessionWindow* GetWindow(SessionID::id_type window_id,
// Returns the tab with the specified id in tabs. If a tab does not exist,
// it is created.
-SessionTab* GetTab(SessionID::id_type tab_id, IdToSessionTab* tabs) {
+SessionTab* GetTab(SessionID tab_id, IdToSessionTab* tabs) {
DCHECK(tabs);
auto i = tabs->find(tab_id);
if (i == tabs->end()) {
SessionTab* tab = new SessionTab();
- tab->tab_id.set_id(tab_id);
+ tab->tab_id = tab_id;
(*tabs)[tab_id] = base::WrapUnique(tab);
return tab;
}
@@ -293,7 +290,7 @@ void AddTabsToWindows(IdToSessionTab* tabs, IdToSessionWindow* windows) {
continue;
SessionTab* tab_ptr = tab.get();
- SessionWindow* window = GetWindow(tab_ptr->window_id.id(), windows);
+ SessionWindow* window = GetWindow(tab_ptr->window_id, windows);
window->tabs.push_back(std::move(tab));
// See note in SessionTab as to why we do this.
@@ -324,7 +321,7 @@ bool CreateTabsAndWindows(
const std::vector<std::unique_ptr<SessionCommand>>& data,
IdToSessionTab* tabs,
IdToSessionWindow* windows,
- SessionID::id_type* active_window_id) {
+ SessionID* active_window_id) {
// If the file is corrupt (command with wrong size, or unknown command), we
// still return true and attempt to restore what we we can.
DVLOG(1) << "CreateTabsAndWindows";
@@ -341,7 +338,9 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- GetTab(payload[1], tabs)->window_id.set_id(payload[0]);
+ SessionID window_id = SessionID::FromSerializedValue(payload[0]);
+ SessionID tab_id = SessionID::FromSerializedValue(payload[1]);
+ GetTab(tab_id, tabs)->window_id = window_id;
break;
}
@@ -353,13 +352,12 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- GetWindow(payload.window_id, windows)->bounds.SetRect(payload.x,
- payload.y,
- payload.w,
- payload.h);
- GetWindow(payload.window_id, windows)->show_state =
- payload.is_maximized ?
- ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL;
+ SessionID window_id = SessionID::FromSerializedValue(payload.window_id);
+ GetWindow(window_id, windows)
+ ->bounds.SetRect(payload.x, payload.y, payload.w, payload.h);
+ GetWindow(window_id, windows)->show_state =
+ payload.is_maximized ? ui::SHOW_STATE_MAXIMIZED
+ : ui::SHOW_STATE_NORMAL;
break;
}
@@ -369,11 +367,10 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- GetWindow(payload.window_id, windows)->bounds.SetRect(payload.x,
- payload.y,
- payload.w,
- payload.h);
- GetWindow(payload.window_id, windows)->show_state =
+ SessionID window_id = SessionID::FromSerializedValue(payload.window_id);
+ GetWindow(window_id, windows)
+ ->bounds.SetRect(payload.x, payload.y, payload.w, payload.h);
+ GetWindow(window_id, windows)->show_state =
PersistedShowStateToShowState(payload.show_state);
break;
}
@@ -384,7 +381,8 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- GetTab(payload.id, tabs)->tab_visual_index = payload.index;
+ SessionID tab_id = SessionID::FromSerializedValue(payload.id);
+ GetTab(tab_id, tabs)->tab_visual_index = payload.index;
break;
}
@@ -396,9 +394,9 @@ bool CreateTabsAndWindows(
return true;
}
if (command->id() == kCommandTabClosed)
- tabs->erase(payload.id);
+ tabs->erase(SessionID::FromSerializedValue(payload.id));
else
- windows->erase(payload.id);
+ windows->erase(SessionID::FromSerializedValue(payload.id));
break;
}
@@ -409,7 +407,8 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- SessionTab* tab = GetTab(payload.id, tabs);
+ SessionTab* tab =
+ GetTab(SessionID::FromSerializedValue(payload.id), tabs);
tab->navigations.erase(
FindClosestNavigationWithIndex(&(tab->navigations), payload.index),
tab->navigations.end());
@@ -423,7 +422,8 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- SessionTab* tab = GetTab(payload.id, tabs);
+ SessionTab* tab =
+ GetTab(SessionID::FromSerializedValue(payload.id), tabs);
// Update the selected navigation index.
tab->current_navigation_index =
@@ -442,7 +442,7 @@ bool CreateTabsAndWindows(
case kCommandUpdateTabNavigation: {
sessions::SerializedNavigationEntry navigation;
- SessionID::id_type tab_id;
+ SessionID tab_id = SessionID::InvalidValue();
if (!RestoreUpdateTabNavigationCommand(*command,
&navigation,
&tab_id)) {
@@ -465,7 +465,8 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- GetTab(payload.id, tabs)->current_navigation_index = payload.index;
+ GetTab(SessionID::FromSerializedValue(payload.id), tabs)
+ ->current_navigation_index = payload.index;
break;
}
@@ -475,7 +476,8 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- GetWindow(payload.id, windows)->selected_tab_index = payload.index;
+ GetWindow(SessionID::FromSerializedValue(payload.id), windows)
+ ->selected_tab_index = payload.index;
break;
}
@@ -485,8 +487,9 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- GetWindow(payload.id, windows)->is_constrained = false;
- GetWindow(payload.id, windows)->type =
+ SessionID window_id = SessionID::FromSerializedValue(payload.id);
+ GetWindow(window_id, windows)->is_constrained = false;
+ GetWindow(window_id, windows)->type =
static_cast<SessionWindow::WindowType>(payload.index);
break;
}
@@ -497,12 +500,13 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- GetTab(payload.tab_id, tabs)->pinned = payload.pinned_state;
+ GetTab(SessionID::FromSerializedValue(payload.tab_id), tabs)->pinned =
+ payload.pinned_state;
break;
}
case kCommandSetWindowAppName: {
- SessionID::id_type window_id;
+ SessionID window_id = SessionID::InvalidValue();
std::string app_name;
if (!RestoreSetWindowAppNameCommand(*command, &window_id, &app_name))
return true;
@@ -512,7 +516,7 @@ bool CreateTabsAndWindows(
}
case kCommandSetExtensionAppID: {
- SessionID::id_type tab_id;
+ SessionID tab_id = SessionID::InvalidValue();
std::string extension_app_id;
if (!RestoreSetTabExtensionAppIDCommand(*command,
&tab_id,
@@ -526,7 +530,7 @@ bool CreateTabsAndWindows(
}
case kCommandSetTabUserAgentOverride: {
- SessionID::id_type tab_id;
+ SessionID tab_id = SessionID::InvalidValue();
std::string user_agent_override;
if (!RestoreSetTabUserAgentOverrideCommand(
*command,
@@ -549,8 +553,8 @@ bool CreateTabsAndWindows(
!iter.ReadString(&session_storage_persistent_id))
return true;
// Associate the session storage back.
- GetTab(command_tab_id, tabs)->session_storage_persistent_id =
- session_storage_persistent_id;
+ GetTab(SessionID::FromSerializedValue(command_tab_id), tabs)
+ ->session_storage_persistent_id = session_storage_persistent_id;
break;
}
@@ -560,7 +564,7 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- *active_window_id = payload;
+ *active_window_id = SessionID::FromSerializedValue(payload);
break;
}
@@ -570,7 +574,8 @@ bool CreateTabsAndWindows(
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- SessionTab* tab = GetTab(payload.tab_id, tabs);
+ SessionTab* tab =
+ GetTab(SessionID::FromSerializedValue(payload.tab_id), tabs);
tab->last_active_time =
base::TimeTicks::FromInternalValue(payload.last_active_time);
break;
@@ -579,13 +584,14 @@ bool CreateTabsAndWindows(
case kCommandSetWindowWorkspace2: {
std::unique_ptr<base::Pickle> pickle(command->PayloadAsPickle());
base::PickleIterator it(*pickle);
- SessionID::id_type window_id;
+ SessionID::id_type window_id = -1;
std::string workspace;
if (!it.ReadInt(&window_id) || !it.ReadString(&workspace)) {
DVLOG(1) << "Failed reading command " << command->id();
return true;
}
- GetWindow(window_id, windows)->workspace = workspace;
+ GetWindow(SessionID::FromSerializedValue(window_id), windows)
+ ->workspace = workspace;
break;
}
@@ -652,14 +658,13 @@ std::unique_ptr<SessionCommand> CreateSetTabIndexInWindowCommand(
return command;
}
-std::unique_ptr<SessionCommand> CreateTabClosedCommand(
- const SessionID::id_type tab_id) {
+std::unique_ptr<SessionCommand> CreateTabClosedCommand(const SessionID tab_id) {
ClosedPayload payload;
// Because of what appears to be a compiler bug setting payload to {0} doesn't
// set the padding to 0, resulting in Purify reporting an UMR when we write
// the structure to disk. To avoid this we explicitly memset the struct.
memset(&payload, 0, sizeof(payload));
- payload.id = tab_id;
+ payload.id = tab_id.id();
payload.close_time = base::Time::Now().ToInternalValue();
std::unique_ptr<SessionCommand> command =
std::make_unique<SessionCommand>(kCommandTabClosed, sizeof(payload));
@@ -668,11 +673,11 @@ std::unique_ptr<SessionCommand> CreateTabClosedCommand(
}
std::unique_ptr<SessionCommand> CreateWindowClosedCommand(
- const SessionID::id_type window_id) {
+ const SessionID window_id) {
ClosedPayload payload;
// See comment in CreateTabClosedCommand as to why we do this.
memset(&payload, 0, sizeof(payload));
- payload.id = window_id;
+ payload.id = window_id.id();
payload.close_time = base::Time::Now().ToInternalValue();
std::unique_ptr<SessionCommand> command =
std::make_unique<SessionCommand>(kCommandWindowClosed, sizeof(payload));
@@ -786,33 +791,29 @@ std::unique_ptr<SessionCommand> CreateTabNavigationPathPrunedFromFrontCommand(
std::unique_ptr<SessionCommand> CreateUpdateTabNavigationCommand(
const SessionID& tab_id,
const sessions::SerializedNavigationEntry& navigation) {
- return CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation,
- tab_id.id(),
- navigation);
+ return CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, tab_id,
+ navigation);
}
std::unique_ptr<SessionCommand> CreateSetTabExtensionAppIDCommand(
const SessionID& tab_id,
const std::string& extension_id) {
- return CreateSetTabExtensionAppIDCommand(kCommandSetExtensionAppID,
- tab_id.id(),
- extension_id);
+ return CreateSetTabExtensionAppIDCommand(kCommandSetExtensionAppID, tab_id,
+ extension_id);
}
std::unique_ptr<SessionCommand> CreateSetTabUserAgentOverrideCommand(
const SessionID& tab_id,
const std::string& user_agent_override) {
return CreateSetTabUserAgentOverrideCommand(kCommandSetTabUserAgentOverride,
- tab_id.id(),
- user_agent_override);
+ tab_id, user_agent_override);
}
std::unique_ptr<SessionCommand> CreateSetWindowAppNameCommand(
const SessionID& window_id,
const std::string& app_name) {
- return CreateSetWindowAppNameCommand(kCommandSetWindowAppName,
- window_id.id(),
- app_name);
+ return CreateSetWindowAppNameCommand(kCommandSetWindowAppName, window_id,
+ app_name);
}
bool ReplacePendingCommand(BaseSessionService* base_session_service,
@@ -880,7 +881,7 @@ bool IsClosingCommand(SessionCommand* command) {
void RestoreSessionFromCommands(
const std::vector<std::unique_ptr<SessionCommand>>& commands,
std::vector<std::unique_ptr<SessionWindow>>* valid_windows,
- SessionID::id_type* active_window_id) {
+ SessionID* active_window_id) {
IdToSessionTab tabs;
IdToSessionWindow windows;
diff --git a/chromium/components/sessions/core/session_service_commands.h b/chromium/components/sessions/core/session_service_commands.h
index be854759c1a..1e3a1746c08 100644
--- a/chromium/components/sessions/core/session_service_commands.h
+++ b/chromium/components/sessions/core/session_service_commands.h
@@ -36,9 +36,9 @@ SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateSetWindowBoundsCommand(
SESSIONS_EXPORT std::unique_ptr<SessionCommand>
CreateSetTabIndexInWindowCommand(const SessionID& tab_id, int new_index);
SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateTabClosedCommand(
- SessionID::id_type tab_id);
+ SessionID tab_id);
SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateWindowClosedCommand(
- SessionID::id_type tab_id);
+ SessionID tab_id);
SESSIONS_EXPORT std::unique_ptr<SessionCommand>
CreateSetSelectedNavigationIndexCommand(const SessionID& tab_id, int index);
SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateSetWindowTypeCommand(
@@ -98,7 +98,7 @@ SESSIONS_EXPORT bool IsClosingCommand(SessionCommand* command);
SESSIONS_EXPORT void RestoreSessionFromCommands(
const std::vector<std::unique_ptr<SessionCommand>>& commands,
std::vector<std::unique_ptr<SessionWindow>>* valid_windows,
- SessionID::id_type* active_window_id);
+ SessionID* active_window_id);
} // namespace sessions
diff --git a/chromium/components/sessions/core/session_types.cc b/chromium/components/sessions/core/session_types.cc
index 4b7ced980ca..ff8a23eb4a8 100644
--- a/chromium/components/sessions/core/session_types.cc
+++ b/chromium/components/sessions/core/session_types.cc
@@ -15,18 +15,19 @@ namespace sessions {
// SessionTab -----------------------------------------------------------------
SessionTab::SessionTab()
- : tab_visual_index(-1),
+ : window_id(SessionID::NewUnique()),
+ tab_id(SessionID::NewUnique()),
+ tab_visual_index(-1),
current_navigation_index(-1),
- pinned(false) {
-}
+ pinned(false) {}
SessionTab::~SessionTab() {
}
void SessionTab::SetFromSyncData(const sync_pb::SessionTab& sync_data,
base::Time timestamp) {
- window_id.set_id(sync_data.window_id());
- tab_id.set_id(sync_data.tab_id());
+ window_id = SessionID::FromSerializedValue(sync_data.window_id());
+ tab_id = SessionID::FromSerializedValue(sync_data.tab_id());
tab_visual_index = sync_data.tab_visual_index();
current_navigation_index = sync_data.current_navigation_index();
pinned = sync_data.pinned();
@@ -58,7 +59,8 @@ sync_pb::SessionTab SessionTab::ToSyncData() const {
// SessionWindow ---------------------------------------------------------------
SessionWindow::SessionWindow()
- : selected_tab_index(-1),
+ : window_id(SessionID::NewUnique()),
+ selected_tab_index(-1),
type(TYPE_TABBED),
is_constrained(true),
show_state(ui::SHOW_STATE_DEFAULT) {}
diff --git a/chromium/components/sessions/core/session_types_unittest.cc b/chromium/components/sessions/core/session_types_unittest.cc
index a9aeee56c36..e672c9e82aa 100644
--- a/chromium/components/sessions/core/session_types_unittest.cc
+++ b/chromium/components/sessions/core/session_types_unittest.cc
@@ -39,8 +39,8 @@ TEST(SessionTab, FromSyncData) {
}
sessions::SessionTab tab;
- tab.window_id.set_id(100);
- tab.tab_id.set_id(100);
+ tab.window_id = SessionID::FromSerializedValue(100);
+ tab.tab_id = SessionID::FromSerializedValue(100);
tab.tab_visual_index = 100;
tab.current_navigation_index = 1000;
tab.pinned = false;
@@ -74,8 +74,8 @@ TEST(SessionTab, FromSyncData) {
TEST(SessionTab, ToSyncData) {
sessions::SessionTab tab;
- tab.window_id.set_id(10);
- tab.tab_id.set_id(5);
+ tab.window_id = SessionID::FromSerializedValue(10);
+ tab.tab_id = SessionID::FromSerializedValue(5);
tab.tab_visual_index = 13;
tab.current_navigation_index = 3;
tab.pinned = true;
diff --git a/chromium/components/sessions/core/tab_restore_service.cc b/chromium/components/sessions/core/tab_restore_service.cc
index bd3183f447b..f6dde300ef0 100644
--- a/chromium/components/sessions/core/tab_restore_service.cc
+++ b/chromium/components/sessions/core/tab_restore_service.cc
@@ -14,11 +14,10 @@ TabRestoreService::TimeFactory::~TimeFactory() {}
// Entry ----------------------------------------------------------------------
-// ID of the next Entry.
-static SessionID::id_type next_entry_id = 1;
-
TabRestoreService::Entry::~Entry() = default;
-TabRestoreService::Entry::Entry(Type type) : id(next_entry_id++), type(type) {}
+
+TabRestoreService::Entry::Entry(Type type)
+ : id(SessionID::NewUnique()), type(type) {}
size_t TabRestoreService::Entry::EstimateMemoryUsage() const {
return 0;
diff --git a/chromium/components/sessions/core/tab_restore_service.h b/chromium/components/sessions/core/tab_restore_service.h
index 5a84024da9d..c83730cec47 100644
--- a/chromium/components/sessions/core/tab_restore_service.h
+++ b/chromium/components/sessions/core/tab_restore_service.h
@@ -58,7 +58,7 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService {
// Unique id for this entry. The id is guaranteed to be unique for a
// session.
- SessionID::id_type id;
+ SessionID id;
// The type of the entry.
const Type type;
@@ -186,7 +186,7 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService {
LiveTabContext* context) = 0;
// Removes the Tab with id |id| from the list and returns it.
- virtual std::unique_ptr<Tab> RemoveTabEntryById(SessionID::id_type id) = 0;
+ virtual std::unique_ptr<Tab> RemoveTabEntryById(SessionID 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
@@ -196,7 +196,7 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService {
// tab(s).
virtual std::vector<LiveTab*> RestoreEntryById(
LiveTabContext* context,
- SessionID::id_type id,
+ SessionID id,
WindowOpenDisposition disposition) = 0;
// Loads the tabs and previous session. This does nothing if the tabs
diff --git a/chromium/components/sessions/core/tab_restore_service_client.h b/chromium/components/sessions/core/tab_restore_service_client.h
index 60cdc1eaf32..f9388fe99b2 100644
--- a/chromium/components/sessions/core/tab_restore_service_client.h
+++ b/chromium/components/sessions/core/tab_restore_service_client.h
@@ -33,7 +33,7 @@ struct SessionWindow;
// The second parameter is the id of the window that was last active.
using GetLastSessionCallback =
base::Callback<void(std::vector<std::unique_ptr<SessionWindow>>,
- SessionID::id_type)>;
+ SessionID)>;
// A client interface that needs to be supplied to the tab restore service by
// the embedder.
@@ -56,8 +56,7 @@ class SESSIONS_EXPORT TabRestoreServiceClient {
// Returns the LiveTabContext instance that is associated with |desired_id|,
// or null if there is no such instance.
- virtual LiveTabContext* FindLiveTabContextWithID(
- SessionID::id_type desired_id) = 0;
+ virtual LiveTabContext* FindLiveTabContextWithID(SessionID desired_id) = 0;
// Returns whether a given URL should be tracked for restoring.
virtual bool ShouldTrackURLForRestore(const GURL& url) = 0;
diff --git a/chromium/components/sessions/core/tab_restore_service_helper.cc b/chromium/components/sessions/core/tab_restore_service_helper.cc
index 3d00472cd6d..d7e3a9543d4 100644
--- a/chromium/components/sessions/core/tab_restore_service_helper.cc
+++ b/chromium/components/sessions/core/tab_restore_service_helper.cc
@@ -37,9 +37,8 @@ void TabRestoreServiceHelper::Observer::OnClearEntries() {}
void TabRestoreServiceHelper::Observer::OnNavigationEntriesDeleted() {}
void TabRestoreServiceHelper::Observer::OnRestoreEntryById(
- SessionID::id_type id,
- Entries::const_iterator entry_iterator) {
-}
+ SessionID id,
+ Entries::const_iterator entry_iterator) {}
void TabRestoreServiceHelper::Observer::OnAddEntry() {}
@@ -144,48 +143,59 @@ void TabRestoreServiceHelper::ClearEntries() {
bool TabRestoreServiceHelper::DeleteFromTab(const DeletionPredicate& predicate,
Tab* tab) {
+ // TODO(dullweber): Change to DCHECK() when this is tested to be true.
+ CHECK(ValidateTab(*tab));
std::vector<SerializedNavigationEntry> new_navigations;
- int deleted_navigations = 0;
- for (auto& navigation : tab->navigations) {
+ int deleted_navigations_count = 0;
+ for (size_t i = 0; i < tab->navigations.size(); i++) {
+ SerializedNavigationEntry& navigation = tab->navigations[i];
if (predicate.Run(navigation)) {
// If the current navigation is deleted, remove this tab.
- if (tab->current_navigation_index == navigation.index())
+ if (static_cast<int>(i) == tab->current_navigation_index)
return true;
- deleted_navigations++;
+ deleted_navigations_count++;
} else {
// Adjust indices according to number of deleted navigations.
- if (tab->current_navigation_index == navigation.index())
- tab->current_navigation_index -= deleted_navigations;
- navigation.set_index(navigation.index() - deleted_navigations);
+ if (static_cast<int>(i) == tab->current_navigation_index)
+ tab->current_navigation_index -= deleted_navigations_count;
+ DCHECK_GE(navigation.index(), deleted_navigations_count);
+ navigation.set_index(navigation.index() - deleted_navigations_count);
new_navigations.push_back(std::move(navigation));
}
}
tab->navigations = std::move(new_navigations);
- DCHECK(tab->navigations.empty() || ValidateTab(*tab));
+ // TODO(dullweber): Change to DCHECK() when this is tested to be true.
+ CHECK(tab->navigations.empty() || ValidateTab(*tab));
return tab->navigations.empty();
}
bool TabRestoreServiceHelper::DeleteFromWindow(
const DeletionPredicate& predicate,
Window* window) {
+ // TODO(dullweber): Change to DCHECK() when this is tested to be true.
+ CHECK(ValidateWindow(*window));
std::vector<std::unique_ptr<Tab>> new_tabs;
- int deleted_tabs = 0;
- for (auto& tab : window->tabs) {
+ int deleted_tabs_count = 0;
+ for (size_t i = 0; i < window->tabs.size(); i++) {
+ std::unique_ptr<Tab>& tab = window->tabs[i];
if (DeleteFromTab(predicate, tab.get())) {
- if (window->tabs[window->selected_tab_index] == tab)
- window->selected_tab_index = 0;
- deleted_tabs++;
+ if (static_cast<int>(i) == window->selected_tab_index)
+ window->selected_tab_index = new_tabs.empty() ? 0 : new_tabs.size() - 1;
+ deleted_tabs_count++;
} else {
// Adjust indices according to number of deleted tabs.
- if (window->tabs[window->selected_tab_index] == tab)
- window->selected_tab_index -= deleted_tabs;
- if (tab->tabstrip_index >= 0)
- tab->tabstrip_index -= deleted_tabs;
+ if (static_cast<int>(i) == window->selected_tab_index)
+ window->selected_tab_index -= deleted_tabs_count;
+ if (tab->tabstrip_index >= 0) {
+ DCHECK_GE(tab->tabstrip_index, deleted_tabs_count);
+ tab->tabstrip_index -= deleted_tabs_count;
+ }
new_tabs.push_back(std::move(tab));
}
}
window->tabs = std::move(new_tabs);
- DCHECK(window->tabs.empty() || ValidateWindow(*window));
+ // TODO(dullweber): Change to DCHECK() when this is tested to be true.
+ CHECK(window->tabs.empty() || ValidateWindow(*window));
return window->tabs.empty();
}
@@ -232,7 +242,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreMostRecentEntry(
}
std::unique_ptr<TabRestoreService::Tab>
-TabRestoreServiceHelper::RemoveTabEntryById(SessionID::id_type id) {
+TabRestoreServiceHelper::RemoveTabEntryById(SessionID id) {
auto it = GetEntryIteratorById(id);
if (it == entries_.end())
return nullptr;
@@ -247,7 +257,7 @@ TabRestoreServiceHelper::RemoveTabEntryById(SessionID::id_type id) {
std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
LiveTabContext* context,
- SessionID::id_type id,
+ SessionID id,
WindowOpenDisposition disposition) {
Entries::iterator entry_iterator = GetEntryIteratorById(id);
if (entry_iterator == entries_.end()) {
@@ -304,7 +314,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
}
// All the window's tabs had the same former browser_id.
if (auto browser_id = window.tabs[0]->browser_id) {
- UpdateTabBrowserIDs(browser_id, context->GetSessionID().id());
+ UpdateTabBrowserIDs(browser_id, context->GetSessionID());
}
} else {
// Restore a single tab from the window. Find the tab that matches the
@@ -332,7 +342,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
// any one is restored, it goes into the same window as the tab
// being restored now.
UpdateTabBrowserIDs(restored_tab_browser_id,
- context->GetSessionID().id());
+ context->GetSessionID());
for (auto& tab_j : window.tabs)
tab_j->browser_id = context->GetSessionID().id();
}
@@ -406,7 +416,7 @@ void TabRestoreServiceHelper::PruneEntries() {
}
TabRestoreService::Entries::iterator
-TabRestoreServiceHelper::GetEntryIteratorById(SessionID::id_type id) {
+TabRestoreServiceHelper::GetEntryIteratorById(SessionID id) {
for (Entries::iterator i = entries_.begin(); i != entries_.end(); ++i) {
if ((*i)->id == id)
return i;
@@ -534,7 +544,8 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTab(
} else {
// We only respect the tab's original browser if there's no disposition.
if (disposition == WindowOpenDisposition::UNKNOWN && tab.browser_id) {
- context = client_->FindLiveTabContextWithID(tab.browser_id);
+ context = client_->FindLiveTabContextWithID(
+ SessionID::FromSerializedValue(tab.browser_id));
}
int tab_index = -1;
@@ -548,7 +559,7 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTab(
context = client_->CreateLiveTabContext(
std::string(), gfx::Rect(), ui::SHOW_STATE_NORMAL, std::string());
if (tab.browser_id)
- UpdateTabBrowserIDs(tab.browser_id, context->GetSessionID().id());
+ UpdateTabBrowserIDs(tab.browser_id, context->GetSessionID());
}
// Place the tab at the end if the tab index is no longer valid or
@@ -627,12 +638,12 @@ bool TabRestoreServiceHelper::FilterEntry(const Entry& entry) {
}
void TabRestoreServiceHelper::UpdateTabBrowserIDs(SessionID::id_type old_id,
- SessionID::id_type new_id) {
+ SessionID new_id) {
for (const auto& entry : entries_) {
if (entry->type == TabRestoreService::TAB) {
auto& tab = static_cast<Tab&>(*entry);
if (tab.browser_id == old_id)
- tab.browser_id = new_id;
+ tab.browser_id = new_id.id();
}
}
}
diff --git a/chromium/components/sessions/core/tab_restore_service_helper.h b/chromium/components/sessions/core/tab_restore_service_helper.h
index abeb588d1ee..19676251cb9 100644
--- a/chromium/components/sessions/core/tab_restore_service_helper.h
+++ b/chromium/components/sessions/core/tab_restore_service_helper.h
@@ -50,7 +50,7 @@ class SESSIONS_EXPORT TabRestoreServiceHelper
// Invoked before the entry is restored. |entry_iterator| points to the
// entry corresponding to the session identified by |id|.
- virtual void OnRestoreEntryById(SessionID::id_type id,
+ virtual void OnRestoreEntryById(SessionID id,
Entries::const_iterator entry_iterator);
// Invoked after an entry was added.
@@ -86,9 +86,9 @@ class SESSIONS_EXPORT TabRestoreServiceHelper
const Entries& entries() const;
std::vector<LiveTab*> RestoreMostRecentEntry(LiveTabContext* context);
- std::unique_ptr<Tab> RemoveTabEntryById(SessionID::id_type id);
+ std::unique_ptr<Tab> RemoveTabEntryById(SessionID id);
std::vector<LiveTab*> RestoreEntryById(LiveTabContext* context,
- SessionID::id_type id,
+ SessionID id,
WindowOpenDisposition disposition);
bool IsRestoring() const;
@@ -112,7 +112,7 @@ class SESSIONS_EXPORT TabRestoreServiceHelper
// identifies a Window, then its iterator position will be returned. If it
// identifies a tab, then the iterator position of the Window in which the Tab
// resides is returned.
- Entries::iterator GetEntryIteratorById(SessionID::id_type id);
+ Entries::iterator GetEntryIteratorById(SessionID id);
// From base::trace_event::MemoryDumpProvider
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
@@ -170,8 +170,7 @@ class SESSIONS_EXPORT TabRestoreServiceHelper
bool FilterEntry(const Entry& entry);
// Finds tab entries with the old browser_id and sets it to the new one.
- void UpdateTabBrowserIDs(SessionID::id_type old_id,
- SessionID::id_type new_id);
+ void UpdateTabBrowserIDs(SessionID::id_type old_id, SessionID new_id);
// Gets the current time. This uses the time_factory_ if there is one.
base::Time TimeNow() const;