Bug 918864. r=bz, a=abillings
authorOlli Pettay <bugs@pettay.fi>
Thu, 17 Oct 2013 13:59:55 -0400
changeset 160736 c3a6190a6d6431fc6b4da9249482ad082486b245
parent 160735 44da28b278bedbf7c453ccd5b5266833b82a2ce1
child 160737 ce79da6bb7ca090299f9efc9d1bc6c5505fa9bcb
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, abillings
bugs918864
milestone26.0a2
Bug 918864. r=bz, a=abillings
uriloader/prefetch/nsOfflineCacheUpdateService.cpp
--- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
@@ -127,25 +127,27 @@ public:
 
     nsOfflineCachePendingUpdate(nsOfflineCacheUpdateService *aService,
                                 nsIURI *aManifestURI,
                                 nsIURI *aDocumentURI,
                                 nsIDOMDocument *aDocument)
         : mService(aService)
         , mManifestURI(aManifestURI)
         , mDocumentURI(aDocumentURI)
+        , mDidReleaseThis(false)
         {
             mDocument = do_GetWeakReference(aDocument);
         }
 
 private:
     nsRefPtr<nsOfflineCacheUpdateService> mService;
     nsCOMPtr<nsIURI> mManifestURI;
     nsCOMPtr<nsIURI> mDocumentURI;
     nsCOMPtr<nsIWeakReference> mDocument;
+    bool mDidReleaseThis;
 };
 
 NS_IMPL_ISUPPORTS2(nsOfflineCachePendingUpdate,
                    nsIWebProgressListener,
                    nsISupportsWeakReference)
 
 //-----------------------------------------------------------------------------
 // nsOfflineCacheUpdateService::nsIWebProgressListener
@@ -164,21 +166,26 @@ nsOfflineCachePendingUpdate::OnProgressC
 }
 
 NS_IMETHODIMP
 nsOfflineCachePendingUpdate::OnStateChange(nsIWebProgress* aWebProgress,
                                            nsIRequest *aRequest,
                                            uint32_t progressStateFlags,
                                            nsresult aStatus)
 {
+    if (mDidReleaseThis) {
+        return NS_OK;
+    }
     nsCOMPtr<nsIDOMDocument> updateDoc = do_QueryReferent(mDocument);
     if (!updateDoc) {
         // The document that scheduled this update has gone away,
         // we don't need to listen anymore.
         aWebProgress->RemoveProgressListener(this);
+        MOZ_ASSERT(!mDidReleaseThis);
+        mDidReleaseThis = true;
         NS_RELEASE_THIS();
         return NS_OK;
     }
 
     if (!(progressStateFlags & STATE_STOP)) {
         return NS_OK;
     }
 
@@ -204,19 +211,24 @@ nsOfflineCachePendingUpdate::OnStateChan
         bool isInBrowserElement;
         nsresult rv = GetAppIDAndInBrowserFromWindow(window, &appId, &isInBrowserElement);
         NS_ENSURE_SUCCESS(rv, rv);
 
         nsCOMPtr<nsIOfflineCacheUpdate> update;
         mService->Schedule(mManifestURI, mDocumentURI,
                            updateDoc, window, nullptr,
                            appId, isInBrowserElement, getter_AddRefs(update));
+        if (mDidReleaseThis) {
+            return NS_OK;
+        }
     }
 
     aWebProgress->RemoveProgressListener(this);
+    MOZ_ASSERT(!mDidReleaseThis);
+    mDidReleaseThis = true;
     NS_RELEASE_THIS();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsOfflineCachePendingUpdate::OnLocationChange(nsIWebProgress* aWebProgress,
                                               nsIRequest* aRequest,