Commit 9d2c67b2 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

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: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771220}
parent 8ea03d47
......@@ -34,6 +34,7 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.BuildInfo;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.LifetimeAssert;
import org.chromium.base.Log;
import org.chromium.base.ObserverList;
import org.chromium.base.PackageManagerUtils;
......@@ -68,6 +69,8 @@ public class WindowAndroid implements AndroidPermissionDelegate, DisplayAndroidO
// exactly match the target rate.
private static final float MAX_REFRESH_RATE_DELTA = 2.f;
private final LifetimeAssert mLifetimeAssert;
private KeyboardVisibilityDelegate mKeyboardVisibilityDelegate =
KeyboardVisibilityDelegate.getInstance();
......@@ -204,6 +207,7 @@ public class WindowAndroid implements AndroidPermissionDelegate, DisplayAndroidO
*/
@SuppressLint("UseSparseArrays")
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
// hold a strong reference to it.
mContextRef = new ImmutableWeakReference<>(context);
......@@ -628,6 +632,7 @@ public class WindowAndroid implements AndroidPermissionDelegate, DisplayAndroidO
* Destroys the c++ WindowAndroid object if one has been created.
*/
public void destroy() {
LifetimeAssert.setSafeToGc(mLifetimeAssert, true);
if (mNativeWindowAndroid != 0) {
// Native code clears |mNativeWindowAndroid|.
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