Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Unified Diff: chrome/browser/sessions/session_restore.cc

Issue 1131373003: [Session restore] Add MRU logic to loading of background pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge to ToT for Time => TimeTicks. Sanitize the times. More covergae on test. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sessions/session_restore.cc
diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc
index c6692162035c06fdb0cb02d7c1b7714f178e2d53..7fdc1d5daa227d95a8526aef61f10a5429a8f6d4 100644
--- a/chrome/browser/sessions/session_restore.cc
+++ b/chrome/browser/sessions/session_restore.cc
@@ -297,10 +297,28 @@ class SessionRestoreImpl : public content::NotificationObserver {
}
if (succeeded) {
- // Start Loading tabs.
if (SessionRestore::GetSmartRestoreMode() !=
- SessionRestore::SMART_RESTORE_MODE_OFF)
+ SessionRestore::SMART_RESTORE_MODE_OFF) {
+ if (SessionRestore::GetSmartRestoreMode() ==
+ SessionRestore::SMART_RESTORE_MODE_MRU) {
+ // Sanitize the last active time by keeping the same time lapse
+ // between tabs. The latest tab will have its time set to Now() while
+ // the rest of the tabs will have theirs set earlier.
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::TimeTicks highest_time = base::TimeTicks::UnixEpoch();
+ for (const auto& tab : *contents_created) {
+ if (tab.contents()->GetLastActiveTime() > highest_time)
+ highest_time = tab.contents()->GetLastActiveTime();
+ }
+ for (const auto& tab : *contents_created) {
+ base::TimeDelta delta =
+ highest_time - tab.contents()->GetLastActiveTime();
+ tab.contents()->SetLastActiveTime(now - delta);
+ }
+ }
std::stable_sort(contents_created->begin(), contents_created->end());
+ }
+ // Start Loading tabs.
SessionRestoreDelegate::RestoreTabs(*contents_created, restore_started_);
}
@@ -591,6 +609,17 @@ class SessionRestoreImpl : public content::NotificationObserver {
// focused tab will be loaded by Browser, and TabLoader will load the rest.
DCHECK(web_contents->GetController().NeedsReload());
+ // Restore the saved last active time since by default, the last active time
+ // of a WebContent is initially set to the creation time of the tab, which
+ // is not necessarly the same as the loading time. This makes sure that the
+ // state is preserved between restores. Also, since TimeTicks only make
+ // sense in their current session, these values are sanitized later on
+ // (before we start loading background tabs).
+ if (SessionRestore::GetSmartRestoreMode() ==
+ SessionRestore::SMART_RESTORE_MODE_MRU) {
+ web_contents->SetLastActiveTime(tab.last_active_time);
sky 2015/05/22 03:00:19 I don't like pushing potentially bogus times to th
Georges Khalil 2015/05/22 20:14:09 That was done because otherwise, by the time we sa
+ }
+
return web_contents;
}
« no previous file with comments | « no previous file | chrome/browser/sessions/session_restore_browsertest.cc » ('j') | components/sessions/session_types.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698