Skip to content

Commit

Permalink
[Android][IncognitoReauth] Fix referencing objects in destruction path.
Browse files Browse the repository at this point in the history
Merge approved at crbug.com/1383016#c12

When the tabswitcher re-auth view is shown and the underlying Activity
is getting destroyed, we are referencing objects that we don't own.
This is racy, as the object might have been garbage collected already.

This CL adds support of a separate path which gets invoked when the
Activity is being destroyed, via a dedicated destroy method of the
co-ordinator.

(cherry picked from commit aedc073)

Bug: 1383016, 1227656
Change-Id: I128f1c4ebffcf38149d6945c88552aaa9d9f7fb1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4023454
Commit-Queue: Rohit Agarwal <roagarwal@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1071505}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4030301
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/5414@{#72}
Cr-Branched-From: 4417ee5-refs/heads/main@{#1070088}
  • Loading branch information
Rohit Agarwal authored and Chromium LUCI CQ committed Nov 16, 2022
1 parent 38eec90 commit 7429fbd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Expand Up @@ -251,7 +251,11 @@ public void destroy() {
if (mLayoutStateProvider != null) {
mLayoutStateProvider.removeObserver(mLayoutStateObserver);
}
hideDialogIfShowing(DialogDismissalCause.ACTIVITY_DESTROYED);

if (mIncognitoReauthCoordinator != null) {
mIncognitoReauthCoordinator.destroy();
mIncognitoReauthCoordinator = null;
}
}

/**
Expand Down
Expand Up @@ -32,4 +32,9 @@ interface IncognitoReauthCoordinator {
* screen.
*/
void hide(@DialogDismissalCause int dismissalCause);

/**
* A method responsible to do any clean-up when the coordinator is being destroyed.
*/
void destroy();
}
Expand Up @@ -69,7 +69,8 @@ public IncognitoReauthCoordinatorBase(@NonNull Context context,
/**
* A method to clean-up any unwanted resource.
*/
protected void destroy() {
@Override
public void destroy() {
assert mModelChangeProcessor != null : "Model must be created before its destroyed.";
mModelChangeProcessor.destroy();
}
Expand Down
Expand Up @@ -78,7 +78,7 @@ public void show() {
* screen.
*/
@Override
public void hide(int dismissalCause) {
public void hide(@DialogDismissalCause int dismissalCause) {
boolean success = mTabSwitcherCustomViewManager.releaseView();
assert success : "Unable to signal removing the re-auth screen from tab switcher.";

Expand Down

0 comments on commit 7429fbd

Please sign in to comment.