Example #1
0
void
FileService::NotifyFileHandleCompleted(FileHandleBase* aFileHandle)
{
  MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
  MOZ_ASSERT(aFileHandle, "Null pointer!");

  MutableFileBase* mutableFile = aFileHandle->MutableFile();
  const nsACString& storageId = mutableFile->mStorageId;

  StorageInfo* storageInfo;
  if (!mStorageInfos.Get(storageId, &storageInfo)) {
    NS_ERROR("We don't know anyting about this file handle?!");
    return;
  }

  storageInfo->RemoveFileHandleQueue(aFileHandle);

  if (!storageInfo->HasRunningFileHandles()) {
    mStorageInfos.Remove(storageId);

    // See if we need to fire any complete callbacks.
    uint32_t index = 0;
    while (index < mCompleteCallbacks.Length()) {
      if (MaybeFireCallback(mCompleteCallbacks[index])) {
        mCompleteCallbacks.RemoveElementAt(index);
      }
      else {
        index++;
      }
    }
  }
}
Example #2
0
void
FileService::NotifyLockedFileCompleted(LockedFile* aLockedFile)
{
  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
  NS_ASSERTION(aLockedFile, "Null pointer!");

  FileHandle* fileHandle = aLockedFile->mFileHandle;
  const nsACString& storageId = fileHandle->mFileStorage->Id();

  FileStorageInfo* fileStorageInfo;
  if (!mFileStorageInfos.Get(storageId, &fileStorageInfo)) {
    NS_ERROR("We don't know anyting about this locked file?!");
    return;
  }

  fileStorageInfo->RemoveLockedFileQueue(aLockedFile);

  if (!fileStorageInfo->HasRunningLockedFiles()) {
    mFileStorageInfos.Remove(storageId);

    // See if we need to fire any complete callbacks.
    uint32_t index = 0;
    while (index < mCompleteCallbacks.Length()) {
      if (MaybeFireCallback(mCompleteCallbacks[index])) {
        mCompleteCallbacks.RemoveElementAt(index);
      }
      else {
        index++;
      }
    }
  }
}
Example #3
0
void
FileService::WaitForStoragesToComplete(nsTArray<nsCString>& aStorageIds,
                                       nsIRunnable* aCallback)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(!aStorageIds.IsEmpty());
  MOZ_ASSERT(aCallback);

  StoragesCompleteCallback* callback = mCompleteCallbacks.AppendElement();
  callback->mCallback = aCallback;
  callback->mStorageIds.SwapElements(aStorageIds);

  if (MaybeFireCallback(*callback)) {
    mCompleteCallbacks.RemoveElementAt(mCompleteCallbacks.Length() - 1);
  }
}
Example #4
0
void
FileService::WaitForStoragesToComplete(
                                 nsTArray<nsCOMPtr<nsIFileStorage> >& aStorages,
                                 nsIRunnable* aCallback)
{
  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
  NS_ASSERTION(!aStorages.IsEmpty(), "No databases to wait on!");
  NS_ASSERTION(aCallback, "Null pointer!");

  StoragesCompleteCallback* callback = mCompleteCallbacks.AppendElement();
  callback->mCallback = aCallback;
  callback->mStorages.SwapElements(aStorages);

  if (MaybeFireCallback(*callback)) {
    mCompleteCallbacks.RemoveElementAt(mCompleteCallbacks.Length() - 1);
  }
}