OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
6 | 6 |
7 import android.app.ActivityManager; | 7 import android.app.ActivityManager; |
8 import android.app.Application; | 8 import android.app.Application; |
9 import android.app.PendingIntent; | 9 import android.app.PendingIntent; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 @VisibleForTesting | 87 @VisibleForTesting |
88 static final int NO_PRERENDERING = 1; | 88 static final int NO_PRERENDERING = 1; |
89 @VisibleForTesting | 89 @VisibleForTesting |
90 static final int PREFETCH_ONLY = 2; | 90 static final int PREFETCH_ONLY = 2; |
91 | 91 |
92 private static AtomicReference<CustomTabsConnection> sInstance = new AtomicR eference<>(); | 92 private static AtomicReference<CustomTabsConnection> sInstance = new AtomicR eference<>(); |
93 | 93 |
94 /** Holds the parameters for the current speculation. */ | 94 /** Holds the parameters for the current speculation. */ |
95 @VisibleForTesting | 95 @VisibleForTesting |
96 static final class SpeculationParams { | 96 static final class SpeculationParams { |
97 @VisibleForTesting | |
98 static final int NO_SPECULATION = 0; | |
99 @VisibleForTesting | |
100 static final int PREFETCH = 1; | |
101 @VisibleForTesting | |
102 static final int PRERENDER = 2; | |
103 | |
97 public final CustomTabsSessionToken session; | 104 public final CustomTabsSessionToken session; |
98 public final String url; | 105 public final String url; |
106 public final int speculationMode; | |
99 | 107 |
100 // Only for prerender. | 108 // Only for prerender. |
101 public final WebContents webContents; | 109 public final WebContents webContents; |
102 public final String referrer; | 110 public final String referrer; |
103 public final Bundle extras; | 111 public final Bundle extras; |
104 | 112 |
105 public final boolean prefetchOnly; | 113 static SpeculationParams forPrefetch(CustomTabsSessionToken session, Str ing url) { |
114 return new SpeculationParams(session, url, PREFETCH, null, null, nul l); | |
115 } | |
106 | 116 |
107 static SpeculationParams forPrerender(CustomTabsSessionToken session, St ring url, | 117 static SpeculationParams forPrerender(CustomTabsSessionToken session, St ring url, |
108 WebContents webcontents, String referrer, Bundle extras) { | 118 WebContents webcontents, String referrer, Bundle extras) { |
109 return new SpeculationParams(session, url, webcontents, referrer, ex tras, false); | 119 return new SpeculationParams(session, url, PRERENDER, webcontents, r eferrer, extras); |
110 } | 120 } |
111 | 121 |
112 static SpeculationParams forPrefetch(CustomTabsSessionToken session, Str ing url) { | 122 private SpeculationParams(CustomTabsSessionToken session, String url, in t speculationMode, |
113 return new SpeculationParams(session, url, null, null, null, true); | 123 WebContents webContents, String referrer, Bundle extras) { |
114 } | |
115 | |
116 private SpeculationParams(CustomTabsSessionToken session, String url, | |
117 WebContents webContents, String referrer, Bundle extras, boolean prefetchOnly) { | |
118 this.session = session; | 124 this.session = session; |
119 this.url = url; | 125 this.url = url; |
126 this.speculationMode = speculationMode; | |
120 this.webContents = webContents; | 127 this.webContents = webContents; |
121 this.referrer = referrer; | 128 this.referrer = referrer; |
122 this.extras = extras; | 129 this.extras = extras; |
123 this.prefetchOnly = prefetchOnly; | |
124 } | 130 } |
125 } | 131 } |
126 | 132 |
127 @VisibleForTesting | 133 @VisibleForTesting |
128 SpeculationParams mSpeculation; | 134 SpeculationParams mSpeculation; |
129 protected final Application mApplication; | 135 protected final Application mApplication; |
130 protected final ClientManager mClientManager; | 136 protected final ClientManager mClientManager; |
131 private final boolean mLogRequests; | 137 private final boolean mLogRequests; |
132 private final AtomicBoolean mWarmupHasBeenCalled = new AtomicBoolean(); | 138 private final AtomicBoolean mWarmupHasBeenCalled = new AtomicBoolean(); |
133 private final AtomicBoolean mWarmupHasBeenFinished = new AtomicBoolean(); | 139 private final AtomicBoolean mWarmupHasBeenFinished = new AtomicBoolean(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 if (mForcePrerenderForTesting) mClientManager.setPrerenderCellularForSes sion(session, true); | 188 if (mForcePrerenderForTesting) mClientManager.setPrerenderCellularForSes sion(session, true); |
183 logCall("newSession()", success); | 189 logCall("newSession()", success); |
184 return success; | 190 return success; |
185 } | 191 } |
186 | 192 |
187 private boolean newSessionInternal(CustomTabsSessionToken session) { | 193 private boolean newSessionInternal(CustomTabsSessionToken session) { |
188 if (session == null) return false; | 194 if (session == null) return false; |
189 ClientManager.DisconnectCallback onDisconnect = new ClientManager.Discon nectCallback() { | 195 ClientManager.DisconnectCallback onDisconnect = new ClientManager.Discon nectCallback() { |
190 @Override | 196 @Override |
191 public void run(CustomTabsSessionToken session) { | 197 public void run(CustomTabsSessionToken session) { |
192 cancelPrerender(session); | 198 cancelSpeculation(session); |
193 } | 199 } |
194 }; | 200 }; |
195 PostMessageHandler handler = new PostMessageHandler(session); | 201 PostMessageHandler handler = new PostMessageHandler(session); |
196 return mClientManager.newSession(session, Binder.getCallingUid(), onDisc onnect, handler); | 202 return mClientManager.newSession(session, Binder.getCallingUid(), onDisc onnect, handler); |
197 } | 203 } |
198 | 204 |
199 /** Warmup activities that should only happen once. */ | 205 /** Warmup activities that should only happen once. */ |
200 @SuppressFBWarnings("DM_EXIT") | 206 @SuppressFBWarnings("DM_EXIT") |
201 private static void initializeBrowser(final Application app) { | 207 private static void initializeBrowser(final Application app) { |
202 ThreadUtils.assertOnUiThread(); | 208 ThreadUtils.assertOnUiThread(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 if (!allowedScheme) return null; | 310 if (!allowedScheme) return null; |
305 return uri.toString(); | 311 return uri.toString(); |
306 } | 312 } |
307 | 313 |
308 /** | 314 /** |
309 * High confidence mayLaunchUrl() call, that is: | 315 * High confidence mayLaunchUrl() call, that is: |
310 * - Tries to prerender if possible. | 316 * - Tries to prerender if possible. |
311 * - An empty URL cancels the current prerender if any. | 317 * - An empty URL cancels the current prerender if any. |
312 * - If prerendering is not possible, makes sure that there is a spare rende rer. | 318 * - If prerendering is not possible, makes sure that there is a spare rende rer. |
313 */ | 319 */ |
314 private void highConfidenceMayLaunchUrl(CustomTabsSessionToken session, | 320 private void highConfidenceMayLaunchUrl(CustomTabsSessionToken session, |
ahemery1
2017/03/27 12:30:01
Main rework for this patch is here, integrating pr
| |
315 int uid, String url, Bundle extras, List<Bundle> otherLikelyBundles) { | 321 int uid, String url, Bundle extras, List<Bundle> otherLikelyBundles) { |
316 ThreadUtils.assertOnUiThread(); | 322 ThreadUtils.assertOnUiThread(); |
317 if (TextUtils.isEmpty(url)) { | 323 if (TextUtils.isEmpty(url)) { |
318 cancelPrerender(session); | 324 cancelSpeculation(session); |
319 return; | 325 return; |
320 } | 326 } |
321 | 327 |
322 WarmupManager warmupManager = WarmupManager.getInstance(); | 328 WarmupManager warmupManager = WarmupManager.getInstance(); |
323 Profile profile = Profile.getLastUsedProfile(); | |
324 | 329 |
325 url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(ur l); | 330 url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(ur l); |
326 int debugOverrideValue = NO_OVERRIDE; | 331 int debugOverrideValue = NO_OVERRIDE; |
327 if (extras != null) debugOverrideValue = extras.getInt(DEBUG_OVERRIDE_KE Y, NO_OVERRIDE); | 332 if (extras != null) debugOverrideValue = extras.getInt(DEBUG_OVERRIDE_KE Y, NO_OVERRIDE); |
328 | 333 |
329 boolean didStartPrerender = false, didStartPrefetch = false; | 334 int baseSpeculationMode = getSpeculationModeForSession(session); |
330 boolean mayPrerender = mayPrerender(session); | 335 int temporarySpeculationMode = |
331 if (mayPrerender) { | 336 getSpeculationModeFromDebugOverride(session, debugOverrideValue) ; |
332 if (debugOverrideValue == PREFETCH_ONLY) { | 337 setSpeculationModeForSession(session, temporarySpeculationMode); |
Benoit L
2017/03/27 13:18:15
That's only a matter of preference, but I don't re
ahemery1
2017/03/27 14:47:33
Done.
| |
333 didStartPrefetch = new ResourcePrefetchPredictor(profile).startP refetching(url); | 338 |
334 if (didStartPrefetch) mSpeculation = SpeculationParams.forPrefet ch(session, url); | 339 boolean didStartSpeculation = false; |
335 } else if (debugOverrideValue != NO_PRERENDERING) { | 340 if (maySpeculate(session)) { |
336 didStartPrerender = prerenderUrl(session, url, extras, uid); | 341 didStartSpeculation = startSpeculation(session, url, extras, uid); |
337 } | |
338 } | 342 } |
339 preconnectUrls(otherLikelyBundles); | 343 preconnectUrls(otherLikelyBundles); |
340 if (!didStartPrefetch) warmupManager.maybePreconnectUrlAndSubResources(p rofile, url); | 344 if (temporarySpeculationMode != SpeculationParams.PREFETCH || !didStartS peculation) { |
mattcary
2017/03/27 13:11:35
Shouldn't some of this logic go into startSpeculat
ahemery1
2017/03/27 14:47:33
I hear you, however not sure about this one since
mattcary
2017/03/27 15:10:13
I was thinking of just pushing this all down into
ahemery1
2017/03/27 15:45:39
Fair enough, I have modified it.
| |
341 if (!didStartPrerender) warmupManager.createSpareWebContents(); | 345 Profile profile = Profile.getLastUsedProfile(); |
346 warmupManager.maybePreconnectUrlAndSubResources(profile, url); | |
347 } | |
348 if (temporarySpeculationMode != SpeculationParams.PRERENDER || !didStart Speculation) { | |
349 warmupManager.createSpareWebContents(); | |
350 } | |
351 setSpeculationModeForSession(session, baseSpeculationMode); | |
342 } | 352 } |
343 | 353 |
344 /** | 354 /** |
345 * Low confidence mayLaunchUrl() call, that is: | 355 * Low confidence mayLaunchUrl() call, that is: |
346 * - Preconnects to the ordered list of URLs. | 356 * - Preconnects to the ordered list of URLs. |
347 * - Makes sure that there is a spare renderer. | 357 * - Makes sure that there is a spare renderer. |
348 */ | 358 */ |
349 @VisibleForTesting | 359 @VisibleForTesting |
350 boolean lowConfidenceMayLaunchUrl(List<Bundle> likelyBundles) { | 360 boolean lowConfidenceMayLaunchUrl(List<Bundle> likelyBundles) { |
351 ThreadUtils.assertOnUiThread(); | 361 ThreadUtils.assertOnUiThread(); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 * @param url The URL the WebContents is for. | 590 * @param url The URL the WebContents is for. |
581 * @param referrer The referrer to use for |url|. | 591 * @param referrer The referrer to use for |url|. |
582 * @return The prerendered WebContents, or null. | 592 * @return The prerendered WebContents, or null. |
583 */ | 593 */ |
584 WebContents takePrerenderedUrl(CustomTabsSessionToken session, String url, S tring referrer) { | 594 WebContents takePrerenderedUrl(CustomTabsSessionToken session, String url, S tring referrer) { |
585 ThreadUtils.assertOnUiThread(); | 595 ThreadUtils.assertOnUiThread(); |
586 if (mSpeculation == null || session == null || !session.equals(mSpeculat ion.session)) { | 596 if (mSpeculation == null || session == null || !session.equals(mSpeculat ion.session)) { |
587 return null; | 597 return null; |
588 } | 598 } |
589 | 599 |
590 if (mSpeculation.prefetchOnly) { | 600 if (mSpeculation.speculationMode == SpeculationParams.PREFETCH) { |
591 Profile profile = Profile.getLastUsedProfile(); | 601 cancelSpeculation(session); |
592 new ResourcePrefetchPredictor(profile).stopPrefetching(mSpeculation. url); | |
593 mSpeculation = null; | |
594 return null; | 602 return null; |
595 } | 603 } |
596 | 604 |
597 WebContents webContents = mSpeculation.webContents; | 605 WebContents webContents = mSpeculation.webContents; |
598 String prerenderedUrl = mSpeculation.url; | 606 String prerenderedUrl = mSpeculation.url; |
599 String prerenderReferrer = mSpeculation.referrer; | 607 String prerenderReferrer = mSpeculation.referrer; |
600 if (referrer == null) referrer = ""; | 608 if (referrer == null) referrer = ""; |
601 boolean ignoreFragments = mClientManager.getIgnoreFragmentsForSession(se ssion); | 609 boolean ignoreFragments = mClientManager.getIgnoreFragmentsForSession(se ssion); |
602 boolean urlsMatch = TextUtils.equals(prerenderedUrl, url) | 610 boolean urlsMatch = TextUtils.equals(prerenderedUrl, url) |
603 || (ignoreFragments | 611 || (ignoreFragments |
604 && UrlUtilities.urlsMatchIgnoringFragments(prerenderedUr l, url)); | 612 && UrlUtilities.urlsMatchIgnoringFragments(prerenderedUr l, url)); |
605 WebContents result = null; | 613 WebContents result = null; |
606 if (urlsMatch && TextUtils.equals(prerenderReferrer, referrer)) { | 614 if (urlsMatch && TextUtils.equals(prerenderReferrer, referrer)) { |
607 result = webContents; | 615 result = webContents; |
608 mSpeculation = null; | 616 mSpeculation = null; |
609 } else { | 617 } else { |
610 cancelPrerender(session); | 618 cancelSpeculation(session); |
611 } | 619 } |
612 if (!mClientManager.usesDefaultSessionParameters(session) && webContents != null) { | 620 if (!mClientManager.usesDefaultSessionParameters(session) && webContents != null) { |
613 RecordHistogram.recordBooleanHistogram( | 621 RecordHistogram.recordBooleanHistogram( |
614 "CustomTabs.NonDefaultSessionPrerenderMatched", result != nu ll); | 622 "CustomTabs.NonDefaultSessionPrerenderMatched", result != nu ll); |
615 } | 623 } |
616 | 624 |
617 return result; | 625 return result; |
618 } | 626 } |
619 | 627 |
620 /** Returns the URL prerendered for a session, or null. */ | 628 /** Returns the URL prerendered for a session, or null. */ |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 mClientManager.setPrerenderCellularForSession(session, value); | 673 mClientManager.setPrerenderCellularForSession(session, value); |
666 } | 674 } |
667 | 675 |
668 /** | 676 /** |
669 * See {@link ClientManager#setSendNavigationInfoForSession(CustomTabsSessio nToken, boolean)}. | 677 * See {@link ClientManager#setSendNavigationInfoForSession(CustomTabsSessio nToken, boolean)}. |
670 */ | 678 */ |
671 void setSendNavigationInfoForSession(CustomTabsSessionToken session, boolean send) { | 679 void setSendNavigationInfoForSession(CustomTabsSessionToken session, boolean send) { |
672 mClientManager.setSendNavigationInfoForSession(session, send); | 680 mClientManager.setSendNavigationInfoForSession(session, send); |
673 } | 681 } |
674 | 682 |
683 public void setSpeculationModeForSession(CustomTabsSessionToken session, int speculationMode) { | |
Benoit L
2017/03/27 13:18:15
nit: For consistency with the setters / getters ab
ahemery1
2017/03/27 14:47:33
Done.
| |
684 mClientManager.setSpeculationModeForSession(session, speculationMode); | |
685 } | |
686 | |
687 public int getSpeculationModeForSession(CustomTabsSessionToken session) { | |
688 return mClientManager.getSpeculationModeForSession(session); | |
689 } | |
690 | |
675 /** | 691 /** |
676 * Extracts the creator package name from the intent. | 692 * Extracts the creator package name from the intent. |
677 * @param intent The intent to get the package name from. | 693 * @param intent The intent to get the package name from. |
678 * @return the package name which can be null. | 694 * @return the package name which can be null. |
679 */ | 695 */ |
680 String extractCreatorPackage(Intent intent) { | 696 String extractCreatorPackage(Intent intent) { |
681 return null; | 697 return null; |
682 } | 698 } |
683 | 699 |
684 /** | 700 /** |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
880 @VisibleForTesting | 896 @VisibleForTesting |
881 void cleanUpSession(final CustomTabsSessionToken session) { | 897 void cleanUpSession(final CustomTabsSessionToken session) { |
882 ThreadUtils.runOnUiThread(new Runnable() { | 898 ThreadUtils.runOnUiThread(new Runnable() { |
883 @Override | 899 @Override |
884 public void run() { | 900 public void run() { |
885 mClientManager.cleanupSession(session); | 901 mClientManager.cleanupSession(session); |
886 } | 902 } |
887 }); | 903 }); |
888 } | 904 } |
889 | 905 |
890 private boolean mayPrerender(CustomTabsSessionToken session) { | 906 private boolean maySpeculate(CustomTabsSessionToken session) { |
891 if (!DeviceClassManager.enablePrerendering()) return false; | 907 if (!DeviceClassManager.enablePrerendering()) return false; |
892 // TODO(yusufo): The check for prerender in PrivacyManager now checks fo r the network | 908 // TODO(yusufo): The check for prerender in PrivacyManager now checks fo r the network |
893 // connection type as well, we should either change that or add another check for custom | 909 // connection type as well, we should either change that or add another check for custom |
894 // tabs. Then PrivacyManager should be used to make the below check. | 910 // tabs. Then PrivacyManager should be used to make the below check. |
895 if (!PrefServiceBridge.getInstance().getNetworkPredictionEnabled()) retu rn false; | 911 if (!PrefServiceBridge.getInstance().getNetworkPredictionEnabled()) retu rn false; |
896 if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled ()) return false; | 912 if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled ()) return false; |
897 ConnectivityManager cm = | 913 ConnectivityManager cm = |
898 (ConnectivityManager) mApplication.getApplicationContext().getSy stemService( | 914 (ConnectivityManager) mApplication.getApplicationContext().getSy stemService( |
899 Context.CONNECTIVITY_SERVICE); | 915 Context.CONNECTIVITY_SERVICE); |
900 return !cm.isActiveNetworkMetered() || shouldPrerenderOnCellularForSessi on(session); | 916 return !cm.isActiveNetworkMetered() || shouldPrerenderOnCellularForSessi on(session); |
901 } | 917 } |
902 | 918 |
903 /** Cancels a prerender for a given session, or any session if null. */ | 919 /** Cancels the speculation for a given session, or any session if null. */ |
904 void cancelPrerender(CustomTabsSessionToken session) { | 920 public void cancelSpeculation(CustomTabsSessionToken session) { |
Benoit L
2017/03/27 13:18:15
nit: Please keep this method package private.
| |
905 ThreadUtils.assertOnUiThread(); | 921 ThreadUtils.assertOnUiThread(); |
906 if (mSpeculation != null && (session == null || session.equals(mSpeculat ion.session)) | 922 if (mSpeculation == null) return; |
907 && mSpeculation.webContents != null) { | 923 if (session == null || session.equals(mSpeculation.session)) { |
908 mExternalPrerenderHandler.cancelCurrentPrerender(); | 924 switch (mSpeculation.speculationMode) { |
909 mSpeculation.webContents.destroy(); | 925 case SpeculationParams.PRERENDER: |
926 cancelPrerender(session); | |
927 break; | |
928 case SpeculationParams.PREFETCH: | |
929 cancelPrefetch(session); | |
930 break; | |
931 default: | |
932 return; | |
933 } | |
910 mSpeculation = null; | 934 mSpeculation = null; |
911 } | 935 } |
912 } | 936 } |
913 | 937 |
938 private void cancelPrerender(CustomTabsSessionToken session) { | |
Benoit L
2017/03/27 13:18:14
These two cancel*() methods are private, trivial a
ahemery1
2017/03/27 14:47:33
Done.
| |
939 if (mSpeculation.webContents == null) return; | |
940 mExternalPrerenderHandler.cancelCurrentPrerender(); | |
941 mSpeculation.webContents.destroy(); | |
942 } | |
943 | |
944 private void cancelPrefetch(CustomTabsSessionToken session) { | |
945 Profile profile = Profile.getLastUsedProfile(); | |
946 new ResourcePrefetchPredictor(profile).stopPrefetching(mSpeculation.url) ; | |
947 } | |
948 | |
949 @VisibleForTesting | |
Benoit L
2017/03/27 13:18:15
This method doesn't seem to be called in tests, wh
ahemery1
2017/03/27 14:47:33
Done.
| |
950 boolean startSpeculation(CustomTabsSessionToken session, String url, Bundle extras, int uid) { | |
951 switch (getSpeculationModeForSession(session)) { | |
952 case SpeculationParams.PRERENDER: | |
953 return prerenderUrl(session, url, extras, uid); | |
954 case SpeculationParams.PREFETCH: | |
955 return prefetchUrl(session, url); | |
956 default: | |
957 return false; | |
958 } | |
959 } | |
960 | |
914 /** | 961 /** |
915 * Tries to request a prerender for a given URL. | 962 * Tries to request a prerender for a given URL. |
916 * | 963 * |
917 * @param session Session the request comes from. | 964 * @param session Session the request comes from. |
918 * @param url URL to prerender. | 965 * @param url URL to prerender. |
919 * @param extras extra parameters. | 966 * @param extras extra parameters. |
920 * @param uid UID of the caller. | 967 * @param uid UID of the caller. |
921 * @return true if a prerender has been initiated. | 968 * @return true if a prerender has been initiated. |
922 */ | 969 */ |
923 private boolean prerenderUrl( | 970 private boolean prerenderUrl( |
924 CustomTabsSessionToken session, String url, Bundle extras, int uid) { | 971 CustomTabsSessionToken session, String url, Bundle extras, int uid) { |
925 ThreadUtils.assertOnUiThread(); | 972 ThreadUtils.assertOnUiThread(); |
926 // Ignores mayPrerender() for an empty URL, since it cancels an existing prerender. | |
927 if (!mayPrerender(session) && !TextUtils.isEmpty(url)) return false; | |
928 if (!mWarmupHasBeenCalled.get()) return false; | 973 if (!mWarmupHasBeenCalled.get()) return false; |
929 // Last one wins and cancels the previous prerender. | 974 |
930 cancelPrerender(null); | |
931 if (TextUtils.isEmpty(url)) return false; | |
932 boolean throttle = !shouldPrerenderOnCellularForSession(session); | 975 boolean throttle = !shouldPrerenderOnCellularForSession(session); |
933 if (throttle && !mClientManager.isPrerenderingAllowed(uid)) return false ; | 976 if (throttle && !mClientManager.isPrerenderingAllowed(uid)) return false ; |
934 | 977 |
935 // A prerender will be requested. Time to destroy the spare WebContents. | 978 // A prerender will be requested. Time to destroy the spare WebContents. |
936 WarmupManager.getInstance().destroySpareWebContents(); | 979 WarmupManager.getInstance().destroySpareWebContents(); |
937 | 980 |
938 Intent extrasIntent = new Intent(); | 981 Intent extrasIntent = new Intent(); |
939 if (extras != null) extrasIntent.putExtras(extras); | 982 if (extras != null) extrasIntent.putExtras(extras); |
940 if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null) retur n false; | 983 if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null) retur n false; |
941 if (mExternalPrerenderHandler == null) { | 984 if (mExternalPrerenderHandler == null) { |
942 mExternalPrerenderHandler = new ExternalPrerenderHandler(); | 985 mExternalPrerenderHandler = new ExternalPrerenderHandler(); |
943 } | 986 } |
944 Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mAppli cation, true); | 987 Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mAppli cation, true); |
945 String referrer = IntentHandler.getReferrerUrlIncludingExtraHeaders(extr asIntent); | 988 String referrer = IntentHandler.getReferrerUrlIncludingExtraHeaders(extr asIntent); |
946 if (referrer == null && getReferrerForSession(session) != null) { | 989 if (referrer == null && getReferrerForSession(session) != null) { |
947 referrer = getReferrerForSession(session).getUrl(); | 990 referrer = getReferrerForSession(session).getUrl(); |
948 } | 991 } |
949 if (referrer == null) referrer = ""; | 992 if (referrer == null) referrer = ""; |
950 Pair<WebContents, WebContents> webContentsPair = mExternalPrerenderHandl er.addPrerender( | 993 Pair<WebContents, WebContents> webContentsPair = |
951 Profile.getLastUsedProfile(), url, referrer, | 994 mExternalPrerenderHandler.addPrerender(Profile.getLastUsedProfil e(), url, referrer, |
952 contentBounds, | 995 contentBounds, shouldPrerenderOnCellularForSession(sessi on)); |
953 shouldPrerenderOnCellularForSession(session)); | |
954 if (webContentsPair == null) return false; | 996 if (webContentsPair == null) return false; |
955 WebContents dummyWebContents = webContentsPair.first; | 997 WebContents dummyWebContents = webContentsPair.first; |
956 if (webContentsPair.second != null) { | 998 if (webContentsPair.second != null) { |
957 mClientManager.resetPostMessageHandlerForSession(session, webContent sPair.second); | 999 mClientManager.resetPostMessageHandlerForSession(session, webContent sPair.second); |
958 } | 1000 } |
959 if (throttle) mClientManager.registerPrerenderRequest(uid, url); | 1001 if (throttle) mClientManager.registerPrerenderRequest(uid, url); |
960 mSpeculation = SpeculationParams.forPrerender( | 1002 mSpeculation = |
961 session, url, dummyWebContents, referrer, extras); | 1003 SpeculationParams.forPrerender(session, url, dummyWebContents, r eferrer, extras); |
962 | 1004 |
963 RecordHistogram.recordBooleanHistogram("CustomTabs.PrerenderSessionUsesD efaultParameters", | 1005 RecordHistogram.recordBooleanHistogram("CustomTabs.PrerenderSessionUsesD efaultParameters", |
964 mClientManager.usesDefaultSessionParameters(session)); | 1006 mClientManager.usesDefaultSessionParameters(session)); |
965 | 1007 |
966 return true; | 1008 return true; |
967 } | 1009 } |
968 | 1010 |
1011 private boolean prefetchUrl(CustomTabsSessionToken session, String url) { | |
1012 Profile profile = Profile.getLastUsedProfile(); | |
1013 boolean didStartPrefetching = new ResourcePrefetchPredictor(profile).sta rtPrefetching(url); | |
1014 if (didStartPrefetching) SpeculationParams.forPrefetch(session, url); | |
1015 return didStartPrefetching; | |
1016 } | |
1017 | |
969 @VisibleForTesting | 1018 @VisibleForTesting |
970 void resetThrottling(Context context, int uid) { | 1019 void resetThrottling(Context context, int uid) { |
971 mClientManager.resetThrottling(uid); | 1020 mClientManager.resetThrottling(uid); |
972 } | 1021 } |
973 | 1022 |
974 @VisibleForTesting | 1023 @VisibleForTesting |
975 void ban(Context context, int uid) { | 1024 void ban(Context context, int uid) { |
976 mClientManager.ban(uid); | 1025 mClientManager.ban(uid); |
977 } | 1026 } |
978 | 1027 |
979 @VisibleForTesting | 1028 @VisibleForTesting |
980 void setForcePrerender(boolean force) { | 1029 void setForcePrerender(boolean force) { |
981 mForcePrerenderForTesting = force; | 1030 mForcePrerenderForTesting = force; |
982 } | 1031 } |
1032 | |
1033 private int getSpeculationModeFromDebugOverride( | |
1034 CustomTabsSessionToken session, int debugOverrideValue) { | |
1035 switch (debugOverrideValue) { | |
1036 case PREFETCH_ONLY: | |
1037 return SpeculationParams.PREFETCH; | |
1038 case NO_PRERENDERING: | |
1039 return SpeculationParams.NO_SPECULATION; | |
1040 default: | |
1041 return getSpeculationModeForSession(session); | |
1042 } | |
1043 } | |
983 } | 1044 } |
OLD | NEW |