diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-30 02:58:36 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-30 02:58:36 +0000 |
commit | 6ea265a8b1b6e1512992945efa08942f575ad4c1 (patch) | |
tree | 5b58bd5a7f6f599db9e08435965fb81ca54c4930 /chrome/browser/session_service.cc | |
parent | 5ffd5e9b703d122dbac2dce9425a88b414f6de97 (diff) | |
download | chromium_src-6ea265a8b1b6e1512992945efa08942f575ad4c1.zip chromium_src-6ea265a8b1b6e1512992945efa08942f575ad4c1.tar.gz chromium_src-6ea265a8b1b6e1512992945efa08942f575ad4c1.tar.bz2 |
Changes session restore to account for apps and popups. If you have
session restore enabled any time you transition from no tabbed
browsers to a tabbed browser (in the same profile) we restore your
last session, where the last session was any previously open tabbed
browsers. For example, if you start Chrome from an installed app
shortcut then create a new tabbed browser (by any means) we'll restore
your last session. This gives the illustion that apps are running in
their own process.
I would love to have test coverage of this, but I'm loathe to write
anymore flakey UI tests. Need to revisit post 1.0.
BUG=1883
TEST=thoroughly test session restore, especially with application
shortcuts and popups.
Review URL: http://codereview.chromium.org/8856
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4202 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/session_service.cc')
-rw-r--r-- | chrome/browser/session_service.cc | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/chrome/browser/session_service.cc b/chrome/browser/session_service.cc index 8305642..813b56a 100644 --- a/chrome/browser/session_service.cc +++ b/chrome/browser/session_service.cc @@ -10,6 +10,7 @@ #include "base/message_loop.h" #include "base/pickle.h" #include "base/thread.h" +#include "chrome/browser/browser_init.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_window.h" @@ -17,6 +18,8 @@ #include "chrome/browser/navigation_entry.h" #include "chrome/browser/profile.h" #include "chrome/browser/session_backend.h" +#include "chrome/browser/session_restore.h" +#include "chrome/browser/session_startup_pref.h" #include "chrome/browser/tab_contents.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_service.h" @@ -132,7 +135,7 @@ SessionService::SessionService(Profile* profile) save_factory_(this), pending_reset_(false), has_open_tabbed_browsers_(false), - tabbed_browser_created_(false) { + move_on_new_browser_(false) { DCHECK(profile); // We should never be created when off the record. DCHECK(!profile->IsOffTheRecord()); @@ -145,7 +148,7 @@ SessionService::SessionService(const std::wstring& save_path) save_factory_(this), pending_reset_(false), has_open_tabbed_browsers_(false), - tabbed_browser_created_(false) { + move_on_new_browser_(false) { Init(save_path); } @@ -169,6 +172,8 @@ SessionService::~SessionService() { this, NOTIFY_NAV_ENTRY_CHANGED, NotificationService::AllSources()); NotificationService::current()->RemoveObserver( this, NOTIFY_NAV_ENTRY_COMMITTED, NotificationService::AllSources()); + NotificationService::current()->RemoveObserver( + this, NOTIFY_BROWSER_OPENED, NotificationService::AllSources()); } void SessionService::ResetFromCurrentBrowsers() { @@ -299,7 +304,7 @@ void SessionService::SetWindowType(const SessionID& window_id, CommitPendingCloses(); has_open_tabbed_browsers_ = true; - tabbed_browser_created_ = true; + move_on_new_browser_ = true; ScheduleCommand(CreateSetWindowTypeCommand(window_id, type)); } @@ -451,6 +456,8 @@ void SessionService::Init(const std::wstring& path) { this, NOTIFY_NAV_ENTRY_CHANGED, NotificationService::AllSources()); NotificationService::current()->AddObserver( this, NOTIFY_NAV_ENTRY_COMMITTED, NotificationService::AllSources()); + NotificationService::current()->AddObserver( + this, NOTIFY_BROWSER_OPENED, NotificationService::AllSources()); DCHECK(!path.empty()); commands_since_reset_ = 0; @@ -465,15 +472,49 @@ void SessionService::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { // All of our messages have the NavigationController as the source. - NavigationController* controller = Source<NavigationController>(source).ptr(); switch (type) { - case NOTIFY_TAB_PARENTED: + case NOTIFY_BROWSER_OPENED: { + Browser* browser = Source<Browser>(source).ptr(); + if (browser->profile() != profile_ || + !should_track_changes_for_browser_type(browser->GetType())) { + return; + } + + if (!has_open_tabbed_browsers_ && !BrowserInit::InProcessStartup()) { + // We're going from no tabbed browsers to a tabbed browser (and not in + // process startup), restore the last session. + if (move_on_new_browser_) { + // Make the current session the last. + MoveCurrentSessionToLastSession(); + move_on_new_browser_ = false; + } + SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile_); + if (pref.type == SessionStartupPref::LAST) { + SessionRestore::RestoreSession( + profile_, browser, false, false, false, std::vector<GURL>()); + } + } + SetWindowType(browser->session_id(), browser->GetType()); + break; + } + + case NOTIFY_TAB_PARENTED: { + NavigationController* controller = + Source<NavigationController>(source).ptr(); SetTabWindow(controller->window_id(), controller->session_id()); break; - case NOTIFY_TAB_CLOSED: + } + + case NOTIFY_TAB_CLOSED: { + NavigationController* controller = + Source<NavigationController>(source).ptr(); TabClosed(controller->window_id(), controller->session_id()); break; + } + case NOTIFY_NAV_LIST_PRUNED: { + NavigationController* controller = + Source<NavigationController>(source).ptr(); Details<NavigationController::PrunedDetails> pruned_details(details); if (pruned_details->from_front) { TabNavigationPathPrunedFromFront(controller->window_id(), @@ -486,13 +527,19 @@ void SessionService::Observe(NotificationType type, } break; } + case NOTIFY_NAV_ENTRY_CHANGED: { + NavigationController* controller = + Source<NavigationController>(source).ptr(); Details<NavigationController::EntryChangedDetails> changed(details); UpdateTabNavigation(controller->window_id(), controller->session_id(), changed->index, *changed->changed_entry); break; } + case NOTIFY_NAV_ENTRY_COMMITTED: { + NavigationController* controller = + Source<NavigationController>(source).ptr(); int current_entry_index = controller->GetCurrentEntryIndex(); SetSelectedNavigationIndex(controller->window_id(), controller->session_id(), @@ -502,6 +549,7 @@ void SessionService::Observe(NotificationType type, *controller->GetEntryAtIndex(current_entry_index)); break; } + default: NOTREACHED(); } @@ -1089,7 +1137,7 @@ void SessionService::ScheduleReset() { // We're lazily created on startup and won't get an initial batch of // SetWindowType messages. Set these here to make sure our state is correct. has_open_tabbed_browsers_ = true; - tabbed_browser_created_ = true; + move_on_new_browser_ = true; } StartSaveTimer(); } |