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

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

Issue 2199393002: Android: Make the spare renderer accessible to all Chrome tabs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 4 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/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.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/WarmupManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/WarmupManager.java b/chrome/android/java/src/org/chromium/chrome/browser/WarmupManager.java
index 1ed116eb2b8235e193a87867445b20610e01cfb5..3f4d6994c884318d725fc9a15a3758741a7bb5fb 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/WarmupManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/WarmupManager.java
@@ -15,11 +15,13 @@ import android.view.ViewStub;
import android.widget.FrameLayout;
import org.chromium.base.Log;
+import org.chromium.base.SysUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.TraceEvent;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.content_public.browser.WebContents;
import java.net.InetAddress;
import java.net.MalformedURLException;
@@ -46,6 +48,7 @@ public final class WarmupManager {
private int mToolbarContainerId;
private ViewGroup mMainView;
+ private WebContents mSpareWebContents;
/**
* @return The singleton instance for the WarmupManager, creating one if necessary.
@@ -192,5 +195,50 @@ public final class WarmupManager {
}
}
+ /**
+ * Creates and initializes a spare WebContents, to be used in a subsequent navigation.
+ *
+ * This creates a renderer that is suitable for any navigation. It can be picked up by any tab.
+ * Can be called multiple times, and must be called from the UI thread.
+ * Note that this is a no-op on low-end devices.
+ */
+ public void createSpareWebContents() {
+ ThreadUtils.assertOnUiThread();
+ if (mSpareWebContents != null || SysUtils.isLowEndDevice()) return;
+ mSpareWebContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
+ }
+
+ /**
+ * Destroys the spare WebContents if there is one.
+ */
+ public void destroySpareWebContents() {
+ ThreadUtils.assertOnUiThread();
+ if (mSpareWebContents == null) return;
+ mSpareWebContents.destroy();
+ mSpareWebContents = null;
+ }
+
+ /**
+ * Returns a spare WebContents or null, depending on the availability of one.
+ *
+ * The parameters are the same as for {@link WebContentsFactory#createWebContents()}.
+ *
+ * @return a WebContents, or null.
+ */
+ public WebContents takeSpareWebContents(boolean incognito, boolean initiallyHidden) {
+ ThreadUtils.assertOnUiThread();
+ if (incognito || initiallyHidden) return null;
+ WebContents result = mSpareWebContents;
+ mSpareWebContents = null;
+ return result;
+ }
+
+ /**
+ * @return Whether a spare renderer is available.
+ */
+ public boolean hasSpareWebContents() {
+ return mSpareWebContents != null;
+ }
+
private static native void nativePreconnectUrlAndSubresources(Profile profile, String url);
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698