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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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, |
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(); | 329 Profile profile = Profile.getLastUsedProfile(); |
324 | 330 |
325 url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(ur l); | 331 url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(ur l); |
326 int debugOverrideValue = NO_OVERRIDE; | 332 int debugOverrideValue = NO_OVERRIDE; |
327 if (extras != null) debugOverrideValue = extras.getInt(DEBUG_OVERRIDE_KE Y, NO_OVERRIDE); | 333 if (extras != null) debugOverrideValue = extras.getInt(DEBUG_OVERRIDE_KE Y, NO_OVERRIDE); |
328 | 334 |
329 boolean didStartPrerender = false, didStartPrefetch = false; | 335 boolean didStartSpeculation = false, didStartPrefetch = false; |
330 boolean mayPrerender = mayPrerender(session); | 336 boolean mayPrerender = mayPrerender(session); |
331 if (mayPrerender) { | 337 if (mayPrerender) { |
332 if (debugOverrideValue == PREFETCH_ONLY) { | 338 if (debugOverrideValue == PREFETCH_ONLY) { |
333 didStartPrefetch = new ResourcePrefetchPredictor(profile).startP refetching(url); | 339 didStartPrefetch = new ResourcePrefetchPredictor(profile).startP refetching(url); |
334 if (didStartPrefetch) mSpeculation = SpeculationParams.forPrefet ch(session, url); | 340 if (didStartPrefetch) mSpeculation = SpeculationParams.forPrefet ch(session, url); |
335 } else if (debugOverrideValue != NO_PRERENDERING) { | 341 } else if (debugOverrideValue != NO_PRERENDERING) { |
336 didStartPrerender = prerenderUrl(session, url, extras, uid); | 342 didStartSpeculation = startSpeculation(session, url, extras, uid ); |
337 } | 343 } |
338 } | 344 } |
339 preconnectUrls(otherLikelyBundles); | 345 preconnectUrls(otherLikelyBundles); |
340 if (!didStartPrefetch) warmupManager.maybePreconnectUrlAndSubResources(p rofile, url); | 346 if (!didStartPrefetch) warmupManager.maybePreconnectUrlAndSubResources(p rofile, url); |
341 if (!didStartPrerender) warmupManager.createSpareWebContents(); | 347 if (!didStartSpeculation) warmupManager.createSpareWebContents(); |
342 } | 348 } |
343 | 349 |
344 /** | 350 /** |
345 * Low confidence mayLaunchUrl() call, that is: | 351 * Low confidence mayLaunchUrl() call, that is: |
346 * - Preconnects to the ordered list of URLs. | 352 * - Preconnects to the ordered list of URLs. |
347 * - Makes sure that there is a spare renderer. | 353 * - Makes sure that there is a spare renderer. |
348 */ | 354 */ |
349 @VisibleForTesting | 355 @VisibleForTesting |
350 boolean lowConfidenceMayLaunchUrl(List<Bundle> likelyBundles) { | 356 boolean lowConfidenceMayLaunchUrl(List<Bundle> likelyBundles) { |
351 ThreadUtils.assertOnUiThread(); | 357 ThreadUtils.assertOnUiThread(); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 * @param url The URL the WebContents is for. | 586 * @param url The URL the WebContents is for. |
581 * @param referrer The referrer to use for |url|. | 587 * @param referrer The referrer to use for |url|. |
582 * @return The prerendered WebContents, or null. | 588 * @return The prerendered WebContents, or null. |
583 */ | 589 */ |
584 WebContents takePrerenderedUrl(CustomTabsSessionToken session, String url, S tring referrer) { | 590 WebContents takePrerenderedUrl(CustomTabsSessionToken session, String url, S tring referrer) { |
585 ThreadUtils.assertOnUiThread(); | 591 ThreadUtils.assertOnUiThread(); |
586 if (mSpeculation == null || session == null || !session.equals(mSpeculat ion.session)) { | 592 if (mSpeculation == null || session == null || !session.equals(mSpeculat ion.session)) { |
587 return null; | 593 return null; |
588 } | 594 } |
589 | 595 |
590 if (mSpeculation.prefetchOnly) { | 596 if (mSpeculation.speculationMode == SpeculationParams.PREFETCH) { |
Benoit L
2017/03/23 18:28:29
Basically the speculation is stopped in two differ
ahemery1
2017/03/27 12:27:31
You're absolutely right, missed it.
| |
591 Profile profile = Profile.getLastUsedProfile(); | 597 Profile profile = Profile.getLastUsedProfile(); |
592 new ResourcePrefetchPredictor(profile).stopPrefetching(mSpeculation. url); | 598 new ResourcePrefetchPredictor(profile).stopPrefetching(mSpeculation. url); |
593 mSpeculation = null; | 599 mSpeculation = null; |
594 return null; | 600 return null; |
595 } | 601 } |
596 | 602 |
597 WebContents webContents = mSpeculation.webContents; | 603 WebContents webContents = mSpeculation.webContents; |
598 String prerenderedUrl = mSpeculation.url; | 604 String prerenderedUrl = mSpeculation.url; |
599 String prerenderReferrer = mSpeculation.referrer; | 605 String prerenderReferrer = mSpeculation.referrer; |
600 if (referrer == null) referrer = ""; | 606 if (referrer == null) referrer = ""; |
601 boolean ignoreFragments = mClientManager.getIgnoreFragmentsForSession(se ssion); | 607 boolean ignoreFragments = mClientManager.getIgnoreFragmentsForSession(se ssion); |
602 boolean urlsMatch = TextUtils.equals(prerenderedUrl, url) | 608 boolean urlsMatch = TextUtils.equals(prerenderedUrl, url) |
603 || (ignoreFragments | 609 || (ignoreFragments |
604 && UrlUtilities.urlsMatchIgnoringFragments(prerenderedUr l, url)); | 610 && UrlUtilities.urlsMatchIgnoringFragments(prerenderedUr l, url)); |
605 WebContents result = null; | 611 WebContents result = null; |
606 if (urlsMatch && TextUtils.equals(prerenderReferrer, referrer)) { | 612 if (urlsMatch && TextUtils.equals(prerenderReferrer, referrer)) { |
607 result = webContents; | 613 result = webContents; |
608 mSpeculation = null; | 614 mSpeculation = null; |
609 } else { | 615 } else { |
610 cancelPrerender(session); | 616 cancelSpeculation(session); |
611 } | 617 } |
612 if (!mClientManager.usesDefaultSessionParameters(session) && webContents != null) { | 618 if (!mClientManager.usesDefaultSessionParameters(session) && webContents != null) { |
613 RecordHistogram.recordBooleanHistogram( | 619 RecordHistogram.recordBooleanHistogram( |
614 "CustomTabs.NonDefaultSessionPrerenderMatched", result != nu ll); | 620 "CustomTabs.NonDefaultSessionPrerenderMatched", result != nu ll); |
615 } | 621 } |
616 | 622 |
617 return result; | 623 return result; |
618 } | 624 } |
619 | 625 |
620 /** Returns the URL prerendered for a session, or null. */ | 626 /** 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); | 671 mClientManager.setPrerenderCellularForSession(session, value); |
666 } | 672 } |
667 | 673 |
668 /** | 674 /** |
669 * See {@link ClientManager#setSendNavigationInfoForSession(CustomTabsSessio nToken, boolean)}. | 675 * See {@link ClientManager#setSendNavigationInfoForSession(CustomTabsSessio nToken, boolean)}. |
670 */ | 676 */ |
671 void setSendNavigationInfoForSession(CustomTabsSessionToken session, boolean send) { | 677 void setSendNavigationInfoForSession(CustomTabsSessionToken session, boolean send) { |
672 mClientManager.setSendNavigationInfoForSession(session, send); | 678 mClientManager.setSendNavigationInfoForSession(session, send); |
673 } | 679 } |
674 | 680 |
681 @VisibleForTesting | |
Benoit L
2017/03/23 18:28:29
This is not strictly true that this is VisibleForT
ahemery1
2017/03/27 12:27:32
Changed to public.
| |
682 void setSpeculationModeForSession(CustomTabsSessionToken session, int specul ationMode) { | |
683 mClientManager.setSpeculationModeForSession(session, speculationMode); | |
684 } | |
685 | |
686 public int getSpeculationModeForSession(CustomTabsSessionToken session) { | |
687 return mClientManager.getSpeculationModeForSession(session); | |
688 } | |
689 | |
675 /** | 690 /** |
676 * Extracts the creator package name from the intent. | 691 * Extracts the creator package name from the intent. |
677 * @param intent The intent to get the package name from. | 692 * @param intent The intent to get the package name from. |
678 * @return the package name which can be null. | 693 * @return the package name which can be null. |
679 */ | 694 */ |
680 String extractCreatorPackage(Intent intent) { | 695 String extractCreatorPackage(Intent intent) { |
681 return null; | 696 return null; |
682 } | 697 } |
683 | 698 |
684 /** | 699 /** |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
894 // tabs. Then PrivacyManager should be used to make the below check. | 909 // tabs. Then PrivacyManager should be used to make the below check. |
895 if (!PrefServiceBridge.getInstance().getNetworkPredictionEnabled()) retu rn false; | 910 if (!PrefServiceBridge.getInstance().getNetworkPredictionEnabled()) retu rn false; |
896 if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled ()) return false; | 911 if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled ()) return false; |
897 ConnectivityManager cm = | 912 ConnectivityManager cm = |
898 (ConnectivityManager) mApplication.getApplicationContext().getSy stemService( | 913 (ConnectivityManager) mApplication.getApplicationContext().getSy stemService( |
899 Context.CONNECTIVITY_SERVICE); | 914 Context.CONNECTIVITY_SERVICE); |
900 return !cm.isActiveNetworkMetered() || shouldPrerenderOnCellularForSessi on(session); | 915 return !cm.isActiveNetworkMetered() || shouldPrerenderOnCellularForSessi on(session); |
901 } | 916 } |
902 | 917 |
903 /** Cancels a prerender for a given session, or any session if null. */ | 918 /** Cancels a prerender for a given session, or any session if null. */ |
904 void cancelPrerender(CustomTabsSessionToken session) { | 919 @VisibleForTesting |
905 ThreadUtils.assertOnUiThread(); | 920 void cancelSpeculation(CustomTabsSessionToken session) { |
Benoit L
2017/03/23 18:28:28
nit: Please keep the assertOnUiThread() here.
ahemery1
2017/03/27 12:27:31
Moved from subfunction to here.
| |
906 if (mSpeculation != null && (session == null || session.equals(mSpeculat ion.session)) | 921 if (mSpeculation == null) return; |
Benoit L
2017/03/23 18:28:29
nit: Why breaking up the condition here?
ahemery1
2017/03/27 12:27:31
Felt like it had two different functions. First li
| |
907 && mSpeculation.webContents != null) { | 922 if (session != null && !session.equals(mSpeculation.session)) return; |
Benoit L
2017/03/23 18:28:29
tiny nit: This reads a bit weird, what about:
if
ahemery1
2017/03/27 12:27:31
Done.
| |
908 mExternalPrerenderHandler.cancelCurrentPrerender(); | 923 switch (mSpeculation.speculationMode) { |
909 mSpeculation.webContents.destroy(); | 924 case SpeculationParams.PRERENDER: |
910 mSpeculation = null; | 925 cancelPrerender(session); |
926 break; | |
927 default: | |
928 return; | |
911 } | 929 } |
912 } | 930 } |
913 | 931 |
932 private void cancelPrerender(CustomTabsSessionToken session) { | |
933 ThreadUtils.assertOnUiThread(); | |
934 if (mSpeculation.webContents == null) return; | |
935 mExternalPrerenderHandler.cancelCurrentPrerender(); | |
936 mSpeculation.webContents.destroy(); | |
937 mSpeculation = null; | |
Benoit L
2017/03/23 18:28:29
All current paths will set mSpeculation to null, c
ahemery1
2017/03/27 12:27:31
Done.
| |
938 } | |
939 | |
940 @VisibleForTesting | |
941 boolean startSpeculation(CustomTabsSessionToken session, String url, Bundle extras, int uid) { | |
942 switch (getSpeculationModeForSession(session)) { | |
Benoit L
2017/03/23 18:28:29
ditto, why isn't prefetch handled here as well?
ahemery1
2017/03/27 12:27:31
I included prefetch in the same process, but doing
| |
943 case SpeculationParams.PRERENDER: | |
944 return prerenderUrl(session, url, extras, uid); | |
945 default: | |
946 return false; | |
947 } | |
948 } | |
949 | |
914 /** | 950 /** |
915 * Tries to request a prerender for a given URL. | 951 * Tries to request a prerender for a given URL. |
916 * | 952 * |
917 * @param session Session the request comes from. | 953 * @param session Session the request comes from. |
918 * @param url URL to prerender. | 954 * @param url URL to prerender. |
919 * @param extras extra parameters. | 955 * @param extras extra parameters. |
920 * @param uid UID of the caller. | 956 * @param uid UID of the caller. |
921 * @return true if a prerender has been initiated. | 957 * @return true if a prerender has been initiated. |
922 */ | 958 */ |
923 private boolean prerenderUrl( | 959 private boolean prerenderUrl( |
924 CustomTabsSessionToken session, String url, Bundle extras, int uid) { | 960 CustomTabsSessionToken session, String url, Bundle extras, int uid) { |
925 ThreadUtils.assertOnUiThread(); | 961 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; | 962 if (!mWarmupHasBeenCalled.get()) return false; |
929 // Last one wins and cancels the previous prerender. | 963 |
930 cancelPrerender(null); | |
931 if (TextUtils.isEmpty(url)) return false; | |
Benoit L
2017/03/23 18:28:28
Was this check redundant?
ahemery1
2017/03/27 12:27:31
It was indeed redundant. Already checked in highCo
| |
932 boolean throttle = !shouldPrerenderOnCellularForSession(session); | 964 boolean throttle = !shouldPrerenderOnCellularForSession(session); |
933 if (throttle && !mClientManager.isPrerenderingAllowed(uid)) return false ; | 965 if (throttle && !mClientManager.isPrerenderingAllowed(uid)) return false ; |
934 | 966 |
935 // A prerender will be requested. Time to destroy the spare WebContents. | 967 // A prerender will be requested. Time to destroy the spare WebContents. |
936 WarmupManager.getInstance().destroySpareWebContents(); | 968 WarmupManager.getInstance().destroySpareWebContents(); |
937 | 969 |
938 Intent extrasIntent = new Intent(); | 970 Intent extrasIntent = new Intent(); |
939 if (extras != null) extrasIntent.putExtras(extras); | 971 if (extras != null) extrasIntent.putExtras(extras); |
940 if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null) retur n false; | 972 if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null) retur n false; |
941 if (mExternalPrerenderHandler == null) { | 973 if (mExternalPrerenderHandler == null) { |
942 mExternalPrerenderHandler = new ExternalPrerenderHandler(); | 974 mExternalPrerenderHandler = new ExternalPrerenderHandler(); |
943 } | 975 } |
944 Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mAppli cation, true); | 976 Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mAppli cation, true); |
945 String referrer = IntentHandler.getReferrerUrlIncludingExtraHeaders(extr asIntent); | 977 String referrer = IntentHandler.getReferrerUrlIncludingExtraHeaders(extr asIntent); |
946 if (referrer == null && getReferrerForSession(session) != null) { | 978 if (referrer == null && getReferrerForSession(session) != null) { |
947 referrer = getReferrerForSession(session).getUrl(); | 979 referrer = getReferrerForSession(session).getUrl(); |
948 } | 980 } |
949 if (referrer == null) referrer = ""; | 981 if (referrer == null) referrer = ""; |
950 Pair<WebContents, WebContents> webContentsPair = mExternalPrerenderHandl er.addPrerender( | 982 Pair<WebContents, WebContents> webContentsPair = |
951 Profile.getLastUsedProfile(), url, referrer, | 983 mExternalPrerenderHandler.addPrerender(Profile.getLastUsedProfil e(), url, referrer, |
952 contentBounds, | 984 contentBounds, shouldPrerenderOnCellularForSession(sessi on)); |
953 shouldPrerenderOnCellularForSession(session)); | |
954 if (webContentsPair == null) return false; | 985 if (webContentsPair == null) return false; |
955 WebContents dummyWebContents = webContentsPair.first; | 986 WebContents dummyWebContents = webContentsPair.first; |
956 if (webContentsPair.second != null) { | 987 if (webContentsPair.second != null) { |
957 mClientManager.resetPostMessageHandlerForSession(session, webContent sPair.second); | 988 mClientManager.resetPostMessageHandlerForSession(session, webContent sPair.second); |
958 } | 989 } |
959 if (throttle) mClientManager.registerPrerenderRequest(uid, url); | 990 if (throttle) mClientManager.registerPrerenderRequest(uid, url); |
960 mSpeculation = SpeculationParams.forPrerender( | 991 mSpeculation = |
961 session, url, dummyWebContents, referrer, extras); | 992 SpeculationParams.forPrerender(session, url, dummyWebContents, r eferrer, extras); |
962 | 993 |
963 RecordHistogram.recordBooleanHistogram("CustomTabs.PrerenderSessionUsesD efaultParameters", | 994 RecordHistogram.recordBooleanHistogram("CustomTabs.PrerenderSessionUsesD efaultParameters", |
964 mClientManager.usesDefaultSessionParameters(session)); | 995 mClientManager.usesDefaultSessionParameters(session)); |
965 | 996 |
966 return true; | 997 return true; |
967 } | 998 } |
968 | 999 |
969 @VisibleForTesting | 1000 @VisibleForTesting |
970 void resetThrottling(Context context, int uid) { | 1001 void resetThrottling(Context context, int uid) { |
971 mClientManager.resetThrottling(uid); | 1002 mClientManager.resetThrottling(uid); |
972 } | 1003 } |
973 | 1004 |
974 @VisibleForTesting | 1005 @VisibleForTesting |
975 void ban(Context context, int uid) { | 1006 void ban(Context context, int uid) { |
976 mClientManager.ban(uid); | 1007 mClientManager.ban(uid); |
977 } | 1008 } |
978 | 1009 |
979 @VisibleForTesting | 1010 @VisibleForTesting |
980 void setForcePrerender(boolean force) { | 1011 void setForcePrerender(boolean force) { |
981 mForcePrerenderForTesting = force; | 1012 mForcePrerenderForTesting = force; |
982 } | 1013 } |
983 } | 1014 } |
OLD | NEW |