Bug 1001361 - HTTP Cache directory created inside Cache directory. r=michal, a=lsblakk
authorHonza Bambas <honzab.moz@firemni.cz>
Fri, 25 Apr 2014 13:02:36 +0200
changeset 193149 8f8dabb5739393b4049ee28661ca5fb545a266a9
parent 193148 f2e10998cd71738d6bbd92c32e1df2d1cd7536b8
child 193150 3f1c2649de3517d577236a7a9afa3efdc762e89b
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal, lsblakk
bugs1001361
milestone30.0a2
Bug 1001361 - HTTP Cache directory created inside Cache directory. r=michal, a=lsblakk
netwerk/cache/nsCacheService.cpp
netwerk/cache/nsCacheService.h
--- a/netwerk/cache/nsCacheService.cpp
+++ b/netwerk/cache/nsCacheService.cpp
@@ -3049,30 +3049,58 @@ nsCacheService::CloseAllStreams()
 bool
 nsCacheService::GetClearingEntries()
 {
     AssertOwnsLock();
     return gService->mClearingEntries;
 }
 
 // static
-void nsCacheService::GetDiskCacheDirectory(nsIFile ** result) {
+void nsCacheService::GetCacheBaseDirectoty(nsIFile ** result)
+{
     *result = nullptr;
-    if (gService && gService->mObserver) {
-        nsCOMPtr<nsIFile> directory =
-            gService->mObserver->DiskCacheParentDirectory();
-        if (!directory)
-            return;
-
-        nsresult rv = directory->AppendNative(NS_LITERAL_CSTRING("Cache"));
-        if (NS_FAILED(rv))
-            return;
-
-        directory.forget(result);
-    }
+    if (!gService || !gService->mObserver)
+        return;
+
+    nsCOMPtr<nsIFile> directory =
+        gService->mObserver->DiskCacheParentDirectory();
+    if (!directory)
+        return;
+
+    directory->Clone(result);
+}
+
+// static
+void nsCacheService::GetDiskCacheDirectory(nsIFile ** result)
+{
+    nsCOMPtr<nsIFile> directory;
+    GetCacheBaseDirectoty(getter_AddRefs(directory));
+    if (!directory)
+        return;
+
+    nsresult rv = directory->AppendNative(NS_LITERAL_CSTRING("Cache"));
+    if (NS_FAILED(rv))
+        return;
+
+    directory.forget(result);
+}
+
+// static
+void nsCacheService::GetAppCacheDirectory(nsIFile ** result)
+{
+    nsCOMPtr<nsIFile> directory;
+    GetCacheBaseDirectoty(getter_AddRefs(directory));
+    if (!directory)
+        return;
+
+    nsresult rv = directory->AppendNative(NS_LITERAL_CSTRING("OfflineCache"));
+    if (NS_FAILED(rv))
+        return;
+
+    directory.forget(result);
 }
 
 
 #if defined(PR_LOGGING)
 void
 nsCacheService::LogCacheStatistics()
 {
     uint32_t hitPercentage = (uint32_t)((((double)mCacheHits) /
--- a/netwerk/cache/nsCacheService.h
+++ b/netwerk/cache/nsCacheService.h
@@ -122,17 +122,19 @@ public:
     static nsresult  SetCacheElement(nsCacheEntry * entry, nsISupports * element);
 
     static nsresult  ValidateEntry(nsCacheEntry * entry);
 
     static int32_t   CacheCompressionLevel();
 
     static bool      GetClearingEntries();
 
+    static void      GetCacheBaseDirectoty(nsIFile ** result);
     static void      GetDiskCacheDirectory(nsIFile ** result);
+    static void      GetAppCacheDirectory(nsIFile ** result);
 
     /**
      * Methods called by any cache classes
      */
 
     static
     nsCacheService * GlobalInstance()   { return gService; }