Commit 1077f992 authored by Xi Han's avatar Xi Han Committed by Commit Bot

[Instant Start] Show grid tab switcher pre-native.

In this CL, an overview page is shown when the feature flags
InstantStart and tab switcher are turned on. The changes of this CL
are behind the flag of InstantStart.

The grid tab switcher overview page can be shown with the following
commandline flags:
--enable-features="TabSwitcherOnReturn<Study,
InstantStart,StartSurfaceAndroid" --force-fieldtrials=Study/Group
--force-fieldtrial-params=Study.Group:tab_switcher_on_return_time_ms/0

"--disable-native-initialization" which stops native library
loading is optional. It helps to test pre-native startup behaviour.

Bug: 1061906
Change-Id: I1898d9602c1ab54dc76d55190a1368e14c1d9e44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144356Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Xi Han <hanxi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#761082}
parent 046e3b83
......@@ -9,6 +9,8 @@ import androidx.annotation.Nullable;
import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.tasks.TasksSurface;
import org.chromium.chrome.browser.tasks.TasksSurfaceProperties;
import org.chromium.chrome.browser.tasks.tab_management.TabManagementDelegate.TabSwitcherType;
......@@ -176,6 +178,12 @@ public class StartSurfaceCoordinator implements StartSurface {
return SurfaceMode.NO_START_SURFACE;
}
// TODO(hanxi): Removes this check once other variations of start surface don't crash when
// the feature flag {@link ChromeFeatureList.INSTANT_START} is true.
if (CachedFeatureFlags.isEnabled(ChromeFeatureList.INSTANT_START)) {
return SurfaceMode.OMNIBOX_ONLY;
}
String feature = StartSurfaceConfiguration.START_SURFACE_VARIATION.getValue();
if (feature.equals("twopanes")) {
......
......@@ -196,8 +196,8 @@ public class InstantStartTest {
@SmallTest
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
// clang-format off
@EnableFeatures({ChromeFeatureList.TAB_SWITCHER_ON_RETURN + "<Study"})
@CommandLineFlags.Add({ChromeSwitches.DISABLE_NATIVE_INITIALIZATION,
"enable-features=" + ChromeFeatureList.TAB_SWITCHER_ON_RETURN + "<Study",
"force-fieldtrials=Study/Group", IMMEDIATE_RETURN_PARAMS})
public void layoutManagerChromePhonePreNativeTest() {
// clang-format on
......
......@@ -19,6 +19,7 @@ import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.DoubleCachedFieldTrialParameter;
import org.chromium.chrome.browser.flags.IntCachedFieldTrialParameter;
import org.chromium.chrome.browser.flags.StringCachedFieldTrialParameter;
import org.chromium.chrome.browser.tasks.ReturnToChromeExperimentsUtil;
import org.chromium.chrome.features.start_surface.StartSurfaceConfiguration;
import org.chromium.ui.base.DeviceFormFactor;
......@@ -168,4 +169,23 @@ public class TabUiFeatureUtilities {
&& SysUtils.amountOfPhysicalMemoryKB() / 1024 >= ZOOMING_MIN_MEMORY.getValue()
&& !StartSurfaceConfiguration.isStartSurfaceSinglePaneEnabled();
}
/**
* @return Whether the instant start is supported.
*/
public static boolean supportInstantStart(boolean isTablet) {
return CachedFeatureFlags.isEnabled(ChromeFeatureList.INSTANT_START) && !isTablet;
}
/**
* @return Whether the start surface is allowed running in the instant start mode.
*/
public static boolean supportStartSurfaceInInstantStart(
boolean isTablet, final long lastBackgroundedTimeMillis) {
// TODO(hanxi): Uses shouldShowTabSwitcherOnStart() instead of
// ReturnToChromeExperimentsUtil.shouldShowTabSwitcher() once the NewTabPage.isNTPUrl()
// works in pre-native.
return supportInstantStart(isTablet)
&& ReturnToChromeExperimentsUtil.shouldShowTabSwitcher(lastBackgroundedTimeMillis);
}
}
......@@ -22,18 +22,23 @@ public class ChromeInactivityTracker
private static final long UNKNOWN_LAST_BACKGROUNDED_TIME = -1;
private final String mPrefName;
private final ActivityLifecycleDispatcher mLifecycleDispatcher;
private ActivityLifecycleDispatcher mLifecycleDispatcher;
/**
* Creates an inactivity tracker without a timeout callback. This is useful if clients only
* want to query the inactivity state manually.
* @param prefName the location in shared preferences that the timestamp is stored.
*/
public ChromeInactivityTracker(String prefName) {
mPrefName = prefName;
}
/**
* Registers to the given lifecycle dispatcher.
* @param lifecycleDispatcher tracks the lifecycle of the Activity of interest, and calls
* observer methods on ChromeInactivityTracker.
*/
public ChromeInactivityTracker(
String prefName, ActivityLifecycleDispatcher lifecycleDispatcher) {
mPrefName = prefName;
public void register(ActivityLifecycleDispatcher lifecycleDispatcher) {
mLifecycleDispatcher = lifecycleDispatcher;
mLifecycleDispatcher.register(this);
}
......
......@@ -77,7 +77,6 @@ import org.chromium.chrome.browser.download.DownloadUtils;
import org.chromium.chrome.browser.feed.FeedProcessScopeFactory;
import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
......@@ -971,7 +970,11 @@ public class ChromeTabbedActivity
// Don't call setInitialOverviewState if we're waiting for the tab's creation or we risk
// showing a glimpse of the tab selector during start up.
if (!mPendingInitialTabCreation) setInitialOverviewState();
if (!mPendingInitialTabCreation
&& !TabUiFeatureUtilities.supportStartSurfaceInInstantStart(
isTablet(), mInactivityTracker.getLastBackgroundedTimeMs())) {
setInitialOverviewState();
}
resetSavedInstanceState();
}
......@@ -1146,9 +1149,7 @@ public class ChromeTabbedActivity
mTabModelSelectorImpl.loadState(ignoreIncognitoFiles);
}
mInactivityTracker = new ChromeInactivityTracker(
ChromePreferenceKeys.TABBED_ACTIVITY_LAST_BACKGROUNDED_TIME_MS_PREF,
this.getLifecycleDispatcher());
mInactivityTracker.register(this.getLifecycleDispatcher());
mIntentWithEffect = false;
if (getSavedInstanceState() == null && intent != null) {
if (!mIntentHandler.shouldIgnoreIntent(intent)) {
......@@ -1227,7 +1228,11 @@ public class ChromeTabbedActivity
// If we didn't call setInitialOverviewState() in startWithNative() because
// mPendingInitialTabCreation was true then do so now.
if (hasStartWithNativeBeenCalled()) setInitialOverviewState();
if (hasStartWithNativeBeenCalled()
&& !TabUiFeatureUtilities.supportStartSurfaceInInstantStart(
isTablet(), mInactivityTracker.getLastBackgroundedTimeMs())) {
setInitialOverviewState();
}
}
@Override
......@@ -1563,10 +1568,13 @@ public class ChromeTabbedActivity
mUndoBarPopupController =
new UndoBarController(this, mTabModelSelectorImpl, this::getSnackbarManager);
mInactivityTracker = new ChromeInactivityTracker(
ChromePreferenceKeys.TABBED_ACTIVITY_LAST_BACKGROUNDED_TIME_MS_PREF);
// When the feature flag {@link ChromeFeatureList.INSTANT_START} turns on phones (not
// tablet), a view-only start page created on Java will be shown before native is
// initialized.
if (CachedFeatureFlags.isEnabled(ChromeFeatureList.INSTANT_START) && !isTablet()) {
if (TabUiFeatureUtilities.supportInstantStart(isTablet())) {
prepareToShowStartPagePreNative();
}
}
......@@ -1576,10 +1584,18 @@ public class ChromeTabbedActivity
* an LayoutManagerChrome object, add overview mode observer and so on.
*/
private void prepareToShowStartPagePreNative() {
setupCompositorContentPreNativeForPhone();
getCompositorViewHolder().setLayoutManager(mLayoutManager);
mLayoutManager.setTabModelSelector(mTabModelSelectorImpl);
addOverviewModeObserverPreNative();
try (TraceEvent e =
TraceEvent.scoped("ChromeTabbedActivity.prepareToShowStartPagePreNative")) {
setupCompositorContentPreNativeForPhone();
getCompositorViewHolder().setLayoutManager(mLayoutManager);
mLayoutManager.setTabModelSelector(mTabModelSelectorImpl);
addOverviewModeObserverPreNative();
if (TabUiFeatureUtilities.supportStartSurfaceInInstantStart(
isTablet(), mInactivityTracker.getLastBackgroundedTimeMs())) {
setInitialOverviewState();
}
}
}
@Override
......
......@@ -38,12 +38,11 @@ import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.LaunchIntentDispatcher;
import org.chromium.chrome.browser.WarmupManager;
import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.multiwindow.MultiWindowModeStateDispatcher;
import org.chromium.chrome.browser.multiwindow.MultiWindowModeStateDispatcherImpl;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.base.WindowAndroid;
......@@ -156,7 +155,7 @@ public abstract class AsyncInitializationActivity extends ChromeBaseAppCompatAct
@Override
public final void setContentViewAndLoadLibrary(Runnable onInflationCompleteCallback) {
boolean enableInstantStart = CachedFeatureFlags.isEnabled(ChromeFeatureList.INSTANT_START);
boolean enableInstantStart = TabUiFeatureUtilities.supportInstantStart(isTablet());
mOnInflationCompleteCallback = onInflationCompleteCallback;
if (enableInstantStart) {
triggerLayoutInflation();
......
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