Bug 1049747: Ensure the history service is up before proceeding, in InsertVisitedURIs::Start() and History::GetPlacesInfo(). r=mak
authorDaniel Holbert <dholbert@cs.stanford.edu>
Sun, 10 Aug 2014 14:26:52 -0700
changeset 220432 5709d54523ef034d4e1e8466ad4e451dcb6116bf
parent 220431 5a35174bd170dbd707ae89a7909e4ff0aad02f3e
child 220433 71a1dcb2697de1356e0f78d71dfe573e60fecaef
push idunknown
push userunknown
push dateunknown
reviewersmak
bugs1049747
milestone34.0a1
Bug 1049747: Ensure the history service is up before proceeding, in InsertVisitedURIs::Start() and History::GetPlacesInfo(). r=mak
toolkit/components/places/History.cpp
--- a/toolkit/components/places/History.cpp
+++ b/toolkit/components/places/History.cpp
@@ -834,16 +834,23 @@ public:
    */
   static nsresult Start(mozIStorageConnection* aConnection,
                         nsTArray<VisitData>& aPlaces,
                         mozIVisitInfoCallback* aCallback = nullptr)
   {
     MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
     MOZ_ASSERT(aPlaces.Length() > 0, "Must pass a non-empty array!");
 
+    // Make sure nsNavHistory service is up before proceeding:
+    nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
+    MOZ_ASSERT(navHistory, "Could not get nsNavHistory?!");
+    if (!navHistory) {
+      return NS_ERROR_FAILURE;
+    }
+
     nsRefPtr<InsertVisitedURIs> event =
       new InsertVisitedURIs(aConnection, aPlaces, aCallback);
 
     // Get the target thread, and then start the work!
     nsCOMPtr<nsIEventTarget> target = do_GetInterface(aConnection);
     NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED);
     nsresult rv = target->Dispatch(event, NS_DISPATCH_NORMAL);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -923,19 +930,16 @@ private:
   , mCallback(aCallback)
   , mHistory(History::GetService())
   {
     MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
 
     (void)mPlaces.SwapElements(aPlaces);
     (void)mReferrers.SetLength(mPlaces.Length());
 
-    nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
-    NS_ABORT_IF_FALSE(navHistory, "Could not get nsNavHistory?!");
-
     for (nsTArray<VisitData>::size_type i = 0; i < mPlaces.Length(); i++) {
       mReferrers[i].spec = mPlaces[i].referrerSpec;
 
 #ifdef DEBUG
       nsCOMPtr<nsIURI> uri;
       (void)NS_NewURI(getter_AddRefs(uri), mPlaces[i].spec);
       NS_ASSERTION(CanAddURI(uri),
                    "Passed a VisitData with a URI we cannot add to history!");
@@ -2684,19 +2688,24 @@ History::RemoveAllDownloads()
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //// mozIAsyncHistory
 
 NS_IMETHODIMP
 History::GetPlacesInfo(JS::Handle<JS::Value> aPlaceIdentifiers,
                        mozIVisitInfoCallback* aCallback,
-                       JSContext* aCtx) {
+                       JSContext* aCtx)
+{
+  // Make sure nsNavHistory service is up before proceeding:
   nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
-  NS_ABORT_IF_FALSE(navHistory, "Could not get nsNavHistory?!");
+  MOZ_ASSERT(navHistory, "Could not get nsNavHistory?!");
+  if (!navHistory) {
+    return NS_ERROR_FAILURE;
+  }
 
   uint32_t placesIndentifiersLength;
   JS::Rooted<JSObject*> placesIndentifiers(aCtx);
   nsresult rv = GetJSArrayFromJSValue(aPlaceIdentifiers, aCtx,
                                       &placesIndentifiers,
                                       &placesIndentifiersLength);
   NS_ENSURE_SUCCESS(rv, rv);