Bug 1551779 part 3. Stop using [array] for nsINavHistoryService.getObservers and nsINavBookmarksService.getObservers. r=mak
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 16 May 2019 15:13:44 +0000
changeset 532935 4c91b3e1fedeb142e9e79460b772c73902016392
parent 532934 f5db7f234584c20947fc4fa592b1263d1582df0b
child 532936 87a537f8e5a89204a95ec7395e9024688e16dfae
push id11276
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:11:24 +0000
treeherdermozilla-beta@847755a7c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1551779
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1551779 part 3. Stop using [array] for nsINavHistoryService.getObservers and nsINavBookmarksService.getObservers. r=mak Differential Revision: https://phabricator.services.mozilla.com/D31239
toolkit/components/places/nsINavBookmarksService.idl
toolkit/components/places/nsINavHistoryService.idl
toolkit/components/places/nsNavBookmarks.cpp
toolkit/components/places/nsNavHistory.cpp
--- a/toolkit/components/places/nsINavBookmarksService.idl
+++ b/toolkit/components/places/nsINavBookmarksService.idl
@@ -451,11 +451,10 @@ interface nsINavBookmarksService : nsISu
   /**
    * Removes a bookmark observer.
    */
   void removeObserver(in nsINavBookmarkObserver observer);
 
   /**
    * Gets an array of registered nsINavBookmarkObserver objects.
    */
-  void getObservers([optional] out unsigned long count,
-                    [retval, array, size_is(count)] out nsINavBookmarkObserver observers);
+  Array<nsINavBookmarkObserver> getObservers();
 };
--- a/toolkit/components/places/nsINavHistoryService.idl
+++ b/toolkit/components/places/nsINavHistoryService.idl
@@ -1256,18 +1256,17 @@ interface nsINavHistoryService : nsISupp
   /**
    * Removes a history observer.
    */
   void removeObserver(in nsINavHistoryObserver observer);
 
   /**
    * Gets an array of registered nsINavHistoryObserver objects.
    */
-  void getObservers([optional] out unsigned long count,
-                    [retval, array, size_is(count)] out nsINavHistoryObserver observers);
+  Array<nsINavHistoryObserver> getObservers();
 
   /**
    * True if history is disabled. currently,
    * history is disabled if the places.history.enabled pref is false.
    */
   readonly attribute boolean historyDisabled;
 
   /**
--- a/toolkit/components/places/nsNavBookmarks.cpp
+++ b/toolkit/components/places/nsNavBookmarks.cpp
@@ -1758,40 +1758,30 @@ nsNavBookmarks::AddObserver(nsINavBookma
 }
 
 NS_IMETHODIMP
 nsNavBookmarks::RemoveObserver(nsINavBookmarkObserver* aObserver) {
   return mObservers.RemoveWeakElement(aObserver);
 }
 
 NS_IMETHODIMP
-nsNavBookmarks::GetObservers(uint32_t* _count,
-                             nsINavBookmarkObserver*** _observers) {
-  NS_ENSURE_ARG_POINTER(_count);
-  NS_ENSURE_ARG_POINTER(_observers);
-
-  *_count = 0;
-  *_observers = nullptr;
+nsNavBookmarks::GetObservers(nsTArray<RefPtr<nsINavBookmarkObserver>>& aObservers) {
+  aObservers.Clear();
 
   if (!mCanNotify) return NS_OK;
 
-  nsCOMArray<nsINavBookmarkObserver> observers;
-
   for (uint32_t i = 0; i < mObservers.Length(); ++i) {
-    const nsCOMPtr<nsINavBookmarkObserver>& observer =
+    nsCOMPtr<nsINavBookmarkObserver> observer =
         mObservers.ElementAt(i).GetValue();
     // Skip nullified weak observers.
-    if (observer) observers.AppendElement(observer);
+    if (observer) {
+      aObservers.AppendElement(observer.forget());
+    }
   }
 
-  if (observers.Count() == 0) return NS_OK;
-
-  *_count = observers.Count();
-  observers.Forget(_observers);
-
   return NS_OK;
 }
 
 void nsNavBookmarks::NotifyItemVisited(const ItemVisitData& aData) {
   nsCOMPtr<nsIURI> uri;
   MOZ_ALWAYS_SUCCEEDS(NS_NewURI(getter_AddRefs(uri), aData.bookmark.url));
   // Notify the visit only if we have a valid uri, otherwise the observer
   // couldn't gather enough data from the notification.
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -2020,45 +2020,35 @@ NS_IMETHODIMP
 nsNavHistory::RemoveObserver(nsINavHistoryObserver* aObserver) {
   NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
   NS_ENSURE_ARG(aObserver);
 
   return mObservers.RemoveWeakElement(aObserver);
 }
 
 NS_IMETHODIMP
-nsNavHistory::GetObservers(uint32_t* _count,
-                           nsINavHistoryObserver*** _observers) {
-  NS_ENSURE_ARG_POINTER(_count);
-  NS_ENSURE_ARG_POINTER(_observers);
-
-  *_count = 0;
-  *_observers = nullptr;
+nsNavHistory::GetObservers(nsTArray<RefPtr<nsINavHistoryObserver>>& aObservers) {
+  aObservers.Clear();
 
   // Clear any cached value, cause it's very likely the consumer has made
   // changes to history and is now trying to notify them.
   mDaysOfHistory = -1;
 
   if (!mCanNotify) return NS_OK;
 
-  nsCOMArray<nsINavHistoryObserver> observers;
-
   // Then add the other observers.
   for (uint32_t i = 0; i < mObservers.Length(); ++i) {
-    const nsCOMPtr<nsINavHistoryObserver>& observer =
+    nsCOMPtr<nsINavHistoryObserver> observer =
         mObservers.ElementAt(i).GetValue();
     // Skip nullified weak observers.
-    if (observer) observers.AppendElement(observer);
+    if (observer) {
+      aObservers.AppendElement(observer.forget());
+    }
   }
 
-  if (observers.Count() == 0) return NS_OK;
-
-  *_count = observers.Count();
-  observers.Forget(_observers);
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNavHistory::GetHistoryDisabled(bool* _retval) {
   NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
   NS_ENSURE_ARG_POINTER(_retval);