Bug 1346987 - Part 2: Stop using the PContent::Msg_OpenAnonymousTemporaryFile sync IPC message for blob storage; r=baku

This commit is contained in:
Ehsan Akhgari 2017-03-13 19:07:15 -04:00
Родитель 4482865081
Коммит e414903d6e
1 изменённых файлов: 16 добавлений и 8 удалений

Просмотреть файл

@ -75,7 +75,6 @@ public:
: mBlobStorage(aBlobStorage)
, mFD(aFD)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aBlobStorage);
MOZ_ASSERT(aFD);
}
@ -111,6 +110,7 @@ public:
: mBlobStorage(aBlobStorage)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(aBlobStorage);
}
@ -118,14 +118,11 @@ public:
Run() override
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(XRE_IsParentProcess());
PRFileDesc* tempFD = nullptr;
nsresult rv = NS_OpenAnonymousTemporaryFile(&tempFD);
if (NS_WARN_IF(NS_FAILED(rv))) {
// In sandboxed context we are not allowed to create temporary files, but
// this doesn't mean that BlobStorage should fail. We can continue to
// store data in memory. We don't change the storageType so that we don't
// try to create a temporary file again.
return NS_OK;
}
@ -534,9 +531,20 @@ MutableBlobStorage::ShouldBeTemporaryStorage(uint64_t aSize) const
nsresult
MutableBlobStorage::MaybeCreateTemporaryFile()
{
nsresult rv = DispatchToIOThread(new CreateTemporaryFileRunnable(this));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
if (XRE_IsParentProcess()) {
nsresult rv = DispatchToIOThread(new CreateTemporaryFileRunnable(this));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else {
RefPtr<MutableBlobStorage> self(this);
ContentChild::GetSingleton()->
AsyncOpenAnonymousTemporaryFile([self](PRFileDesc* prfile) {
if (prfile) {
// The ownership of the prfile is moved to the FileCreatedRunnable.
NS_DispatchToMainThread(new FileCreatedRunnable(self, prfile));
}
});
}
mStorageState = eWaitingForTemporaryFile;