Commit ac7db509 authored by Mehran Mahmoudi's avatar Mehran Mahmoudi Committed by Commit Bot

[Paint Preview] Limit display on tab restoration to the first tab

This limits the number of times paint preview is displayed on tab
restoration to only 1 tab. This means that this will only happen for
the tab that is dispalyed right after Chrome startup.

Bug: 1064011
Change-Id: I4a95eaeccb63f62b38dd36521fa79eff952b09d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2264507Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarCalder Kitagawa <ckitagawa@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Auto-Submit: Mehran Mahmoudi <mahmoudi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782990}
parent 43f72917
......@@ -112,7 +112,6 @@ import org.chromium.chrome.browser.omaha.notification.UpdateNotificationControll
import org.chromium.chrome.browser.omaha.notification.UpdateNotificationControllerFactory;
import org.chromium.chrome.browser.page_info.ChromePageInfoControllerDelegate;
import org.chromium.chrome.browser.page_info.ChromePermissionParamsListBuilderDelegate;
import org.chromium.chrome.browser.paint_preview.PaintPreviewHelper;
import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomizations;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
......@@ -614,7 +613,6 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
mIncognitoTabCreator = tabCreators.second;
OfflinePageUtils.observeTabModelSelector(this, mTabModelSelector);
PaintPreviewHelper.observeTabModelSelector(this, mTabModelSelector);
if (mTabModelSelectorTabObserver != null) mTabModelSelectorTabObserver.destroy();
......
......@@ -110,6 +110,7 @@ import org.chromium.chrome.browser.ntp.NewTabPageUma;
import org.chromium.chrome.browser.ntp.cards.promo.HomepagePromoVariationManager;
import org.chromium.chrome.browser.omaha.OmahaBase;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.paint_preview.PaintPreviewHelper;
import org.chromium.chrome.browser.paint_preview.PaintPreviewTabHelper;
import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomizations;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
......@@ -1589,6 +1590,7 @@ public class ChromeTabbedActivity extends ChromeActivity<ChromeActivityComponent
mInactivityTracker = new ChromeInactivityTracker(
ChromePreferenceKeys.TABBED_ACTIVITY_LAST_BACKGROUNDED_TIME_MS_PREF);
PaintPreviewHelper.initialize(this, getTabModelSelector());
}
@Override
......
......@@ -18,14 +18,24 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector;
*/
public class PaintPreviewHelper {
/**
* Observes a {@link TabModelSelector} to monitor for initialization completion.
* Tracks whether there has been an attempt to display a paint preview before. We use this to
* only attempt to display a paint preview on the first tab restoration that happens after
* Chrome startup.
*/
private static boolean sHasAttemptedToShowOnRestore;
/**
* Initializes the logic required for the Paint Preview on startup feature. Mainly, observes a
* {@link TabModelSelector} to monitor for initialization completion.
* @param activity The ChromeActivity that corresponds to the tabModelSelector.
* @param tabModelSelector The TabModelSelector to observe.
*/
public static void observeTabModelSelector(
ChromeActivity activity, TabModelSelector tabModelSelector) {
public static void initialize(ChromeActivity activity, TabModelSelector tabModelSelector) {
if (!CachedFeatureFlags.isEnabled(ChromeFeatureList.PAINT_PREVIEW_SHOW_ON_STARTUP)) return;
if (!MultiWindowUtils.getInstance().areMultipleChromeInstancesRunning(activity)) {
sHasAttemptedToShowOnRestore = false;
}
// TODO(crbug/1074428): verify this doesn't cause a memory leak if the user exits Chrome
// prior to onTabStateInitialized being called.
tabModelSelector.addObserver(new EmptyTabModelSelectorObserver() {
......@@ -43,7 +53,7 @@ public class PaintPreviewHelper {
}
/**
* Attemps to display the Paint Preview representation of for the given Tab.
* Attempts to display the Paint Preview representation of for the given Tab.
* @param onShown The callback for when the Paint Preview is shown.
* @param onDismissed The callback for when the Paint Preview is dismissed.
* @return Whether the Paint Preview started to initialize or is already initializating.
......@@ -51,10 +61,12 @@ public class PaintPreviewHelper {
*/
public static boolean showPaintPreviewOnRestore(
Tab tab, Runnable onShown, Runnable onDismissed) {
if (!CachedFeatureFlags.isEnabled(ChromeFeatureList.PAINT_PREVIEW_SHOW_ON_STARTUP)) {
if (!CachedFeatureFlags.isEnabled(ChromeFeatureList.PAINT_PREVIEW_SHOW_ON_STARTUP)
|| sHasAttemptedToShowOnRestore) {
return false;
}
sHasAttemptedToShowOnRestore = true;
return TabbedPaintPreviewPlayer.get(tab).maybeShow(onShown, onDismissed);
}
}
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