Bug 1365534 - In non-e10s, open temp file in FileBlockCache thread - r?cpearce draft
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 17 May 2017 15:30:32 +1200
changeset 580042 a7a9122cbcb902f68ff7763866c05007d475a2b7
parent 580041 6587d2987558d5fb6e86df6d6e2d01cb18c21b10
child 580043 14363204f5a48ea636d8b97c271ef81502b0b458
push id59433
push usergsquelart@mozilla.com
push dateThu, 18 May 2017 04:39:26 +0000
reviewerscpearce
bugs1365534
milestone55.0a1
Bug 1365534 - In non-e10s, open temp file in FileBlockCache thread - r?cpearce In a parent process, the temporary file was created and opened by calling NS_OpenAnonymousTemporaryFile() from Init, which was called from the main thread. In addition to being called at least once when the first media file is fetched, it may also be called if caches need to be emptied. So it should help to move this operation on the FileBlockCache thread, if only to remove potential background-hang reports from non-e10s configurations. MozReview-Commit-ID: CjPsHEsL3Ch
dom/media/FileBlockCache.cpp
--- a/dom/media/FileBlockCache.cpp
+++ b/dom/media/FileBlockCache.cpp
@@ -38,17 +38,17 @@ FileBlockCache::SetCacheFile(PRFileDesc*
     MonitorAutoLock lock(mDataMonitor);
     if (!mIsOpen) {
       // We've been closed while waiting for the file descriptor. Bail out.
       // Rely on the destructor to close the file descriptor.
       return;
     }
     mInitialized = true;
     if (mIsWriteScheduled) {
-      // A write was scheduled while waiting for FD. We need to dispatch a
+      // A write was scheduled while waiting for FD. We need to run/dispatch a
       // task to service the request.
       mThread->Dispatch(this, NS_DISPATCH_NORMAL);
     }
   }
 }
 
 nsresult
 FileBlockCache::Init()
@@ -61,20 +61,26 @@ FileBlockCache::Init()
                                   nullptr,
                                   SharedThreadPool::kStackSize);
   if (NS_FAILED(rv)) {
     return rv;
   }
   mIsOpen = true;
 
   if (XRE_IsParentProcess()) {
-    rv = NS_OpenAnonymousTemporaryFile(&mFD);
-    if (NS_SUCCEEDED(rv)) {
-      mInitialized = true;
-    }
+    RefPtr<FileBlockCache> self = this;
+    rv = mThread->Dispatch(NS_NewRunnableFunction([self] {
+      PRFileDesc* fd = nullptr;
+      nsresult rv = NS_OpenAnonymousTemporaryFile(&fd);
+      if (NS_SUCCEEDED(rv)) {
+        self->SetCacheFile(fd);
+      } else {
+        self->Close();
+      }
+    }), NS_DISPATCH_NORMAL);
   } else {
     // We must request a temporary file descriptor from the parent process.
     RefPtr<FileBlockCache> self = this;
     rv = dom::ContentChild::GetSingleton()->AsyncOpenAnonymousTemporaryFile(
       [self](PRFileDesc* aFD) { self->SetCacheFile(aFD); });
   }
 
   if (NS_FAILED(rv)) {