summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sessions/tab_restore_service.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 20:20:09 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 20:20:09 +0000
commit5c0e648d6f4ea988be36e74cae045ba5f041e5cb (patch)
treef0fb62cf06be0ef7afa2b74babb0fe0ee7c1bc02 /chrome/browser/sessions/tab_restore_service.cc
parent2e7054c0c76fe1c9a12de5925b7ad1a7aff94e45 (diff)
downloadchromium_src-5c0e648d6f4ea988be36e74cae045ba5f041e5cb.zip
chromium_src-5c0e648d6f4ea988be36e74cae045ba5f041e5cb.tar.gz
chromium_src-5c0e648d6f4ea988be36e74cae045ba5f041e5cb.tar.bz2
Wires up restoring pinned tabs for session and tab restore
services. And turns on pinned tabs by default on linux. BUG=16634 TEST=Currently this linux only. Try tab pinning and make sure it works. Review URL: http://codereview.chromium.org/149621 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions/tab_restore_service.cc')
-rw-r--r--chrome/browser/sessions/tab_restore_service.cc36
1 files changed, 32 insertions, 4 deletions
diff --git a/chrome/browser/sessions/tab_restore_service.cc b/chrome/browser/sessions/tab_restore_service.cc
index 4bbd660..fc44204 100644
--- a/chrome/browser/sessions/tab_restore_service.cc
+++ b/chrome/browser/sessions/tab_restore_service.cc
@@ -38,8 +38,9 @@ const size_t TabRestoreService::kMaxEntries = 10;
// The ordering in the file is as follows:
// . When the user closes a tab a command of type
// kCommandSelectedNavigationInTab is written identifying the tab and
-// the selected index. This is followed by any number of
-// kCommandUpdateTabNavigation commands (1 per navigation entry).
+// the selected index, then a kCommandPinnedState command if the tab was
+// pinned. This is followed by any number of kCommandUpdateTabNavigation
+// commands (1 per navigation entry).
// . When the user closes a window a kCommandSelectedNavigationInTab command
// is written out and followed by n tab closed sequences (as previoulsy
// described).
@@ -49,6 +50,7 @@ static const SessionCommand::id_type kCommandUpdateTabNavigation = 1;
static const SessionCommand::id_type kCommandRestoredEntry = 2;
static const SessionCommand::id_type kCommandWindow = 3;
static const SessionCommand::id_type kCommandSelectedNavigationInTab = 4;
+static const SessionCommand::id_type kCommandPinnedState = 5;
// Number of entries (not commands) before we clobber the file and write
// everything.
@@ -73,6 +75,9 @@ struct SelectedNavigationInTabPayload {
int32 index;
};
+// Only written if the tab is pinned.
+typedef bool PinnedStatePayload;
+
typedef std::map<SessionID::id_type, TabRestoreService::Entry*> IDToEntry;
// If |id_to_entry| contains an entry for |id| the corresponding entry is
@@ -248,7 +253,8 @@ void TabRestoreService::RestoreEntryById(Browser* browser,
if (tab_index < 0 || tab_index > tab_browser->tab_count())
tab_index = tab_browser->tab_count();
tab_browser->AddRestoredTab(tab->navigations, tab_index,
- tab->current_navigation_index, true);
+ tab->current_navigation_index, true,
+ tab->pinned);
}
} else if (entry->type == WINDOW) {
const Window* window = static_cast<Window*>(entry);
@@ -259,7 +265,8 @@ void TabRestoreService::RestoreEntryById(Browser* browser,
browser->AddRestoredTab(tab.navigations, browser->tab_count(),
tab.current_navigation_index,
(static_cast<int>(tab_i) ==
- window->selected_tab_index));
+ window->selected_tab_index),
+ tab.pinned);
if (restored_tab)
restored_tab->controller().LoadIfNecessary();
}
@@ -360,6 +367,7 @@ void TabRestoreService::PopulateTab(Tab* tab,
tab->browser_id = browser->session_id().id();
tab->tabstrip_index =
browser->tabstrip_model()->GetIndexOfController(controller);
+ tab->pinned = browser->tabstrip_model()->IsTabPinned(tab->tabstrip_index);
}
}
@@ -446,6 +454,14 @@ void TabRestoreService::ScheduleCommandsForTab(const Tab& tab,
CreateSelectedNavigationInTabCommand(tab.id,
valid_count_before_selected));
+ if (tab.pinned) {
+ PinnedStatePayload payload = true;
+ SessionCommand* command =
+ new SessionCommand(kCommandPinnedState, sizeof(payload));
+ memcpy(command->contents(), &payload, sizeof(payload));
+ ScheduleCommand(command);
+ }
+
// Then write the navigations.
for (int i = first_index_to_persist, wrote_count = 0;
i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) {
@@ -636,6 +652,17 @@ void TabRestoreService::CreateEntriesFromCommands(
break;
}
+ case kCommandPinnedState: {
+ if (!current_tab) {
+ // Should be in a tab when we get this.
+ return;
+ }
+ // NOTE: payload doesn't matter. kCommandPinnedState is only written if
+ // tab is pinned.
+ current_tab->pinned = true;
+ break;
+ }
+
default:
// Unknown type, usually indicates corruption of file. Ignore it.
return;
@@ -744,6 +771,7 @@ bool TabRestoreService::ConvertSessionWindowToWindow(
if (!session_window->tabs[i]->navigations.empty()) {
window->tabs.resize(window->tabs.size() + 1);
Tab& tab = window->tabs.back();
+ tab.pinned = session_window->tabs[i]->pinned;
tab.navigations.swap(session_window->tabs[i]->navigations);
tab.current_navigation_index =
session_window->tabs[i]->current_navigation_index;