Commit 81a813fc authored by tobiasjs's avatar tobiasjs Committed by Commit bot

Ensure that native WindowAndroid outlives native AwContents.

ContentViewCore holds a window pointer that is used during
destruction of native AwContents to remove observers. However the
current CleanupReference based finalization scheme does not enforce
an ordering on the destruction of native WindowAndroid and AwContents
instances. Satisfaction of the constraint that AwContents is destroyed
before WindowAndroid is therefore dependent on the CleanupReference
implementation, and possibly the implementation of the JVM as well.

Making the AwContents DestroyRunnable strongly reference the
associated WindowAndroidWrapper enforces the correct ordering.

BUG=595336

Review URL: https://codereview.chromium.org/1809643002

Cr-Commit-Position: refs/heads/master@{#381675}
parent 24eb1ea4
...@@ -316,9 +316,13 @@ public class AwContents implements SmartClipProvider, ...@@ -316,9 +316,13 @@ public class AwContents implements SmartClipProvider,
private static final class DestroyRunnable implements Runnable { private static final class DestroyRunnable implements Runnable {
private final long mNativeAwContents; private final long mNativeAwContents;
// Hold onto a reference to the window (via its wrapper), so that it is not destroyed
// until we are done here.
private final WindowAndroidWrapper mWindowAndroid;
private DestroyRunnable(long nativeAwContents) { private DestroyRunnable(long nativeAwContents, WindowAndroidWrapper windowAndroid) {
mNativeAwContents = nativeAwContents; mNativeAwContents = nativeAwContents;
mWindowAndroid = windowAndroid;
} }
@Override @Override
public void run() { public void run() {
...@@ -991,7 +995,7 @@ public class AwContents implements SmartClipProvider, ...@@ -991,7 +995,7 @@ public class AwContents implements SmartClipProvider,
// The native side object has been bound to this java instance, so now is the time to // The native side object has been bound to this java instance, so now is the time to
// bind all the native->java relationships. // bind all the native->java relationships.
mCleanupReference = mCleanupReference =
new CleanupReference(this, new DestroyRunnable(mNativeAwContents)); new CleanupReference(this, new DestroyRunnable(mNativeAwContents, mWindowAndroid));
} }
private void installWebContentsObserver() { private void installWebContentsObserver() {
......
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