Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1382)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java

Issue 2919433005: customtabs: Don't always destroy the spare WebContents before prerender. (Closed)
Patch Set: Add a test/ Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
index e956f15e993554de848da6485ceea32ff6d9ec4e..0caac7e5c9188b3a15bcb983f685df6eb3c95b96 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
@@ -29,7 +29,6 @@ import android.widget.RemoteViews;
import org.chromium.base.CommandLine;
import org.chromium.base.Log;
-import org.chromium.base.SysUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.TimeUtils;
import org.chromium.base.TraceEvent;
@@ -287,8 +286,7 @@ public class CustomTabsConnection {
if (!initialized) initializeBrowser(mApplication);
// (2)
- if (mayCreateSpareWebContents && mSpeculation == null
- && !SysUtils.isLowEndDevice()) {
+ if (mayCreateSpareWebContents && mSpeculation == null) {
WarmupManager.getInstance().createSpareWebContents();
}
@@ -626,9 +624,12 @@ public class CustomTabsConnection {
"CustomTabs.NonDefaultSessionPrerenderMatched", result != null);
}
+ // Since the prerender is used, discard the spare webcontents.
+ if (result != null) WarmupManager.getInstance().destroySpareWebContents();
return result;
}
+ @VisibleForTesting
String getSpeculatedUrl(CustomTabsSessionToken session) {
if (mSpeculation == null || session == null || !session.equals(mSpeculation.session)) {
return null;
@@ -1040,9 +1041,6 @@ public class CustomTabsConnection {
boolean throttle = !shouldPrerenderOnCellularForSession(session);
if (throttle && !mClientManager.isPrerenderingAllowed(uid)) return false;
- // A prerender will be requested. Time to destroy the spare WebContents.
- WarmupManager.getInstance().destroySpareWebContents();
-
Intent extrasIntent = new Intent();
if (extras != null) extrasIntent.putExtras(extras);
if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null) return false;
@@ -1052,9 +1050,9 @@ public class CustomTabsConnection {
Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mApplication, true);
String referrer = getReferrer(session, extrasIntent);
- Pair<WebContents, WebContents> webContentsPair =
- mExternalPrerenderHandler.addPrerender(Profile.getLastUsedProfile(), url, referrer,
- contentBounds, shouldPrerenderOnCellularForSession(session));
+ boolean forced = shouldPrerenderOnCellularForSession(session);
+ Pair<WebContents, WebContents> webContentsPair = mExternalPrerenderHandler.addPrerender(
+ Profile.getLastUsedProfile(), url, referrer, contentBounds, forced);
if (webContentsPair == null) return false;
WebContents dummyWebContents = webContentsPair.first;
if (webContentsPair.second != null) {
@@ -1067,6 +1065,9 @@ public class CustomTabsConnection {
RecordHistogram.recordBooleanHistogram("CustomTabs.PrerenderSessionUsesDefaultParameters",
mClientManager.usesDefaultSessionParameters(session));
+ // Forced prerenders are often discarded, and take a small amount of memory. In this case,
+ // don't kill the spare renderer as it's highly likely to be used later.
+ if (!forced) WarmupManager.getInstance().destroySpareWebContents();
return true;
}
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698