nsresult
DeviceStorageRequestParent::StatFileEvent::CancelableRun()
{
  NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");

  nsCOMPtr<nsIRunnable> r;
  PRUint64 diskUsage = DeviceStorageFile::DirectoryDiskUsage(mFile->mFile);
  PRInt64 freeSpace = 0;
  nsresult rv = mFile->mFile->GetDiskSpaceAvailable(&freeSpace);
  if (NS_FAILED(rv)) {
    r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
    NS_DispatchToMainThread(r);
    return NS_OK;
  }
  nsString state;
  state.Assign(NS_LITERAL_STRING("available"));

#ifdef MOZ_WIDGET_GONK
  rv = GetSDCardStatus(state);
  if (NS_FAILED(rv)) {
    r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
    NS_DispatchToMainThread(r);
    return NS_OK;
  }
#endif
  r = new PostStatResultEvent(mParent, diskUsage, freeSpace, state);
  NS_DispatchToMainThread(r);
  return NS_OK;
}
nsresult
DeviceStorageRequestParent::PostAvailableResultEvent::CancelableRun()
{
  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");

  nsString state;
  state.Assign(NS_LITERAL_STRING("available"));
#ifdef MOZ_WIDGET_GONK
  nsresult rv = GetSDCardStatus(state);
  if (NS_FAILED(rv)) {
    state.Assign(NS_LITERAL_STRING("unavailable"));
  }
#endif

  AvailableStorageResponse response(state);
  unused << mParent->Send__delete__(mParent, response);
  return NS_OK;
}