Upstream version 6.35.131.0
[platform/framework/web/crosswalk.git] / src / content / public / android / java / src / org / chromium / content / browser / ResourceExtractor.java
index 89857ff..3b75d1f 100644 (file)
@@ -67,7 +67,7 @@ public class ResourceExtractor {
 
             String timestampFile = checkPakTimestamp();
             if (timestampFile != null) {
-                deleteFiles();
+                deleteFiles(mContext);
             }
 
             SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
@@ -185,7 +185,7 @@ public class ResourceExtractor {
                 // returning null? It might be useful to gather UMA here too to track if
                 // this happens with regularity.
                 Log.w(LOGTAG, "Exception unpacking required pak resources: " + e.getMessage());
-                deleteFiles();
+                deleteFiles(mContext);
                 return null;
             }
 
@@ -307,9 +307,9 @@ public class ResourceExtractor {
     }
 
     private ResourceExtractor(Context context) {
-        mContext = context.getApplicationContext();
-        mAppDataDir = getAppDataDir();
-        mOutputDir = getOutputDir();
+        mContext = context;
+        mAppDataDir = getAppDataDirFromContext(mContext);
+        mOutputDir = getOutputDirFromContext(mContext);
     }
 
     public void waitForCompletion() {
@@ -321,13 +321,17 @@ public class ResourceExtractor {
 
         try {
             mExtractTask.get();
+            // ResourceExtractor is not needed any more.
+            // Release static objects to avoid leak of Context.
+            sIntercepter = null;
+            sInstance = null;
         } catch (CancellationException e) {
             // Don't leave the files in an inconsistent state.
-            deleteFiles();
+            deleteFiles(mContext);
         } catch (ExecutionException e2) {
-            deleteFiles();
+            deleteFiles(mContext);
         } catch (InterruptedException e3) {
-            deleteFiles();
+            deleteFiles(mContext);
         }
     }
 
@@ -349,12 +353,12 @@ public class ResourceExtractor {
         mExtractTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
     }
 
-    private File getAppDataDir() {
-        return new File(PathUtils.getDataDirectory(mContext));
+    public static File getAppDataDirFromContext(Context context) {
+        return new File(PathUtils.getDataDirectory(context.getApplicationContext()));
     }
 
-    private File getOutputDir() {
-        return new File(getAppDataDir(), "paks");
+    public static File getOutputDirFromContext(Context context) {
+        return new File(getAppDataDirFromContext(context), "paks");
     }
 
     /**
@@ -364,12 +368,12 @@ public class ResourceExtractor {
      * lead to malfunction/UX misbehavior. So, we regard failing to update them
      * as an error.
      */
-    private void deleteFiles() {
-        File icudata = new File(getAppDataDir(), ICU_DATA_FILENAME);
+    public static void deleteFiles(Context context) {
+        File icudata = new File(getAppDataDirFromContext(context), ICU_DATA_FILENAME);
         if (icudata.exists() && !icudata.delete()) {
             Log.e(LOGTAG, "Unable to remove the icudata " + icudata.getName());
         }
-        File dir = getOutputDir();
+        File dir = getOutputDirFromContext(context);
         if (dir.exists()) {
             File[] files = dir.listFiles();
             for (File file : files) {