Пример #1
0
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();
  }
}
Пример #2
0
/* 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();
}