Bug 1314084 - Implement `nsIAnnotationService::getObservers`. r?mak draft
authorKit Cambridge <kit@yakshaving.ninja>
Mon, 31 Oct 2016 11:13:14 -0700
changeset 431827 80180e156612015492d55fc535db0a0d41a31af6
parent 431575 7ed3556cf0888bbc078aad5917ddddf7e93303d4
child 535473 a29593d4893650ac4b0c6b0eeb01821db15fcb07
push id34118
push userbmo:kcambridge@mozilla.com
push dateMon, 31 Oct 2016 18:14:10 +0000
reviewersmak
bugs1314084
milestone52.0a1
Bug 1314084 - Implement `nsIAnnotationService::getObservers`. r?mak MozReview-Commit-ID: 42y8d1fbfJO
toolkit/components/places/nsAnnotationService.cpp
toolkit/components/places/nsIAnnotationService.idl
toolkit/components/places/tests/unit/test_null_interfaces.js
--- a/toolkit/components/places/nsAnnotationService.cpp
+++ b/toolkit/components/places/nsAnnotationService.cpp
@@ -1668,16 +1668,37 @@ nsAnnotationService::RemoveObserver(nsIA
 {
   NS_ENSURE_ARG(aObserver);
 
   if (!mObservers.RemoveObject(aObserver))
     return NS_ERROR_INVALID_ARG;
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsAnnotationService::GetObservers(uint32_t* _count,
+                                  nsIAnnotationObserver*** _observers)
+{
+  NS_ENSURE_ARG_POINTER(_count);
+  NS_ENSURE_ARG_POINTER(_observers);
+
+  *_count = 0;
+  *_observers = nullptr;
+
+  nsCOMArray<nsIAnnotationObserver> observers(mObservers);
+
+  if (observers.Count() == 0)
+    return NS_OK;
+
+  *_count = observers.Count();
+  observers.Forget(_observers);
+
+  return NS_OK;
+}
+
 nsresult
 nsAnnotationService::HasAnnotationInternal(nsIURI* aURI,
                                            int64_t aItemId,
                                            const nsACString& aName,
                                            bool* _hasAnno)
 {
   bool isItemAnnotation = (aItemId > 0);
   nsCOMPtr<mozIStorageStatement> stmt;
--- a/toolkit/components/places/nsIAnnotationService.idl
+++ b/toolkit/components/places/nsIAnnotationService.idl
@@ -373,16 +373,22 @@ interface nsIAnnotationService : nsISupp
      */
     void addObserver(in nsIAnnotationObserver aObserver);
 
 
     /**
      * Removes an annotaton observer previously registered by addObserver.
      */
     void removeObserver(in nsIAnnotationObserver aObserver);
+
+    /**
+     * Gets an array of registered nsIAnnotationObserver objects.
+     */
+    void getObservers([optional] out unsigned long count,
+                      [retval, array, size_is(count)] out nsIAnnotationObserver observers);
 };
 
 /**
  * Represents a place annotated with a given annotation.  If a place has
  * multiple annotations, it can be represented by multiple
  * mozIAnnotatedResult(s).
  */
 [scriptable, uuid(81fd0188-db6a-492e-80b6-f6414913b396)]
--- a/toolkit/components/places/tests/unit/test_null_interfaces.js
+++ b/toolkit/components/places/tests/unit/test_null_interfaces.js
@@ -14,17 +14,17 @@ var testServices = [
     ["queryStringToQueries", "removePagesByTimeframe", "removePagesFromHost", "getObservers"]
   ],
   ["browser/nav-bookmarks-service;1",
     ["nsINavBookmarksService", "nsINavHistoryObserver", "nsIAnnotationObserver"],
     ["createFolder", "getObservers", "onFrecencyChanged", "onTitleChanged",
      "onPageAnnotationSet", "onPageAnnotationRemoved"]
   ],
   ["browser/livemark-service;2", ["mozIAsyncLivemarks"], ["reloadLivemarks"]],
-  ["browser/annotation-service;1", ["nsIAnnotationService"], []],
+  ["browser/annotation-service;1", ["nsIAnnotationService"], ["getObservers"]],
   ["browser/favicon-service;1", ["nsIFaviconService"], []],
   ["browser/tagging-service;1", ["nsITaggingService"], []],
 ];
 do_print(testServices.join("\n"));
 
 function run_test()
 {
   for (let [cid, ifaces, nothrow] of testServices) {