Commit e1c3a451 authored by Clark DuVall's avatar Clark DuVall Committed by Chromium LUCI CQ

[WebLayer] Only load splits which are used by WebLayer

This should help startup on Monochrome since we can avoid loading splits
that will not be used by WebLayer. This will likely have memory benefits
in the field.

-4.4% weblayer_startup_wall_time:
https://pinpoint-dot-chromeperf.appspot.com/job/10843ff4d20000

Bug: 1146438
Change-Id: I1c1dfcda323e9f8c41d05959c580ce050f76bf0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626101Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843363}
parent 603e3ccf
...@@ -7,6 +7,7 @@ package org.chromium.weblayer; ...@@ -7,6 +7,7 @@ package org.chromium.weblayer;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
...@@ -802,9 +803,10 @@ public class WebLayer { ...@@ -802,9 +803,10 @@ public class WebLayer {
} }
} }
/** Utility class to use new APIs that were added in O (API level 26). */
@VerifiesOnO @VerifiesOnO
@TargetApi(Build.VERSION_CODES.O) @TargetApi(Build.VERSION_CODES.O)
private static final class ApiHelperForO { /* package */ static final class ApiHelperForO {
/** See {@link Context.createContextForSplit(String) }. */ /** See {@link Context.createContextForSplit(String) }. */
public static Context createContextForSplit(Context context, String name) public static Context createContextForSplit(Context context, String name)
throws PackageManager.NameNotFoundException { throws PackageManager.NameNotFoundException {
...@@ -815,6 +817,11 @@ public class WebLayer { ...@@ -815,6 +817,11 @@ public class WebLayer {
StrictMode.setThreadPolicy(oldPolicy); StrictMode.setThreadPolicy(oldPolicy);
} }
} }
/** See {@link ApplicationInfo#splitNames}. */
public static String[] getSplitNames(ApplicationInfo info) {
return info.splitNames;
}
} }
@VerifiesOnR @VerifiesOnR
......
...@@ -69,17 +69,31 @@ final class WebViewCompatibilityHelper { ...@@ -69,17 +69,31 @@ final class WebViewCompatibilityHelper {
private static String getAllApkPaths(ApplicationInfo info) { private static String getAllApkPaths(ApplicationInfo info) {
// The OS version of this method also includes resourceDirs, but this is not available in // The OS version of this method also includes resourceDirs, but this is not available in
// the SDK. // the SDK.
final String[][] inputLists = {info.sharedLibraryFiles, info.splitSourceDirs};
final List<String> output = new ArrayList<>(10); final List<String> output = new ArrayList<>(10);
for (String[] inputList : inputLists) { // First add the base APK path, since this is always needed.
if (inputList != null) { if (info.sourceDir != null) {
for (String input : inputList) { output.add(info.sourceDir);
output.add(input); }
// Next add split paths that are used by WebLayer.
if (info.splitSourceDirs != null) {
String[] splitNames = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
splitNames = WebLayer.ApiHelperForO.getSplitNames(info);
}
for (int i = 0; i < info.splitSourceDirs.length; i++) {
// WebLayer only uses the "chrome" and "weblayer" splits.
if (splitNames != null && !splitNames[i].equals("chrome")
&& !splitNames[i].equals("weblayer")) {
continue;
} }
output.add(info.splitSourceDirs[i]);
} }
} }
if (info.sourceDir != null) { // Last, add shared library paths.
output.add(info.sourceDir); if (info.sharedLibraryFiles != null) {
for (String input : info.sharedLibraryFiles) {
output.add(input);
}
} }
return TextUtils.join(File.pathSeparator, output); return TextUtils.join(File.pathSeparator, output);
} }
......
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