1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/scheduler/common/features.h"
#include "base/command_line.h"
#include "components/miracle_parameter/common/public/miracle_parameter.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/switches.h"
namespace blink {
namespace scheduler {
namespace {
enum class PolicyOverride { kNoOverride, kForceDisable, kForceEnable };
bool g_intensive_wake_up_throttling_policy_override_cached_ = false;
// Returns the IntensiveWakeUpThrottling policy settings. This is checked once
// on first access and cached. Note that that this is *not* thread-safe!
PolicyOverride GetIntensiveWakeUpThrottlingPolicyOverride() {
static PolicyOverride policy = PolicyOverride::kNoOverride;
if (g_intensive_wake_up_throttling_policy_override_cached_)
return policy;
// Otherwise, check the command-line. Only values of "0" and "1" are valid,
// anything else is ignored (and allows the base::Feature to control the
// feature). This slow path will only be hit once per renderer process.
g_intensive_wake_up_throttling_policy_override_cached_ = true;
std::string value =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kIntensiveWakeUpThrottlingPolicy);
if (value == switches::kIntensiveWakeUpThrottlingPolicy_ForceEnable) {
policy = PolicyOverride::kForceEnable;
} else if (value == switches::kIntensiveWakeUpThrottlingPolicy_ForceDisable) {
policy = PolicyOverride::kForceDisable;
} else {
// Necessary in testing configurations, as the policy can be parsed
// repeatedly.
policy = PolicyOverride::kNoOverride;
}
return policy;
}
} // namespace
void ClearIntensiveWakeUpThrottlingPolicyOverrideCacheForTesting() {
g_intensive_wake_up_throttling_policy_override_cached_ = false;
}
bool IsIntensiveWakeUpThrottlingEnabled() {
// If policy is present then respect it.
auto policy = GetIntensiveWakeUpThrottlingPolicyOverride();
if (policy != PolicyOverride::kNoOverride)
return policy == PolicyOverride::kForceEnable;
// Otherwise respect the base::Feature.
return base::FeatureList::IsEnabled(features::kIntensiveWakeUpThrottling);
}
// If a policy override is specified then stick to the published defaults so
// that admins get consistent behaviour that clients can't override. Otherwise
// use the base::FeatureParams.
base::TimeDelta GetIntensiveWakeUpThrottlingGracePeriod(bool loading) {
// Controls the time that elapses after a page is backgrounded before the
// throttling policy takes effect.
static const base::FeatureParam<int>
kIntensiveWakeUpThrottling_GracePeriodSeconds{
&features::kIntensiveWakeUpThrottling,
features::kIntensiveWakeUpThrottling_GracePeriodSeconds_Name,
kIntensiveWakeUpThrottling_GracePeriodSeconds_Default};
int seconds = kIntensiveWakeUpThrottling_GracePeriodSeconds_Default;
if (GetIntensiveWakeUpThrottlingPolicyOverride() ==
PolicyOverride::kNoOverride) {
if (loading) {
seconds = kIntensiveWakeUpThrottling_GracePeriodSeconds.Get();
} else {
seconds = kIntensiveWakeUpThrottling_GracePeriodSecondsLoaded_Default;
}
}
return base::Seconds(seconds);
}
// TODO(crbug.com/1475915): convert this param value to TimeDelta instead of int
// after the experiment.
MIRACLE_PARAMETER_FOR_INT(
GetLoadingPhaseBufferTimeAfterFirstMeaningfulPaintMillis,
features::kLoadingPhaseBufferTimeAfterFirstMeaningfulPaint,
"LoadingPhaseBufferTimeAfterFirstMeaningfulPaintMillis",
0)
base::TimeDelta GetLoadingPhaseBufferTimeAfterFirstMeaningfulPaint() {
return base::Milliseconds(
GetLoadingPhaseBufferTimeAfterFirstMeaningfulPaintMillis());
}
BASE_FEATURE(kThrottleTimedOutIdleTasks,
"ThrottleTimedOutIdleTasks",
base::FEATURE_ENABLED_BY_DEFAULT);
} // namespace scheduler
} // namespace blink
|