Commit 5238f251 authored by lizeb's avatar lizeb Committed by Commit bot

customtabs: Re-Create a spare renderer on Tab close.

In a lot of cases, several Custom Tabs are created in a sequence,
without the embedding application calling warmup() in between
launches. This means that spare renderer is only available the first
time.

This changes re-creates a spare renderer once the Custom Tab is closed.

BUG=617214

Review-Url: https://chromiumcodereview.appspot.com/2431833002
Cr-Commit-Position: refs/heads/master@{#426552}
parent 0ed6c761
...@@ -157,7 +157,7 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -157,7 +157,7 @@ public class CustomTabActivity extends ChromeActivity {
public void didCloseTab(int tabId, boolean incognito) { public void didCloseTab(int tabId, boolean incognito) {
PageLoadMetrics.removeObserver(mMetricsObserver); PageLoadMetrics.removeObserver(mMetricsObserver);
// Finish the activity after we intent out. // Finish the activity after we intent out.
if (getTabModelSelector().getCurrentModel().getCount() == 0) finish(); if (getTabModelSelector().getCurrentModel().getCount() == 0) finishAndClose(false);
} }
}; };
...@@ -363,7 +363,7 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -363,7 +363,7 @@ public class CustomTabActivity extends ChromeActivity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
RecordUserAction.record("CustomTabs.CloseButtonClicked"); RecordUserAction.record("CustomTabs.CloseButtonClicked");
finishAndClose(); finishAndClose(false);
} }
}); });
...@@ -644,9 +644,25 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -644,9 +644,25 @@ public class CustomTabActivity extends ChromeActivity {
/** /**
* Finishes the activity and removes the reference from the Android recents. * Finishes the activity and removes the reference from the Android recents.
*
* @param reparenting true iff the activity finishes due to tab reparenting.
*/ */
public final void finishAndClose() { public final void finishAndClose(boolean reparenting) {
mIsClosing = true; mIsClosing = true;
if (!reparenting) {
// Closing the activity destroys the renderer as well. Re-create a spare renderer some
// time after, so that we have one ready for the next tab open. This does not increase
// memory consumption, as the current renderer goes away. We create a renderer as a lot
// of users open several Custom Tabs in a row. The delay is there to avoid jank in the
// transition animation when closing the tab.
ThreadUtils.postOnUiThreadDelayed(new Runnable() {
@Override
public void run() {
WarmupManager.getInstance().createSpareWebContents();
}
}, 500);
}
handleFinishAndClose(); handleFinishAndClose();
} }
...@@ -671,7 +687,7 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -671,7 +687,7 @@ public class CustomTabActivity extends ChromeActivity {
if (getCurrentTabModel().getCount() > 1) { if (getCurrentTabModel().getCount() > 1) {
getCurrentTabModel().closeTab(getActivityTab(), false, false, false); getCurrentTabModel().closeTab(getActivityTab(), false, false, false);
} else { } else {
finishAndClose(); finishAndClose(false);
} }
} }
return true; return true;
...@@ -823,7 +839,7 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -823,7 +839,7 @@ public class CustomTabActivity extends ChromeActivity {
Runnable finalizeCallback = new Runnable() { Runnable finalizeCallback = new Runnable() {
@Override @Override
public void run() { public void run() {
finishAndClose(); finishAndClose(true);
} }
}; };
......
...@@ -54,6 +54,7 @@ import org.chromium.chrome.browser.ChromeSwitches; ...@@ -54,6 +54,7 @@ import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ChromeTabbedActivity; import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.IntentHandler; import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.TabsOpenedFromExternalAppTest; import org.chromium.chrome.browser.TabsOpenedFromExternalAppTest;
import org.chromium.chrome.browser.WarmupManager;
import org.chromium.chrome.browser.appmenu.AppMenuHandler; import org.chromium.chrome.browser.appmenu.AppMenuHandler;
import org.chromium.chrome.browser.document.ChromeLauncherActivity; import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.metrics.PageLoadMetrics; import org.chromium.chrome.browser.metrics.PageLoadMetrics;
...@@ -1146,6 +1147,35 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { ...@@ -1146,6 +1147,35 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
}); });
} }
@SmallTest
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testRecreateSpareRendererOnTabClose() throws Exception {
Context context = getInstrumentation().getTargetContext().getApplicationContext();
warmUpAndWait();
try {
startCustomTabActivityWithIntent(
CustomTabsTestUtils.createMinimalCustomTabIntent(context, mTestPage));
} catch (InterruptedException e) {
fail();
}
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
assertFalse(WarmupManager.getInstance().hasSpareWebContents());
final CustomTabActivity activity = (CustomTabActivity) getActivity();
activity.finishAndClose(false);
}
});
CriteriaHelper.pollUiThread(new Criteria("No new spare renderer") {
@Override
public boolean isSatisfied() {
return WarmupManager.getInstance().hasSpareWebContents();
}
}, 2000, 200);
}
/** /**
* Tests that prerendering accepts a referrer, and that this is not lost when launching the * Tests that prerendering accepts a referrer, and that this is not lost when launching the
* Custom Tab. * Custom Tab.
......
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