Commit fe102ceb authored by Wei-Yin Chen (陳威尹)'s avatar Wei-Yin Chen (陳威尹) Committed by Commit Bot

Automatically list Finch parameters to cache

Bug: 1067145
Change-Id: I25d2b9b8537ea665767f90658702a3316a6ff58d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134572
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarHenrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#761326}
parent 81b3f38f
......@@ -4,6 +4,9 @@
package org.chromium.chrome.browser.app.flags;
import android.text.TextUtils;
import org.chromium.base.annotations.RemovableInRelease;
import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
import org.chromium.chrome.browser.firstrun.FirstRunUtils;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
......@@ -16,6 +19,7 @@ import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.chrome.browser.toolbar.bottom.BottomToolbarVariationManager;
import org.chromium.chrome.features.start_surface.StartSurfaceConfiguration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -84,6 +88,7 @@ public class ChromeCachedFlags {
TabUiFeatureUtilities.TAB_GRID_LAYOUT_ANDROID_NEW_TAB_TILE,
TabUiFeatureUtilities.THUMBNAIL_ASPECT_RATIO);
// clang-format on
tryToCatchMissingParameters(fieldTrialsToCache);
CachedFeatureFlags.cacheFieldTrialParameters(fieldTrialsToCache);
// TODO(crbug.com/1062013): Remove this after M85.
......@@ -98,6 +103,22 @@ public class ChromeCachedFlags {
mIsFinishedCachingNativeFlags = true;
}
@RemovableInRelease
private void tryToCatchMissingParameters(List<CachedFieldTrialParameter> listed) {
// All instances of CachedFieldTrialParameter should be manually passed to
// CachedFeatureFlags.cacheFieldTrialParameters(). The following checking is a best-effort
// attempt to try to catch accidental omissions. It cannot replace the list because some
// instances might not be instantiated if the classes they belong to are not accessed yet.
List<String> omissions = new ArrayList<>();
for (CachedFieldTrialParameter trial : CachedFieldTrialParameter.getAllInstances()) {
if (listed.contains(trial)) continue;
omissions.add(trial.getFeatureName() + ":" + trial.getParameterName());
}
assert omissions.isEmpty()
: "The following trials are not correctly cached: "
+ TextUtils.join(", ", omissions);
}
/**
* Caches flags that are enabled in ServiceManager only mode and must take effect on startup but
* are set via native code. This function needs to be called in ServiceManager only mode to mark
......
......@@ -7,10 +7,14 @@ package org.chromium.chrome.browser.flags;
import androidx.annotation.IntDef;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.annotations.CheckDiscard;
import org.chromium.base.annotations.RemovableInRelease;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.HashSet;
import java.util.Set;
/**
* A field trial parameter in the variations framework that is cached by {@link CachedFeatureFlags}.
......@@ -29,6 +33,9 @@ public abstract class CachedFieldTrialParameter {
int DOUBLE = 3;
}
@CheckDiscard("crbug.com/1067145")
private static Set<CachedFieldTrialParameter> sAllInstances;
private final String mFeatureName;
private final String mParameterName;
private final @FieldTrialParameterType int mType;
......@@ -40,6 +47,21 @@ public abstract class CachedFieldTrialParameter {
mParameterName = parameterName;
mType = type;
mPreferenceKeyOverride = preferenceKeyOverride;
registerInstance();
}
@RemovableInRelease
private void registerInstance() {
if (sAllInstances == null) {
sAllInstances = new HashSet<>();
}
sAllInstances.add(this);
}
@CheckDiscard("crbug.com/1067145")
public static Set<CachedFieldTrialParameter> getAllInstances() {
return sAllInstances;
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment