Bug 1408722 - Fix sync runnables to return NS_OK and pass result differently. r=aceman
authorJorg K <jorgk@jorgk.com>
Sun, 15 Oct 2017 23:51:31 +0200
changeset 29190 af57e5297b947197ec47b3fc529446ceccaee146
parent 29189 57c2c0059ba57102d7d80d6749a862daff1973bf
child 29191 56ff0ad0e707eba1500736aa30b1c0e6b8e0c7d1
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman
bugs1408722
Bug 1408722 - Fix sync runnables to return NS_OK and pass result differently. r=aceman
mailnews/import/becky/src/nsBeckyMail.cpp
mailnews/mime/src/mimecms.cpp
--- a/mailnews/import/becky/src/nsBeckyMail.cpp
+++ b/mailnews/import/becky/src/nsBeckyMail.cpp
@@ -365,16 +365,18 @@ IsEndOfMessage(const nsCString &aLine)
 }
 
 class ImportMessageRunnable: public mozilla::Runnable
 {
 public:
   ImportMessageRunnable(nsIFile *aMessageFile,
                         nsIMsgFolder *aFolder);
   NS_DECL_NSIRUNNABLE
+  nsresult mResult;
+
 private:
   nsresult WriteHeaders(nsCString &aHeaders, nsIOutputStream *aOutputStream);
   nsresult HandleHeaderLine(const nsCString &aHeaderLine, nsACString &aHeaders);
   nsresult GetAttachmentFile(nsIFile *aMailboxFile,
                              const nsCString &aHeader,
                              nsIFile **_retval);
   nsresult WriteAttachmentFile(nsIFile *aMailboxFile,
                                const nsCString &aHeader,
@@ -492,84 +494,86 @@ ImportMessageRunnable::WriteAttachmentFi
   }
 
   return rv;
 }
 
 NS_IMETHODIMP ImportMessageRunnable::Run()
 {
   nsCOMPtr<nsIMsgPluggableStore> msgStore;
-  nsresult rv = mFolder->GetMsgStore(getter_AddRefs(msgStore));
-  NS_ENSURE_SUCCESS(rv, rv);
+  mResult = mFolder->GetMsgStore(getter_AddRefs(msgStore));
+  NS_ENSURE_SUCCESS(mResult, NS_OK);
 
   nsCOMPtr<nsILineInputStream> lineStream;
-  rv = nsBeckyUtils::CreateLineInputStream(mMessageFile,
-                                           getter_AddRefs(lineStream));
-  NS_ENSURE_SUCCESS(rv, rv);
+  mResult = nsBeckyUtils::CreateLineInputStream(mMessageFile,
+                                                getter_AddRefs(lineStream));
+  NS_ENSURE_SUCCESS(mResult, NS_OK);
 
   bool reusable;
   nsCOMPtr<nsIMsgDBHdr> msgHdr;
   nsCOMPtr<nsIOutputStream> outputStream;
-  rv = msgStore->GetNewMsgOutputStream(mFolder, getter_AddRefs(msgHdr), &reusable,
-                                       getter_AddRefs(outputStream));
-  NS_ENSURE_SUCCESS(rv, rv);
+  mResult = msgStore->GetNewMsgOutputStream(mFolder, getter_AddRefs(msgHdr), &reusable,
+                                            getter_AddRefs(outputStream));
+  NS_ENSURE_SUCCESS(mResult, NS_OK);
 
   bool inHeader = true;
   bool more = true;
   nsAutoCString headers;
-  while (NS_SUCCEEDED(rv) && more) {
+  while (NS_SUCCEEDED(mResult) && more) {
     nsAutoCString line;
-    rv = lineStream->ReadLine(line, &more);
-    if (NS_FAILED(rv))
+    mResult = lineStream->ReadLine(line, &more);
+    if (NS_FAILED(mResult))
       break;
 
     if (inHeader) {
       if (IsEndOfHeaders(line)) {
         inHeader = false;
-        rv = WriteHeaders(headers, outputStream);
+        mResult = WriteHeaders(headers, outputStream);
       } else {
-        rv = HandleHeaderLine(line, headers);
+        mResult = HandleHeaderLine(line, headers);
       }
     } else if (IsEndOfMessage(line)) {
       inHeader = true;
-      rv = msgStore->FinishNewMessage(outputStream, msgHdr);
+      mResult = msgStore->FinishNewMessage(outputStream, msgHdr);
       if (!reusable)
         outputStream->Close();
-      rv = msgStore->GetNewMsgOutputStream(mFolder, getter_AddRefs(msgHdr), &reusable,
-                                           getter_AddRefs(outputStream));
+      mResult = msgStore->GetNewMsgOutputStream(mFolder, getter_AddRefs(msgHdr), &reusable,
+                                                getter_AddRefs(outputStream));
     } else if (IsBeckyIncludeLine(line)) {
-      rv = WriteAttachmentFile(mMessageFile, line, outputStream);
+      mResult = WriteAttachmentFile(mMessageFile, line, outputStream);
     } else {
       uint32_t writtenBytes = 0;
       if (StringBeginsWith(line, NS_LITERAL_CSTRING("..")))
         line.Cut(0, 1);
       else if (CheckHeaderKey(line, "From"))
         line.Insert('>', 0);
 
       line.AppendLiteral(MSG_LINEBREAK);
-      rv = outputStream->Write(line.get(), line.Length(), &writtenBytes);
+      mResult = outputStream->Write(line.get(), line.Length(), &writtenBytes);
     }
   }
 
   if (outputStream) {
-    if (NS_FAILED(rv))
+    if (NS_FAILED(mResult))
       msgStore->DiscardNewMessage(outputStream, msgHdr);
     outputStream->Close();
   }
 
-  return rv;
+  return NS_OK;
 }
 
 static
 nsresult ProxyImportMessage(nsIFile *aMessageFile,
                             nsIMsgFolder *aFolder)
 {
   RefPtr<ImportMessageRunnable> importMessage =
     new ImportMessageRunnable(aMessageFile, aFolder);
-  return NS_DispatchToMainThread(importMessage, NS_DISPATCH_SYNC);
+  nsresult rv = NS_DispatchToMainThread(importMessage, NS_DISPATCH_SYNC);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return importMessage->mResult;
 }
 
 nsresult
 nsBeckyMail::ImportMailFile(nsIFile *aMailFile,
                             nsIMsgFolder *aDestination)
 {
   int64_t size;
   aMailFile->GetFileSize(&size);
--- a/mailnews/mime/src/mimecms.cpp
+++ b/mailnews/mime/src/mimecms.cpp
@@ -242,16 +242,18 @@ protected:
 };
 
 class SignedStatusRunnable : public mozilla::Runnable
 {
 public:
   SignedStatusRunnable(const nsMainThreadPtrHandle<nsIMsgSMIMEHeaderSink> &aSink, int32_t aNestingLevel,
                        int32_t aSignatureStatus, nsIX509Cert *aSignerCert);
   NS_DECL_NSIRUNNABLE
+  nsresult mResult;
+
 protected:
   nsMainThreadPtrHandle<nsIMsgSMIMEHeaderSink> m_sink;
   int32_t m_nestingLevel;
   int32_t m_signatureStatus;
   nsCOMPtr<nsIX509Cert> m_signerCert;
 };
 
 SignedStatusRunnable::SignedStatusRunnable(const nsMainThreadPtrHandle<nsIMsgSMIMEHeaderSink> &aSink,
@@ -261,28 +263,31 @@ SignedStatusRunnable::SignedStatusRunnab
   mozilla::Runnable("SignedStatusRunnable"),
   m_sink(aSink), m_nestingLevel(aNestingLevel),
   m_signatureStatus(aSignatureStatus), m_signerCert(aSignerCert)
 {
 }
 
 NS_IMETHODIMP SignedStatusRunnable::Run()
 {
-  return m_sink->SignedStatus(m_nestingLevel, m_signatureStatus, m_signerCert);
+  mResult = m_sink->SignedStatus(m_nestingLevel, m_signatureStatus, m_signerCert);
+  return NS_OK;
 }
 
 
 nsresult ProxySignedStatus(const nsMainThreadPtrHandle<nsIMsgSMIMEHeaderSink> &aSink,
                            int32_t aNestingLevel,
                            int32_t aSignatureStatus,
                            nsIX509Cert *aSignerCert)
 {
   RefPtr<SignedStatusRunnable> signedStatus =
     new SignedStatusRunnable(aSink, aNestingLevel, aSignatureStatus, aSignerCert);
-  return NS_DispatchToMainThread(signedStatus, NS_DISPATCH_SYNC);
+  nsresult rv = NS_DispatchToMainThread(signedStatus, NS_DISPATCH_SYNC);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return signedStatus->mResult;
 }
 
 NS_IMPL_ISUPPORTS(nsSMimeVerificationListener, nsISMimeVerificationListener)
 
 nsSMimeVerificationListener::nsSMimeVerificationListener(const char *aFromAddr, const char *aFromName,
                                                          const char *aSenderAddr, const char *aSenderName,
                                                          nsIMsgSMIMEHeaderSink *aHeaderSink, int32_t aMimeNestingLevel)
 {