Skip to content

Commit

Permalink
[AW][Dev-UI] add FlagsAtStartup for toggled flags
Browse files Browse the repository at this point in the history
This adds Android.WebView.Launch.FlagsAtStartup, WebView's analog of
Launch.FlagsAtStartup. This should be more-or-less compatible with
Chrome histogram, with the caveat the Developer UI is only easily
accessible on pre-stable channels whereas chrome://flags is easy to
toggle in stable.

This extends FlagsAtStartup's enum for the flags already exposed in the
WebView Developer UI.

Fixed: 1084178
Test: Manually verify WebView's hash mechanism produces correct results
Test: Verify new enum hashes with 'AboutFlagsHistogramTest.*'
Change-Id: Ifd09a98a8f994c7ef2041725d6e6e1233ef8da1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2223332
Commit-Queue: Nate Fischer <[email protected]>
Reviewed-by: Hazem Ashmawy <[email protected]>
Reviewed-by: Alexei Svitkine <[email protected]>
Reviewed-by: Richard Coles <[email protected]>
Cr-Commit-Position: refs/heads/master@{#775750}
  • Loading branch information
ntfschr-chromium authored and Commit Bot committed Jun 5, 2020
1 parent 18f9cbb commit ee15b0f
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 5 deletions.
1 change: 1 addition & 0 deletions android_webview/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ source_set("browser") {
"//components/cdm/browser",
"//components/content_capture/android",
"//components/content_capture/browser",
"//components/flags_ui",

# Called via JNI in CrashpadMain
"//components/crash/android:crashpad_main",
Expand Down
1 change: 1 addition & 0 deletions android_webview/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include_rules = [
"+components/crash/core",
"+components/download/public/common",
"+components/embedder_support/android/metrics",
"+components/flags_ui",
"+components/heap_profiling",
"+components/keyed_service/core",
"+components/minidump_uploader",
Expand Down
18 changes: 18 additions & 0 deletions android_webview/browser/aw_contents_statics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "components/flags_ui/flags_ui_metrics.h"
#include "components/google/core/common/google_util.h"
#include "components/security_interstitials/core/urls.h"
#include "components/version_info/version_info.h"
Expand Down Expand Up @@ -138,6 +139,23 @@ void JNI_AwContentsStatics_LogCommandLineForDebugging(JNIEnv* env) {
}
}

// static
void JNI_AwContentsStatics_LogFlagMetrics(
JNIEnv* env,
const JavaParamRef<jobjectArray>& jswitches,
const JavaParamRef<jobjectArray>& jfeatures) {
std::set<std::string> switches;
for (const auto& jswitch : jswitches.ReadElements<jstring>()) {
switches.insert(ConvertJavaStringToUTF8(jswitch));
}
std::set<std::string> features;
for (const auto& jfeature : jfeatures.ReadElements<jstring>()) {
features.insert(ConvertJavaStringToUTF8(jfeature));
}
flags_ui::ReportAboutFlagsHistogram("Launch.FlagsAtStartup", switches,
features);
}

// static
jboolean JNI_AwContentsStatics_IsMultiProcessEnabled(JNIEnv* env) {
return !content::RenderProcessHost::run_renderer_in_process();
Expand Down
3 changes: 3 additions & 0 deletions android_webview/docs/developer-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ If you're intending to launch a feature in WebView or start a field trial (AKA
Finch experiment), we **highly encourage** you to [add to the
list](/android_webview/java/src/org/chromium/android_webview/common/ProductionSupportedFlagList.java)
(ex. [CL](https://crrev.com/c/2008007), [CL](https://crrev.com/c/2066144)).
After that, follow [these
steps](/tools/metrics/histograms/README.md#Flag-Histograms) to collect metrics
about your feature usage.

Exposing your feature this way has several benefits:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import org.chromium.android_webview.AwBrowserContext;
import org.chromium.android_webview.AwBrowserProcess;
import org.chromium.android_webview.AwContentsStatics;
import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.ProductConfig;
import org.chromium.android_webview.WebViewChromiumRunQueue;
Expand Down Expand Up @@ -332,13 +333,13 @@ private void initialize(WebViewDelegate webViewDelegate) {
developerModeEnd - developerModeStart);
RecordHistogram.recordBooleanHistogram(
"Android.WebView.DevUi.DeveloperModeEnabled", isDeveloperModeEnabled);
Map<String, Boolean> flagOverrides = null;
if (isDeveloperModeEnabled) {
long start = SystemClock.elapsedRealtime();
try {
FlagOverrideHelper helper =
new FlagOverrideHelper(ProductionSupportedFlagList.sFlagList);
Map<String, Boolean> flagOverrides =
DeveloperModeUtils.getFlagOverrides(webViewPackageName);
flagOverrides = DeveloperModeUtils.getFlagOverrides(webViewPackageName);
helper.applyFlagOverrides(flagOverrides);

RecordHistogram.recordCount100Histogram(
Expand Down Expand Up @@ -375,6 +376,10 @@ private void initialize(WebViewDelegate webViewDelegate) {

// Now safe to use WebView data directory.

if (flagOverrides != null) {
AwContentsStatics.logFlagOverridesWithNative(flagOverrides);
}

mAwInit.startVariationsInit();

mShouldDisableThreadChecking = shouldDisableThreadChecking(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@
import android.content.Context;
import android.net.Uri;

import org.chromium.android_webview.common.Flag;
import org.chromium.android_webview.common.FlagOverrideHelper;
import org.chromium.android_webview.common.PlatformServiceBridge;
import org.chromium.android_webview.common.ProductionSupportedFlagList;
import org.chromium.base.Callback;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.task.PostTask;
import org.chromium.base.task.TaskTraits;
import org.chromium.content_public.browser.UiThreadTaskTraits;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Implementations of various static methods, and also a home for static
Expand Down Expand Up @@ -129,6 +135,29 @@ public static void logCommandLineForDebugging() {
AwContentsStaticsJni.get().logCommandLineForDebugging();
}

public static void logFlagOverridesWithNative(Map<String, Boolean> flagOverrides) {
// Do work asynchronously to avoid blocking startup.
PostTask.postTask(TaskTraits.THREAD_POOL_BEST_EFFORT, () -> {
FlagOverrideHelper helper =
new FlagOverrideHelper(ProductionSupportedFlagList.sFlagList);
ArrayList<String> switches = new ArrayList<>();
ArrayList<String> features = new ArrayList<>();
for (Map.Entry<String, Boolean> entry : flagOverrides.entrySet()) {
Flag flag = helper.getFlagForName(entry.getKey());
boolean enabled = entry.getValue();
if (flag.isBaseFeature()) {
features.add(flag.getName() + (enabled ? ":enabled" : ":disabled"));
} else if (enabled) {
switches.add("--" + flag.getName());
}
// Only insert enabled switches; ignore explicitly disabled switches since this is
// usually a NOOP.
}
AwContentsStaticsJni.get().logFlagMetrics(
switches.toArray(new String[0]), features.toArray(new String[0]));
});
}

/**
* Return the first substring consisting of the address of a physical location.
* @see {@link android.webkit.WebView#findAddress(String)}
Expand All @@ -153,6 +182,7 @@ public static boolean isMultiProcessEnabled() {
@NativeMethods
interface Natives {
void logCommandLineForDebugging();
void logFlagMetrics(String[] switches, String[] features);

String getSafeBrowsingPrivacyPolicyUrl();
void clearClientCertPreferences(Runnable callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void applyFlagOverrides(Map<String, Boolean> overrides) {
* @return the desired {@link Flag}.
* @throws RuntimeException if this cannot find {@code name} in the list.
*/
private Flag getFlagForName(@NonNull String name) {
public Flag getFlagForName(@NonNull String name) {
if (mFlagMap.containsKey(name)) {
return mFlagMap.get(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public final class ProductionSupportedFlagList {
private ProductionSupportedFlagList() {}

/**
* A list of commandline flags supported on user devices.
* A list of commandline flags supported on user devices. If updating this list, please also
* update enums.xml. See android_webview/docs/developer-ui.md
* (https://chromium.googlesource.com/chromium/src/+/HEAD/android_webview/docs/developer-ui.md#Adding-your-flags-and-features-to-the-UI).
*/
public static final Flag[] sFlagList = {
Flag.commandLine(AwSwitches.HIGHLIGHT_ALL_WEBVIEWS,
Expand Down
19 changes: 19 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38686,6 +38686,7 @@ from previous Chrome versions.
<int value="-1993730028" label="CrostiniPortForwarding:enabled"/>
<int value="-1990614981" label="StoragePressureUI:disabled"/>
<int value="-1989747818" label="TabStripKeyboardFocus:disabled"/>
<int value="-1988840552" label="WebViewExtraHeadersSameOriginOnly:disabled"/>
<int value="-1985452239" label="SmartDim20190221:disabled"/>
<int value="-1985239289" label="AutofillRichMetadataQueries:enabled"/>
<int value="-1985025593" label="file-manager-enable-new-gallery"/>
Expand Down Expand Up @@ -39038,6 +39039,7 @@ from previous Chrome versions.
label="AndroidPartnerCustomizationPhenotype:enabled"/>
<int value="-1607691647" label="MojoVideoEncodeAccelerator:disabled"/>
<int value="-1607297082" label="ash-enable-persistent-window-bounds"/>
<int value="-1607175130" label="force-enable-metrics-reporting"/>
<int value="-1605567628" label="disable-overlay-scrollbar"/>
<int value="-1604051051" label="SpecialLocale:disabled"/>
<int value="-1603404046" label="V8VmFuture:disabled"/>
Expand Down Expand Up @@ -39201,6 +39203,7 @@ from previous Chrome versions.
<int value="-1433087548" label="enable-app-install-alerts"/>
<int value="-1431722713" label="TabFreeze:disabled"/>
<int value="-1431563697" label="WebPaymentsMethodSectionOrderV2:enabled"/>
<int value="-1430090822" label="EnableSharedImageForWebview:disabled"/>
<int value="-1428589407" label="WebRTCPipeWireCapturer:disabled"/>
<int value="-1426817842" label="BlockTabUnders:enabled"/>
<int value="-1426150007" label="ignore-previews-blacklist"/>
Expand Down Expand Up @@ -39656,6 +39659,7 @@ from previous Chrome versions.
<int value="-969332901" label="stop-non-timers-in-background:disabled"/>
<int value="-968675274" label="Rar2Fs:enabled"/>
<int value="-968010468" label="SharedArrayBuffer:disabled"/>
<int value="-967825290" label="WebViewConnectionlessSafeBrowsing:disabled"/>
<int value="-966290456" label="WebAuthenticationCtap2:enabled"/>
<int value="-965842218" label="MultiDeviceApi:disabled"/>
<int value="-964676765" label="enable-accelerated-mjpeg-decode"/>
Expand Down Expand Up @@ -40092,6 +40096,7 @@ from previous Chrome versions.
<int value="-470247915"
label="AutofillUpstreamEditableExpirationDate:enabled"/>
<int value="-468697885" label="ArcInputMethod:enabled"/>
<int value="-466704882" label="webview-log-js-console-messages"/>
<int value="-462554210"
label="OminboxUIExperimentUseGenericSearchEngineIcon:enabled"/>
<int value="-462404204" label="CryptAuthV2DeviceSync:disabled"/>
Expand All @@ -40108,6 +40113,7 @@ from previous Chrome versions.
<int value="-450976085"
label="AutofillSaveCreditCardUsesImprovedMessaging:disabled"/>
<int value="-449465495" label="disable-browser-task-scheduler"/>
<int value="-446560063" label="finch-seed-min-update-period"/>
<int value="-444867364" label="Metal:enabled"/>
<int value="-442352394" label="IframeOneGoogleBar:disabled"/>
<int value="-438379844" label="SwapSideVolumeButtonsForOrientation:enabled"/>
Expand All @@ -40133,6 +40139,7 @@ from previous Chrome versions.
<int value="-406850932" label="EnableEmojiContextMenu:enabled"/>
<int value="-405380243" label="enable-encryption-migration"/>
<int value="-403701720" label="DirectActions:enabled"/>
<int value="-403649153" label="WebViewBrotliSupport:disabled"/>
<int value="-402038055"
label="OmniboxUIExperimentBlueTitlesAndGrayUrlsOnPageSuggestions:enabled"/>
<int value="-401170566"
Expand Down Expand Up @@ -40553,6 +40560,7 @@ from previous Chrome versions.
<int value="59784035" label="ImeThread:disabled"/>
<int value="59964519" label="OmniboxEnableClipboardProvider:disabled"/>
<int value="60023885" label="AutofillNoLocalSaveOnUnmaskSuccess:disabled"/>
<int value="61130490" label="WebViewBrotliSupport:enabled"/>
<int value="61205887" label="enable-text-input-focus-manager"/>
<int value="61466986" label="AsyncDns:disabled"/>
<int value="63187126" label="DownloadsAutoResumptionNative:enabled"/>
Expand Down Expand Up @@ -40773,6 +40781,7 @@ from previous Chrome versions.
<int value="339671131" label="disable-per-user-timezone"/>
<int value="341152650" label="SoundContentSetting:enabled"/>
<int value="341851350" label="EnableDbusAndX11StatusIcons:enabled"/>
<int value="342431487" label="VizForWebView:enabled"/>
<int value="342960463" label="SharingQRCodeGenerator:enabled"/>
<int value="343445783" label="AllowScrollSettings:enabled"/>
<int value="345664265" label="BlinkHeapIncrementalMarking:disabled"/>
Expand Down Expand Up @@ -40896,6 +40905,7 @@ from previous Chrome versions.
<int value="470011024" label="NonValidatingReloadOnNormalReload:enabled"/>
<int value="471224152" label="WinUseHybridSpellChecker:enabled"/>
<int value="471519375" label="NewOsSettingsSearch:disabled"/>
<int value="471560693" label="webview-verbose-logging"/>
<int value="471969274" label="MediaControlsExpandGesture:enabled"/>
<int value="473958125" label="OmniboxWrapPopupPosition:enabled"/>
<int value="474743272" label="material-design-ink-drop"/>
Expand All @@ -40908,6 +40918,7 @@ from previous Chrome versions.
<int value="480677983" label="WebXRARDOMOverlay:disabled"/>
<int value="481506759" label="ServiceWorkerScriptStreaming:enabled"/>
<int value="482232604" label="PercentBasedScrolling:enabled"/>
<int value="485957747" label="finch-seed-ignore-pending-download"/>
<int value="487810392" label="EnablePalmOnToolTypePalm:enabled"/>
<int value="491334698" label="ConditionalTabStripAndroid:enabled"/>
<int value="492113129" label="ExperimentalAppBanners:enabled"/>
Expand Down Expand Up @@ -41178,6 +41189,7 @@ from previous Chrome versions.
<int value="783270752" label="AndroidHistoryManager:enabled"/>
<int value="787080596" label="DynamicTcmallocTuning:enabled"/>
<int value="787385958" label="RegionalLocalesAsDisplayUI:enabled"/>
<int value="792884862" label="EnableSharedImageForWebview:enabled"/>
<int value="798696013" label="ImeInputLogicMozc:enabled"/>
<int value="799680074" label="ContextualSearchTranslationModel:enabled"/>
<int value="803282885" label="PreferHtmlOverPlugins:disabled"/>
Expand Down Expand Up @@ -41250,6 +41262,7 @@ from previous Chrome versions.
<int value="883190338" label="PrintWithReducedRasterization:disabled"/>
<int value="884106779" label="supervised-user-safesites"/>
<int value="885004540" label="ArcEnableApplicationZoomFeature:enabled"/>
<int value="885186849" label="finch-seed-expiration-age"/>
<int value="885971656" label="EnablePlayStoreAppSearch:enabled"/>
<int value="886907524" label="autoplay-policy"/>
<int value="887011602" label="enable-spelling-auto-correct"/>
Expand All @@ -41273,6 +41286,7 @@ from previous Chrome versions.
<int value="916316159" label="disable-new-app-list-mixer"/>
<int value="917561046" label="ConversionMeasurement:disabled"/>
<int value="918046854" label="NtlmV2Enabled:disabled"/>
<int value="918608729" label="finch-seed-min-download-period"/>
<int value="921536672" label="OfflinePagesDescriptiveFailStatus:enabled"/>
<int value="921561616" label="WebAssemblyTiering:disabled"/>
<int value="925712999" label="V8Orinoco:enabled"/>
Expand Down Expand Up @@ -41313,6 +41327,7 @@ from previous Chrome versions.
<int value="972228058" label="SyncUSSSessions:disabled"/>
<int value="973601997" label="SafeBrowsingUseLocalBlacklistsV2:disabled"/>
<int value="975104092" label="show-taps"/>
<int value="975463471" label="WebViewExtraHeadersSameOriginOnly:enabled"/>
<int value="976079108" label="TouchpadOverscrollHistoryNavigation:disabled"/>
<int value="976278412" label="google-password-manager:enabled"/>
<int value="977968353" label="WebUITabStrip:disabled"/>
Expand Down Expand Up @@ -41447,6 +41462,7 @@ from previous Chrome versions.
label="PrefetchMainResourceNetworkIsolationKey:enabled"/>
<int value="1111871757" label="ForceUnifiedConsentBump:enabled"/>
<int value="1112051724" label="DetectingHeavyPages:enabled"/>
<int value="1112817963" label="WebViewConnectionlessSafeBrowsing:enabled"/>
<int value="1113196543" label="ShowManagedUi:disabled"/>
<int value="1113365156" label="tab-management-experiment-type-chive"/>
<int value="1114270092" label="PortalsCrossOrigin:disabled"/>
Expand Down Expand Up @@ -41863,6 +41879,7 @@ from previous Chrome versions.
<int value="1579084737" label="TemporaryUnexpireFlagsM80:disabled"/>
<int value="1579461102" label="MemoryCoordinator:disabled"/>
<int value="1581002467" label="enable-explicit-dma-fences"/>
<int value="1584039096" label="highlight-all-webviews"/>
<int value="1584536816" label="LimitAltTabToActiveDesk:enabled"/>
<int value="1586022426" label="AutofillCreditCardAssist:enabled"/>
<int value="1587521886" label="SSLCommittedInterstitials:enabled"/>
Expand All @@ -41881,8 +41898,10 @@ from previous Chrome versions.
<int value="1597972555" label="ChromeSharingHubV15:enabled"/>
<int value="1600850069" label="MobileIdentityConsistency:disabled"/>
<int value="1600926040" label="TranslateCompactUI:enabled"/>
<int value="1601582484" label="enable-crash-reporter-for-testing"/>
<int value="1602869271" label="ChromeShareScreenshot:disabled"/>
<int value="1603578716" label="CaptionSettings:disabled"/>
<int value="1604893983" label="VizForWebView:disabled"/>
<int value="1605398303" label="MacSystemMediaPermissionsInfoUI:enabled"/>
<int value="1605611615" label="enable-webrtc-srtp-aes-gcm"/>
<int value="1609059016" label="CupsIppPrintingBackend:enabled"/>
Expand Down
6 changes: 5 additions & 1 deletion tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71830,10 +71830,14 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
<histogram name="Launch.FlagsAtStartup" enum="LoginCustomFlags"
expires_after="2020-11-29">
<owner>[email protected]</owner>
<owner>[email protected]</owner>
<summary>
Logs which Chrome flags from about:flags were active on start up. Note that
this flag is not really used on Chrome OS; on that platform, look at
Login.CustomFlags instead.
Login.CustomFlags instead. Android WebView supports flags differently than
most platforms, see
https://chromium.googlesource.com/chromium/src/+/HEAD/android_webview/docs/developer-ui.md
for details.
</summary>
</histogram>

Expand Down

0 comments on commit ee15b0f

Please sign in to comment.