Commit 2f469295 authored by georgesak's avatar georgesak Committed by Commit bot

[Session restore] Expose lazy mode and fix browser tests.

- SessionRestore now exposes IsLoadingActiveTabsOnly
- Fixed 2 browser tests that were failing with new behavior
- One last telemetry test still failing, will be addressed in a separate CL

Notes:
- First patchset inverts the default behavior to show tests succeeding
- Second patchset restores default behavior

BUG=

Review URL: https://codereview.chromium.org/1087063003

Cr-Commit-Position: refs/heads/master@{#325528}
parent 7174c6a4
......@@ -214,6 +214,14 @@ class BetterSessionRestoreTest : public InProcessBrowserTest {
}
void CheckReloadedPageNotRestored() {
// If only active tabs are loaded, force loading of the tabs.
if (SessionRestore::WillLoadActiveTabsOnly()) {
for (int i = 0; i < browser()->tab_strip_model()->count(); i++) {
content::WebContents* web_contents =
browser()->tab_strip_model()->GetWebContentsAt(i);
web_contents->GetController().LoadIfNecessary();
}
}
CheckReloadedPageNotRestored(browser());
}
......
......@@ -16,6 +16,7 @@
#include "base/debug/alias.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
......@@ -298,7 +299,9 @@ class SessionRestoreImpl : public content::NotificationObserver {
if (succeeded) {
// Start Loading tabs.
SessionRestoreDelegate::RestoreTabs(contents_created, restore_started_);
bool active_only = SessionRestore::WillLoadActiveTabsOnly();
SessionRestoreDelegate::RestoreTabs(contents_created, restore_started_,
active_only);
}
if (!synchronous_) {
......@@ -817,6 +820,15 @@ SessionRestore::CallbackSubscription
return on_session_restored_callbacks()->Add(callback);
}
// static
bool SessionRestore::WillLoadActiveTabsOnly() {
base::FieldTrial* trial =
base::FieldTrialList::Find("SessionRestoreBackgroundLoading");
if (!trial || trial->group_name() == "Restore")
return false;
return true;
}
// static
base::CallbackList<void(int)>*
SessionRestore::on_session_restored_callbacks_ = nullptr;
......@@ -98,6 +98,11 @@ class SessionRestore {
static CallbackSubscription RegisterOnSessionRestoredCallback(
const base::Callback<void(int)>& callback);
// Returns true if only active tabs are to be loaded during session restore
// (lazy load). Otherwise returns false if all tabs will be loaded when
// restored.
static bool WillLoadActiveTabsOnly();
private:
SessionRestore();
......
......@@ -10,17 +10,12 @@
#include "components/favicon/content/content_favicon_driver.h"
// static
void SessionRestoreDelegate::RestoreTabs(
const std::vector<RestoredTab>& tabs,
const base::TimeTicks& restore_started) {
// TODO(georgesak): make tests aware of that behavior so that they succeed if
// tab loading is disabled.
base::FieldTrial* trial =
base::FieldTrialList::Find("SessionRestoreBackgroundLoading");
bool active_only = true;
if (!trial || trial->group_name() == "Restore") {
void SessionRestoreDelegate::RestoreTabs(const std::vector<RestoredTab>& tabs,
const base::TimeTicks& restore_started,
bool active_only) {
SessionRestoreStatsCollector::TrackTabs(tabs, restore_started, active_only);
if (!active_only) {
TabLoader::RestoreTabs(tabs, restore_started);
active_only = false;
} else {
// If we are not loading inactive tabs, restore their favicons (title has
// already been set by now).
......@@ -32,5 +27,4 @@ void SessionRestoreDelegate::RestoreTabs(
}
}
}
SessionRestoreStatsCollector::TrackTabs(tabs, restore_started, active_only);
}
......@@ -23,7 +23,8 @@ class SessionRestoreDelegate {
};
static void RestoreTabs(const std::vector<RestoredTab>& tabs,
const base::TimeTicks& restore_started);
const base::TimeTicks& restore_started,
bool active_only);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(SessionRestoreDelegate);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment