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 34346 89ebd1b371c673db7506a7ab80df43549629f6c2
parent 34345 f3b778e7c52ffb688f3e3a574fa0ee9347ba2f4a
child 34347 415d630ef78a7911889452dd8350d92fb6e457c3
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
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;
 }
 
 //