Commit e7dece2e authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

Reland "android: Add LifetimeAssert to WindowAndroid"

This is a reland of 9d2c67b2
Landed changes to relax LifetimeAssert when DestroyActivitiesRule
fails. See bug for details.

Original change's description:
> android: Add LifetimeAssert to WindowAndroid
>
> Bug: 1081250
> Change-Id: Id0924545fbdb1eb28ae3c8fe015559fd3e9c53d1
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2191785
> Commit-Queue: Bo <boliu@chromium.org>
> Reviewed-by: Andrew Grieve <agrieve@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#771220}

Bug: 1081250
Change-Id: Iea2dd27c5b114d748c6f0de8edf17c68b3ec98de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2216798Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772259}
parent fb08cc35
...@@ -34,6 +34,7 @@ import org.chromium.base.ApiCompatibilityUtils; ...@@ -34,6 +34,7 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.BuildInfo; import org.chromium.base.BuildInfo;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.LifetimeAssert;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
import org.chromium.base.PackageManagerUtils; import org.chromium.base.PackageManagerUtils;
...@@ -68,6 +69,8 @@ public class WindowAndroid implements AndroidPermissionDelegate, DisplayAndroidO ...@@ -68,6 +69,8 @@ public class WindowAndroid implements AndroidPermissionDelegate, DisplayAndroidO
// exactly match the target rate. // exactly match the target rate.
private static final float MAX_REFRESH_RATE_DELTA = 2.f; private static final float MAX_REFRESH_RATE_DELTA = 2.f;
private final LifetimeAssert mLifetimeAssert;
private KeyboardVisibilityDelegate mKeyboardVisibilityDelegate = private KeyboardVisibilityDelegate mKeyboardVisibilityDelegate =
KeyboardVisibilityDelegate.getInstance(); KeyboardVisibilityDelegate.getInstance();
...@@ -204,6 +207,7 @@ public class WindowAndroid implements AndroidPermissionDelegate, DisplayAndroidO ...@@ -204,6 +207,7 @@ public class WindowAndroid implements AndroidPermissionDelegate, DisplayAndroidO
*/ */
@SuppressLint("UseSparseArrays") @SuppressLint("UseSparseArrays")
protected WindowAndroid(Context context, DisplayAndroid display) { protected WindowAndroid(Context context, DisplayAndroid display) {
mLifetimeAssert = LifetimeAssert.create(this);
// context does not have the same lifetime guarantees as an application context so we can't // context does not have the same lifetime guarantees as an application context so we can't
// hold a strong reference to it. // hold a strong reference to it.
mContextRef = new ImmutableWeakReference<>(context); mContextRef = new ImmutableWeakReference<>(context);
...@@ -628,6 +632,7 @@ public class WindowAndroid implements AndroidPermissionDelegate, DisplayAndroidO ...@@ -628,6 +632,7 @@ public class WindowAndroid implements AndroidPermissionDelegate, DisplayAndroidO
* Destroys the c++ WindowAndroid object if one has been created. * Destroys the c++ WindowAndroid object if one has been created.
*/ */
public void destroy() { public void destroy() {
LifetimeAssert.setSafeToGc(mLifetimeAssert, true);
if (mNativeWindowAndroid != 0) { if (mNativeWindowAndroid != 0) {
// Native code clears |mNativeWindowAndroid|. // Native code clears |mNativeWindowAndroid|.
WindowAndroidJni.get().destroy(mNativeWindowAndroid, WindowAndroid.this); WindowAndroidJni.get().destroy(mNativeWindowAndroid, WindowAndroid.this);
......
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