/*
 * Copyright 2021 The Bazel Authors. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.idea.blaze.base.console;

import com.google.common.primitives.Ints;
import com.google.idea.common.experiments.BoolExperiment;
import com.google.idea.common.experiments.IntExperiment;
import com.google.idea.common.util.MorePlatformUtils;

/**
 * The experiments that turn on/off the new (v2) and old (v1) Blaze Consoles. The IDE restart is
 * needed for the new experiment values to take effect. The experiment also allows users to set a
 * limit on how much task history is to be displayed in the new (v2) Blaze console's tree-view.
 */
public final class BlazeConsoleExperimentManager {

  // The values of experiments are being read once on startup. This because dynamic switching
  // between v1 and v2 consoles is not supported.
  private static final boolean V1_ENABLED = new BoolExperiment("blazeconsole.v1", true).getValue();
  private static final boolean V2_ENABLED = new BoolExperiment("blazeconsole.v2", false).getValue();

  private BlazeConsoleExperimentManager() {}

  public static boolean isBlazeConsoleV1Enabled() {
    return V1_ENABLED || !V2_ENABLED;
  }

  public static boolean isBlazeConsoleV2Enabled() {
    return V2_ENABLED;
  }

  public static int getTasksHistorySize() {
    int historySize =
        new IntExperiment(
                "blazeconsole.v2.history.size", MorePlatformUtils.isAndroidStudio() ? 1 : 10)
            .getValue();
    return Ints.constrainToRange(historySize, 1, 10);
  }
}

@@ -744,20 +744,30 @@
 riments.
-Bool
+FeatureRollout
 Experime
@@ -1246,242 +1246,119 @@
 The 
-values of experiments are being read once on startup. This because dynamic switching%0A  // between v1 and v2 consoles is not suppor
+experiment is read once on startup, as the tool window is only crea
 ted
-.
 %0A  
-private static final boolean V1_ENABLED = new BoolExperiment(%22blazeconsole.v1%22, true).getValue();
+// once during the lifetime of the IDE
 %0A  p
@@ -1401,17 +1401,33 @@
 ED =
- new Bool
+%0A      new FeatureRollout
 Expe
@@ -1453,26 +1453,28 @@
 e.v2
-%22, false).getValue
+.rollout%22).isEnabled
 ();%0A
@@ -1564,32 +1564,32 @@
 leV1Enabled() %7B%0A
+
     return V1_EN
@@ -1586,22 +1586,8 @@
 turn
- V1_ENABLED %7C%7C
  !V2

Make new blaze console experiment a feature rollout experiment