Commit b583dea0 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

[Android] Do not close chrome automatically if homepage is set to NTP

When the homepage is enabled, Chrome is automatically closed when
closing the last tab.  This ensures the homepage is shown when the
user next uses Chrome.  When the homepage is set to the NTP, this
does not make sense as the homepage is the primary surface that you
can actually open from the empty state.

BUG=466410

Change-Id: Ib3f0c1c14840220088214c7dd97a96273cf4a26e
Reviewed-on: https://chromium-review.googlesource.com/1010885Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550412}
parent 6010b023
......@@ -476,7 +476,7 @@ public class ChromeTabbedActivity
private void closeIfNoTabsAndHomepageEnabled(boolean isPendingClosure) {
if (getTabModelSelector().getTotalTabCount() == 0) {
// If the last tab is closed, and homepage is enabled, then exit Chrome.
if (HomepageManager.isHomepageEnabled()) {
if (HomepageManager.shouldCloseAppWithZeroTabs()) {
finish();
} else if (isPendingClosure) {
NewTabPageUma.recordNTPImpression(
......
......@@ -634,7 +634,7 @@ public abstract class StackLayoutBase
public void uiDoneClosingTab(long time, int id, boolean canUndo, boolean incognito) {
// If homepage is enabled and there is a maximum of 1 tab in both models
// (this is the last tab), the tab closure cannot be undone.
canUndo &= !(HomepageManager.isHomepageEnabled()
canUndo &= !(HomepageManager.shouldCloseAppWithZeroTabs()
&& (mTabModelSelector.getModel(true).getCount()
+ mTabModelSelector.getModel(false).getCount()
< 2));
......
......@@ -11,6 +11,7 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.ObserverList;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.util.FeatureUtilities;
/**
......@@ -89,6 +90,14 @@ public class HomepageManager {
return false;
}
/**
* @return Whether to close the app when the user has zero tabs.
*/
public static boolean shouldCloseAppWithZeroTabs() {
return HomepageManager.isHomepageEnabled()
&& !NewTabPage.isNTPUrl(HomepageManager.getHomepageUri());
}
/**
* @return Whether or not homepage setting should be shown.
*/
......
......@@ -390,7 +390,7 @@ public class TabModelImpl extends TabModelJniBridge {
if (allowDelegation && mModelDelegate.closeAllTabsRequest(isIncognito())) return;
if (HomepageManager.isHomepageEnabled()) {
if (HomepageManager.shouldCloseAppWithZeroTabs()) {
commitAllTabClosures();
for (int i = 0; i < getCount(); i++) getTabAt(i).setClosing(true);
......
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