Commit 7757f6c3 authored by Scott Haseley's avatar Scott Haseley Committed by Commit Bot

[scheduler] Move stop-non-timers-in-background flag to blink features

The StopNonTimersInBackground flag is used by scheduler to initialize
the freezable bits for tasks. This happens before Blink initialization,
so the flag wasn't set yet when initializing QueueTraits. This CL moves
the flag from runtime enabled features to blink features, which are
initialized earlier and can be checked directly during QueueTraits
initialization.

BUG: 859963

Change-Id: I62e9896cd3c75a04d23372b44e9697432d109088
Reviewed-on: https://chromium-review.googlesource.com/1159205Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Scott Haseley <shaseley@google.com>
Cr-Commit-Position: refs/heads/master@{#580540}
parent 5763c978
......@@ -3631,7 +3631,7 @@ const FeatureEntry kFeatureEntries[] = {
{"stop-non-timers-in-background",
flag_descriptions::kStopNonTimersInBackgroundName,
flag_descriptions::kStopNonTimersInBackgroundDescription, kOsAll,
FEATURE_VALUE_TYPE(features::kStopNonTimersInBackground)},
FEATURE_VALUE_TYPE(blink::features::kStopNonTimersInBackground)},
{"stop-in-background", flag_descriptions::kStopInBackgroundName,
flag_descriptions::kStopInBackgroundDescription, kOsAll,
......
......@@ -428,9 +428,6 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
if (base::FeatureList::IsEnabled(features::kStopInBackground))
WebRuntimeFeatures::EnableStopInBackground(true);
if (base::FeatureList::IsEnabled(features::kStopNonTimersInBackground))
WebRuntimeFeatures::EnableStopNonTimersInBackground(true);
WebRuntimeFeatures::EnablePWAFullCodeCache(
base::FeatureList::IsEnabled(features::kPWAFullCodeCache));
......
......@@ -409,11 +409,6 @@ const base::Feature kStopInBackground {
#endif
};
// Stop non-timer task queues in background, on Android,
// after allowed grace time. Launch bug: https://crbug.com/822954.
const base::Feature kStopNonTimersInBackground{
"stop-non-timers-in-background", base::FEATURE_DISABLED_BY_DEFAULT};
// Throttle Blink timers in out-of-view cross origin frames.
const base::Feature kTimerThrottlingForHiddenFrames{
"TimerThrottlingForHiddenFrames", base::FEATURE_ENABLED_BY_DEFAULT};
......
......@@ -97,7 +97,6 @@ CONTENT_EXPORT extern const base::Feature kSignedHTTPExchange;
CONTENT_EXPORT extern const base::Feature kSignedHTTPExchangeOriginTrial;
CONTENT_EXPORT extern const base::Feature kSpareRendererForSitePerProcess;
CONTENT_EXPORT extern const base::Feature kStopInBackground;
CONTENT_EXPORT extern const base::Feature kStopNonTimersInBackground;
CONTENT_EXPORT extern const base::Feature kTimerThrottlingForHiddenFrames;
CONTENT_EXPORT extern const base::Feature kTopDocumentIsolation;
CONTENT_EXPORT extern const base::Feature kTouchpadAsyncPinchEvents;
......
......@@ -43,5 +43,10 @@ const base::Feature kRecordAnchorMetricsVisible{
// Enable Portals. https://crbug.com/865123.
const base::Feature kPortals{"Portals", base::FEATURE_DISABLED_BY_DEFAULT};
// Stop non-timer task queues in background, after allowed grace time. Launch
// bug: https://crbug.com/822954.
const base::Feature kStopNonTimersInBackground{
"stop-non-timers-in-background", base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace features
} // namespace blink
......@@ -20,6 +20,7 @@ BLINK_COMMON_EXPORT extern const base::Feature kNestedWorkers;
BLINK_COMMON_EXPORT extern const base::Feature kRecordAnchorMetricsClicked;
BLINK_COMMON_EXPORT extern const base::Feature kRecordAnchorMetricsVisible;
BLINK_COMMON_EXPORT extern const base::Feature kPortals;
BLINK_COMMON_EXPORT extern const base::Feature kStopNonTimersInBackground;
} // namespace features
} // namespace blink
......
......@@ -194,7 +194,6 @@ class WebRuntimeFeatures {
BLINK_PLATFORM_EXPORT static void EnableWorkStealingInScriptRunner(bool);
BLINK_PLATFORM_EXPORT static void EnableScheduledScriptStreaming(bool);
BLINK_PLATFORM_EXPORT static void EnableStopInBackground(bool);
BLINK_PLATFORM_EXPORT static void EnableStopNonTimersInBackground(bool);
BLINK_PLATFORM_EXPORT static void EnablePWAFullCodeCache(bool);
BLINK_PLATFORM_EXPORT static void EnableOffMainThreadWebSocket(bool);
BLINK_PLATFORM_EXPORT static void EnableExperimentalProductivityFeatures(
......
......@@ -536,10 +536,6 @@ void WebRuntimeFeatures::EnableStopInBackground(bool enable) {
RuntimeEnabledFeatures::SetStopInBackgroundEnabled(enable);
}
void WebRuntimeFeatures::EnableStopNonTimersInBackground(bool enable) {
RuntimeEnabledFeatures::SetStopNonTimersInBackgroundEnabled(enable);
}
void WebRuntimeFeatures::EnablePWAFullCodeCache(bool enable) {
RuntimeEnabledFeatures::SetPWAFullCodeCacheEnabled(enable);
}
......
......@@ -1245,10 +1245,6 @@
name: "StopInBackground",
status: "test",
},
{
name: "StopNonTimersInBackground",
status: "test",
},
{
name: "TextUnderlinePositionLeftRight",
status: "experimental",
......
......@@ -11,6 +11,7 @@
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "base/trace_event/blame_context.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/blame_context.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
......@@ -924,16 +925,16 @@ MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::DeferrableTaskQueueTraits() {
return QueueTraits()
.SetCanBeDeferred(true)
.SetCanBeFrozen(
RuntimeEnabledFeatures::StopNonTimersInBackgroundEnabled())
.SetCanBeFrozen(base::FeatureList::IsEnabled(
blink::features::kStopNonTimersInBackground))
.SetCanBePaused(true);
}
// static
MainThreadTaskQueue::QueueTraits FrameSchedulerImpl::PausableTaskQueueTraits() {
return QueueTraits()
.SetCanBeFrozen(
RuntimeEnabledFeatures::StopNonTimersInBackgroundEnabled())
.SetCanBeFrozen(base::FeatureList::IsEnabled(
blink::features::kStopNonTimersInBackground))
.SetCanBePaused(true);
}
......
......@@ -16,7 +16,7 @@
#include "base/test/scoped_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/platform/scheduler/child/features.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/frame_task_queue_controller.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl.h"
......@@ -152,6 +152,14 @@ class FrameSchedulerImplTest : public testing::Test {
scoped_refptr<TaskQueue> throttleable_task_queue_;
};
class FrameSchedulerImplStopNonTimersInBackgroundEnabledTest
: public FrameSchedulerImplTest {
public:
FrameSchedulerImplStopNonTimersInBackgroundEnabledTest()
: FrameSchedulerImplTest({blink::features::kStopNonTimersInBackground},
{}) {}
};
namespace {
class MockLifecycleObserver final : public FrameScheduler::Observer {
......@@ -353,8 +361,8 @@ TEST_F(FrameSchedulerImplTest, PauseAndResume) {
EXPECT_EQ(5, counter);
}
TEST_F(FrameSchedulerImplTest, PageFreezeAndUnfreezeFlagEnabled) {
ScopedStopNonTimersInBackgroundForTest stop_non_timers_enabler(true);
TEST_F(FrameSchedulerImplStopNonTimersInBackgroundEnabledTest,
PageFreezeAndUnfreezeFlagEnabled) {
int counter = 0;
LoadingTaskQueue()->PostTask(
FROM_HERE, base::BindOnce(&IncrementCounter, base::Unretained(&counter)));
......@@ -384,7 +392,6 @@ TEST_F(FrameSchedulerImplTest, PageFreezeAndUnfreezeFlagEnabled) {
}
TEST_F(FrameSchedulerImplTest, PageFreezeAndUnfreezeFlagDisabled) {
ScopedStopNonTimersInBackgroundForTest stop_non_timers_enabler(false);
int counter = 0;
LoadingTaskQueue()->PostTask(
FROM_HERE, base::BindOnce(&IncrementCounter, base::Unretained(&counter)));
......@@ -414,7 +421,6 @@ TEST_F(FrameSchedulerImplTest, PageFreezeAndUnfreezeFlagDisabled) {
}
TEST_F(FrameSchedulerImplTest, PageFreezeWithKeepActive) {
ScopedStopNonTimersInBackgroundForTest stop_non_timers_enabler(false);
std::vector<std::string> tasks;
LoadingTaskQueue()->PostTask(
FROM_HERE, base::BindOnce(&RecordQueueName, LoadingTaskQueue(), &tasks));
......@@ -471,8 +477,8 @@ TEST_F(FrameSchedulerImplTest, PageFreezeWithKeepActive) {
UnorderedElementsAre(std::string(LoadingTaskQueue()->GetName())));
}
TEST_F(FrameSchedulerImplTest, PageFreezeAndPageVisible) {
ScopedStopNonTimersInBackgroundForTest stop_non_timers_enabler(true);
TEST_F(FrameSchedulerImplStopNonTimersInBackgroundEnabledTest,
PageFreezeAndPageVisible) {
int counter = 0;
LoadingTaskQueue()->PostTask(
FROM_HERE, base::BindOnce(&IncrementCounter, base::Unretained(&counter)));
......@@ -1526,8 +1532,7 @@ class ThrottleAndFreezeTaskTypesExperimentTest : public FrameSchedulerImplTest {
public:
ThrottleAndFreezeTaskTypesExperimentTest(
std::map<std::string, std::string> params,
const char* group_name)
: stop_non_timers_enabler_(false) {
const char* group_name) {
const char kStudyName[] = "ThrottleAndFreezeTaskTypes";
field_trial_list_ = std::make_unique<base::FieldTrialList>(nullptr);
......@@ -1544,9 +1549,6 @@ class ThrottleAndFreezeTaskTypesExperimentTest : public FrameSchedulerImplTest {
base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial.get());
scoped_feature_list().InitWithFeatureList(std::move(feature_list));
}
private:
ScopedStopNonTimersInBackgroundForTest stop_non_timers_enabler_;
};
class ThrottleableAndFreezableTaskTypesTest
......
......@@ -17,9 +17,11 @@
#include "base/task/sequence_manager/test/fake_task.h"
#include "base/task/sequence_manager/test/sequence_manager_for_test.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_mock_time_task_runner.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/frame_scheduler_impl.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/frame_task_queue_controller.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl.h"
......@@ -139,8 +141,6 @@ class PageSchedulerImplTest : public testing::Test {
// set the page as visible or unfreezes it while still hidden (depending on
// the argument), and verifies that tasks can run.
void TestFreeze(bool make_page_visible) {
ScopedStopNonTimersInBackgroundForTest stop_non_timers_enabler(true);
int counter = 0;
LoadingTaskQueue()->PostTask(
FROM_HERE,
......@@ -207,6 +207,20 @@ class PageSchedulerImplTest : public testing::Test {
std::unique_ptr<FrameSchedulerImpl> frame_scheduler_;
};
class PageSchedulerImplStopNonTimersInBackgroundEnabledTest
: public PageSchedulerImplTest {
public:
PageSchedulerImplStopNonTimersInBackgroundEnabledTest() {
feature_list_.InitWithFeatures(
{blink::features::kStopNonTimersInBackground}, {});
}
~PageSchedulerImplStopNonTimersInBackgroundEnabledTest() override = default;
private:
base::test::ScopedFeatureList feature_list_;
};
TEST_F(PageSchedulerImplTest, TestDestructionOfFrameSchedulersBefore) {
std::unique_ptr<blink::FrameScheduler> frame1(
page_scheduler_->CreateFrameScheduler(
......@@ -1263,13 +1277,15 @@ TEST_F(PageSchedulerImplTest, OpenWebSocketExemptsFromBudgetThrottling) {
// Verify that freezing a page prevents tasks in its task queues from running.
// Then, verify that making the page visible unfreezes it and allows tasks in
// its task queues to run.
TEST_F(PageSchedulerImplTest, PageFreezeAndSetVisible) {
TEST_F(PageSchedulerImplStopNonTimersInBackgroundEnabledTest,
PageFreezeAndSetVisible) {
TestFreeze(true);
}
// Same as before, but unfreeze the page explicitly instead of making it
// visible.
TEST_F(PageSchedulerImplTest, PageFreezeAndUnfreeze) {
TEST_F(PageSchedulerImplStopNonTimersInBackgroundEnabledTest,
PageFreezeAndUnfreeze) {
TestFreeze(false);
}
......
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