Commit a449371f authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Lazy load the bottom sheet instead of using feature checks

With the growing number of bottom sheet users, it no longer makes sense
to initialize it based on a list of feature flags. Instead, the bottom
sheet is initialized the first time someone queries for the controller.

Bug: 986310, 1002277
Change-Id: I61e68a1a89c98f72bfa9ef5e9d75cf6172cd51cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1808180Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697401}
parent 392f6747
......@@ -150,8 +150,7 @@ class AutofillAssistantUiTestUtil {
return new BottomSheetController(activity, activity.getLifecycleDispatcher(),
activity.getActivityTabProvider(), activity.getScrim(), bottomSheet,
activity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager(),
/* suppressSheetForContextualSearch= */ false);
activity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager());
}
/**
......
......@@ -1425,13 +1425,9 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
getCompositorViewHolder().addCompositorViewResizer(
mManualFillingComponent.getKeyboardExtensionViewResizer());
if (mBottomSheet == null && shouldInitializeBottomSheet()) {
// TODO(yusufo): Unify initialization.
initializeBottomSheet(true);
}
if (mBottomSheet != null) {
mEphemeralTabCoordinator = new EphemeralTabCoordinator(this, mBottomSheetController);
if (ChromeFeatureList.isEnabled(ChromeFeatureList.EPHEMERAL_TAB_USING_BOTTOM_SHEET)) {
mEphemeralTabCoordinator =
new EphemeralTabCoordinator(this, getBottomSheetController());
}
// TODO(crbug.com/959841): Once crrev.com/c/1669360 is submitted, make the code below
......@@ -1452,7 +1448,10 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
*/
protected void registerDirectActions() {
mDirectActionInitializer.registerCommonChromeActions(this, getActivityType(), this,
this::onBackPressed, mTabModelSelector, mBottomSheetController, mScrimView);
this::onBackPressed, mTabModelSelector,
AutofillAssistantFacade.areDirectActionsAvailable(getActivityType()) ?
getBottomSheetController() : null,
mScrimView);
}
/**
......@@ -1471,19 +1470,10 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
return null;
}
/**
* @return Whether this Activity should initialize the BottomSheet and BottomSheetController.
*/
protected boolean shouldInitializeBottomSheet() {
return AutofillAssistantFacade.areDirectActionsAvailable(getActivityType());
}
/**
* Initializes the {@link BottomSheet} and {@link BottomSheetController} for use.
* @param suppressSheetForContextualSearch Whether the sheet should be suppressed when
* Contextual search is showing.
*/
protected void initializeBottomSheet(boolean suppressSheetForContextualSearch) {
protected void initializeBottomSheet() {
ViewGroup coordinator = findViewById(R.id.coordinator);
getLayoutInflater().inflate(R.layout.bottom_sheet, coordinator);
mBottomSheet = coordinator.findViewById(R.id.bottom_sheet);
......@@ -1493,8 +1483,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
mBottomSheetController = new BottomSheetController(this, getLifecycleDispatcher(),
mActivityTabProvider, mScrimView, mBottomSheet,
getCompositorViewHolder().getLayoutManager().getOverlayPanelManager(),
suppressSheetForContextualSearch);
getCompositorViewHolder().getLayoutManager().getOverlayPanelManager());
}
/**
......@@ -2550,9 +2539,12 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
return toPropagate == null || super.dispatchKeyEvent(toPropagate);
}
/** Returns {@link BottomSheetController}, if present. */
@Nullable
/**
* @return A lazily created {@link BottomSheetController}. The first time this method is called,
* a new controller is created.
*/
public BottomSheetController getBottomSheetController() {
if (mBottomSheetController == null) initializeBottomSheet();
return mBottomSheetController;
}
......
......@@ -110,7 +110,6 @@ import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.search_engines.SearchEngineChoiceNotification;
import org.chromium.chrome.browser.send_tab_to_self.SendTabToSelfAndroidBridge;
import org.chromium.chrome.browser.signin.SigninPromoUtil;
import org.chromium.chrome.browser.snackbar.undo.UndoBarController;
import org.chromium.chrome.browser.suggestions.SuggestionsEventReporterBridge;
......@@ -748,10 +747,6 @@ public class ChromeTabbedActivity extends ChromeActivity implements ScreenshotMo
};
OnClickListener bookmarkClickHandler = v -> addOrEditBookmark(getActivityTab());
if (shouldInitializeBottomSheet()) {
initializeBottomSheet(false);
}
getToolbarManager().initializeWithNative(mTabModelSelectorImpl,
getFullscreenManager().getBrowserVisibilityDelegate(), mOverviewModeController,
mLayoutManager, tabSwitcherClickHandler, newTabClickHandler,
......@@ -2358,13 +2353,6 @@ public class ChromeTabbedActivity extends ChromeActivity implements ScreenshotMo
isIncognito ? "new-incognito-tab-shortcut" : "new-tab-shortcut");
}
@Override
protected boolean shouldInitializeBottomSheet() {
return super.shouldInitializeBottomSheet() || FeatureUtilities.isTabGroupsAndroidEnabled()
|| ChromeFeatureList.isEnabled(ChromeFeatureList.OVERSCROLL_HISTORY_NAVIGATION)
|| SendTabToSelfAndroidBridge.isSendingEnabled();
}
@Override
public void onScreenshotTaken() {
Tracker tracker = TrackerFactory.getTrackerForProfile(Profile.getLastUsedProfile());
......
......@@ -604,11 +604,6 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
return component;
}
@Override
protected boolean shouldInitializeBottomSheet() {
return super.shouldInitializeBottomSheet() || isAutofillAssistantEnabled();
}
private boolean isAutofillAssistantEnabled() {
return ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT)
&& AutofillAssistantFacade.isConfigured(getInitialIntent().getExtras());
......
......@@ -11,7 +11,6 @@ import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.ActivityTabProvider.HintlessActivityTabObserver;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager.OverlayPanelManagerObserver;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.browser.snackbar.SnackbarManager;
......@@ -64,9 +63,6 @@ public class BottomSheetController implements Destroyable {
/** The manager for overlay panels to attach listeners to. */
private OverlayPanelManager mOverlayPanelManager;
/** Whether the bottom sheet should be suppressed when Contextual Search is showing. */
private boolean mSuppressSheetForContextualSearch;
/** A means for getting the activity's current tab and observing change events. */
private ActivityTabProvider mTabProvider;
......@@ -81,18 +77,14 @@ public class BottomSheetController implements Destroyable {
* @param scrim The scrim that shows when the bottom sheet is opened.
* @param bottomSheet The bottom sheet that this class will be controlling.
* @param overlayManager The manager for overlay panels to attach listeners to.
* @param suppressSheetForContextualSearch Whether the bottom sheet should be suppressed when
* Contextual Search is showing.
*/
public BottomSheetController(final Activity activity,
final ActivityLifecycleDispatcher lifecycleDispatcher,
final ActivityTabProvider activityTabProvider, final ScrimView scrim,
BottomSheet bottomSheet, OverlayPanelManager overlayManager,
boolean suppressSheetForContextualSearch) {
BottomSheet bottomSheet, OverlayPanelManager overlayManager) {
mBottomSheet = bottomSheet;
mTabProvider = activityTabProvider;
mOverlayPanelManager = overlayManager;
mSuppressSheetForContextualSearch = suppressSheetForContextualSearch;
mSnackbarManager = new SnackbarManager(
activity, mBottomSheet.findViewById(R.id.bottom_sheet_snackbar_container));
......@@ -216,20 +208,6 @@ public class BottomSheetController implements Destroyable {
mSnackbarManager.dismissAllSnackbars();
}
});
if (mSuppressSheetForContextualSearch) {
mOverlayPanelManager.addObserver(new OverlayPanelManagerObserver() {
@Override
public void onOverlayPanelShown() {
suppressSheet(StateChangeReason.COMPOSITED_UI);
}
@Override
public void onOverlayPanelHidden() {
unsuppressSheet();
}
});
}
}
// Destroyable implementation.
......
......@@ -74,8 +74,7 @@ public class ScrimTest {
mSheetController = new BottomSheetController(activity,
activity.getLifecycleDispatcher(), activity.getActivityTabProvider(), mScrim,
mBottomSheet,
activity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager(),
true);
activity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager());
});
}
......
......@@ -75,8 +75,7 @@ public class BottomSheetControllerTest {
mSheetController = new BottomSheetController(activity,
activity.getLifecycleDispatcher(), activity.getActivityTabProvider(), scrim,
mBottomSheet,
activity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager(),
true);
activity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager());
mLowPriorityContent = new TestBottomSheetContent(
mActivityTestRule.getActivity(), ContentPriority.LOW, false);
......
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