diff options
author | Kristian Monsen <kristianm@google.com> | 2010-12-08 15:29:29 +0000 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2010-12-09 11:41:02 +0000 |
commit | 851730552166bf6e99ed60438ba91f09f36b829f (patch) | |
tree | 0659607b0d0b5e692194e27ab24d37134114af8a | |
parent | 5c1619fff46670612fdcf3cd4cf9e6c7347fd694 (diff) | |
download | frameworks_base-851730552166bf6e99ed60438ba91f09f36b829f.zip frameworks_base-851730552166bf6e99ed60438ba91f09f36b829f.tar.gz frameworks_base-851730552166bf6e99ed60438ba91f09f36b829f.tar.bz2 |
Make CookieManager.removeSessionCookies async
Webkit loadurl() will wait on the webcore thread until oustanding
cookie operations complete.
Change-Id: I067408fdb9acd2e2d1f1f21eef910d0b26304332
-rw-r--r-- | core/java/android/webkit/CookieManager.java | 31 | ||||
-rw-r--r-- | core/java/android/webkit/WebViewCore.java | 3 |
2 files changed, 33 insertions, 1 deletions
diff --git a/core/java/android/webkit/CookieManager.java b/core/java/android/webkit/CookieManager.java index 0cbd51b..3ba7f81 100644 --- a/core/java/android/webkit/CookieManager.java +++ b/core/java/android/webkit/CookieManager.java @@ -19,6 +19,7 @@ package android.webkit; import android.net.ParseException; import android.net.WebAddress; import android.net.http.AndroidHttpClient; +import android.os.AsyncTask; import android.util.Log; @@ -102,6 +103,8 @@ public final class CookieManager { // http:/b/3118772 private static Boolean sUseChromiumHttpStack; + private int pendingCookieOperations = 0; + /** * This contains a list of 2nd-level domains that aren't allowed to have * wildcards when combined with country-codes. For example: [.co.uk]. @@ -523,12 +526,37 @@ public final class CookieManager { } } + synchronized void waitForCookieOperationsToComplete() { + while (pendingCookieOperations > 0) { + try { + wait(); + } catch (InterruptedException e) { } + } + } + + private synchronized void signalCookieOperationsComplete() { + pendingCookieOperations--; + assert pendingCookieOperations > -1; + notify(); + } + + private synchronized void signalCookieOperationsStart() { + pendingCookieOperations++; + } + /** * Remove all session cookies, which are cookies without expiration date */ public void removeSessionCookie() { + signalCookieOperationsStart(); if (useChromiumHttpStack()) { - nativeRemoveSessionCookie(); + new AsyncTask<Void, Void, Void>() { + protected Void doInBackground(Void... none) { + nativeRemoveSessionCookie(); + signalCookieOperationsComplete(); + return null; + } + }.execute(); return; } @@ -548,6 +576,7 @@ public final class CookieManager { } } CookieSyncManager.getInstance().clearSessionCookies(); + signalCookieOperationsComplete(); } } }; diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index d2c7fce..942fe0b 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -1056,17 +1056,20 @@ final class WebViewCore { break; case LOAD_URL: { + CookieManager.getInstance().waitForCookieOperationsToComplete(); GetUrlData param = (GetUrlData) msg.obj; loadUrl(param.mUrl, param.mExtraHeaders); break; } case POST_URL: { + CookieManager.getInstance().waitForCookieOperationsToComplete(); PostUrlData param = (PostUrlData) msg.obj; mBrowserFrame.postUrl(param.mUrl, param.mPostData); break; } case LOAD_DATA: + CookieManager.getInstance().waitForCookieOperationsToComplete(); BaseUrlData loadParams = (BaseUrlData) msg.obj; String baseUrl = loadParams.mBaseUrl; if (baseUrl != null) { |