NS_IMETHODIMP FileSystemTaskParentBase::Run() { // This method can run in 2 different threads. Here why: // 1. We are are on the I/O thread and we call IOWork(). // 2. After step 1, it returns back to the PBackground thread. // 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; }
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; }