Commit 5b74b87c authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

Remove default constructor for SessionID

It was recently deprecated in favor of the less subtle
SessionID::NewUnique(), with the same implementation. This patch
removes the deprecated API which includes the aforementioned default
constructor as well as SessionID::set_id().

Most calling sites have been migrated in recent CLs and the remaining
ones are now surfaced, both intentional and accidental.

The plan for follow-up patches will consider:
1. Reintroducing the default constructor, but with
   SessionID::InvalidValue() as the default.
2. Moving SessionID::NewUnique() to a factory method in a newly
   introduced KeyedService for this purpose.

Bug: 823798
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I3abbc9b5a1497c11a99c9f80c6b2eadb7b7c6df8
Reviewed-on: https://chromium-review.googlesource.com/995899
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarrajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550127}
parent aacb7cf3
...@@ -184,6 +184,8 @@ void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) { ...@@ -184,6 +184,8 @@ void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) {
TabAndroid::TabAndroid(JNIEnv* env, const JavaRef<jobject>& obj) TabAndroid::TabAndroid(JNIEnv* env, const JavaRef<jobject>& obj)
: weak_java_tab_(env, obj), : weak_java_tab_(env, obj),
session_tab_id_(SessionID::NewUnique()),
session_window_id_(SessionID::InvalidValue()),
content_layer_(cc::Layer::Create()), content_layer_(cc::Layer::Create()),
tab_content_manager_(NULL), tab_content_manager_(NULL),
synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)), synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)),
...@@ -417,8 +419,8 @@ void TabAndroid::InitWebContents( ...@@ -417,8 +419,8 @@ void TabAndroid::InitWebContents(
SetWindowSessionID(session_window_id_); SetWindowSessionID(session_window_id_);
session_tab_id_.set_id( session_tab_id_ =
SessionTabHelper::FromWebContents(web_contents())->session_id().id()); SessionTabHelper::FromWebContents(web_contents())->session_id();
ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( ContextMenuHelper::FromWebContents(web_contents())->SetPopulator(
jcontext_menu_populator); jcontext_menu_populator);
ViewAndroidHelper::FromWebContents(web_contents())-> ViewAndroidHelper::FromWebContents(web_contents())->
......
...@@ -24,6 +24,13 @@ namespace { ...@@ -24,6 +24,13 @@ namespace {
typedef base::OnceCallback<SessionID(void)> TabIdGetter; typedef base::OnceCallback<SessionID(void)> TabIdGetter;
typedef base::OnceCallback<void(SessionID)> TabIdCallback; typedef base::OnceCallback<void(SessionID)> TabIdCallback;
// Temporary workaround because base::PostTaskAndReplyWithResult() does not
// support types without a default constructor.
// TODO(crbug.com/823798): Revert once a default constructor is reintroduced.
SessionID::id_type WrapTabIdGetter(TabIdGetter tab_id_getter) {
return std::move(tab_id_getter).Run().id();
}
} // namespace } // namespace
// Object that can run a list of callbacks that take tab IDs. New callbacks // Object that can run a list of callbacks that take tab IDs. New callbacks
...@@ -44,7 +51,7 @@ class TabIdProvider::CallbackRunner { ...@@ -44,7 +51,7 @@ class TabIdProvider::CallbackRunner {
// Runs all the callbacks in the order that they were added. This method must // Runs all the callbacks in the order that they were added. This method must
// not be called more than once. // not be called more than once.
void RunAll(SessionID tab_info) { void RunAll(SessionID::id_type tab_info_value) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!is_done_); DCHECK(!is_done_);
is_done_ = true; is_done_ = true;
...@@ -52,6 +59,7 @@ class TabIdProvider::CallbackRunner { ...@@ -52,6 +59,7 @@ class TabIdProvider::CallbackRunner {
std::vector<TabIdCallback> running_callbacks; std::vector<TabIdCallback> running_callbacks;
running_callbacks.swap(callbacks_); running_callbacks.swap(callbacks_);
SessionID tab_info = SessionID::FromSerializedValue(tab_info_value);
for (auto& callback : running_callbacks) for (auto& callback : running_callbacks)
std::move(callback).Run(tab_info); std::move(callback).Run(tab_info);
} }
...@@ -84,7 +92,8 @@ TabIdProvider::TabIdProvider(base::TaskRunner* task_runner, ...@@ -84,7 +92,8 @@ TabIdProvider::TabIdProvider(base::TaskRunner* task_runner,
// -1 to OnTabIdReady, so that case doesn't need to be explicitly handled // -1 to OnTabIdReady, so that case doesn't need to be explicitly handled
// here. // here.
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
task_runner, from_here, std::move(tab_id_getter), task_runner, from_here,
base::BindOnce(&WrapTabIdGetter, std::move(tab_id_getter)),
base::BindOnce(&CallbackRunner::RunAll, base::BindOnce(&CallbackRunner::RunAll,
base::Owned(callback_runner.release()))); base::Owned(callback_runner.release())));
} }
......
...@@ -68,14 +68,15 @@ class PersistentTabRestoreTimeFactory ...@@ -68,14 +68,15 @@ class PersistentTabRestoreTimeFactory
class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness { class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness {
public: public:
PersistentTabRestoreServiceTest() PersistentTabRestoreServiceTest()
: url1_("http://1"), : url1_("http://1"),
url2_("http://2"), url2_("http://2"),
url3_("http://3"), url3_("http://3"),
user_agent_override_( user_agent_override_(
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19"
" (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19"), " (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19"),
time_factory_(NULL) { time_factory_(NULL),
} window_id_(SessionID::FromSerializedValue(1)),
tab_id_(SessionID::FromSerializedValue(2)) {}
~PersistentTabRestoreServiceTest() override {} ~PersistentTabRestoreServiceTest() override {}
...@@ -142,8 +143,8 @@ class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness { ...@@ -142,8 +143,8 @@ class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness {
// If |pinned| is true, the tab is marked as pinned in the session service. // If |pinned| is true, the tab is marked as pinned in the session service.
void AddWindowWithOneTabToSessionService(bool pinned) { void AddWindowWithOneTabToSessionService(bool pinned) {
// Create new window / tab IDs so that these remain distinct. // Create new window / tab IDs so that these remain distinct.
window_id_ = SessionID(); window_id_ = SessionID::NewUnique();
tab_id_ = SessionID(); tab_id_ = SessionID::NewUnique();
SessionService* session_service = SessionService* session_service =
SessionServiceFactory::GetForProfile(profile()); SessionServiceFactory::GetForProfile(profile());
......
...@@ -108,7 +108,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest { ...@@ -108,7 +108,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest {
// pinned state of the tab is updated. The session service is then recreated // pinned state of the tab is updated. The session service is then recreated
// and the pinned state of the read back tab is returned. // and the pinned state of the read back tab is returned.
bool CreateAndWriteSessionWithOneTab(bool pinned_state, bool write_always) { bool CreateAndWriteSessionWithOneTab(bool pinned_state, bool write_always) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
SerializedNavigationEntry nav1 = SerializedNavigationEntry nav1 =
SerializedNavigationEntryTestHelper::CreateNavigation( SerializedNavigationEntryTestHelper::CreateNavigation(
"http://google.com", "abc"); "http://google.com", "abc");
...@@ -166,7 +166,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest { ...@@ -166,7 +166,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest {
const std::string window_workspace = "abc"; const std::string window_workspace = "abc";
SessionID window_id; const SessionID window_id = SessionID::NewUnique();
// Path used in testing. // Path used in testing.
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
...@@ -176,7 +176,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest { ...@@ -176,7 +176,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest {
}; };
TEST_F(SessionServiceTest, Basic) { TEST_F(SessionServiceTest, Basic) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
ASSERT_NE(window_id, tab_id); ASSERT_NE(window_id, tab_id);
SerializedNavigationEntry nav1 = SerializedNavigationEntry nav1 =
...@@ -207,7 +207,7 @@ TEST_F(SessionServiceTest, Basic) { ...@@ -207,7 +207,7 @@ TEST_F(SessionServiceTest, Basic) {
// Make sure we persist post entries. // Make sure we persist post entries.
TEST_F(SessionServiceTest, PersistPostData) { TEST_F(SessionServiceTest, PersistPostData) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
ASSERT_NE(window_id, tab_id); ASSERT_NE(window_id, tab_id);
SerializedNavigationEntry nav1 = SerializedNavigationEntry nav1 =
...@@ -225,8 +225,8 @@ TEST_F(SessionServiceTest, PersistPostData) { ...@@ -225,8 +225,8 @@ TEST_F(SessionServiceTest, PersistPostData) {
} }
TEST_F(SessionServiceTest, ClosingTabStaysClosed) { TEST_F(SessionServiceTest, ClosingTabStaysClosed) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
SessionID tab2_id; SessionID tab2_id = SessionID::NewUnique();
ASSERT_NE(tab_id, tab2_id); ASSERT_NE(tab_id, tab2_id);
SerializedNavigationEntry nav1 = SerializedNavigationEntry nav1 =
...@@ -258,7 +258,7 @@ TEST_F(SessionServiceTest, ClosingTabStaysClosed) { ...@@ -258,7 +258,7 @@ TEST_F(SessionServiceTest, ClosingTabStaysClosed) {
} }
TEST_F(SessionServiceTest, Pruning) { TEST_F(SessionServiceTest, Pruning) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
SerializedNavigationEntry nav1 = SerializedNavigationEntry nav1 =
SerializedNavigationEntryTestHelper::CreateNavigation( SerializedNavigationEntryTestHelper::CreateNavigation(
...@@ -294,9 +294,9 @@ TEST_F(SessionServiceTest, Pruning) { ...@@ -294,9 +294,9 @@ TEST_F(SessionServiceTest, Pruning) {
} }
TEST_F(SessionServiceTest, TwoWindows) { TEST_F(SessionServiceTest, TwoWindows) {
SessionID window2_id; SessionID window2_id = SessionID::NewUnique();
SessionID tab1_id; SessionID tab1_id = SessionID::NewUnique();
SessionID tab2_id; SessionID tab2_id = SessionID::NewUnique();
SerializedNavigationEntry nav1; SerializedNavigationEntry nav1;
SerializedNavigationEntry nav2; SerializedNavigationEntry nav2;
...@@ -338,9 +338,9 @@ TEST_F(SessionServiceTest, TwoWindows) { ...@@ -338,9 +338,9 @@ TEST_F(SessionServiceTest, TwoWindows) {
} }
TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) { TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) {
SessionID window2_id; SessionID window2_id = SessionID::NewUnique();
SessionID tab1_id; SessionID tab1_id = SessionID::NewUnique();
SessionID tab2_id; SessionID tab2_id = SessionID::NewUnique();
SerializedNavigationEntry nav1 = SerializedNavigationEntry nav1 =
SerializedNavigationEntryTestHelper::CreateNavigation( SerializedNavigationEntryTestHelper::CreateNavigation(
...@@ -372,8 +372,8 @@ TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) { ...@@ -372,8 +372,8 @@ TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) {
} }
TEST_F(SessionServiceTest, ClosingWindowDoesntCloseTabs) { TEST_F(SessionServiceTest, ClosingWindowDoesntCloseTabs) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
SessionID tab2_id; SessionID tab2_id = SessionID::NewUnique();
ASSERT_NE(tab_id, tab2_id); ASSERT_NE(tab_id, tab2_id);
SerializedNavigationEntry nav1 = SerializedNavigationEntry nav1 =
...@@ -409,9 +409,9 @@ TEST_F(SessionServiceTest, ClosingWindowDoesntCloseTabs) { ...@@ -409,9 +409,9 @@ TEST_F(SessionServiceTest, ClosingWindowDoesntCloseTabs) {
} }
TEST_F(SessionServiceTest, LockingWindowRemembersAll) { TEST_F(SessionServiceTest, LockingWindowRemembersAll) {
SessionID window2_id; SessionID window2_id = SessionID::NewUnique();
SessionID tab1_id; SessionID tab1_id = SessionID::NewUnique();
SessionID tab2_id; SessionID tab2_id = SessionID::NewUnique();
SerializedNavigationEntry nav1; SerializedNavigationEntry nav1;
SerializedNavigationEntry nav2; SerializedNavigationEntry nav2;
...@@ -440,9 +440,9 @@ TEST_F(SessionServiceTest, LockingWindowRemembersAll) { ...@@ -440,9 +440,9 @@ TEST_F(SessionServiceTest, LockingWindowRemembersAll) {
} }
TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) { TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) {
SessionID window2_id; SessionID window2_id = SessionID::NewUnique();
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
SessionID tab2_id; SessionID tab2_id = SessionID::NewUnique();
ASSERT_NE(window2_id, window_id); ASSERT_NE(window2_id, window_id);
service()->SetWindowType(window2_id, service()->SetWindowType(window2_id,
...@@ -484,9 +484,9 @@ TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) { ...@@ -484,9 +484,9 @@ TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) {
// Makes sure we don't track popups. // Makes sure we don't track popups.
TEST_F(SessionServiceTest, IgnorePopups) { TEST_F(SessionServiceTest, IgnorePopups) {
SessionID window2_id; SessionID window2_id = SessionID::NewUnique();
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
SessionID tab2_id; SessionID tab2_id = SessionID::NewUnique();
ASSERT_NE(window2_id, window_id); ASSERT_NE(window2_id, window_id);
service()->SetWindowType(window2_id, service()->SetWindowType(window2_id,
...@@ -538,9 +538,9 @@ TEST_F(SessionServiceTest, RemoveUnusedRestoreWindowsTest) { ...@@ -538,9 +538,9 @@ TEST_F(SessionServiceTest, RemoveUnusedRestoreWindowsTest) {
#if defined (OS_CHROMEOS) #if defined (OS_CHROMEOS)
// Makes sure we track apps. Only applicable on chromeos. // Makes sure we track apps. Only applicable on chromeos.
TEST_F(SessionServiceTest, RestoreApp) { TEST_F(SessionServiceTest, RestoreApp) {
SessionID window2_id; SessionID window2_id = SessionID::NewUnique();
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
SessionID tab2_id; SessionID tab2_id = SessionID::NewUnique();
ASSERT_NE(window2_id, window_id); ASSERT_NE(window2_id, window_id);
service()->SetWindowType(window2_id, service()->SetWindowType(window2_id,
...@@ -594,7 +594,7 @@ TEST_F(SessionServiceTest, RestoreApp) { ...@@ -594,7 +594,7 @@ TEST_F(SessionServiceTest, RestoreApp) {
// Tests pruning from the front. // Tests pruning from the front.
TEST_F(SessionServiceTest, PruneFromFront) { TEST_F(SessionServiceTest, PruneFromFront) {
const std::string base_url("http://google.com/"); const std::string base_url("http://google.com/");
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
helper_.PrepareTabInWindow(window_id, tab_id, 0, true); helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
...@@ -637,7 +637,7 @@ TEST_F(SessionServiceTest, PruneFromFront) { ...@@ -637,7 +637,7 @@ TEST_F(SessionServiceTest, PruneFromFront) {
// Prunes from front so that we have no entries. // Prunes from front so that we have no entries.
TEST_F(SessionServiceTest, PruneToEmpty) { TEST_F(SessionServiceTest, PruneToEmpty) {
const std::string base_url("http://google.com/"); const std::string base_url("http://google.com/");
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
helper_.PrepareTabInWindow(window_id, tab_id, 0, true); helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
...@@ -677,7 +677,7 @@ TEST_F(SessionServiceTest, PinnedTrue) { ...@@ -677,7 +677,7 @@ TEST_F(SessionServiceTest, PinnedTrue) {
// Make sure application extension ids are persisted. // Make sure application extension ids are persisted.
TEST_F(SessionServiceTest, PersistApplicationExtensionID) { TEST_F(SessionServiceTest, PersistApplicationExtensionID) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
ASSERT_NE(window_id, tab_id); ASSERT_NE(window_id, tab_id);
std::string app_id("foo"); std::string app_id("foo");
...@@ -698,7 +698,7 @@ TEST_F(SessionServiceTest, PersistApplicationExtensionID) { ...@@ -698,7 +698,7 @@ TEST_F(SessionServiceTest, PersistApplicationExtensionID) {
// Check that user agent overrides are persisted. // Check that user agent overrides are persisted.
TEST_F(SessionServiceTest, PersistUserAgentOverrides) { TEST_F(SessionServiceTest, PersistUserAgentOverrides) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
ASSERT_NE(window_id, tab_id); ASSERT_NE(window_id, tab_id);
std::string user_agent_override = "Mozilla/5.0 (X11; Linux x86_64) " std::string user_agent_override = "Mozilla/5.0 (X11; Linux x86_64) "
"AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 " "AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 "
...@@ -725,7 +725,7 @@ TEST_F(SessionServiceTest, PersistUserAgentOverrides) { ...@@ -725,7 +725,7 @@ TEST_F(SessionServiceTest, PersistUserAgentOverrides) {
// Makes sure a tab closed by a user gesture is not restored. // Makes sure a tab closed by a user gesture is not restored.
TEST_F(SessionServiceTest, CloseTabUserGesture) { TEST_F(SessionServiceTest, CloseTabUserGesture) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
ASSERT_NE(window_id, tab_id); ASSERT_NE(window_id, tab_id);
SerializedNavigationEntry nav1 = SerializedNavigationEntry nav1 =
...@@ -744,7 +744,7 @@ TEST_F(SessionServiceTest, CloseTabUserGesture) { ...@@ -744,7 +744,7 @@ TEST_F(SessionServiceTest, CloseTabUserGesture) {
// Verifies SetWindowBounds maps SHOW_STATE_DEFAULT to SHOW_STATE_NORMAL. // Verifies SetWindowBounds maps SHOW_STATE_DEFAULT to SHOW_STATE_NORMAL.
TEST_F(SessionServiceTest, DontPersistDefault) { TEST_F(SessionServiceTest, DontPersistDefault) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
ASSERT_NE(window_id, tab_id); ASSERT_NE(window_id, tab_id);
SerializedNavigationEntry nav1 = SerializedNavigationEntry nav1 =
SerializedNavigationEntryTestHelper::CreateNavigation( SerializedNavigationEntryTestHelper::CreateNavigation(
...@@ -762,7 +762,7 @@ TEST_F(SessionServiceTest, DontPersistDefault) { ...@@ -762,7 +762,7 @@ TEST_F(SessionServiceTest, DontPersistDefault) {
} }
TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
ASSERT_NE(window_id, tab_id); ASSERT_NE(window_id, tab_id);
// Create a page state representing a HTTP body without posted passwords. // Create a page state representing a HTTP body without posted passwords.
...@@ -803,7 +803,7 @@ TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { ...@@ -803,7 +803,7 @@ TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) {
} }
TEST_F(SessionServiceTest, RemovePostDataWithPasswords) { TEST_F(SessionServiceTest, RemovePostDataWithPasswords) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
ASSERT_NE(window_id, tab_id); ASSERT_NE(window_id, tab_id);
// Create a page state representing a HTTP body with posted passwords. // Create a page state representing a HTTP body with posted passwords.
...@@ -834,7 +834,7 @@ TEST_F(SessionServiceTest, RemovePostDataWithPasswords) { ...@@ -834,7 +834,7 @@ TEST_F(SessionServiceTest, RemovePostDataWithPasswords) {
TEST_F(SessionServiceTest, ReplacePendingNavigation) { TEST_F(SessionServiceTest, ReplacePendingNavigation) {
const std::string base_url("http://google.com/"); const std::string base_url("http://google.com/");
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
helper_.PrepareTabInWindow(window_id, tab_id, 0, true); helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
...@@ -865,7 +865,7 @@ TEST_F(SessionServiceTest, ReplacePendingNavigation) { ...@@ -865,7 +865,7 @@ TEST_F(SessionServiceTest, ReplacePendingNavigation) {
TEST_F(SessionServiceTest, ReplacePendingNavigationAndPrune) { TEST_F(SessionServiceTest, ReplacePendingNavigationAndPrune) {
const std::string base_url("http://google.com/"); const std::string base_url("http://google.com/");
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
helper_.PrepareTabInWindow(window_id, tab_id, 0, true); helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
...@@ -901,9 +901,9 @@ TEST_F(SessionServiceTest, ReplacePendingNavigationAndPrune) { ...@@ -901,9 +901,9 @@ TEST_F(SessionServiceTest, ReplacePendingNavigationAndPrune) {
} }
TEST_F(SessionServiceTest, RestoreActivation1) { TEST_F(SessionServiceTest, RestoreActivation1) {
SessionID window2_id; SessionID window2_id = SessionID::NewUnique();
SessionID tab1_id; SessionID tab1_id = SessionID::NewUnique();
SessionID tab2_id; SessionID tab2_id = SessionID::NewUnique();
SerializedNavigationEntry nav1; SerializedNavigationEntry nav1;
SerializedNavigationEntry nav2; SerializedNavigationEntry nav2;
...@@ -923,9 +923,9 @@ TEST_F(SessionServiceTest, RestoreActivation1) { ...@@ -923,9 +923,9 @@ TEST_F(SessionServiceTest, RestoreActivation1) {
// It's easier to have two separate tests with setup/teardown than to manualy // It's easier to have two separate tests with setup/teardown than to manualy
// reset the state for the different flavors of the test. // reset the state for the different flavors of the test.
TEST_F(SessionServiceTest, RestoreActivation2) { TEST_F(SessionServiceTest, RestoreActivation2) {
SessionID window2_id; SessionID window2_id = SessionID::NewUnique();
SessionID tab1_id; SessionID tab1_id = SessionID::NewUnique();
SessionID tab2_id; SessionID tab2_id = SessionID::NewUnique();
SerializedNavigationEntry nav1; SerializedNavigationEntry nav1;
SerializedNavigationEntry nav2; SerializedNavigationEntry nav2;
...@@ -946,7 +946,7 @@ TEST_F(SessionServiceTest, RestoreActivation2) { ...@@ -946,7 +946,7 @@ TEST_F(SessionServiceTest, RestoreActivation2) {
// Makes sure we don't track blacklisted URLs. // Makes sure we don't track blacklisted URLs.
TEST_F(SessionServiceTest, IgnoreBlacklistedUrls) { TEST_F(SessionServiceTest, IgnoreBlacklistedUrls) {
SessionID tab_id; SessionID tab_id = SessionID::NewUnique();
SerializedNavigationEntry nav1 = SerializedNavigationEntry nav1 =
SerializedNavigationEntryTestHelper::CreateNavigation( SerializedNavigationEntryTestHelper::CreateNavigation(
......
...@@ -232,7 +232,8 @@ bool GetLocalWindows(int index, ScopedWindowMap* local_windows) { ...@@ -232,7 +232,8 @@ bool GetLocalWindows(int index, ScopedWindowMap* local_windows) {
const sessions::SessionWindow& window = w->second->wrapped_window; const sessions::SessionWindow& window = w->second->wrapped_window;
std::unique_ptr<sync_sessions::SyncedSessionWindow> new_window = std::unique_ptr<sync_sessions::SyncedSessionWindow> new_window =
std::make_unique<sync_sessions::SyncedSessionWindow>(); std::make_unique<sync_sessions::SyncedSessionWindow>();
new_window->wrapped_window.window_id.set_id(window.window_id.id()); new_window->wrapped_window.window_id =
SessionID::FromSerializedValue(window.window_id.id());
for (size_t t = 0; t < window.tabs.size(); ++t) { for (size_t t = 0; t < window.tabs.size(); ++t) {
const sessions::SessionTab& tab = *window.tabs.at(t); const sessions::SessionTab& tab = *window.tabs.at(t);
std::unique_ptr<sessions::SessionTab> new_tab = std::unique_ptr<sessions::SessionTab> new_tab =
......
...@@ -25,7 +25,8 @@ TabModel::TabModel(Profile* profile, bool is_tabbed_activity) ...@@ -25,7 +25,8 @@ TabModel::TabModel(Profile* profile, bool is_tabbed_activity)
live_tab_context_(new AndroidLiveTabContext(this)), live_tab_context_(new AndroidLiveTabContext(this)),
synced_window_delegate_( synced_window_delegate_(
new browser_sync::SyncedWindowDelegateAndroid(this, new browser_sync::SyncedWindowDelegateAndroid(this,
is_tabbed_activity)) { is_tabbed_activity)),
session_id_(SessionID::NewUnique()) {
if (profile) { if (profile) {
// A normal Profile creates an OTR profile if it does not exist when // A normal Profile creates an OTR profile if it does not exist when
// GetOffTheRecordProfile() is called, so we guard it with // GetOffTheRecordProfile() is called, so we guard it with
......
...@@ -367,6 +367,7 @@ Browser::Browser(const CreateParams& params) ...@@ -367,6 +367,7 @@ Browser::Browser(const CreateParams& params)
params.profile)), params.profile)),
app_name_(params.app_name), app_name_(params.app_name),
is_trusted_source_(params.trusted_source), is_trusted_source_(params.trusted_source),
session_id_(SessionID::NewUnique()),
cancel_download_confirmation_state_(NOT_PROMPTED), cancel_download_confirmation_state_(NOT_PROMPTED),
override_bounds_(params.initial_bounds), override_bounds_(params.initial_bounds),
initial_show_state_(params.initial_show_state), initial_show_state_(params.initial_show_state),
......
...@@ -64,7 +64,10 @@ void SettingsWindowManager::ShowChromePageForProfile(Profile* profile, ...@@ -64,7 +64,10 @@ void SettingsWindowManager::ShowChromePageForProfile(Profile* profile,
params.user_gesture = true; params.user_gesture = true;
params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE; params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE;
Navigate(&params); Navigate(&params);
settings_session_map_[profile] = params.browser->session_id();
// operator[] not used because SessionID has no default constructor.
settings_session_map_.emplace(profile, SessionID::InvalidValue())
.first->second = params.browser->session_id();
DCHECK(params.browser->is_trusted_source()); DCHECK(params.browser->is_trusted_source());
for (SettingsWindowManagerObserver& observer : observers_) for (SettingsWindowManagerObserver& observer : observers_)
......
...@@ -34,7 +34,7 @@ struct WindowMetrics { ...@@ -34,7 +34,7 @@ struct WindowMetrics {
bool operator!=(const WindowMetrics& other) { return !operator==(other); } bool operator!=(const WindowMetrics& other) { return !operator==(other); }
// ID for the window, unique within the Chrome session. // ID for the window, unique within the Chrome session.
SessionID window_id; SessionID window_id = SessionID::InvalidValue();
WindowMetricsEvent::Type type; WindowMetricsEvent::Type type;
// TODO(michaelpg): Observe the show state and log when it changes. // TODO(michaelpg): Observe the show state and log when it changes.
WindowMetricsEvent::ShowState show_state; WindowMetricsEvent::ShowState show_state;
......
...@@ -372,8 +372,8 @@ TEST_F(RecentTabsSubMenuModelTest, ...@@ -372,8 +372,8 @@ TEST_F(RecentTabsSubMenuModelTest,
SessionService* session_service = new SessionService(profile()); SessionService* session_service = new SessionService(profile());
SessionServiceFactory::SetForTestProfile(profile(), SessionServiceFactory::SetForTestProfile(profile(),
base::WrapUnique(session_service)); base::WrapUnique(session_service));
SessionID tab_id; SessionID tab_id = SessionID::FromSerializedValue(1);
SessionID window_id; SessionID window_id = SessionID::FromSerializedValue(2);
session_service->SetWindowType(window_id, session_service->SetWindowType(window_id,
Browser::TYPE_TABBED, Browser::TYPE_TABBED,
SessionService::TYPE_NORMAL); SessionService::TYPE_NORMAL);
......
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
TestOmniboxClient::TestOmniboxClient() TestOmniboxClient::TestOmniboxClient()
: autocomplete_classifier_( : session_id_(SessionID::FromSerializedValue(1)),
autocomplete_classifier_(
std::make_unique<AutocompleteController>( std::make_unique<AutocompleteController>(
CreateAutocompleteProviderClient(), CreateAutocompleteProviderClient(),
nullptr, nullptr,
......
...@@ -10,11 +10,7 @@ static SessionID::id_type next_id = 1; ...@@ -10,11 +10,7 @@ static SessionID::id_type next_id = 1;
// static // static
SessionID SessionID::NewUnique() { SessionID SessionID::NewUnique() {
return SessionID(); return SessionID(next_id++);
}
SessionID::SessionID() {
id_ = next_id++;
} }
std::ostream& operator<<(std::ostream& out, SessionID id) { std::ostream& operator<<(std::ostream& out, SessionID id) {
......
...@@ -34,18 +34,12 @@ class SESSIONS_EXPORT SessionID { ...@@ -34,18 +34,12 @@ class SESSIONS_EXPORT SessionID {
// SessionID instance. Note that zero is also considered invalid. // SessionID instance. Note that zero is also considered invalid.
static constexpr bool IsValidValue(id_type value) { return value > 0; } static constexpr bool IsValidValue(id_type value) { return value > 0; }
// Generates a new unique ID (deprecated: use NewUnique() instead).
SessionID();
// All IDs are valid except InvalidValue() above. // All IDs are valid except InvalidValue() above.
bool is_valid() const { return IsValidValue(id_); } bool is_valid() const { return IsValidValue(id_); }
// Returns the underlying id. // Returns the underlying id.
id_type id() const { return id_; } id_type id() const { return id_; }
// Sets underlying type (deprecated: use FromSerializedValue() instead).
void set_id(id_type id) { id_ = id; }
struct Hasher { struct Hasher {
inline std::size_t operator()(SessionID id) const { return id.id(); } inline std::size_t operator()(SessionID id) const { return id.id(); }
}; };
......
...@@ -39,8 +39,8 @@ TEST(SessionTab, FromSyncData) { ...@@ -39,8 +39,8 @@ TEST(SessionTab, FromSyncData) {
} }
sessions::SessionTab tab; sessions::SessionTab tab;
tab.window_id.set_id(100); tab.window_id = SessionID::FromSerializedValue(100);
tab.tab_id.set_id(100); tab.tab_id = SessionID::FromSerializedValue(100);
tab.tab_visual_index = 100; tab.tab_visual_index = 100;
tab.current_navigation_index = 1000; tab.current_navigation_index = 1000;
tab.pinned = false; tab.pinned = false;
...@@ -74,8 +74,8 @@ TEST(SessionTab, FromSyncData) { ...@@ -74,8 +74,8 @@ TEST(SessionTab, FromSyncData) {
TEST(SessionTab, ToSyncData) { TEST(SessionTab, ToSyncData) {
sessions::SessionTab tab; sessions::SessionTab tab;
tab.window_id.set_id(10); tab.window_id = SessionID::FromSerializedValue(10);
tab.tab_id.set_id(5); tab.tab_id = SessionID::FromSerializedValue(5);
tab.tab_visual_index = 13; tab.tab_visual_index = 13;
tab.current_navigation_index = 3; tab.current_navigation_index = 3;
tab.pinned = true; tab.pinned = true;
......
...@@ -454,8 +454,8 @@ bool SessionsSyncManager::InitFromSyncModel( ...@@ -454,8 +454,8 @@ bool SessionsSyncManager::InitFromSyncModel(
// the specifics in place. // the specifics in place.
for (auto& window : for (auto& window :
*rewritten_specifics.mutable_header()->mutable_window()) { *rewritten_specifics.mutable_header()->mutable_window()) {
session_id_map[window.window_id()] = SessionID::NewUnique(); session_id_map.emplace(window.window_id(), SessionID::NewUnique());
window.set_window_id(session_id_map[window.window_id()].id()); window.set_window_id(session_id_map.at(window.window_id()).id());
google::protobuf::RepeatedField<int>* tab_ids = window.mutable_tab(); google::protobuf::RepeatedField<int>* tab_ids = window.mutable_tab();
for (int i = 0; i < tab_ids->size(); i++) { for (int i = 0; i < tab_ids->size(); i++) {
...@@ -463,9 +463,9 @@ bool SessionsSyncManager::InitFromSyncModel( ...@@ -463,9 +463,9 @@ bool SessionsSyncManager::InitFromSyncModel(
if (tab_iter == session_id_map.end()) { if (tab_iter == session_id_map.end()) {
// SessionID::SessionID() automatically increments a static // SessionID::SessionID() automatically increments a static
// variable, forcing a new id to be generated each time. // variable, forcing a new id to be generated each time.
session_id_map[tab_ids->Get(i)] = SessionID::NewUnique(); session_id_map.emplace(tab_ids->Get(i), SessionID::NewUnique());
} }
*(tab_ids->Mutable(i)) = session_id_map[tab_ids->Get(i)].id(); *(tab_ids->Mutable(i)) = session_id_map.at(tab_ids->Get(i)).id();
// Note: the tab id of the SessionTab will be updated when the tab // Note: the tab id of the SessionTab will be updated when the tab
// node itself is processed. // node itself is processed.
} }
......
...@@ -241,6 +241,7 @@ AppWindow::AppWindow(BrowserContext* context, ...@@ -241,6 +241,7 @@ AppWindow::AppWindow(BrowserContext* context,
const Extension* extension) const Extension* extension)
: browser_context_(context), : browser_context_(context),
extension_id_(extension->id()), extension_id_(extension->id()),
session_id_(SessionID::NewUnique()),
app_delegate_(app_delegate), app_delegate_(app_delegate),
image_loader_ptr_factory_(this) { image_loader_ptr_factory_(this) {
ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get(); ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get();
......
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
DEFINE_WEB_STATE_USER_DATA_KEY(IOSChromeSessionTabHelper); DEFINE_WEB_STATE_USER_DATA_KEY(IOSChromeSessionTabHelper);
IOSChromeSessionTabHelper::IOSChromeSessionTabHelper(web::WebState* web_state) { IOSChromeSessionTabHelper::IOSChromeSessionTabHelper(web::WebState* web_state)
} : session_id_(SessionID::NewUnique()),
window_id_(SessionID::InvalidValue()) {}
IOSChromeSessionTabHelper::~IOSChromeSessionTabHelper() {} IOSChromeSessionTabHelper::~IOSChromeSessionTabHelper() {}
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
TabRestoreServiceDelegateImplIOS::TabRestoreServiceDelegateImplIOS( TabRestoreServiceDelegateImplIOS::TabRestoreServiceDelegateImplIOS(
ios::ChromeBrowserState* browser_state) ios::ChromeBrowserState* browser_state)
: browser_state_(browser_state) {} : browser_state_(browser_state), session_id_(SessionID::NewUnique()) {}
TabRestoreServiceDelegateImplIOS::~TabRestoreServiceDelegateImplIOS() {} TabRestoreServiceDelegateImplIOS::~TabRestoreServiceDelegateImplIOS() {}
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
TabModelSyncedWindowDelegate::TabModelSyncedWindowDelegate( TabModelSyncedWindowDelegate::TabModelSyncedWindowDelegate(
WebStateList* web_state_list) WebStateList* web_state_list)
: web_state_list_(web_state_list) { : web_state_list_(web_state_list), session_id_(SessionID::NewUnique()) {
web_state_list_->AddObserver(this); web_state_list_->AddObserver(this);
for (int index = 0; index < web_state_list_->count(); ++index) { for (int index = 0; index < web_state_list_->count(); ++index) {
SetWindowIdForWebState(web_state_list_->GetWebStateAt(index)); SetWindowIdForWebState(web_state_list_->GetWebStateAt(index));
......
...@@ -58,7 +58,7 @@ void AddTabToDistantSession(const sessions::SessionTab& session_tab, ...@@ -58,7 +58,7 @@ void AddTabToDistantSession(const sessions::SessionTab& session_tab,
namespace synced_sessions { namespace synced_sessions {
DistantTab::DistantTab() {} DistantTab::DistantTab() : tab_id(SessionID::InvalidValue()) {}
size_t DistantTab::hashOfUserVisibleProperties() { size_t DistantTab::hashOfUserVisibleProperties() {
std::stringstream ss; std::stringstream ss;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment