OSDN Git Service

Update Chromium HTTP stack to get database and cache paths from CookieSyncManager
authorSteve Block <steveblock@google.com>
Wed, 27 Oct 2010 10:29:42 +0000 (11:29 +0100)
committerSteve Block <steveblock@google.com>
Wed, 27 Oct 2010 13:06:53 +0000 (14:06 +0100)
Currently these paths are obtained from the BrowserFrame via JNI.
However, the paths are not synced to the BrowserFrame until the
WebCore thread has started up. This means that if the
WebRequestContext is created on the IO thread, the paths may not be
available.

This change moves the paths from BrowserFrame to CookieSyncManager to
avoid the need to wait for the WebCore thread.

Note that the new methods may be called on either the UI or WebCore
threads, so are synchronised.

Requires a change to external/webkit ...
https://android-git.corp.google.com/g/76579

Change-Id: I8e910ee209c570e90181bd308a78d1987b4d120c

core/java/android/webkit/BrowserFrame.java
core/java/android/webkit/CookieSyncManager.java

index 5254027..2087664 100644 (file)
@@ -74,8 +74,6 @@ class BrowserFrame extends Handler {
     // queue has been cleared,they are ignored.
     private boolean mBlockMessages = false;
     private int mOrientation = -1;
-    private static String sDatabaseDirectory;
-    private static String sCacheDirectory;
 
     // Is this frame the main frame?
     private boolean mIsMainFrame;
@@ -229,13 +227,6 @@ class BrowserFrame extends Handler {
         AssetManager am = context.getAssets();
         nativeCreateFrame(w, am, proxy.getBackForwardList());
 
-        if (sDatabaseDirectory == null) {
-            sDatabaseDirectory = appContext.getDatabasePath("dummy").getParent();
-        }
-        if (sCacheDirectory == null) {
-            sCacheDirectory = appContext.getCacheDir().getAbsolutePath();
-        }
-
         if (DebugFlags.BROWSER_FRAME) {
             Log.v(LOGTAG, "BrowserFrame constructor: this=" + this);
         }
@@ -658,22 +649,6 @@ class BrowserFrame extends Handler {
     }
 
     /**
-     * Called by JNI. Gets the application's database directory, excluding the trailing slash.
-     * @return String The application's database directory
-     */
-    private static String getDatabaseDirectory() {
-        return sDatabaseDirectory;
-    }
-
-    /**
-     * Called by JNI. Gets the application's cache directory, excluding the trailing slash.
-     * @return String The application's cache directory
-     */
-    private static String getCacheDirectory() {
-        return sCacheDirectory;
-    }
-
-    /**
      * Called by JNI.
      * Read from an InputStream into a supplied byte[]
      * This method catches any exceptions so they don't crash the JVM.
index abe9178..8b76a3b 100644 (file)
@@ -65,6 +65,11 @@ public final class CookieSyncManager extends WebSyncManager {
     // time when last update happened
     private long mLastUpdate;
 
+    // Used by the Chromium HTTP stack. Everything else in this class is used only by the Android
+    // Java HTTP stack.
+    private static String sDatabaseDirectory;
+    private static String sCacheDirectory;
+
     private CookieSyncManager(Context context) {
         super(context, "CookieSyncManager");
     }
@@ -77,11 +82,7 @@ public final class CookieSyncManager extends WebSyncManager {
      * @return CookieSyncManager
      */
     public static synchronized CookieSyncManager getInstance() {
-        if (sRef == null) {
-            throw new IllegalStateException(
-                    "CookieSyncManager::createInstance() needs to be called "
-                            + "before CookieSyncManager::getInstance()");
-        }
+        checkInstanceIsCreated();
         return sRef;
     }
 
@@ -92,8 +93,11 @@ public final class CookieSyncManager extends WebSyncManager {
      */
     public static synchronized CookieSyncManager createInstance(
             Context context) {
+        Context appContext = context.getApplicationContext();
         if (sRef == null) {
-            sRef = new CookieSyncManager(context.getApplicationContext());
+            sRef = new CookieSyncManager(appContext);
+            sDatabaseDirectory = appContext.getDatabasePath("dummy").getParent();
+            sCacheDirectory = appContext.getCacheDir().getAbsolutePath();
         }
         return sRef;
     }
@@ -210,4 +214,30 @@ public final class CookieSyncManager extends WebSyncManager {
             }
         }
     }
+
+    private static void checkInstanceIsCreated() {
+        if (sRef == null) {
+            throw new IllegalStateException(
+                    "CookieSyncManager::createInstance() needs to be called "
+                            + "before CookieSyncManager::getInstance()");
+        }
+    }
+
+    /**
+     * Called by JNI. Gets the application's database directory, excluding the trailing slash.
+     * @return String The application's database directory
+     */
+    private static synchronized String getDatabaseDirectory() {
+        checkInstanceIsCreated();
+        return sDatabaseDirectory;
+    }
+
+    /**
+     * Called by JNI. Gets the application's cache directory, excluding the trailing slash.
+     * @return String The application's cache directory
+     */
+    private static synchronized String getCacheDirectory() {
+        checkInstanceIsCreated();
+        return sCacheDirectory;
+    }
 }