Commit 66dced4d authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

[blink scheduler] Actually check intensive throttling feature state.

In https://crrev.com/c/2171976, we forgot to check if the
IntensiveWakeUpThrottling feature was enabled in the code. This
CL adds the check and a test to prevent this from happening again.

Bug: 1075553
Change-Id: I5c669a62ce56aa32c08d57d0929c6e52aa0f05c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2233016
Commit-Queue: Alexander Timin <altimin@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Auto-Submit: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776085}
parent 5b75f083
......@@ -390,6 +390,13 @@ class FrameSchedulerImplStopNonTimersInBackgroundDisabledTest
{blink::features::kStopNonTimersInBackground}) {}
};
class FrameSchedulerImplStopInBackgroundDisabledTest
: public FrameSchedulerImplTest {
public:
FrameSchedulerImplStopInBackgroundDisabledTest()
: FrameSchedulerImplTest({}, {blink::features::kStopInBackground}) {}
};
namespace {
class MockLifecycleObserver final : public FrameScheduler::Observer {
......@@ -633,6 +640,62 @@ TEST_F(FrameSchedulerImplTest, PauseAndResumeForCooperativeScheduling) {
EXPECT_TRUE(UnpausableTaskQueue()->IsQueueEnabled());
}
namespace {
// A task that re-posts itself with a delay in order until it has run
// |num_remaining_tasks| times.
void RePostTask(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
base::TimeDelta delay,
int* num_remaining_tasks) {
--(*num_remaining_tasks);
if (*num_remaining_tasks > 0) {
task_runner->PostDelayedTask(
FROM_HERE,
base::BindOnce(&RePostTask, task_runner, delay,
base::Unretained(num_remaining_tasks)),
delay);
}
}
} // namespace
// Verify that tasks in a throttled task queues run at the expected time, when
// intensive wake up throttling is disabled. Disable the kStopInBackground
// feature because it hides the effect of intensive wake up throttling.
TEST_F(FrameSchedulerImplStopInBackgroundDisabledTest, ThrottledTaskExecution) {
// This test posts enough tasks to run past the default intensive wake up
// throttling grace period. This allows verifying that intensive wake up
// throttling is disabled by default.
constexpr int kNumTasks =
base::TimeDelta::FromMinutes(10) / base::TimeDelta::FromSeconds(1);
// Tasks are posted with a delay shorter than the default throttled wake up
// period, to allow verifying that the default throttled wake up period is
// correctly enforced.
constexpr base::TimeDelta kShortDelay = base::TimeDelta::FromMilliseconds(10);
// This TaskRunner is throttled.
const scoped_refptr<base::SingleThreadTaskRunner> task_runner =
frame_scheduler_->GetTaskRunner(TaskType::kJavascriptTimer);
// Hide the page. This enables wake up throttling.
EXPECT_TRUE(page_scheduler_->IsPageVisible());
page_scheduler_->SetPageVisible(false);
// Post an initial task.
int num_remaining_tasks = kNumTasks;
task_runner->PostDelayedTask(
FROM_HERE,
base::BindOnce(&RePostTask, task_runner, kShortDelay,
base::Unretained(&num_remaining_tasks)),
kShortDelay);
// A task should run every second.
while (num_remaining_tasks > 0) {
int previous_num_remaining_tasks = num_remaining_tasks;
task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_EQ(previous_num_remaining_tasks - 1, num_remaining_tasks);
}
}
TEST_F(FrameSchedulerImplTest, FreezeForegroundOnlyTasks) {
int counter = 0;
ForegroundOnlyTaskQueue()->task_runner()->PostTask(
......
......@@ -645,7 +645,8 @@ void PageSchedulerImpl::UpdateBackgroundSchedulingLifecycleState(
FROM_HERE, do_throttle_cpu_time_callback_.GetCallback(),
kThrottlingDelayAfterBackgrounding);
}
if (wake_up_budget_pool_) {
if (wake_up_budget_pool_ &&
base::FeatureList::IsEnabled(kIntensiveWakeUpThrottling)) {
main_thread_scheduler_->ControlTaskRunner()->PostDelayedTask(
FROM_HERE, do_intensively_throttle_wake_ups_callback_.GetCallback(),
base::TimeDelta::FromSeconds(
......@@ -667,6 +668,8 @@ void PageSchedulerImpl::DoThrottleCPUTime() {
}
void PageSchedulerImpl::DoIntensivelyThrottleWakeUps() {
DCHECK(base::FeatureList::IsEnabled(kIntensiveWakeUpThrottling));
do_intensively_throttle_wake_ups_callback_.Cancel();
are_wake_ups_intensively_throttled_ = true;
......
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