Commit e2deb497 authored by Matthew Cary's avatar Matthew Cary Committed by Commit Bot

Custom Tabs: (reland) permanently disable prerender from custom tabs.

Removes the ability to set a prerender speculation mode for custom tabs,
making the background (hidden) tab the only option. Where appropriate,
method names mentioning "prerender" have been changed to generically
refer to "speculation". In one case shims for
shouldPrerenderOnCellularForSession, etc, have been left in so that
downstream code can be changed in a future CL.

This is a reland of the CL after a downstream patch that allow removing
the constants in SpeculationParams.

TBR: lizeb@chromium.org,pasko@chromium.org,bauerb@chromium.org,gayane@chromium.org
Bug: 755921,710720, 828968
Change-Id: I9a8002d1f0b8c2513d32469d2d7c4ed787912cb4
Reviewed-on: https://chromium-review.googlesource.com/998100
Commit-Queue: Matthew Cary <mattcary@chromium.org>
Reviewed-by: default avatarMatthew Cary <mattcary@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550116}
parent 1f5e2685
...@@ -140,13 +140,13 @@ class ClientManager { ...@@ -140,13 +140,13 @@ class ClientManager {
public boolean highConfidencePrediction; public boolean highConfidencePrediction;
private String mPackageName; private String mPackageName;
private boolean mShouldHideDomain; private boolean mShouldHideDomain;
private boolean mShouldPrerenderOnCellular; private boolean mShouldSpeculateLoadOnCellular;
private boolean mShouldSendNavigationInfo; private boolean mShouldSendNavigationInfo;
private boolean mShouldSendBottomBarScrollState; private boolean mShouldSendBottomBarScrollState;
private KeepAliveServiceConnection mKeepAliveConnection; private KeepAliveServiceConnection mKeepAliveConnection;
private String mPredictedUrl; private String mPredictedUrl;
private long mLastMayLaunchUrlTimestamp; private long mLastMayLaunchUrlTimestamp;
private int mSpeculationMode; private boolean mCanUseHiddenTab;
private boolean mAllowParallelRequest; private boolean mAllowParallelRequest;
public SessionParams(Context context, int uid, DisconnectCallback callback, public SessionParams(Context context, int uid, DisconnectCallback callback,
...@@ -156,7 +156,6 @@ class ClientManager { ...@@ -156,7 +156,6 @@ class ClientManager {
disconnectCallback = callback; disconnectCallback = callback;
this.postMessageHandler = postMessageHandler; this.postMessageHandler = postMessageHandler;
if (postMessageHandler != null) this.postMessageHandler.setPackageName(mPackageName); if (postMessageHandler != null) this.postMessageHandler.setPackageName(mPackageName);
this.mSpeculationMode = CustomTabsConnection.SpeculationParams.PRERENDER;
} }
/** /**
...@@ -219,7 +218,7 @@ class ClientManager { ...@@ -219,7 +218,7 @@ class ClientManager {
* @return Whether the default parameters are used for this session. * @return Whether the default parameters are used for this session.
*/ */
public boolean isDefault() { public boolean isDefault() {
return !mIgnoreFragments && !mShouldPrerenderOnCellular; return !mIgnoreFragments && !mShouldSpeculateLoadOnCellular;
} }
} }
...@@ -568,14 +567,14 @@ class ClientManager { ...@@ -568,14 +567,14 @@ class ClientManager {
} }
/** /**
* @return Whether the fragment should be ignored for prerender matching. * @return Whether the fragment should be ignored for speculation matching.
*/ */
public synchronized boolean getIgnoreFragmentsForSession(CustomTabsSessionToken session) { public synchronized boolean getIgnoreFragmentsForSession(CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session); SessionParams params = mSessionParams.get(session);
return params == null ? false : params.mIgnoreFragments; return params == null ? false : params.mIgnoreFragments;
} }
/** Sets whether the fragment should be ignored for prerender matching. */ /** Sets whether the fragment should be ignored for speculation matching. */
public synchronized void setIgnoreFragmentsForSession( public synchronized void setIgnoreFragmentsForSession(
CustomTabsSessionToken session, boolean value) { CustomTabsSessionToken session, boolean value) {
SessionParams params = mSessionParams.get(session); SessionParams params = mSessionParams.get(session);
...@@ -583,17 +582,17 @@ class ClientManager { ...@@ -583,17 +582,17 @@ class ClientManager {
} }
/** /**
* @return Whether prerender should be turned on for cellular networks for given session. * @return Whether load speculation should be turned on for cellular networks for given session.
*/ */
public synchronized boolean shouldPrerenderOnCellularForSession( public synchronized boolean shouldSpeculateLoadOnCellularForSession(
CustomTabsSessionToken session) { CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session); SessionParams params = mSessionParams.get(session);
return params != null ? params.mShouldPrerenderOnCellular : false; return params != null ? params.mShouldSpeculateLoadOnCellular : false;
} }
/** /**
* @return Whether the session is using the default parameters (that is, * @return Whether the session is using the default parameters (that is, don't ignore
* don't ignore fragments and don't prerender on cellular connections). * fragments and don't speculate loads on cellular connections).
*/ */
public synchronized boolean usesDefaultSessionParameters(CustomTabsSessionToken session) { public synchronized boolean usesDefaultSessionParameters(CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session); SessionParams params = mSessionParams.get(session);
...@@ -601,31 +600,47 @@ class ClientManager { ...@@ -601,31 +600,47 @@ class ClientManager {
} }
/** /**
* Sets whether prerender should be turned on for mobile networks for given session. * Sets whether speculation should be turned on for mobile networks for given session.
* If it is turned on, hidden tab speculation is turned on as well.
*/ */
public synchronized void setSpeculateLoadOnCellularForSession(
CustomTabsSessionToken session, boolean shouldSpeculate) {
SessionParams params = mSessionParams.get(session);
if (params != null) {
params.mShouldSpeculateLoadOnCellular = shouldSpeculate;
params.mCanUseHiddenTab = shouldSpeculate;
}
}
/** TODO(mattcary): remove when downstream uses are removed. **/
public synchronized void setPrerenderCellularForSession( public synchronized void setPrerenderCellularForSession(
CustomTabsSessionToken session, boolean prerender) { CustomTabsSessionToken session, boolean prerender) {
SessionParams params = mSessionParams.get(session); setSpeculateLoadOnCellularForSession(session, prerender);
if (params != null) params.mShouldPrerenderOnCellular = prerender; }
/** TODO(mattcary): remove when downstream uses are removed. **/
public synchronized void setSpeculationModeForSession(
CustomTabsSessionToken session, int mode) {
// No-op.
} }
/** /**
* Sets the speculation mode to be used by default for given session. * Sets whether hidden tab speculation can be used.
*/ */
public synchronized void setSpeculationModeForSession( public synchronized void setCanUseHiddenTab(
CustomTabsSessionToken session, int speculationMode) { CustomTabsSessionToken session, boolean canUseHiddenTab) {
SessionParams params = mSessionParams.get(session); SessionParams params = mSessionParams.get(session);
if (params != null) params.mSpeculationMode = speculationMode; if (params != null) {
params.mCanUseHiddenTab = canUseHiddenTab;
}
} }
/** /**
* Get the speculation mode to be used by default for the given session. * Get whether hidden tab speculation can be used. The default is false.
* If no value has been set will default to PRERENDER mode.
*/ */
public synchronized int getSpeculationModeForSession(CustomTabsSessionToken session) { public synchronized boolean getCanUseHiddenTab(CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session); SessionParams params = mSessionParams.get(session);
return params == null ? CustomTabsConnection.SpeculationParams.PRERENDER return params == null ? false : params.mCanUseHiddenTab;
: params.mSpeculationMode;
} }
public synchronized void setAllowParallelRequestForSession( public synchronized void setAllowParallelRequestForSession(
......
...@@ -138,14 +138,13 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -138,14 +138,13 @@ public class CustomTabActivity extends ChromeActivity {
private String mSpeculatedUrl; private String mSpeculatedUrl;
private boolean mUsingPrerender;
private boolean mUsingHiddenTab; private boolean mUsingHiddenTab;
private boolean mIsClosing; private boolean mIsClosing;
private boolean mIsKeepAlive; private boolean mIsKeepAlive;
// This boolean is used to do a hack in navigation history for // This boolean is used to do a hack in navigation history for hidden tab loads with
// prerender and hidden tab loads with unmatching fragments. // unmatching fragments.
private boolean mIsFirstLoad; private boolean mIsFirstLoad;
private final CustomTabsConnection mConnection = CustomTabsConnection.getInstance(); private final CustomTabsConnection mConnection = CustomTabsConnection.getInstance();
...@@ -401,8 +400,8 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -401,8 +400,8 @@ public class CustomTabActivity extends ChromeActivity {
public void finishNativeInitialization() { public void finishNativeInitialization() {
if (!mIntentDataProvider.isInfoPage()) FirstRunSignInProcessor.start(this); if (!mIntentDataProvider.isInfoPage()) FirstRunSignInProcessor.start(this);
// If extra headers have been passed, cancel any current prerender, as // If extra headers have been passed, cancel any current speculation, as
// prerendering doesn't support extra headers. // speculation doesn't support extra headers.
if (IntentHandler.getExtraHeadersFromIntent(getIntent()) != null) { if (IntentHandler.getExtraHeadersFromIntent(getIntent()) != null) {
mConnection.cancelSpeculation(mSession); mConnection.cancelSpeculation(mSession);
} }
...@@ -612,42 +611,30 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -612,42 +611,30 @@ public class CustomTabActivity extends ChromeActivity {
} }
private WebContents takeWebContents() { private WebContents takeWebContents() {
mUsingPrerender = true;
int webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS; int webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS;
WebContents webContents = takePrerenderedWebContents();
if (webContents == null) { WebContents webContents = takeAsyncWebContents();
mUsingPrerender = false; if (webContents != null) {
webContents = takeAsyncWebContents(); webContentsStateOnLaunch = WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS;
webContents.resumeLoadingCreatedWebContents();
} else {
webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
if (webContents != null) { if (webContents != null) {
webContentsStateOnLaunch = WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS; webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS;
webContents.resumeLoadingCreatedWebContents();
} else { } else {
webContents = WarmupManager.getInstance().takeSpareWebContents(false, false); webContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
if (webContents != null) { webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS;
webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS;
} else {
webContents =
WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS;
}
} }
} }
RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOnLaunch", RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOnLaunch",
webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX); webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX);
if (!mUsingPrerender) mConnection.resetPostMessageHandlerForSession(mSession, webContents); mConnection.resetPostMessageHandlerForSession(mSession, webContents);
return webContents; return webContents;
} }
private WebContents takePrerenderedWebContents() {
String url = getUrlToLoad();
String referrerUrl = mConnection.getReferrer(mSession, getIntent());
return mConnection.takePrerenderedUrl(mSession, url, referrerUrl);
}
private WebContents takeAsyncWebContents() { private WebContents takeAsyncWebContents() {
int assignedTabId = IntentUtils.safeGetIntExtra( int assignedTabId = IntentUtils.safeGetIntExtra(
getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID); getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
...@@ -774,11 +761,6 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -774,11 +761,6 @@ public class CustomTabActivity extends ChromeActivity {
// the wrong fragment. Does an extra pageload and replaces history. // the wrong fragment. Does an extra pageload and replaces history.
if (mHasSpeculated && isFirstLoad if (mHasSpeculated && isFirstLoad
&& UrlUtilities.urlsFragmentsDiffer(mSpeculatedUrl, url)) { && UrlUtilities.urlsFragmentsDiffer(mSpeculatedUrl, url)) {
if (mUsingPrerender) {
LoadUrlParams temporaryParams = new LoadUrlParams(mSpeculatedUrl);
IntentHandler.addReferrerAndHeaders(temporaryParams, intent);
tab.loadUrl(temporaryParams);
}
params.setShouldReplaceCurrentEntry(true); params.setShouldReplaceCurrentEntry(true);
} }
......
...@@ -13696,6 +13696,9 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -13696,6 +13696,9 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<histogram name="CustomTabs.NonDefaultSessionPrerenderMatched" <histogram name="CustomTabs.NonDefaultSessionPrerenderMatched"
enum="BooleanMatched"> enum="BooleanMatched">
<obsolete>
Deprecated 4/2018 when prerender was removed from Custom Tabs.
</obsolete>
<owner>lizeb@chromium.org</owner> <owner>lizeb@chromium.org</owner>
<summary> <summary>
Android: When there is a prerender for a session with non-default Android: When there is a prerender for a session with non-default
...@@ -13731,6 +13734,9 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -13731,6 +13734,9 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<histogram name="CustomTabs.PrerenderSessionUsesDefaultParameters" <histogram name="CustomTabs.PrerenderSessionUsesDefaultParameters"
enum="BooleanDefault"> enum="BooleanDefault">
<obsolete>
Deprecated 4/2018 when prerender was removed from Custom Tabs.
</obsolete>
<owner>lizeb@chromium.org</owner> <owner>lizeb@chromium.org</owner>
<summary> <summary>
Android: When prerendering a URL for Custom Tabs, whether the client session Android: When prerendering a URL for Custom Tabs, whether the client session
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