File: runtime_enabled_features.h.tmpl

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (148 lines) | stat: -rw-r--r-- 4,944 bytes parent folder | download | duplicates (6)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
{% 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}}