Bug 1522453 - Allow tests to reload the address book with a notification. r=mkmelin,jorgk a=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 18 Feb 2019 11:01:40 +1300
changeset 32110 82a60dbc0d9521e028dec410908ddb882a8066ce
parent 32109 361e33494b4d407f0868f7907b73297cf70dabbb
child 32111 710e2086db86f72a57a822235ab6d3a4cb055f6a
push id162
push usermozilla@jorgk.com
push dateSat, 09 Mar 2019 10:20:28 +0000
treeherdercomm-esr60@62a9df6d2883 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, jorgk, jorgk
bugs1522453
Bug 1522453 - Allow tests to reload the address book with a notification. r=mkmelin,jorgk a=jorgk
mailnews/addrbook/src/nsAbManager.cpp
--- a/mailnews/addrbook/src/nsAbManager.cpp
+++ b/mailnews/addrbook/src/nsAbManager.cpp
@@ -132,16 +132,19 @@ nsresult nsAbManager::Init()
 
   nsCOMPtr<nsIObserverService> observerService =
     mozilla::services::GetObserverService();
   NS_ENSURE_TRUE(observerService, NS_ERROR_UNEXPECTED);
 
   nsresult rv = observerService->AddObserver(this, "profile-do-change", false);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  rv = observerService->AddObserver(this, "addrbook-reload", false);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
                                     false);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAbManager::Observe(nsISupports *aSubject, const char *aTopic,
@@ -154,27 +157,38 @@ NS_IMETHODIMP nsAbManager::Observe(nsISu
   // that happens in nsAbBSDirectory::GetChildNodes()
   // when we call DIR_GetDirectories().
   if (!strcmp(aTopic, "profile-do-change"))
   {
     DIR_ShutDown();
     return NS_OK;
   }
 
+  if (!strcmp(aTopic, "addrbook-reload"))
+  {
+    DIR_ShutDown();
+    mCacheTopLevelAb = nullptr;
+    mAbStore.Clear();
+    return NS_OK;
+  }
+
   if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
   {
     DIR_ShutDown();
 
     nsCOMPtr<nsIObserverService> observerService =
       mozilla::services::GetObserverService();
     NS_ENSURE_TRUE(observerService, NS_ERROR_UNEXPECTED);
 
     nsresult rv = observerService->RemoveObserver(this, "profile-do-change");
     NS_ENSURE_SUCCESS(rv, rv);
 
+    rv = observerService->RemoveObserver(this, "addrbook-reload");
+    NS_ENSURE_SUCCESS(rv, rv);
+
     rv = observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 //