Bug 1606284 - Remove nsIAddrDBAnnouncer and nsIAddrDBListener; r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 27 Dec 2019 22:44:16 +1300
changeset 37842 20abf751b302882b21564283e628455764d044a1
parent 37841 63c80dbc24de60213e10ffe993a2f3fd24be65b6
child 37843 5a245657c1497b0cd6d9964c185ecaa959a2eb5d
push id397
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:16:13 +0000
reviewersmkmelin
bugs1606284
Bug 1606284 - Remove nsIAddrDBAnnouncer and nsIAddrDBListener; r=mkmelin
mailnews/addrbook/public/moz.build
mailnews/addrbook/public/nsIAddrDBAnnouncer.idl
mailnews/addrbook/public/nsIAddrDBListener.idl
mailnews/addrbook/public/nsIAddrDatabase.idl
mailnews/addrbook/src/nsAddrDatabase.cpp
mailnews/addrbook/src/nsAddrDatabase.h
--- a/mailnews/addrbook/public/moz.build
+++ b/mailnews/addrbook/public/moz.build
@@ -16,18 +16,16 @@ XPIDL_SOURCES += [
     'nsIAbDirSearchListener.idl',
     'nsIAbLDAPAttributeMap.idl',
     'nsIAbLDIFService.idl',
     'nsIAbListener.idl',
     'nsIAbManager.idl',
     'nsIAbView.idl',
     'nsIAddbookUrl.idl',
     'nsIAddrDatabase.idl',
-    'nsIAddrDBAnnouncer.idl',
-    'nsIAddrDBListener.idl',
     'nsIMsgVCardService.idl',
 ]
 
 if CONFIG['MOZ_LDAP_XPCOM']:
     XPIDL_SOURCES += [
         'nsIAbLDAPCard.idl',
         'nsIAbLDAPDirectory.idl',
         'nsIAbLDAPReplicationData.idl',
deleted file mode 100644
--- a/mailnews/addrbook/public/nsIAddrDBAnnouncer.idl
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsISupports.idl"
-
-
-interface nsIAbCard;
-interface nsIAbDirectory;
-interface nsIAddrDBListener;
-
-[scriptable, uuid(166b19a1-1235-4613-9601-816dedc48c9e)]
-interface nsIAddrDBAnnouncer : nsISupports {
-
-  void addListener(in nsIAddrDBListener listener);
-  void removeListener(in nsIAddrDBListener listener);
-
-  void notifyCardAttribChange(in unsigned long abCode);
-
-  /**
-   * Notify all the listeners of the database about an event performed
-   * on a card entry.
-   *
-   * @param     aAbCode               The code to indicate the type of event
-   *                                  (see nsAddrDatabase.h AB_NOTIFY_CODE for values).
-   * @param     aCard                 The card entry on which the event occurred.
-   * @param     aParent               The parent of card entry. This is set by
-   *                                  object which performs the operation.
-   */
-  void notifyCardEntryChange(in unsigned long aAbCode,
-                             in nsIAbCard aCard,
-                             in nsIAbDirectory aParent);
-
-  void notifyAnnouncerGoingAway();
-};
deleted file mode 100644
--- a/mailnews/addrbook/public/nsIAddrDBListener.idl
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "nsISupports.idl"
-
-interface nsIAbCard;
-interface nsIAbDirectory;
-
-[scriptable, uuid(5d7e5a7a-1ac9-46dc-abfd-758c98be26e9)]
-interface nsIAddrDBListener : nsISupports {
-
-  void onCardAttribChange(in unsigned long abCode);
-
-  /**
-   * Handle the card entry change event.
-   *
-   * @param     aAbCode         The code to indicate the type of event
-   *                            (see nsAddrDatabase.h AB_NOTIFY_CODE for values).
-   * @param     aCard           The card entry on which the event occurred.
-   * @param     aParent         The parent of card entry.
-   *                            If set to null, the event can be ignored.
-   *                            This happens during import & sync operations when
-   *                            listeners of a database need not be notified about
-   *                            card entry changes.
-   */
-  void onCardEntryChange(in unsigned long aAbCode,
-                         in nsIAbCard aCard,
-                         in nsIAbDirectory aParent);
-
-  void onListEntryChange(in unsigned long abCode,
-                         in nsIAbDirectory list);
-  void onAnnouncerGoingAway();
-
-};
--- a/mailnews/addrbook/public/nsIAddrDatabase.idl
+++ b/mailnews/addrbook/public/nsIAddrDatabase.idl
@@ -1,14 +1,13 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsIAddrDBAnnouncer.idl"
 #include "nsIAbCard.idl"
 #include "nsIAbDirectory.idl"
 
 interface nsIFile;
 [ptr] native nsIMdbRow (nsIMdbRow);
 %{C++
 class nsIMdbRow;
 %}
@@ -44,17 +43,17 @@ interface nsISimpleEnumerator;
 interface nsAddrDBCommitType
 {
   const long kLargeCommit = 1;
   const long kSessionCommit = 2;
   const long kCompressCommit = 3;
 };
 
 [scriptable, uuid(c54973e4-d251-4b93-a0d0-81a616225061)]
-interface nsIAddrDatabase : nsIAddrDBAnnouncer {
+interface nsIAddrDatabase : nsISupports {
 
   /**
    * Path to the address book database that this instance represents.
    */
   attribute nsIFile dbPath;
   nsIAddrDatabase open(in nsIFile dbFile, in boolean create, in boolean upgrading);
 
   void close(in boolean forceCommit);
--- a/mailnews/addrbook/src/nsAddrDatabase.cpp
+++ b/mailnews/addrbook/src/nsAddrDatabase.cpp
@@ -131,75 +131,24 @@ nsAddrDatabase::nsAddrDatabase()
       m_PopularityIndexColumnToken(0),
       m_AddressCharSetColumnToken(0),
       m_LastRecordKey(0),
       m_dbDirectory(nullptr) {}
 
 nsAddrDatabase::~nsAddrDatabase() {
   Close(false);  // better have already been closed.
 
-  // better not be any listeners, because we're going away.
-  NS_ASSERTION(m_ChangeListeners.Length() == 0, "shouldn't have any listeners");
-
   RemoveFromCache(this);
   // clean up after ourself!
   if (m_mdbPabTable) m_mdbPabTable->Release();
   NS_IF_RELEASE(m_mdbStore);
   NS_IF_RELEASE(m_mdbEnv);
 }
 
-NS_IMPL_ISUPPORTS(nsAddrDatabase, nsIAddrDatabase, nsIAddrDBAnnouncer)
-
-NS_IMETHODIMP nsAddrDatabase::AddListener(nsIAddrDBListener *listener) {
-  NS_ENSURE_ARG_POINTER(listener);
-  m_ChangeListeners.AppendElement(listener);
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsAddrDatabase::RemoveListener(nsIAddrDBListener *listener) {
-  NS_ENSURE_ARG_POINTER(listener);
-  return m_ChangeListeners.RemoveElement(listener) ? NS_OK : NS_ERROR_FAILURE;
-}
-
-NS_IMETHODIMP nsAddrDatabase::NotifyCardAttribChange(uint32_t abCode) {
-  NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(m_ChangeListeners, nsIAddrDBListener,
-                                     OnCardAttribChange, (abCode));
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsAddrDatabase::NotifyCardEntryChange(uint32_t aAbCode,
-                                                    nsIAbCard *aCard,
-                                                    nsIAbDirectory *aParent) {
-  int32_t currentDisplayNameVersion = 0;
-
-  // Update "mail.displayname.version" prefernce
-  nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-
-  prefs->GetIntPref("mail.displayname.version", &currentDisplayNameVersion);
-
-  prefs->SetIntPref("mail.displayname.version", ++currentDisplayNameVersion);
-
-  NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(m_ChangeListeners, nsIAddrDBListener,
-                                     OnCardEntryChange,
-                                     (aAbCode, aCard, aParent));
-  return NS_OK;
-}
-
-nsresult nsAddrDatabase::NotifyListEntryChange(uint32_t abCode,
-                                               nsIAbDirectory *dir) {
-  NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(m_ChangeListeners, nsIAddrDBListener,
-                                     OnListEntryChange, (abCode, dir));
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsAddrDatabase::NotifyAnnouncerGoingAway(void) {
-  NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(m_ChangeListeners, nsIAddrDBListener,
-                                     OnAnnouncerGoingAway, ());
-  return NS_OK;
-}
+NS_IMPL_ISUPPORTS(nsAddrDatabase, nsIAddrDatabase)
 
 // Apparently its not good for nsTArray to be allocated as static. Don't know
 // why it isn't but its not, so don't think about making it a static variable.
 // Maybe bz knows.
 nsTArray<nsAddrDatabase *> *nsAddrDatabase::m_dbCache = nullptr;
 
 nsTArray<nsAddrDatabase *> *nsAddrDatabase::GetDBCache() {
   if (!m_dbCache)
@@ -555,17 +504,16 @@ NS_IMETHODIMP nsAddrDatabase::CloseMDB(b
 // This is evil in the com world, but there are times we need to delete the
 // file.
 NS_IMETHODIMP nsAddrDatabase::ForceClosed() {
   nsresult err = NS_OK;
 
   // make sure someone has a reference so object won't get deleted out from
   // under us.
   NS_ADDREF_THIS();
-  NotifyAnnouncerGoingAway();
   // OK, remove from cache first and close the store.
   RemoveFromCache(this);
 
   err = CloseMDB(false);  // since we're about to delete it, no need to commit.
   NS_IF_RELEASE(m_mdbStore);
   NS_RELEASE_THIS();
   return err;
 }
@@ -1128,23 +1076,18 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewC
 
     nsCOMPtr<nsIAbDirectory> abDir = do_QueryReferent(m_dbDirectory);
     if (abDir) abDir->GetUuid(id);
 
     aNewCard->SetDirectoryId(id);
 
     nsresult merror = m_mdbPabTable->AddRow(m_mdbEnv, cardRow);
     NS_ENSURE_SUCCESS(merror, NS_ERROR_FAILURE);
-  } else
-    return rv;
-
-  //  do notification
-  if (aNotify) {
-    NotifyCardEntryChange(AB_NotifyInserted, aNewCard, aParent);
   }
+
   return rv;
 }
 
 NS_IMETHODIMP nsAddrDatabase::CreateNewListCardAndAddToDB(
     nsIAbDirectory *aList, uint32_t listRowID, nsIAbCard *newCard,
     bool notify /* = FALSE */) {
   if (!newCard || !m_mdbPabTable || !m_mdbStore || !m_mdbEnv)
     return NS_ERROR_NULL_POINTER;
@@ -1206,18 +1149,16 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewL
   nsCOMPtr<nsIAbCard> pNewCard;
   rv = AddListCardColumnsToRow(newCard, pListRow, totalAddress,
                                getter_AddRefs(pNewCard),
                                true /* aInMailingList */, aList, nullptr);
   NS_ENSURE_SUCCESS(rv, rv);
 
   addressList->AppendElement(newCard);
 
-  if (notify) NotifyCardEntryChange(AB_NotifyInserted, newCard, aList);
-
   return rv;
 }
 
 NS_IMETHODIMP nsAddrDatabase::AddListCardColumnsToRow(
     nsIAbCard *aPCard, nsIMdbRow *aPListRow, uint32_t aPos,
     nsIAbCard **aPNewCard, bool aInMailingList, nsIAbDirectory *aParent,
     nsIAbDirectory *aRoot) {
   if (!aPCard || !aPListRow || !m_mdbStore || !m_mdbEnv)
@@ -1253,32 +1194,16 @@ NS_IMETHODIMP nsAddrDatabase::AddListCar
     aPCard->GetDisplayName(name);
     if (!name.IsEmpty()) {
       AddDisplayName(pCardRow, NS_ConvertUTF16toUTF8(name).get());
       err = m_mdbPabTable->AddRow(m_mdbEnv, pCardRow);
     }
 
     CreateABCard(pCardRow, 0, aPNewCard);
 
-    if (cardWasAdded) {
-      NotifyCardEntryChange(AB_NotifyInserted, *aPNewCard, aParent);
-      if (aRoot) NotifyCardEntryChange(AB_NotifyInserted, *aPNewCard, aRoot);
-    } else if (!aInMailingList) {
-      nsresult rv;
-      nsCOMPtr<nsIAddrDBListener> parentListener(
-          do_QueryInterface(aParent, &rv));
-
-      // Ensure the parent is in the listener list (and hence wants to be
-      // notified)
-      if (NS_SUCCEEDED(rv) && m_ChangeListeners.Contains(parentListener))
-        parentListener->OnCardEntryChange(AB_NotifyInserted, aPCard, aParent);
-    } else {
-      NotifyCardEntryChange(AB_NotifyPropertyChanged, aPCard, aParent);
-    }
-
     // add a column with address row id to the list row
     mdb_token listAddressColumnToken;
 
     char columnStr[COLUMN_STR_MAX];
     PR_snprintf(columnStr, COLUMN_STR_MAX, kMailListAddressFormat, aPos);
     m_mdbStore->StringToToken(m_mdbEnv, columnStr, &listAddressColumnToken);
 
     mdbOid outOid;
@@ -1349,17 +1274,16 @@ NS_IMETHODIMP nsAddrDatabase::CreateMail
   if (NS_SUCCEEDED(err) && listRow) {
     AddListAttributeColumnsToRow(aNewList, listRow, aParent);
     AddRecordKeyColumnToRow(listRow);
     nsresult merror = m_mdbPabTable->AddRow(m_mdbEnv, listRow);
     NS_ENSURE_SUCCESS(merror, NS_ERROR_FAILURE);
 
     nsCOMPtr<nsIAbCard> listCard;
     CreateABListCard(listRow, getter_AddRefs(listCard));
-    NotifyCardEntryChange(AB_NotifyInserted, listCard, aParent);
 
     NS_RELEASE(listRow);
     return NS_OK;
   }
 
   return NS_ERROR_FAILURE;
 }
 
@@ -1449,20 +1373,16 @@ NS_IMETHODIMP nsAddrDatabase::DeleteCard
       deletedCardsTable->CutAllRows(m_mdbEnv);
       deletedCardsTable->Release();
       Commit(nsAddrDBCommitType::kCompressCommit);
     }
   }
 
   err = DeleteRow(m_mdbPabTable, pCardRow);
 
-  if (NS_SUCCEEDED(err)) {
-    if (aNotify) NotifyCardEntryChange(AB_NotifyDeleted, aCard, aParent);
-  }
-
   NS_RELEASE(pCardRow);
   return NS_OK;
 }
 
 nsresult nsAddrDatabase::DeleteCardFromListRow(nsIMdbRow *pListRow,
                                                mdb_id cardRowID,
                                                bool *cardFound) {
   NS_ENSURE_ARG_POINTER(pListRow);
@@ -1616,18 +1536,16 @@ NS_IMETHODIMP nsAddrDatabase::EditCard(n
   err = m_mdbStore->GetRow(m_mdbEnv, &rowOid, getter_AddRefs(cardRow));
   NS_ENSURE_SUCCESS(err, err);
 
   if (!cardRow) return NS_OK;
 
   err = AddAttributeColumnsToRow(aCard, cardRow);
   NS_ENSURE_SUCCESS(err, err);
 
-  if (aNotify) NotifyCardEntryChange(AB_NotifyPropertyChanged, aCard, aParent);
-
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAddrDatabase::ContainsCard(nsIAbCard *card, bool *hasCard) {
   if (!card || !m_mdbPabTable || !m_mdbEnv) return NS_ERROR_NULL_POINTER;
 
   nsresult err = NS_OK;
   mdb_bool hasOid;
@@ -2014,55 +1932,37 @@ nsresult nsAddrDatabase::GetListCardFrom
   return err;
 }
 
 nsresult nsAddrDatabase::GetListFromDB(nsIAbDirectory *newList,
                                        nsIMdbRow *listRow) {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
-class nsAddrDBEnumerator : public nsSimpleEnumerator, public nsIAddrDBListener {
+class nsAddrDBEnumerator : public nsSimpleEnumerator {
  public:
-  NS_DECL_ISUPPORTS_INHERITED
-
   const nsID &DefaultInterface() override { return NS_GET_IID(nsIAbCard); }
 
   // nsISimpleEnumerator methods:
   NS_DECL_NSISIMPLEENUMERATOR
-  NS_DECL_NSIADDRDBLISTENER
 
   // nsAddrDBEnumerator methods:
   explicit nsAddrDBEnumerator(nsAddrDatabase *aDb);
   void Clear();
 
  protected:
-  ~nsAddrDBEnumerator() override;
   RefPtr<nsAddrDatabase> mDb;
   nsIMdbTable *mDbTable;
   nsCOMPtr<nsIMdbTableRowCursor> mRowCursor;
   nsCOMPtr<nsIMdbRow> mCurrentRow;
   mdb_pos mRowPos;
 };
 
 nsAddrDBEnumerator::nsAddrDBEnumerator(nsAddrDatabase *aDb)
-    : mDb(aDb), mDbTable(aDb->GetPabTable()), mRowPos(-1) {
-  if (aDb) aDb->AddListener(this);
-}
-
-nsAddrDBEnumerator::~nsAddrDBEnumerator() { Clear(); }
-
-void nsAddrDBEnumerator::Clear() {
-  mRowCursor = nullptr;
-  mCurrentRow = nullptr;
-  mDbTable = nullptr;
-  if (mDb) mDb->RemoveListener(this);
-}
-
-NS_IMPL_ISUPPORTS_INHERITED(nsAddrDBEnumerator, nsSimpleEnumerator,
-                            nsIAddrDBListener)
+    : mDb(aDb), mDbTable(aDb->GetPabTable()), mRowPos(-1) {}
 
 NS_IMETHODIMP
 nsAddrDBEnumerator::HasMoreElements(bool *aResult) {
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = false;
 
   if (!mDbTable || !mDb->GetEnv()) {
     return NS_ERROR_NULL_POINTER;
@@ -2130,40 +2030,16 @@ nsAddrDBEnumerator::GetNext(nsISupports 
     }
 
     mRowCursor->NextRow(mDb->GetEnv(), getter_AddRefs(mCurrentRow), &mRowPos);
   }
 
   return NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP nsAddrDBEnumerator::OnCardAttribChange(uint32_t abCode) {
-  return NS_OK;
-}
-
-/* void onCardEntryChange (in unsigned long aAbCode, in nsIAbCard aCard, in
- * nsIAbDirectory aParent); */
-NS_IMETHODIMP nsAddrDBEnumerator::OnCardEntryChange(uint32_t aAbCode,
-                                                    nsIAbCard *aCard,
-                                                    nsIAbDirectory *aParent) {
-  return NS_OK;
-}
-
-/* void onListEntryChange (in unsigned long abCode, in nsIAbDirectory list); */
-NS_IMETHODIMP nsAddrDBEnumerator::OnListEntryChange(uint32_t abCode,
-                                                    nsIAbDirectory *list) {
-  return NS_OK;
-}
-
-/* void onAnnouncerGoingAway (); */
-NS_IMETHODIMP nsAddrDBEnumerator::OnAnnouncerGoingAway() {
-  Clear();
-  return NS_OK;
-}
-
 class nsListAddressEnumerator final : public nsSimpleEnumerator {
  public:
   const nsID &DefaultInterface() override { return NS_GET_IID(nsIAbCard); }
 
   // nsISimpleEnumerator methods:
   NS_DECL_NSISIMPLEENUMERATOR
 
   // nsListAddressEnumerator methods:
--- a/mailnews/addrbook/src/nsAddrDatabase.h
+++ b/mailnews/addrbook/src/nsAddrDatabase.h
@@ -6,33 +6,31 @@
 #ifndef _nsAddrDatabase_H_
 #define _nsAddrDatabase_H_
 
 #include "mozilla/Attributes.h"
 #include "nsIAddrDatabase.h"
 #include "nsIFile.h"
 #include "mdb.h"
 #include "nsString.h"
-#include "nsIAddrDBListener.h"
 #include "nsCOMPtr.h"
 #include "nsTObserverArray.h"
 #include "nsIWeakReferenceUtils.h"
 
 typedef enum {
   AB_NotifyInserted,
   AB_NotifyDeleted,
   AB_NotifyPropertyChanged
 } AB_NOTIFY_CODE;
 
 class nsAddrDatabase : public nsIAddrDatabase {
   using PathString = mozilla::PathString;
 
  public:
   NS_DECL_THREADSAFE_ISUPPORTS
-  NS_DECL_NSIADDRDBANNOUNCER
   //////////////////////////////////////////////////////////////////////////////
   // nsIAddrDatabase methods:
 
   NS_IMETHOD GetDbPath(nsIFile **aDbPath) override;
   NS_IMETHOD SetDbPath(nsIFile *aDbPath) override;
   NS_IMETHOD Open(nsIFile *aMabFile, bool aCreate, bool upgrading,
                   nsIAddrDatabase **pCardDB) override;
   NS_IMETHOD Close(bool forceCommit) override;
@@ -424,17 +422,16 @@ class nsAddrDatabase : public nsIAddrDat
   nsresult DeleteRow(nsIMdbTable *dbTable, nsIMdbRow *dbRow);
 
   nsIMdbEnv *m_mdbEnv;  // to be used in all the db calls.
   nsIMdbStore *m_mdbStore;
   nsIMdbTable *m_mdbPabTable;
   nsCOMPtr<nsIFile> m_dbName;
   bool m_mdbTokensInitialized;
   bool m_mdbDeletedCardsTableRemoved;
-  nsTObserverArray<nsIAddrDBListener *> m_ChangeListeners;
 
   mdb_kind m_PabTableKind;
   mdb_kind m_MailListTableKind;
   mdb_kind m_DeletedCardsTableKind;
 
   mdb_scope m_CardRowScopeToken;
   mdb_scope m_ListRowScopeToken;
   mdb_scope m_DataRowScopeToken;