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

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: Addressed comments. 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
« no previous file with comments | « no previous file | chrome/browser/sessions/session_restore_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b1a74985e5cce915ac067426f56f54458a335a53 100644
--- a/chrome/browser/sessions/session_restore.cc
+++ b/chrome/browser/sessions/session_restore.cc
@@ -297,10 +297,11 @@ class SessionRestoreImpl : public content::NotificationObserver {
}
if (succeeded) {
- // Start Loading tabs.
if (SessionRestore::GetSmartRestoreMode() !=
- SessionRestore::SMART_RESTORE_MODE_OFF)
+ SessionRestore::SMART_RESTORE_MODE_OFF) {
std::stable_sort(contents_created->begin(), contents_created->end());
+ }
+ // Start Loading tabs.
SessionRestoreDelegate::RestoreTabs(*contents_created, restore_started_);
}
@@ -507,7 +508,26 @@ class SessionRestoreImpl : public content::NotificationObserver {
std::vector<RestoredTab>* created_contents) {
DVLOG(1) << "RestoreTabsToBrowser " << window.tabs.size();
DCHECK(!window.tabs.empty());
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::TimeTicks highest_time = base::TimeTicks::UnixEpoch();
if (initial_tab_count == 0) {
+ if (SessionRestore::GetSmartRestoreMode() ==
+ SessionRestore::SMART_RESTORE_MODE_MRU) {
+ // The last active time of a WebContents is initially set to the
+ // creation time of the tab, which is not necessarly the same as the
+ // loading time, so we have to restore the values. Also, since TimeTicks
+ // only make sense in their current session, these values have to be
+ // sanitized first. To do so, we need to first figure out the largest
+ // time. This will then be used to set the last active time of
+ // each tab where the most recent tab will have its time set to |now|
+ // and the rest of the tabs will have theirs set earlier by the same
+ // delta as they originally had.
+ for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) {
+ const sessions::SessionTab& tab = *(window.tabs[i]);
+ if (tab.last_active_time > highest_time)
+ highest_time = tab.last_active_time;
+ }
+ }
for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) {
const sessions::SessionTab& tab = *(window.tabs[i]);
@@ -520,6 +540,13 @@ class SessionRestoreImpl : public content::NotificationObserver {
if (!contents)
continue;
+ // Sanitize the last active time.
+ if (SessionRestore::GetSmartRestoreMode() ==
+ SessionRestore::SMART_RESTORE_MODE_MRU) {
+ base::TimeDelta delta = highest_time - tab.last_active_time;
+ contents->SetLastActiveTime(now - delta);
+ }
+
RestoredTab restored_tab(contents, is_selected_tab,
tab.extension_app_id.empty(), tab.pinned);
created_contents->push_back(restored_tab);
@@ -544,6 +571,12 @@ class SessionRestoreImpl : public content::NotificationObserver {
WebContents* contents =
RestoreTab(tab, tab_index_offset + i, browser, false);
if (contents) {
+ // Sanitize the last active time.
+ if (SessionRestore::GetSmartRestoreMode() ==
+ SessionRestore::SMART_RESTORE_MODE_MRU) {
+ base::TimeDelta delta = highest_time - tab.last_active_time;
+ contents->SetLastActiveTime(now - delta);
+ }
RestoredTab restored_tab(contents, false,
tab.extension_app_id.empty(), tab.pinned);
created_contents->push_back(restored_tab);
« no previous file with comments | « no previous file | chrome/browser/sessions/session_restore_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698