Bug 1594892 - xpidl [array] removal from nsIMsgDatabase.MarkThreadRead(). r=mkmelin
authorBen Campbell <benc@thunderbird.net>
Thu, 19 Dec 2019 14:11:05 +0200
changeset 37781 867262f56df2d72a359131a2b6c8ee2cb3dd1135
parent 37780 205335c2060659b8df60817d1d2cd2ef6356e700
child 37782 f6484bfeb6afeb5b28322713847e6e4d4563c1b4
push id397
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:16:13 +0000
reviewersmkmelin
bugs1594892
Bug 1594892 - xpidl [array] removal from nsIMsgDatabase.MarkThreadRead(). r=mkmelin
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/db/msgdb/public/nsIMsgDatabase.idl
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/local/src/nsLocalMailFolder.cpp
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -1409,23 +1409,19 @@ nsMsgDBFolder::MarkAllMessagesRead(nsIMs
   }
 
   SetHasNewMessages(false);
   return rv;
 }
 
 NS_IMETHODIMP nsMsgDBFolder::MarkThreadRead(nsIMsgThread *thread) {
   nsresult rv = GetDatabase();
-  if (NS_SUCCEEDED(rv)) {
-    nsMsgKey *keys;
-    uint32_t numKeys;
-    rv = mDatabase->MarkThreadRead(thread, nullptr, &numKeys, &keys);
-    free(keys);
-  }
-  return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
+  nsTArray<nsMsgKey> keys;
+  return mDatabase->MarkThreadRead(thread, nullptr, keys);
 }
 
 NS_IMETHODIMP
 nsMsgDBFolder::OnStartRunningUrl(nsIURI *aUrl) { return NS_OK; }
 
 NS_IMETHODIMP
 nsMsgDBFolder::OnStopRunningUrl(nsIURI *aUrl, nsresult aExitCode) {
   NS_ENSURE_ARG_POINTER(aUrl);
--- a/mailnews/db/msgdb/public/nsIMsgDatabase.idl
+++ b/mailnews/db/msgdb/public/nsIMsgDatabase.idl
@@ -383,19 +383,17 @@ interface nsIMsgDatabase : nsIDBChangeAn
                          in nsIDBChangeListener instigator);
 
   void MarkForwarded(in nsMsgKey key, in boolean bForwarded,
                            in nsIDBChangeListener instigator);
 
   void MarkHasAttachments(in nsMsgKey key, in boolean bHasAttachments,
                                 in nsIDBChangeListener instigator);
 
-  void MarkThreadRead(in nsIMsgThread thread, in nsIDBChangeListener instigator,
-                      out unsigned long aCount,
-                      [array, size_is(aCount)] out nsMsgKey aKeys);
+  Array<nsMsgKey> MarkThreadRead(in nsIMsgThread thread, in nsIDBChangeListener instigator);
 
   /// Mark the specified thread ignored.
   void MarkThreadIgnored(in nsIMsgThread thread, in nsMsgKey threadKey,
                          in boolean bIgnored,
                          in nsIDBChangeListener instigator);
 
   /// Mark the specified thread watched.
   void MarkThreadWatched(in nsIMsgThread thread, in nsMsgKey threadKey,
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -2047,51 +2047,40 @@ NS_IMETHODIMP nsMsgDatabase::MarkHasAtta
     nsMsgKey key, bool bHasAttachments, nsIDBChangeListener *instigator) {
   return SetKeyFlag(key, bHasAttachments, nsMsgMessageFlags::Attachment,
                     instigator);
 }
 
 NS_IMETHODIMP
 nsMsgDatabase::MarkThreadRead(nsIMsgThread *thread,
                               nsIDBChangeListener *instigator,
-                              uint32_t *aNumMarked, nsMsgKey **aThoseMarked) {
+                              nsTArray<nsMsgKey> &aThoseMarkedRead) {
   NS_ENSURE_ARG_POINTER(thread);
-  NS_ENSURE_ARG_POINTER(aNumMarked);
-  NS_ENSURE_ARG_POINTER(aThoseMarked);
+  aThoseMarkedRead.ClearAndRetainStorage();
   nsresult rv = NS_OK;
 
   uint32_t numChildren;
-  nsTArray<nsMsgKey> thoseMarked;
   thread->GetNumChildren(&numChildren);
+  aThoseMarkedRead.SetCapacity(numChildren);
   for (uint32_t curChildIndex = 0; curChildIndex < numChildren;
        curChildIndex++) {
     nsCOMPtr<nsIMsgDBHdr> child;
 
     rv = thread->GetChildHdrAt(curChildIndex, getter_AddRefs(child));
     if (NS_SUCCEEDED(rv) && child) {
       bool isRead = true;
       IsHeaderRead(child, &isRead);
       if (!isRead) {
         nsMsgKey key;
         if (NS_SUCCEEDED(child->GetMessageKey(&key)))
-          thoseMarked.AppendElement(key);
+          aThoseMarkedRead.AppendElement(key);
         MarkHdrRead(child, true, instigator);
       }
     }
   }
-
-  *aNumMarked = thoseMarked.Length();
-
-  if (thoseMarked.Length()) {
-    *aThoseMarked = (nsMsgKey *)moz_xmemdup(
-        &thoseMarked[0], thoseMarked.Length() * sizeof(nsMsgKey));
-    if (!*aThoseMarked) return NS_ERROR_OUT_OF_MEMORY;
-  } else
-    *aThoseMarked = nullptr;
-
   return rv;
 }
 
 NS_IMETHODIMP
 nsMsgDatabase::MarkThreadIgnored(nsIMsgThread *thread, nsMsgKey threadKey,
                                  bool bIgnored,
                                  nsIDBChangeListener *instigator) {
   NS_ENSURE_ARG(thread);
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -1722,23 +1722,22 @@ nsImapMailFolder::MarkAllMessagesRead(ns
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP nsImapMailFolder::MarkThreadRead(nsIMsgThread *thread) {
   nsresult rv = GetDatabase();
   if (NS_SUCCEEDED(rv)) {
-    nsMsgKey *keys;
-    uint32_t numKeys;
-    rv = mDatabase->MarkThreadRead(thread, nullptr, &numKeys, &keys);
-    if (NS_SUCCEEDED(rv) && numKeys) {
-      rv = StoreImapFlags(kImapMsgSeenFlag, true, keys, numKeys, nullptr);
+    nsTArray<nsMsgKey> keys;
+    rv = mDatabase->MarkThreadRead(thread, nullptr, keys);
+    if (NS_SUCCEEDED(rv) && keys.Length() > 0) {
+      rv = StoreImapFlags(kImapMsgSeenFlag, true, keys.Elements(),
+                          keys.Length(), nullptr);
       mDatabase->Commit(nsMsgDBCommitType::kLargeCommit);
-      free(keys);
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP nsImapMailFolder::ReadFromFolderCacheElem(
     nsIMsgFolderCacheElement *element) {
   nsresult rv = nsMsgDBFolder::ReadFromFolderCacheElem(element);
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -1157,38 +1157,38 @@ nsMsgLocalMailFolder::MarkAllMessagesRea
   free(thoseMarked);
   return rv;
 }
 
 NS_IMETHODIMP nsMsgLocalMailFolder::MarkThreadRead(nsIMsgThread *thread) {
   nsresult rv = GetDatabase();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsMsgKey *thoseMarked = nullptr;
-  uint32_t numMarked = 0;
-  rv = mDatabase->MarkThreadRead(thread, nullptr, &numMarked, &thoseMarked);
-  if (NS_FAILED(rv) || !numMarked || !thoseMarked) return rv;
-
-  do {
-    nsCOMPtr<nsIMutableArray> messages;
-    rv = MsgGetHdrsFromKeys(mDatabase, thoseMarked, numMarked,
-                            getter_AddRefs(messages));
-    if (NS_FAILED(rv)) break;
-
-    nsCOMPtr<nsIMsgPluggableStore> msgStore;
-    rv = GetMsgStore(getter_AddRefs(msgStore));
-    if (NS_FAILED(rv)) break;
-
-    rv = msgStore->ChangeFlags(messages, nsMsgMessageFlags::Read, true);
-    if (NS_FAILED(rv)) break;
-
-    mDatabase->Commit(nsMsgDBCommitType::kLargeCommit);
-  } while (false);
-
-  free(thoseMarked);
+  nsTArray<nsMsgKey> thoseMarked;
+  rv = mDatabase->MarkThreadRead(thread, nullptr, thoseMarked);
+  NS_ENSURE_SUCCESS(rv, rv);
+  if (thoseMarked.IsEmpty()) {
+    return NS_OK;
+  }
+
+  nsCOMPtr<nsIMutableArray> messages;
+  rv = MsgGetHdrsFromKeys(mDatabase, thoseMarked.Elements(),
+                          thoseMarked.Length(),
+                          getter_AddRefs(messages));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIMsgPluggableStore> msgStore;
+  rv = GetMsgStore(getter_AddRefs(msgStore));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  rv = msgStore->ChangeFlags(messages, nsMsgMessageFlags::Read, true);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  mDatabase->Commit(nsMsgDBCommitType::kLargeCommit);
+
   return rv;
 }
 
 nsresult nsMsgLocalMailFolder::InitCopyState(
     nsISupports *aSupport, nsIArray *messages, bool isMove,
     nsIMsgCopyServiceListener *listener, nsIMsgWindow *msgWindow, bool isFolder,
     bool allowUndo) {
   nsCOMPtr<nsIFile> path;