Exemplo n.º 1
0
bool
GMPStorageParent::RecvWrite(const nsCString& aRecordName,
                            InfallibleTArray<uint8_t>&& aBytes)
{
  LOGD(("GMPStorageParent[%p]::RecvWrite(record='%s') %d bytes",
        this, aRecordName.get(), aBytes.Length()));

  if (mShutdown) {
    return false;
  }

  if (!mStorage->IsOpen(aRecordName)) {
    LOGD(("GMPStorageParent[%p]::RecvWrite(record='%s') failed record not open",
          this, aRecordName.get()));
    Unused << SendWriteComplete(aRecordName, GMPClosedErr);
    return true;
  }

  if (aBytes.Length() > GMP_MAX_RECORD_SIZE) {
    LOGD(("GMPStorageParent[%p]::RecvWrite(record='%s') failed record too big",
          this, aRecordName.get()));
    Unused << SendWriteComplete(aRecordName, GMPQuotaExceededErr);
    return true;
  }

  GMPErr rv = mStorage->Write(aRecordName, aBytes);
  LOGD(("GMPStorageParent[%p]::RecvWrite(record='%s') write complete rv=%d",
        this, aRecordName.get(), rv));

  Unused << SendWriteComplete(aRecordName, rv);

  return true;
}
Exemplo n.º 2
0
bool
GMPStorageParent::RecvWrite(const nsCString& aRecordName,
                            const InfallibleTArray<uint8_t>& aBytes)
{
  LOGD(("%s::%s: %p record=%s", __CLASS__, __FUNCTION__, this, aRecordName.get()));

  if (mShutdown) {
    return true;
  }
  if (aBytes.Length() > GMP_MAX_RECORD_SIZE) {
    unused << SendWriteComplete(aRecordName, GMPQuotaExceededErr);
    return true;
  }

  PRFileDesc* fd = mFiles.Get(aRecordName);
  if (!fd) {
    unused << SendWriteComplete(aRecordName, GMPGenericErr);
    return true;
  }

  // Write operations overwrite the entire record. So re-open the file
  // in truncate mode, to clear its contents.
  PR_Close(fd);
  mFiles.Remove(aRecordName);
  if (NS_FAILED(OpenStorageFile(aRecordName, mOrigin, Truncate, &fd))) {
    unused << SendWriteComplete(aRecordName, GMPGenericErr);
    return true;
  }
  mFiles.Put(aRecordName, fd);

  int32_t bytesWritten = PR_Write(fd, aBytes.Elements(), aBytes.Length());
  auto res = (bytesWritten == (int32_t)aBytes.Length()) ? GMPNoErr : GMPGenericErr;
  unused << SendWriteComplete(aRecordName, res);
  return true;
}