diff --git a/embedding/android/GeckoAppShell.java b/embedding/android/GeckoAppShell.java index ba614cc32d00..7b9002cb1953 100644 --- a/embedding/android/GeckoAppShell.java +++ b/embedding/android/GeckoAppShell.java @@ -331,6 +331,10 @@ public class GeckoAppShell File cacheFile = getCacheDir(); GeckoAppShell.putenv("MOZ_LINKER_CACHE=" + cacheFile.getPath()); + // setup the app-specific cache path + f = geckoApp.getCacheDir(); + GeckoAppShell.putenv("CACHE_DIRECTORY=" + f.getPath()); + // gingerbread introduces File.getUsableSpace(). We should use that. long freeSpace = getFreeSpace(); try { diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 509348dc1430..08cf09891baa 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -386,6 +386,10 @@ public class GeckoAppShell // Enable fixed position layers GeckoAppShell.putenv("MOZ_ENABLE_FIXED_POSITION_LAYERS=1"); + // setup the app-specific cache path + f = context.getCacheDir(); + GeckoAppShell.putenv("CACHE_DIRECTORY=" + f.getPath()); + putLocaleEnv(); } diff --git a/netwerk/cache/nsDeleteDir.cpp b/netwerk/cache/nsDeleteDir.cpp index f516d2259ed9..564db485cd1b 100644 --- a/netwerk/cache/nsDeleteDir.cpp +++ b/netwerk/cache/nsDeleteDir.cpp @@ -215,9 +215,6 @@ nsDeleteDir::DeleteDir(nsIFile *dirIn, bool moveToTrash, PRUint32 delay) if (NS_FAILED(rv)) return rv; - // Important: must rename directory w/o changing parent directory: else on - // NTFS we'll wait (with cache lock) while nsIFile's ACL reset walks file - // tree: was hanging GUI for *minutes* on large cache dirs. // Append random number to the trash directory and check if it exists. srand(PR_Now()); nsCAutoString leaf; @@ -240,7 +237,18 @@ nsDeleteDir::DeleteDir(nsIFile *dirIn, bool moveToTrash, PRUint32 delay) if (!leaf.Length()) return NS_ERROR_FAILURE; +#if defined(MOZ_WIDGET_ANDROID) + nsCOMPtr parent; + rv = trash->GetParent(getter_AddRefs(parent)); + if (NS_FAILED(rv)) + return rv; + rv = dir->MoveToNative(parent, leaf); +#else + // Important: must rename directory w/o changing parent directory: else on + // NTFS we'll wait (with cache lock) while nsIFile's ACL reset walks file + // tree: was hanging GUI for *minutes* on large cache dirs. rv = dir->MoveToNative(nsnull, leaf); +#endif if (NS_FAILED(rv)) return rv; } else { @@ -262,7 +270,25 @@ nsDeleteDir::DeleteDir(nsIFile *dirIn, bool moveToTrash, PRUint32 delay) nsresult nsDeleteDir::GetTrashDir(nsIFile *target, nsCOMPtr *result) { - nsresult rv = target->Clone(getter_AddRefs(*result)); + nsresult rv; +#if defined(MOZ_WIDGET_ANDROID) + // Try to use the app cache folder for cache trash on Android + char* cachePath = getenv("CACHE_DIRECTORY"); + if (cachePath) { + rv = NS_NewNativeLocalFile(nsDependentCString(cachePath), + true, getter_AddRefs(*result)); + if (NS_FAILED(rv)) + return rv; + + // Add a sub folder with the cache folder name + nsCAutoString leaf; + rv = target->GetNativeLeafName(leaf); + (*result)->AppendNative(leaf); + } else +#endif + { + rv = target->Clone(getter_AddRefs(*result)); + } if (NS_FAILED(rv)) return rv; @@ -301,7 +327,11 @@ nsDeleteDir::RemoveOldTrashes(nsIFile *cacheDir) return rv; nsCOMPtr parent; +#if defined(MOZ_WIDGET_ANDROID) + rv = trash->GetParent(getter_AddRefs(parent)); +#else rv = cacheDir->GetParent(getter_AddRefs(parent)); +#endif if (NS_FAILED(rv)) return rv;