Commit 85405358 authored by Xi Han's avatar Xi Han Committed by Commit Bot

Cache all flags enabled in ServiceManager only mode when native is loaded.

This is a follow up CL for https://crrev.com/c/1758500. In this CL, caching the
native flags is called when native is loaded in ServiceManager only mode,
including:
- ServiceManagerForDownload
- ServiceManagerForBackgroundPrefetch

Bug: 984559,995355
Change-Id: I51b00b3be048dc6ec377eeef0f81bbc0ce4e9023
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1759682
Commit-Queue: Xi Han <hanxi@chromium.org>
Reviewed-by: default avatarHenrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688198}
parent beae7966
...@@ -37,6 +37,7 @@ import org.chromium.chrome.browser.FileProviderHelper; ...@@ -37,6 +37,7 @@ import org.chromium.chrome.browser.FileProviderHelper;
import org.chromium.chrome.browser.crash.LogcatExtractionRunnable; import org.chromium.chrome.browser.crash.LogcatExtractionRunnable;
import org.chromium.chrome.browser.download.DownloadManagerService; import org.chromium.chrome.browser.download.DownloadManagerService;
import org.chromium.chrome.browser.services.GoogleServicesManager; import org.chromium.chrome.browser.services.GoogleServicesManager;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.chrome.browser.webapps.ActivityAssigner; import org.chromium.chrome.browser.webapps.ActivityAssigner;
import org.chromium.chrome.browser.webapps.ChromeWebApkHost; import org.chromium.chrome.browser.webapps.ChromeWebApkHost;
import org.chromium.components.background_task_scheduler.BackgroundTaskSchedulerExternalUma; import org.chromium.components.background_task_scheduler.BackgroundTaskSchedulerExternalUma;
...@@ -438,6 +439,9 @@ public class ChromeBrowserInitializer { ...@@ -438,6 +439,9 @@ public class ChromeBrowserInitializer {
// TODO(crbug.com/960767): Remove this in M77. // TODO(crbug.com/960767): Remove this in M77.
ServiceManagerStartupUtils.cleanupSharedPreferences(); ServiceManagerStartupUtils.cleanupSharedPreferences();
// Needed for field trial metrics to be properly collected in ServiceManager only mode.
FeatureUtilities.cacheNativeFlagsForServiceManagerOnlyMode();
PostTask.postTask( PostTask.postTask(
TaskTraits.BEST_EFFORT_MAY_BLOCK, LibraryPrefetcher::maybePinOrderedCodeInMemory); TaskTraits.BEST_EFFORT_MAY_BLOCK, LibraryPrefetcher::maybePinOrderedCodeInMemory);
} }
......
...@@ -90,23 +90,12 @@ public class PrefetchBackgroundTask extends NativeBackgroundTask { ...@@ -90,23 +90,12 @@ public class PrefetchBackgroundTask extends NativeBackgroundTask {
sAlwaysSupportServiceManagerOnlyForTesting = true; sAlwaysSupportServiceManagerOnlyForTesting = true;
} }
@VisibleForTesting
static void skipCachingFlagForTesting() {
sSkipCachingFlagForTesting = true;
}
@Override @Override
protected void onStartTaskWithNative( protected void onStartTaskWithNative(
Context context, TaskParameters taskParameters, TaskFinishedCallback callback) { Context context, TaskParameters taskParameters, TaskFinishedCallback callback) {
assert taskParameters.getTaskId() == TaskIds.OFFLINE_PAGES_PREFETCH_JOB_ID; assert taskParameters.getTaskId() == TaskIds.OFFLINE_PAGES_PREFETCH_JOB_ID;
if (mNativeTask != 0) return; if (mNativeTask != 0) return;
// Caches the flag. If a field trial isn't explicitly checked in the code, it won't be
// tagged as active. This might cause many UMA data of "Servicification.Startup2" are shown
// in the "not in study" bucket.
if (!sSkipCachingFlagForTesting)
FeatureUtilities.cacheServiceManagerForBackgroundPrefetch();
// Only Feed is supported in reduced mode. // Only Feed is supported in reduced mode.
// If we launched chrome in reduced mode but it turns out that Feed is not enabled (because // If we launched chrome in reduced mode but it turns out that Feed is not enabled (because
// the cached value of the flag was stale), we should cache the new value and reschedule // the cached value of the flag was stale), we should cache the new value and reschedule
......
...@@ -186,8 +186,6 @@ public class FeatureUtilities { ...@@ -186,8 +186,6 @@ public class FeatureUtilities {
cacheDownloadAutoResumptionEnabledInNative(); cacheDownloadAutoResumptionEnabledInNative();
cachePrioritizeBootstrapTasks(); cachePrioritizeBootstrapTasks();
cacheFeedEnabled(); cacheFeedEnabled();
cacheServiceManagerForDownloadResumption();
cacheServiceManagerForBackgroundPrefetch();
cacheNetworkServiceWarmUpEnabled(); cacheNetworkServiceWarmUpEnabled();
cacheImmersiveUiModeEnabled(); cacheImmersiveUiModeEnabled();
cacheSwapPixelFormatToFixConvertFromTranslucentEnabled(); cacheSwapPixelFormatToFixConvertFromTranslucentEnabled();
...@@ -202,6 +200,18 @@ public class FeatureUtilities { ...@@ -202,6 +200,18 @@ public class FeatureUtilities {
ChromeFeatureList.isEnabled(ChromeFeatureList.REACHED_CODE_PROFILER)); ChromeFeatureList.isEnabled(ChromeFeatureList.REACHED_CODE_PROFILER));
} }
/**
* 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
* these field trials as active, otherwise histogram data recorded in ServiceManager only mode
* won't be tagged with their corresponding field trial experiments.
*/
public static void cacheNativeFlagsForServiceManagerOnlyMode() {
// TODO(crbug.com/995355): Move other related flags from {@link cacheNativeFlags} to here.
cacheServiceManagerForDownloadResumption();
cacheServiceManagerForBackgroundPrefetch();
}
/** /**
* @return True if tab model merging for Android N+ is enabled. * @return True if tab model merging for Android N+ is enabled.
*/ */
......
...@@ -133,8 +133,6 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -133,8 +133,6 @@ public class PrefetchBackgroundTaskUnitTest {
mFakeTaskScheduler = new FakeBackgroundTaskScheduler(); mFakeTaskScheduler = new FakeBackgroundTaskScheduler();
BackgroundTaskSchedulerFactory.setSchedulerForTesting(mFakeTaskScheduler); BackgroundTaskSchedulerFactory.setSchedulerForTesting(mFakeTaskScheduler);
PrefetchBackgroundTask.skipCachingFlagForTesting();
} }
@Test @Test
......
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