summaryrefslogtreecommitdiffstats
path: root/chrome/browser/session_service.cc
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-17 16:28:49 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-17 16:28:49 +0000
commitc12bf1a1aa1a24d7f516b7e76428518c594d7da5 (patch)
treea8417e738ef3f6017f93972cba7eea0ca8a2f8e3 /chrome/browser/session_service.cc
parent5753fae33db5da0f5ca75490ea0eff8c91084392 (diff)
downloadchromium_src-c12bf1a1aa1a24d7f516b7e76428518c594d7da5.zip
chromium_src-c12bf1a1aa1a24d7f516b7e76428518c594d7da5.tar.gz
chromium_src-c12bf1a1aa1a24d7f516b7e76428518c594d7da5.tar.bz2
Wires up session restore so that it correctly deals with the
navigation controller removing entries from the front of its list. BUG=1324021 TEST=covered by unit tests, but make sure you don't see problems with session restore. Review URL: http://codereview.chromium.org/2906 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2310 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/session_service.cc')
-rw-r--r--chrome/browser/session_service.cc90
1 files changed, 77 insertions, 13 deletions
diff --git a/chrome/browser/session_service.cc b/chrome/browser/session_service.cc
index 2694357..6b44952 100644
--- a/chrome/browser/session_service.cc
+++ b/chrome/browser/session_service.cc
@@ -32,12 +32,15 @@ static const SessionCommand::id_type kCommandSetTabWindow = 0;
static const SessionCommand::id_type kCommandSetTabIndexInWindow = 2;
static const SessionCommand::id_type kCommandTabClosed = 3;
static const SessionCommand::id_type kCommandWindowClosed = 4;
-static const SessionCommand::id_type kCommandTabNavigationPathPruned = 5;
+static const SessionCommand::id_type
+ kCommandTabNavigationPathPrunedFromBack = 5;
static const SessionCommand::id_type kCommandUpdateTabNavigation = 6;
static const SessionCommand::id_type kCommandSetSelectedNavigationIndex = 7;
static const SessionCommand::id_type kCommandSetSelectedTabInIndex = 8;
static const SessionCommand::id_type kCommandSetWindowType = 9;
static const SessionCommand::id_type kCommandSetWindowBounds2 = 10;
+static const SessionCommand::id_type
+ kCommandTabNavigationPathPrunedFromFront = 11;
// Max number of navigation entries in each direction we'll persist.
static const int kMaxNavigationCountToPersist = 6;
@@ -73,7 +76,7 @@ struct IDAndIndexPayload {
typedef IDAndIndexPayload TabIndexInWindowPayload;
-typedef IDAndIndexPayload TabNavigationPathPrunedPayload;
+typedef IDAndIndexPayload TabNavigationPathPrunedFromBackPayload;
typedef IDAndIndexPayload SelectedNavigationIndexPayload;
@@ -81,6 +84,8 @@ typedef IDAndIndexPayload SelectedTabInIndexPayload;
typedef IDAndIndexPayload WindowTypePayload;
+typedef IDAndIndexPayload TabNavigationPathPrunedFromFrontPayload;
+
} // namespace
// SessionID ------------------------------------------------------------------
@@ -271,17 +276,43 @@ void SessionService::SetWindowType(const SessionID& window_id,
ScheduleCommand(CreateSetWindowTypeCommand(window_id, type));
}
-void SessionService::TabNavigationPathPruned(const SessionID& window_id,
- const SessionID& tab_id,
- int index) {
+void SessionService::TabNavigationPathPrunedFromBack(const SessionID& window_id,
+ const SessionID& tab_id,
+ int count) {
if (!ShouldTrackChangesToWindow(window_id))
return;
- TabNavigationPathPrunedPayload payload = { 0 };
+ TabNavigationPathPrunedFromBackPayload payload = { 0 };
payload.id = tab_id.id();
- payload.index = index;
+ payload.index = count;
+ SessionCommand* command =
+ new SessionCommand(kCommandTabNavigationPathPrunedFromBack,
+ sizeof(payload));
+ memcpy(command->contents(), &payload, sizeof(payload));
+ ScheduleCommand(command);
+}
+
+void SessionService::TabNavigationPathPrunedFromFront(
+ const SessionID& window_id,
+ const SessionID& tab_id,
+ int count) {
+ if (!ShouldTrackChangesToWindow(window_id))
+ return;
+
+ // Update the range of indices.
+ if (tab_to_available_range_.find(tab_id.id()) !=
+ tab_to_available_range_.end()) {
+ std::pair<int, int>& range = tab_to_available_range_[tab_id.id()];
+ range.first = std::max(0, range.first - count);
+ range.second = std::max(0, range.second - count);
+ }
+
+ TabNavigationPathPrunedFromFrontPayload payload = { 0 };
+ payload.id = tab_id.id();
+ payload.index = count;
SessionCommand* command =
- new SessionCommand(kCommandTabNavigationPathPruned, sizeof(payload));
+ new SessionCommand(kCommandTabNavigationPathPrunedFromFront,
+ sizeof(payload));
memcpy(command->contents(), &payload, sizeof(payload));
ScheduleCommand(command);
}
@@ -414,10 +445,19 @@ void SessionService::Observe(NotificationType type,
case NOTIFY_TAB_CLOSED:
TabClosed(controller->window_id(), controller->session_id());
break;
- case NOTIFY_NAV_LIST_PRUNED:
- TabNavigationPathPruned(controller->window_id(), controller->session_id(),
- controller->GetEntryCount());
+ case NOTIFY_NAV_LIST_PRUNED: {
+ Details<NavigationController::PrunedDetails> pruned_details(details);
+ if (pruned_details->from_front) {
+ TabNavigationPathPrunedFromFront(controller->window_id(),
+ controller->session_id(),
+ pruned_details->count);
+ } else {
+ TabNavigationPathPrunedFromBack(controller->window_id(),
+ controller->session_id(),
+ controller->GetEntryCount());
+ }
break;
+ }
case NOTIFY_NAV_ENTRY_CHANGED: {
Details<NavigationController::EntryChangedDetails> changed(details);
UpdateTabNavigation(controller->window_id(), controller->session_id(),
@@ -807,8 +847,8 @@ bool SessionService::CreateTabsAndWindows(
break;
}
- case kCommandTabNavigationPathPruned: {
- TabNavigationPathPrunedPayload payload;
+ case kCommandTabNavigationPathPrunedFromBack: {
+ TabNavigationPathPrunedFromBackPayload payload;
if (!command->GetPayload(&payload, sizeof(payload)))
return true;
SessionTab* tab = GetTab(payload.id, tabs);
@@ -818,6 +858,30 @@ bool SessionService::CreateTabsAndWindows(
break;
}
+ case kCommandTabNavigationPathPrunedFromFront: {
+ TabNavigationPathPrunedFromFrontPayload payload;
+ if (!command->GetPayload(&payload, sizeof(payload)) ||
+ payload.index <= 0) {
+ return true;
+ }
+ SessionTab* tab = GetTab(payload.id, tabs);
+
+ // Update the selected navigation index.
+ tab->current_navigation_index =
+ std::max(-1, tab->current_navigation_index - payload.index);
+
+ // And update the index of existing navigations.
+ for (std::vector<TabNavigation>::iterator i = tab->navigations.begin();
+ i != tab->navigations.end();) {
+ i->index -= payload.index;
+ if (i->index < 0)
+ i = tab->navigations.erase(i);
+ else
+ ++i;
+ }
+ break;
+ }
+
case kCommandUpdateTabNavigation: {
scoped_ptr<Pickle> pickle(command->PayloadAsPickle());
if (!pickle.get())