Bug 1314084 - Implement `nsIAnnotationService::getObservers`. r=mak
authorKit Cambridge <kit@yakshaving.ninja>
Mon, 31 Oct 2016 11:13:14 -0700
changeset 323817 eba5ce187e61a31ce72597c5262a775cad6d0541
parent 323816 b327c38531cc9fac0bddd9b5da14b865f05e172e
child 323818 60a3dc6b2c6a17923f563771e5e2d3599d88803e
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersmak
bugs1314084
milestone53.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) {