Bug 856478 - Remove nsISupportsArray from mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp. r=Neil
authoraceman <acelists@atlas.sk>
Wed, 03 Apr 2013 08:01:13 -0400
changeset 16821 bbdfb610ba028bdcf0558c4fad7c217e0ba3e6bb
parent 16820 174f5ed7dc28e19371aba8e3e402476e8e53f57f
child 16822 125f9c2a7a678211b59f2c90cf076694f236eabf
push id691
push userbugzilla@standard8.plus.com
push dateSat, 06 Apr 2013 08:45:43 +0000
treeherdertry-comm-central@7e1e985cbebe [default view] [failures only]
reviewersNeil
bugs856478
Bug 856478 - Remove nsISupportsArray from mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp. r=Neil
mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp
mailnews/extensions/mailviews/src/nsMsgMailViewList.h
--- a/mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp
+++ b/mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp
@@ -130,51 +130,45 @@ nsMsgMailViewList::~nsMsgMailViewList()
 {
 
 }
 
 NS_IMETHODIMP nsMsgMailViewList::GetMailViewCount(uint32_t * aCount)
 {
     NS_ENSURE_ARG_POINTER(aCount);
 
-    if (m_mailViews)
-       m_mailViews->Count(aCount);
-    else
-        *aCount = 0;
+    *aCount = m_mailViews.Length();
     return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgMailViewList::GetMailViewAt(uint32_t aMailViewIndex, nsIMsgMailView ** aMailView)
 {
     NS_ENSURE_ARG_POINTER(aMailView);
-    NS_ENSURE_TRUE(m_mailViews, NS_ERROR_FAILURE);
+
+    uint32_t mailViewCount = m_mailViews.Length();
 
-    uint32_t mailViewCount;
-    m_mailViews->Count(&mailViewCount);
-    NS_ENSURE_TRUE(mailViewCount >= aMailViewIndex, NS_ERROR_FAILURE);
+    NS_ENSURE_ARG(mailViewCount > aMailViewIndex);
 
-    return m_mailViews->QueryElementAt(aMailViewIndex, NS_GET_IID(nsIMsgMailView),
-                                      (void **)aMailView);
+    NS_IF_ADDREF(*aMailView = m_mailViews[aMailViewIndex]);
+    return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgMailViewList::AddMailView(nsIMsgMailView * aMailView)
 {
     NS_ENSURE_ARG_POINTER(aMailView);
-    NS_ENSURE_TRUE(m_mailViews, NS_ERROR_FAILURE);
 
-    m_mailViews->AppendElement(static_cast<nsISupports*>(aMailView));
+    m_mailViews.AppendElement(aMailView);
     return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgMailViewList::RemoveMailView(nsIMsgMailView * aMailView)
 {
     NS_ENSURE_ARG_POINTER(aMailView);
-    NS_ENSURE_TRUE(m_mailViews, NS_ERROR_FAILURE);
 
-    m_mailViews->RemoveElement(static_cast<nsISupports*>(aMailView));
+    m_mailViews.RemoveElement(aMailView);
     return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgMailViewList::CreateMailView(nsIMsgMailView ** aMailView)
 {
     NS_ENSURE_ARG_POINTER(aMailView);
 
     nsMsgMailView * mailView = new nsMsgMailView;
@@ -202,20 +196,17 @@ NS_IMETHODIMP nsMsgMailViewList::Save()
     ConvertMailViewListToFilterList();
 
     // now save the filters to our file
     return mFilterList ? mFilterList->SaveToDefaultFile() : NS_ERROR_FAILURE;
 }
 
 nsresult nsMsgMailViewList::ConvertMailViewListToFilterList()
 {
-  uint32_t mailViewCount = 0;
-
-  if (m_mailViews)
-    m_mailViews->Count(&mailViewCount);
+  uint32_t mailViewCount = m_mailViews.Length();
   nsCOMPtr<nsIMsgMailView> mailView;
   nsCOMPtr<nsIMsgFilter> newMailFilter;
   nsString mailViewName;
   for (uint32_t index = 0; index < mailViewCount; index++)
   {
       GetMailViewAt(index, getter_AddRefs(mailView));
       if (!mailView)
           continue;
@@ -265,51 +256,50 @@ nsresult nsMsgMailViewList::LoadMailView
     // we wish to give to our consumers. 
       
     nsCOMPtr<nsIMsgFilterService> filterService = do_GetService(NS_MSGFILTERSERVICE_CONTRACTID, &rv);
     nsCOMPtr<nsIMsgFilterList> mfilterList;
       
     rv = filterService->OpenFilterList(file, NULL, NULL, getter_AddRefs(mFilterList));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    // now convert the filter list into our mail view objects, stripping out just the info we need
-    ConvertFilterListToMailView(mFilterList, getter_AddRefs(m_mailViews));
-    return rv;
+    return ConvertFilterListToMailViews();
 }
-
-nsresult nsMsgMailViewList::ConvertFilterListToMailView(nsIMsgFilterList * aFilterList, nsISupportsArray ** aMailViewList)
+/**
+ * Converts the filter list into our mail view objects,
+ * stripping out just the info we need.
+ */
+nsresult nsMsgMailViewList::ConvertFilterListToMailViews()
 {
     nsresult rv = NS_OK;
-    NS_ENSURE_ARG_POINTER(aFilterList);
-    NS_ENSURE_ARG_POINTER(aMailViewList);
-
-    nsCOMPtr<nsISupportsArray> mailViewList = do_CreateInstance(
-        NS_SUPPORTSARRAY_CONTRACTID);
+    m_mailViews.Clear();
 
     // iterate over each filter in the list
-    nsCOMPtr<nsIMsgFilter> msgFilter;
-    uint32_t numFilters;
-    aFilterList->GetFilterCount(&numFilters);
+    uint32_t numFilters = 0;
+    mFilterList->GetFilterCount(&numFilters);
     for (uint32_t index = 0; index < numFilters; index++)
     {
-        aFilterList->GetFilterAt(index, getter_AddRefs(msgFilter));
-        if (!msgFilter)
+        nsCOMPtr<nsIMsgFilter> msgFilter;
+        rv = mFilterList->GetFilterAt(index, getter_AddRefs(msgFilter));
+        if (NS_FAILED(rv) || !msgFilter)
             continue;
+
         // create a new nsIMsgMailView for this item
-        nsCOMPtr<nsIMsgMailView> newMailView; 
+        nsCOMPtr<nsIMsgMailView> newMailView;
         rv = CreateMailView(getter_AddRefs(newMailView));
         NS_ENSURE_SUCCESS(rv, rv);
+
         nsString filterName;
         msgFilter->GetFilterName(filterName);
         newMailView->SetMailViewName(filterName.get());
 
         nsCOMPtr<nsISupportsArray> filterSearchTerms;
-        msgFilter->GetSearchTerms(getter_AddRefs(filterSearchTerms));
-        newMailView->SetSearchTerms(filterSearchTerms);
+        rv = msgFilter->GetSearchTerms(getter_AddRefs(filterSearchTerms));
+        NS_ENSURE_SUCCESS(rv, rv);
+        rv = newMailView->SetSearchTerms(filterSearchTerms);
+        NS_ENSURE_SUCCESS(rv, rv);
 
         // now append this new mail view to our global list view
-        mailViewList->AppendElement(static_cast<nsISupports*>(newMailView));
+        m_mailViews.AppendElement(newMailView);
     }
 
-    NS_IF_ADDREF(*aMailViewList = mailViewList);
-
     return rv;
 }
--- a/mailnews/extensions/mailviews/src/nsMsgMailViewList.h
+++ b/mailnews/extensions/mailviews/src/nsMsgMailViewList.h
@@ -5,16 +5,17 @@
 
 
 #ifndef _nsMsgMailViewList_H_
 #define _nsMsgMailViewList_H_
 
 #include "nscore.h"
 #include "nsIMsgMailViewList.h"
 #include "nsCOMPtr.h"
+#include "nsCOMArray.h"
 #include "nsISupportsArray.h"
 #include "nsIStringBundle.h"
 #include "nsStringGlue.h"
 #include "nsIMsgFilterList.h"
 
 // a mail View is just a name and an array of search terms
 class nsMsgMailView : public nsIMsgMailView
 {
@@ -38,16 +39,16 @@ public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIMSGMAILVIEWLIST
 
   nsMsgMailViewList();
   virtual ~nsMsgMailViewList();
 
 protected:
   nsresult LoadMailViews(); // reads in user defined mail views from our default file
-  nsresult ConvertFilterListToMailView(nsIMsgFilterList * aFilterList, nsISupportsArray ** aMailViewList);
+  nsresult ConvertFilterListToMailViews();
   nsresult ConvertMailViewListToFilterList();
 
-  nsCOMPtr<nsISupportsArray> m_mailViews;
+  nsCOMArray<nsIMsgMailView> m_mailViews;
   nsCOMPtr<nsIMsgFilterList> mFilterList; // our internal filter list representation
 };
 
 #endif