Commit c135680f authored by Theresa's avatar Theresa Committed by Commit Bot

[EoC] Speculative crash fix for showing suggestions after destruction

This adds a speculative fix for a crash reported when tapping both the
EoC toolbar button and clear tab button at the same time. This CL
ignores clicks on the toolbar button if the model is not prepared (e.g.
has been cleared before the click handler is invoked) and adds a
null check before showing content.

BUG=873052

Change-Id: I073919ce38f73046d9644523135d5b6cdbd42c59
Reviewed-on: https://chromium-review.googlesource.com/1172940
Commit-Queue: Theresa <twellington@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582684}
parent ee556059
...@@ -105,6 +105,13 @@ public class ContextualSuggestionsCoordinator { ...@@ -105,6 +105,13 @@ public class ContextualSuggestionsCoordinator {
* things needed to display suggestions (e.g. favicons, thumbnails). * things needed to display suggestions (e.g. favicons, thumbnails).
*/ */
void showSuggestions(ContextualSuggestionsSource suggestionsSource) { void showSuggestions(ContextualSuggestionsSource suggestionsSource) {
// If the content coordinator has already been destroyed when this method is called, return
// early. See https://crbug.com/873052.
if (mContentCoordinator == null) {
assert false : "ContentCoordinator false when #showSuggestions was called.";
return;
}
SuggestionsNavigationDelegate navigationDelegate = new SuggestionsNavigationDelegateImpl( SuggestionsNavigationDelegate navigationDelegate = new SuggestionsNavigationDelegateImpl(
mActivity, mProfile, mBottomSheetController.getBottomSheet(), mTabModelSelector); mActivity, mProfile, mBottomSheetController.getBottomSheet(), mTabModelSelector);
SuggestionsUiDelegateImpl uiDelegate = new SuggestionsUiDelegateImpl(suggestionsSource, SuggestionsUiDelegateImpl uiDelegate = new SuggestionsUiDelegateImpl(suggestionsSource,
......
...@@ -73,6 +73,7 @@ class ContextualSuggestionsMediator ...@@ -73,6 +73,7 @@ class ContextualSuggestionsMediator
private @Nullable TextBubble mHelpBubble; private @Nullable TextBubble mHelpBubble;
private @Nullable WebContents mCurrentWebContents; private @Nullable WebContents mCurrentWebContents;
private boolean mModelPreparedForCurrentTab;
private boolean mSuggestionsSetOnBottomSheet; private boolean mSuggestionsSetOnBottomSheet;
private boolean mDidSuggestionsShowForTab; private boolean mDidSuggestionsShowForTab;
private boolean mHasRecordedPeekEventForTab; private boolean mHasRecordedPeekEventForTab;
...@@ -279,7 +280,7 @@ class ContextualSuggestionsMediator ...@@ -279,7 +280,7 @@ class ContextualSuggestionsMediator
} }
private void onToolbarButtonClicked() { private void onToolbarButtonClicked() {
if (mSuggestionsSetOnBottomSheet) return; if (mSuggestionsSetOnBottomSheet || !mModelPreparedForCurrentTab) return;
maybeShowContentInSheet(); maybeShowContentInSheet();
mCoordinator.showSuggestions(mSuggestionsSource); mCoordinator.showSuggestions(mSuggestionsSource);
...@@ -395,7 +396,7 @@ class ContextualSuggestionsMediator ...@@ -395,7 +396,7 @@ class ContextualSuggestionsMediator
* be cleared. * be cleared.
*/ */
private void clearSuggestions() { private void clearSuggestions() {
// TODO(twellington): Does this signal need to go back to FetchHelper? mModelPreparedForCurrentTab = false;
// Remove suggestions before clearing model state so that views don't respond to model // Remove suggestions before clearing model state so that views don't respond to model
// changes while suggestions are hiding. See https://crbug.com/840579. // changes while suggestions are hiding. See https://crbug.com/840579.
...@@ -470,6 +471,8 @@ class ContextualSuggestionsMediator ...@@ -470,6 +471,8 @@ class ContextualSuggestionsMediator
mModel.setMenuButtonDelegate(this); mModel.setMenuButtonDelegate(this);
mModel.setDefaultToolbarClickListener(view -> mCoordinator.expandBottomSheet()); mModel.setDefaultToolbarClickListener(view -> mCoordinator.expandBottomSheet());
mModel.setTitle(title); mModel.setTitle(title);
mModelPreparedForCurrentTab = true;
} }
private void maybeShowContentInSheet() { private void maybeShowContentInSheet() {
......
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