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
--- 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)) {