{% from 'templates/macros.tmpl' import license, source_files_for_generated_file %}
{{license()}}
{{source_files_for_generated_file(template_file, input_files)}}
#ifndef {{header_guard}}
#define {{header_guard}}
#include <string>
#include "base/gtest_prod_util.h"
#include "base/memory/protected_memory.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#define ASSERT_ORIGIN_TRIAL(feature) \
static_assert(std::is_same<decltype(::blink::RuntimeEnabledFeatures:: \
feature##EnabledByRuntimeFlag()), \
bool>(), \
#feature " must be part of an origin trial");
namespace blink {
class FeatureContext;
// A class that stores static enablers for all experimental features.
class PLATFORM_EXPORT RuntimeEnabledFeaturesBase {
STATIC_ONLY(RuntimeEnabledFeaturesBase);
public:
class PLATFORM_EXPORT Backup {
public:
explicit Backup();
void Restore();
private:
{% for feature in features %}
bool {{feature.data_member_name}};
{% endfor %}
};
// Simple getter methods for protected memory values that ensure they are
// properly initialized before first access.
{% for feature in features %}
{% if feature.is_protected_feature %}
static bool get_{{feature.data_member_name}}();
{% endif %}
{% endfor %}
{% for feature in features %}
{% if not feature.in_origin_trial %}
static bool {{feature.name}}Enabled() {
{% for depends_on in feature.depends_on %}
if (!{{depends_on}}Enabled())
return false;
{% endfor %}
{% for implied_by in feature.implied_by %}
if ({{implied_by}}Enabled())
return true;
{% endfor %}
{% if feature.is_protected_feature %}
return get_{{feature.data_member_name}}();
{% else %}
return {{feature.data_member_name}};
{% endif %}
}
{% if feature.is_overridable_feature %}
static bool {{feature.name}}Enabled(const FeatureContext*);
{% else %}
static bool {{feature.name}}Enabled(const FeatureContext*) { return {{feature.name}}Enabled(); }
{% endif %}
{% endif %}
{% endfor %}
// Origin-trial-enabled features:
//
// These features are currently part of an origin trial (see
// https://www.chromium.org/blink/origin-trials). <feature>EnabledByRuntimeFlag()
// can be used to test whether the feature is unconditionally enabled
// (for example, by starting the browser with the appropriate command-line flag).
// However, that is almost always the incorrect check. Most renderer code should
// be calling <feature>Enabled(const FeatureContext*) instead, to test if the
// feature is enabled in a given context.
{% for feature in origin_trial_controlled_features %}
static bool {{feature.name}}EnabledByRuntimeFlag() { return {{feature.name}}Enabled(nullptr); }
static bool {{feature.name}}Enabled(const FeatureContext*);
{% endfor %}
static bool IsFeatureEnabledFromString(const std::string& name);
protected:
// See the comment in RuntimeEnabledFeatures for why these are protected.
{% for feature_set in feature_sets %}
static void Set{{feature_set|capitalize}}FeaturesEnabled(bool);
{% endfor %}
static void SetOriginTrialControlledFeaturesEnabled(bool);
static void SetFeatureEnabledFromString(const std::string& name, bool enabled);
static void UpdateStatusFromBaseFeatures();
{% for feature in features %}
{% if feature.is_protected_feature %}
static void Set{{feature.name}}Enabled(bool enabled);
{% else %}
static void Set{{feature.name}}Enabled(bool enabled) { {{feature.data_member_name}} = enabled; }
{%endif %}
{% endfor %}
private:
friend class RuntimeEnabledFeaturesTestHelpers;
{% for feature in features %}
{% if not feature.is_protected_feature %}
static bool {{feature.data_member_name}};
{% endif %}
{% endfor %}
{% for feature in features %}
{% if feature.is_protected_feature %}
static DECLARE_PROTECTED_DATA base::ProtectedMemory<bool> {{feature.data_member_name}};
{% endif %}
{% endfor %}
};
class PLATFORM_EXPORT RuntimeEnabledFeatures : public RuntimeEnabledFeaturesBase {
STATIC_ONLY(RuntimeEnabledFeatures);
// Only the following friends are allowed to use the setters defined in the
// protected section of RuntimeEnabledFeaturesBase. Normally, unit tests
// should use the ScopedFeatureNameForTest classes defined in
// platform/testing/runtime_enabled_features_test_helpers.h.
friend class DevToolsEmulator;
friend class InternalRuntimeFlags;
friend class V8ContextSnapshotImpl;
friend class WebRuntimeFeaturesBase;
friend class WebRuntimeFeatures;
friend class WebView;
friend class RuntimeEnabledFeaturesTestTraits;
friend class RuntimeProtectedEnabledFeaturesTestTraits;
};
} // namespace blink
#endif // {{header_guard}}