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 { ...@@ -121,15 +121,15 @@ public class ExternalNavigationHandler {
return result; return result;
} }
private boolean intentsHaveSameResolvers(Intent intent, Intent previousIntent) { private boolean resolversSubsetOf(List<ResolveInfo> infos, List<ResolveInfo> container) {
HashSet<ComponentName> previousHandlers = new HashSet<>(); HashSet<ComponentName> containerSet = new HashSet<>();
for (ResolveInfo r : mDelegate.queryIntentActivities(previousIntent)) { for (ResolveInfo info : container) {
previousHandlers.add(new ComponentName(r.activityInfo.packageName, containerSet.add(
r.activityInfo.name)); new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
} }
for (ResolveInfo r : mDelegate.queryIntentActivities(intent)) { for (ResolveInfo info : infos) {
if (!previousHandlers.contains(new ComponentName( if (!containerSet.contains(new ComponentName(
r.activityInfo.packageName, r.activityInfo.name))) { info.activityInfo.packageName, info.activityInfo.name))) {
return false; return false;
} }
} }
...@@ -377,10 +377,10 @@ public class ExternalNavigationHandler { ...@@ -377,10 +377,10 @@ public class ExternalNavigationHandler {
previousIntent = null; previousIntent = null;
} }
if (previousIntent != null) { if (previousIntent != null
if (intentsHaveSameResolvers(intent, previousIntent)) { && resolversSubsetOf(resolvingInfos,
return OverrideUrlLoadingResult.NO_OVERRIDE; 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