Commit 20e7ceaf authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

[TM] Unfreeze a tab if it opt-out while frozen.

This is unlikely to happen in practice, but there's still a tiny race
possibility that could cause this if we ever decide to immediately
freeze tabs after they're being sent to background.

Change-Id: I33fbd9f31692e3e1c8c2c269da01f83c9d672363
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869721
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Auto-Submit: Sébastien Marchand <sebmarchand@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709457}
parent 2efec3cd
...@@ -421,6 +421,14 @@ void TabLifecycleUnitSource::TabLifecycleUnit::UpdateOriginTrialFreezePolicy( ...@@ -421,6 +421,14 @@ void TabLifecycleUnitSource::TabLifecycleUnit::UpdateOriginTrialFreezePolicy(
performance_manager::mojom::InterventionPolicy policy) { performance_manager::mojom::InterventionPolicy policy) {
// The origin trial policy should only be updated when its value changes. // The origin trial policy should only be updated when its value changes.
DCHECK_NE(policy, origin_trial_freeze_policy_); DCHECK_NE(policy, origin_trial_freeze_policy_);
// Unfreeze the tab if needed. This can happen if the tab gets frozen
// before all its frames are loaded and if one of these frames
// causes the tab to be opted out.
if (policy == performance_manager::mojom::InterventionPolicy::kOptOut &&
IsFrozenOrPendingFreeze(GetState())) {
Unfreeze();
}
origin_trial_freeze_policy_ = policy; origin_trial_freeze_policy_ = policy;
} }
......
...@@ -955,4 +955,33 @@ TEST_F(TabLifecycleUnitTest, TabUnfreezeOnIndexedDBLockAcquisition) { ...@@ -955,4 +955,33 @@ TEST_F(TabLifecycleUnitTest, TabUnfreezeOnIndexedDBLockAcquisition) {
tab_lifecycle_unit.SetIsHoldingIndexedDBLock(false); tab_lifecycle_unit.SetIsHoldingIndexedDBLock(false);
} }
TEST_F(TabLifecycleUnitTest, TabUnfreezeOnOriginTrialOptOut) {
TabLifecycleUnit tab_lifecycle_unit(GetTabLifecycleUnitSource(), &observers_,
usage_clock_.get(), web_contents_,
tab_strip_model_.get());
TabLoadTracker::Get()->TransitionStateForTesting(web_contents_,
LoadingState::LOADED);
// Advance time enough that the tab is urgent discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
ExpectCanDiscardTrueAllReasons(&tab_lifecycle_unit);
DecisionDetails decision_details;
EXPECT_TRUE(tab_lifecycle_unit.CanFreeze(&decision_details));
// Freeze the tab.
EXPECT_CALL(observer_, OnFrozenStateChange(web_contents_, true));
tab_lifecycle_unit.Freeze();
::testing::Mock::VerifyAndClear(&observer_);
EXPECT_EQ(LifecycleUnitState::PENDING_FREEZE, tab_lifecycle_unit.GetState());
// Indicates that the tab opted out from the Freeze policy via Origin Trial,
// this should unfreeze it.
EXPECT_CALL(observer_, OnFrozenStateChange(web_contents_, false));
tab_lifecycle_unit.UpdateOriginTrialFreezePolicy(
performance_manager::mojom::InterventionPolicy::kOptOut);
::testing::Mock::VerifyAndClear(&observer_);
EXPECT_EQ(LifecycleUnitState::PENDING_UNFREEZE,
tab_lifecycle_unit.GetState());
}
} // namespace resource_coordinator } // namespace resource_coordinator
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