Chromium Code Reviews| Index: android_webview/java/src/org/chromium/android_webview/AwContents.java |
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java |
| index cb996fa2002677f431d198bf7989e9a65589d556..6150908b5702cde4a29832622275b92fe64aa617 100644 |
| --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java |
| +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java |
| @@ -20,6 +20,7 @@ import android.net.http.SslCertificate; |
| import android.os.AsyncTask; |
| import android.os.Build; |
| import android.os.Bundle; |
| +import android.os.Handler; |
| import android.os.Message; |
| import android.text.TextUtils; |
| import android.util.Log; |
| @@ -177,6 +178,7 @@ public class AwContents { |
| } |
| } |
| + private final Handler mHandler; |
| private long mNativeAwContents; |
| private final AwBrowserContext mBrowserContext; |
| private ViewGroup mContainerView; |
| @@ -567,6 +569,7 @@ public class AwContents { |
| InternalAccessDelegate internalAccessAdapter, NativeGLDelegate nativeGLDelegate, |
| AwContentsClient contentsClient, AwSettings settings, |
| DependencyFactory dependencyFactory) { |
| + mHandler = new Handler(); |
|
benm (inactive)
2014/10/31 13:53:29
does this need to be a member? destroy should come
boliu
2014/10/31 23:15:24
I wasn't concerned about threading issues as much
|
| mBrowserContext = browserContext; |
| mContainerView = containerView; |
| mContext = context; |
| @@ -878,8 +881,19 @@ public class AwContents { |
| * Destroys this object and deletes its native counterpart. |
| */ |
| public void destroy() { |
| + if (isDestroyed()) return; |
| + // If we are attached, we have to call native detach to clean up |
| + // hardware resources. |
| + if (mIsAttachedToWindow) { |
| + nativeOnDetachedFromWindow(mNativeAwContents); |
| + } |
| mIsDestroyed = true; |
| - destroyNatives(); |
| + mHandler.post(new Runnable() { |
| + @Override |
| + public void run() { |
| + destroyNatives(); |
| + } |
| + }); |
| } |
| /** |
| @@ -888,11 +902,6 @@ public class AwContents { |
| private void destroyNatives() { |
| if (mCleanupReference != null) { |
| assert mNativeAwContents != 0; |
| - // If we are attached, we have to call native detach to clean up |
| - // hardware resources. |
| - if (mIsAttachedToWindow) { |
| - nativeOnDetachedFromWindow(mNativeAwContents); |
| - } |
| mWebContentsObserver.detachFromWebContents(); |
| mWebContentsObserver = null; |
| @@ -913,12 +922,7 @@ public class AwContents { |
| } |
| private boolean isDestroyed() { |
| - if (mIsDestroyed) { |
| - assert mContentViewCore == null; |
| - assert mWebContents == null; |
| - assert mNavigationController == null; |
| - assert mNativeAwContents == 0; |
| - } else { |
| + if (!mIsDestroyed) { |
| assert mContentViewCore != null; |
| assert mWebContents != null; |
| assert mNavigationController != null; |