コード例 #1
0
void
FileSystemTaskParentBase::Start()
{
  AssertIsOnBackgroundThread();
  mFileSystem->AssertIsOnOwningThread();

  DebugOnly<nsresult> rv = DispatchToIOThread(this);
  NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "DispatchToIOThread failed");
}
コード例 #2
0
NS_IMETHODIMP
FileSystemTaskParentBase::Run()
{
  // This method can run in 3 different threads. Here why:
  // 1. if we are on the main-thread it's because the task must do something
  //    here. If no errors are returned we go the step 2.
  // 2. We can be here directly if the task doesn't have nothing to do on the
  //    main-thread. We are are on the I/O thread and we call IOWork().
  // 3. Both step 1 (in case of error) and step 2 end up here where return the
  //    value back to the PBackground thread.
  if (NS_IsMainThread()) {
    MOZ_ASSERT(NeedToGoToMainThread());

    nsresult rv = MainThreadWork();
    if (NS_WARN_IF(NS_FAILED(rv))) {
      SetError(rv);

      // Something when wrong. Let's go to the Background thread directly
      // skipping the I/O thread step.
      rv = mBackgroundEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
      if (NS_WARN_IF(NS_FAILED(rv))) {
        return rv;
      }
    }

    // Next step must happen on the I/O thread.
    rv = DispatchToIOThread(this);
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
    }

    return NS_OK;
  }

  // Run I/O thread tasks
  if (!IsOnBackgroundThread()) {
    nsresult rv = IOWork();
    if (NS_WARN_IF(NS_FAILED(rv))) {
      SetError(rv);
    }

    // Let's go back to PBackground thread to finish the work.
    rv = mBackgroundEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
    }

    return NS_OK;
  }

  // If we are here, it's because the I/O work has been done and we have to
  // handle the result back via IPC.
  AssertIsOnBackgroundThread();
  HandleResult();
  return NS_OK;
}
コード例 #3
0
void
FileSystemTaskParentBase::Start()
{
  AssertIsOnBackgroundThread();
  mFileSystem->AssertIsOnOwningThread();

  if (NeedToGoToMainThread()) {
    nsresult rv = NS_DispatchToMainThread(this, NS_DISPATCH_NORMAL);
    NS_WARN_IF(NS_FAILED(rv));
    return;
  }

  nsresult rv = DispatchToIOThread(this);
  NS_WARN_IF(NS_FAILED(rv));
}