xref: /aosp_15_r20/external/perfetto/ui/src/public/feature_flag.ts (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1// Copyright (C) 2024 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15export interface FeatureFlagManager {
16  register(settings: FlagSettings): Flag;
17}
18
19export interface FlagSettings {
20  id: string;
21  defaultValue: boolean;
22  description: string;
23  name?: string;
24  devOnly?: boolean;
25}
26
27export interface Flag {
28  // A unique identifier for this flag ("magicSorting")
29  readonly id: string;
30
31  // The name of the flag the user sees ("New track sorting algorithm")
32  readonly name: string;
33
34  // A longer description which is displayed to the user.
35  // "Sort tracks using an embedded tfLite model based on your expression
36  // while waiting for the trace to load."
37  readonly description: string;
38
39  // Whether the flag defaults to true or false.
40  // If !flag.isOverridden() then flag.get() === flag.defaultValue
41  readonly defaultValue: boolean;
42
43  // Get the current value of the flag.
44  get(): boolean;
45
46  // Override the flag and persist the new value.
47  set(value: boolean): void;
48
49  // If the flag has been overridden.
50  // Note: A flag can be overridden to its default value.
51  isOverridden(): boolean;
52
53  // Reset the flag to its default setting.
54  reset(): void;
55
56  // Get the current state of the flag.
57  overriddenState(): OverrideState;
58}
59
60export enum OverrideState {
61  DEFAULT = 'DEFAULT',
62  TRUE = 'OVERRIDE_TRUE',
63  FALSE = 'OVERRIDE_FALSE',
64}
65