CreateFileTask::CreateFileTask(FileSystemBase* aFileSystem, const FileSystemCreateFileParams& aParam, FileSystemRequestParent* aParent) : FileSystemTaskBase(aFileSystem, aParam, aParent) , mReplace(false) { MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!"); MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); MOZ_ASSERT(aFileSystem); GetOutputBufferSize(); mTargetRealPath = aParam.realPath(); mReplace = aParam.replace(); auto& data = aParam.data(); if (data.type() == FileSystemFileDataValue::TArrayOfuint8_t) { mArrayData = data; return; } BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(data)); RefPtr<BlobImpl> blobImpl = bp->GetBlobImpl(); MOZ_ASSERT(blobImpl, "blobData should not be null."); ErrorResult rv; blobImpl->GetInternalStream(getter_AddRefs(mBlobStream), rv); if (NS_WARN_IF(rv.Failed())) { rv.SuppressException(); } }
CreateFileTask::CreateFileTask(FileSystemBase* aFileSystem, const FileSystemCreateFileParams& aParam, FileSystemRequestParent* aParent) : FileSystemTaskBase(aFileSystem, aParam, aParent) , mReplace(false) { MOZ_ASSERT(FileSystemUtils::IsParentProcess(), "Only call from parent process!"); MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); MOZ_ASSERT(aFileSystem); GetOutputBufferSize(); mTargetRealPath = aParam.realPath(); mReplace = aParam.replace(); auto& data = aParam.data(); if (data.type() == FileSystemFileDataValue::TArrayOfuint8_t) { mArrayData = data; return; } BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(data)); nsCOMPtr<nsIDOMBlob> blobData = bp->GetBlob(); MOZ_ASSERT(blobData, "blobData should not be null."); nsresult rv = blobData->GetInternalStream(getter_AddRefs(mBlobStream)); NS_WARN_IF(NS_FAILED(rv)); }
FileSystemParams CreateFileTask::GetRequestParams(const nsString& aFileSystem) const { MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); FileSystemCreateFileParams param; param.filesystem() = aFileSystem; param.realPath() = mTargetRealPath; param.replace() = mReplace; if (mBlobData) { BlobChild* actor = ContentChild::GetSingleton()->GetOrCreateActorForBlob(mBlobData); if (actor) { param.data() = actor; } } else { param.data() = mArrayData; } return param; }
/* static */ already_AddRefed<CreateFileTaskParent> CreateFileTaskParent::Create(FileSystemBase* aFileSystem, const FileSystemCreateFileParams& aParam, FileSystemRequestParent* aParent, ErrorResult& aRv) { MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!"); AssertIsOnBackgroundThread(); MOZ_ASSERT(aFileSystem); RefPtr<CreateFileTaskParent> task = new CreateFileTaskParent(aFileSystem, aParam, aParent); NS_ConvertUTF16toUTF8 path(aParam.realPath()); aRv = NS_NewNativeLocalFile(path, true, getter_AddRefs(task->mTargetPath)); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } task->mReplace = aParam.replace(); const FileSystemFileDataValue& data = aParam.data(); if (data.type() == FileSystemFileDataValue::TArrayOfuint8_t) { task->mArrayData = data; return task.forget(); } MOZ_ASSERT(data.type() == FileSystemFileDataValue::TPBlobParent); BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(data)); task->mBlobImpl = bp->GetBlobImpl(); MOZ_ASSERT(task->mBlobImpl, "blobData should not be null."); return task.forget(); }