Clear session cookies in a bg thread

This buys us very little, as we wait on function returning
just below. At least we are not doing disk access on the
UI thread.

Change-Id: I899a795ffbdd2ed63bf6ece70de52cfd48f65a1c
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 7acdfe5..a2caf90 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -249,7 +249,14 @@
                 mUi.needsRestoreAllTabs())) {
             // there is no quit on Android. But if we can't restore the state,
             // we can treat it as a new Browser, remove the old session cookies.
-            CookieManager.getInstance().removeSessionCookie();
+            AsyncTask cookieCleaningTask = new AsyncTask<Object, Void, Void>() {
+                protected Void doInBackground(Object... none) {
+                    CookieManager.getInstance().removeSessionCookie();
+                    return null;
+                }
+            };
+            cookieCleaningTask.execute();
+
             // remove any incognito files
             WebView.cleanupPrivateBrowsingFiles();
             final Bundle extra = intent.getExtras();
@@ -277,6 +284,11 @@
                 }
             }
 
+            // Wait for sessions cookies to be cleared before loading urls
+            try {
+                cookieCleaningTask.get();
+            } catch(InterruptedException e) {
+            } catch(java.util.concurrent.ExecutionException e) {}
             if (urlData.isEmpty()) {
                 loadUrl(webView, mSettings.getHomePage());
             } else {