Commit e3343a30 authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Make ExternalNavigationHandler#intentsHaveSameResolvers() faster

ExternalNavigationHandler#intentsHaveSameResolvers() will be called on each
WebAPK navigation. Removing the duplicate call to
PackageManager#queryIntentActivities() saves 2ms per navigation.

BUG=609122
TEST=None

Review-Url: https://codereview.chromium.org/2035203002
Cr-Commit-Position: refs/heads/master@{#398194}
parent f56bda6f
......@@ -121,15 +121,15 @@ public class ExternalNavigationHandler {
return result;
}
private boolean intentsHaveSameResolvers(Intent intent, Intent previousIntent) {
HashSet<ComponentName> previousHandlers = new HashSet<>();
for (ResolveInfo r : mDelegate.queryIntentActivities(previousIntent)) {
previousHandlers.add(new ComponentName(r.activityInfo.packageName,
r.activityInfo.name));
private boolean resolversSubsetOf(List<ResolveInfo> infos, List<ResolveInfo> container) {
HashSet<ComponentName> containerSet = new HashSet<>();
for (ResolveInfo info : container) {
containerSet.add(
new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
}
for (ResolveInfo r : mDelegate.queryIntentActivities(intent)) {
if (!previousHandlers.contains(new ComponentName(
r.activityInfo.packageName, r.activityInfo.name))) {
for (ResolveInfo info : infos) {
if (!containerSet.contains(new ComponentName(
info.activityInfo.packageName, info.activityInfo.name))) {
return false;
}
}
......@@ -377,10 +377,10 @@ public class ExternalNavigationHandler {
previousIntent = null;
}
if (previousIntent != null) {
if (intentsHaveSameResolvers(intent, previousIntent)) {
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
if (previousIntent != null
&& resolversSubsetOf(resolvingInfos,
mDelegate.queryIntentActivities(previousIntent))) {
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
}
}
......
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