Bug 612246 - Store the media cache in the profile directory for single process Gecko and the system temp directory for multi-process. r=cpearce
authorAdam Dane <unusualtears@gmail.com>
Mon, 05 Mar 2012 14:40:56 -0600
changeset 88337 50527c658f6016d97c2a68355609757b665bedfc
parent 88322 a8115574617b873c217914e1a44f63ffa9958eff
child 88338 4df4dcacedef255bac787b694b1e7b66c59dcc84
push id22194
push usermak77@bonardo.net
push dateWed, 07 Mar 2012 09:33:54 +0000
treeherdermozilla-central@8ef88a69f861 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs612246
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 612246 - Store the media cache in the profile directory for single process Gecko and the system temp directory for multi-process. r=cpearce
content/media/nsMediaCache.cpp
xpcom/io/nsMediaCacheRemover.cpp
--- a/content/media/nsMediaCache.cpp
+++ b/content/media/nsMediaCache.cpp
@@ -37,16 +37,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/ReentrantMonitor.h"
 #include "mozilla/XPCOM.h"
 
 #include "nsMediaCache.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsDirectoryServiceDefs.h"
+#include "nsXULAppAPI.h"
 #include "nsNetUtil.h"
 #include "prio.h"
 #include "nsThreadUtils.h"
 #include "MediaResource.h"
 #include "nsMathUtils.h"
 #include "prlog.h"
 #include "nsIPrivateBrowsingService.h"
 #include "mozilla/Preferences.h"
@@ -540,18 +541,25 @@ nsMediaCacheStream::BlockList::NotifyBlo
 }
 
 nsresult
 nsMediaCache::Init()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
   NS_ASSERTION(!mFD, "Cache file already open?");
 
+  // In single process Gecko, store the media cache in the profile directory
+  // so that multiple users can use separate media caches concurrently.
+  // In multi-process Gecko, there is no profile dir, so just store it in the
+  // system temp directory instead.
+  nsresult rv;
   nsCOMPtr<nsIFile> tmp;
-  nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmp));
+  const char* dir = (XRE_GetProcessType() == GeckoProcessType_Content) ?
+    NS_OS_TEMP_DIR : NS_APP_USER_PROFILE_LOCAL_50_DIR;
+  rv = NS_GetSpecialDirectory(dir, getter_AddRefs(tmp));
   NS_ENSURE_SUCCESS(rv,rv);
 
   nsCOMPtr<nsILocalFile> tmpFile = do_QueryInterface(tmp);
   NS_ENSURE_TRUE(tmpFile != nsnull, NS_ERROR_FAILURE);
 
   // We put the media cache file in
   // ${TempDir}/mozilla-media-cache/media_cache
   rv = tmpFile->AppendNative(nsDependentCString("mozilla-media-cache"));
--- a/xpcom/io/nsMediaCacheRemover.cpp
+++ b/xpcom/io/nsMediaCacheRemover.cpp
@@ -40,16 +40,17 @@
 #endif
 
 #include "nsIObserver.h"
 #include "nsIIdleService.h"
 #include "nsISimpleEnumerator.h"
 #include "nsILocalFile.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsDirectoryServiceDefs.h"
+#include "nsXULAppAPI.h"
 #include "nsString.h"
 #include "nsAutoPtr.h"
 #include "nsITimer.h"
 
 // Duration of idle time before we'll get a callback whereupon we attempt to
 // remove any stray and unused media cache temp files.
 #define TEMP_FILE_IDLE_TIME 30
 
@@ -102,20 +103,24 @@ public:
 
   void RemoveMediaCacheFiles() {
     nsCOMPtr<nsIIdleService> idleSvc =
       do_GetService("@mozilla.org/widget/idleservice;1");
     if (idleSvc)
       idleSvc->RemoveIdleObserver(this, TEMP_FILE_IDLE_TIME);
 
     nsCOMPtr<nsIFile> tmpDir;
-    nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR,
+    nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_LOCAL_50_DIR,
                                          getter_AddRefs(tmpDir));
     if (NS_FAILED(rv))
       return;
+
+    NS_ABORT_IF_FALSE(XRE_GetProcessType() == GeckoProcessType_Default,
+                      "Need to update media cache file location");
+
     rv = tmpDir->AppendNative(nsDependentCString("mozilla-media-cache"));
     if (NS_FAILED(rv))
       return;
 
     nsCOMPtr<nsILocalFile> tmpFile = do_QueryInterface(tmpDir);
     if (!tmpFile)
       return;