summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sessions
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 12:21:32 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 12:21:32 +0000
commit76263ea3a6e1879b70355e8ef93b14d617cb50e5 (patch)
tree5bdf02930d764a450fe7b9e112f716cda77d6e82 /chrome/browser/sessions
parent98d2ab145e18daa11d471dedc5cc6e425fd9dcfd (diff)
downloadchromium_src-76263ea3a6e1879b70355e8ef93b14d617cb50e5.zip
chromium_src-76263ea3a6e1879b70355e8ef93b14d617cb50e5.tar.gz
chromium_src-76263ea3a6e1879b70355e8ef93b14d617cb50e5.tar.bz2
In the TabRestoreService, do not create Window entries that only have 1 Tab.
BUG=56744 TEST=Open a window and navigate 1 tab. Close window. Both NTP and the Mac History menu show the tab, without being in a window. Review URL: http://codereview.chromium.org/3397032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62537 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions')
-rw-r--r--chrome/browser/sessions/session_restore_browsertest.cc28
-rw-r--r--chrome/browser/sessions/tab_restore_service.cc16
-rw-r--r--chrome/browser/sessions/tab_restore_service.h10
3 files changed, 42 insertions, 12 deletions
diff --git a/chrome/browser/sessions/session_restore_browsertest.cc b/chrome/browser/sessions/session_restore_browsertest.cc
index 8ec1281..9ff065d 100644
--- a/chrome/browser/sessions/session_restore_browsertest.cc
+++ b/chrome/browser/sessions/session_restore_browsertest.cc
@@ -117,3 +117,31 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreIndividualTabFromWindow) {
window = static_cast<TabRestoreService::Window*>(service->entries().front());
EXPECT_EQ(2U, window->tabs.size());
}
+
+IN_PROC_BROWSER_TEST_F(SessionRestoreTest, WindowWithOneTab) {
+ GURL url(ui_test_utils::GetTestUrl(
+ FilePath(FilePath::kCurrentDirectory),
+ FilePath(FILE_PATH_LITERAL("title1.html"))));
+
+ // Add a single tab.
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ TabRestoreService* service = browser()->profile()->GetTabRestoreService();
+ service->ClearEntries();
+ EXPECT_EQ(0U, service->entries().size());
+
+ // Close the window.
+ browser()->window()->Close();
+
+ // Expect the window to be converted to a tab by the TRS.
+ EXPECT_EQ(1U, service->entries().size());
+ ASSERT_EQ(TabRestoreService::TAB, service->entries().front()->type);
+ const TabRestoreService::Tab* tab =
+ static_cast<TabRestoreService::Tab*>(service->entries().front());
+
+ // Restore the tab.
+ service->RestoreEntryById(NULL, tab->id, false);
+
+ // Make sure the restore was successful.
+ EXPECT_EQ(0U, service->entries().size());
+}
diff --git a/chrome/browser/sessions/tab_restore_service.cc b/chrome/browser/sessions/tab_restore_service.cc
index 5b5f59f..3d78771 100644
--- a/chrome/browser/sessions/tab_restore_service.cc
+++ b/chrome/browser/sessions/tab_restore_service.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -222,7 +222,7 @@ void TabRestoreService::BrowserClosing(Browser* browser) {
closing_browsers_.insert(browser);
- Window* window = new Window();
+ scoped_ptr<Window> window(new Window());
window->selected_tab_index = browser->selected_index();
window->timestamp = TimeNow();
// Don't use std::vector::resize() because it will push copies of an empty tab
@@ -242,14 +242,16 @@ void TabRestoreService::BrowserClosing(Browser* browser) {
entry_index++;
}
}
- if (window->tabs.empty()) {
- delete window;
- window = NULL;
- } else {
+ if (window->tabs.size() == 1) {
+ // Short-circuit creating a Window if only 1 tab was present. This fixes
+ // http://crbug.com/56744. Copy the Tab because it's owned by an object on
+ // the stack.
+ AddEntry(new Tab(window->tabs[0]), true, true);
+ } else if (!window->tabs.empty()) {
window->selected_tab_index =
std::min(static_cast<int>(window->tabs.size() - 1),
window->selected_tab_index);
- AddEntry(window, true, true);
+ AddEntry(window.release(), true, true);
}
}
diff --git a/chrome/browser/sessions/tab_restore_service.h b/chrome/browser/sessions/tab_restore_service.h
index 48c9dab..932de55 100644
--- a/chrome/browser/sessions/tab_restore_service.h
+++ b/chrome/browser/sessions/tab_restore_service.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -202,10 +202,10 @@ class TabRestoreService : public BaseSessionService {
// Notifies observers the tabs have changed.
void NotifyTabsChanged();
- // Adds |entry| to the list of entries. If |prune| is true |PruneAndNotify|
- // is invoked. If |to_front| is true the entry is added to the front,
- // otherwise the back. Normal closes go to the front, but tab/window closes
- // from the previous session are added to the back.
+ // Adds |entry| to the list of entries and takes ownership. If |prune| is true
+ // |PruneAndNotify| is invoked. If |to_front| is true the entry is added to
+ // the front, otherwise the back. Normal closes go to the front, but
+ // tab/window closes from the previous session are added to the back.
void AddEntry(Entry* entry, bool prune, bool to_front);
// Prunes entries_ to contain only kMaxEntries and invokes NotifyTabsChanged.