Bug 1624279 - Convert nsOnStartRequestEvent* to RefPtr<nsOnStartRequestEvent> r=valentin
authorMahakBansal <mbansal@cs.iitr.ac.in>
Wed, 25 Mar 2020 12:28:31 +0000
changeset 520350 c85b4839c96465336e60adca42734970b14289ad
parent 520349 671f500ae8aa0b3d8ebd4327d5309f82ed3bf849
child 520351 592a05a2a15958b9b2628a95e13f8e0731721024
push id37248
push userbtara@mozilla.com
push dateWed, 25 Mar 2020 16:40:49 +0000
treeherdermozilla-central@c5112a7573ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1624279
milestone76.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 1624279 - Convert nsOnStartRequestEvent* to RefPtr<nsOnStartRequestEvent> r=valentin Differential Revision: https://phabricator.services.mozilla.com/D67907
netwerk/base/nsRequestObserverProxy.cpp
--- a/netwerk/base/nsRequestObserverProxy.cpp
+++ b/netwerk/base/nsRequestObserverProxy.cpp
@@ -36,18 +36,16 @@ class nsOnStartRequestEvent : public nsA
   RefPtr<nsRequestObserverProxy> mProxy;
 
  public:
   nsOnStartRequestEvent(nsRequestObserverProxy* proxy, nsIRequest* request)
       : nsARequestObserverEvent(request), mProxy(proxy) {
     MOZ_ASSERT(mProxy, "null pointer");
   }
 
-  virtual ~nsOnStartRequestEvent() = default;
-
   NS_IMETHOD Run() override {
     LOG(("nsOnStartRequestEvent::HandleEvent [req=%p]\n", mRequest.get()));
 
     if (!mProxy->mObserver) {
       MOZ_ASSERT_UNREACHABLE(
           "already handled onStopRequest event "
           "(observer is null)");
       return NS_OK;
@@ -59,33 +57,34 @@ class nsOnStartRequestEvent : public nsA
       LOG(("OnStartRequest failed [rv=%" PRIx32 "] canceling request!\n",
            static_cast<uint32_t>(rv)));
       rv = mRequest->Cancel(rv);
       NS_ASSERTION(NS_SUCCEEDED(rv), "Cancel failed for request!");
     }
 
     return NS_OK;
   }
+
+ private:
+  virtual ~nsOnStartRequestEvent() = default;
 };
 
 //-----------------------------------------------------------------------------
 // nsOnStopRequestEvent internal class...
 //-----------------------------------------------------------------------------
 
 class nsOnStopRequestEvent : public nsARequestObserverEvent {
   RefPtr<nsRequestObserverProxy> mProxy;
 
  public:
   nsOnStopRequestEvent(nsRequestObserverProxy* proxy, nsIRequest* request)
       : nsARequestObserverEvent(request), mProxy(proxy) {
     MOZ_ASSERT(mProxy, "null pointer");
   }
 
-  virtual ~nsOnStopRequestEvent() = default;
-
   NS_IMETHOD Run() override {
     LOG(("nsOnStopRequestEvent::HandleEvent [req=%p]\n", mRequest.get()));
 
     nsMainThreadPtrHandle<nsIRequestObserver> observer = mProxy->mObserver;
     if (!observer) {
       MOZ_ASSERT_UNREACHABLE(
           "already handled onStopRequest event "
           "(observer is null)");
@@ -98,16 +97,19 @@ class nsOnStopRequestEvent : public nsAR
     DebugOnly<nsresult> rv = mRequest->GetStatus(&status);
     NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed for request!");
 
     LOG(("handle stopevent=%p\n", this));
     (void)observer->OnStopRequest(mRequest, status);
 
     return NS_OK;
   }
+
+ private:
+  virtual ~nsOnStopRequestEvent() = default;
 };
 
 //-----------------------------------------------------------------------------
 // nsRequestObserverProxy::nsISupports implementation...
 //-----------------------------------------------------------------------------
 
 NS_IMPL_ISUPPORTS(nsRequestObserverProxy, nsIRequestObserver,
                   nsIRequestObserverProxy)
@@ -116,43 +118,37 @@ NS_IMPL_ISUPPORTS(nsRequestObserverProxy
 // nsRequestObserverProxy::nsIRequestObserver implementation...
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 nsRequestObserverProxy::OnStartRequest(nsIRequest* request) {
   LOG(("nsRequestObserverProxy::OnStartRequest [this=%p req=%p]\n", this,
        request));
 
-  nsOnStartRequestEvent* ev = new nsOnStartRequestEvent(this, request);
-  if (!ev) return NS_ERROR_OUT_OF_MEMORY;
+  RefPtr<nsOnStartRequestEvent> ev = new nsOnStartRequestEvent(this, request);
 
-  LOG(("post startevent=%p\n", ev));
-  nsresult rv = FireEvent(ev);
-  if (NS_FAILED(rv)) delete ev;
-  return rv;
+  LOG(("post startevent=%p\n", ev.get()));
+  return FireEvent(ev);
 }
 
 NS_IMETHODIMP
 nsRequestObserverProxy::OnStopRequest(nsIRequest* request, nsresult status) {
   LOG(("nsRequestObserverProxy: OnStopRequest [this=%p req=%p status=%" PRIx32
        "]\n",
        this, request, static_cast<uint32_t>(status)));
 
   // The status argument is ignored because, by the time the OnStopRequestEvent
   // is actually processed, the status of the request may have changed :-(
   // To make sure that an accurate status code is always used, GetStatus() is
   // called when the OnStopRequestEvent is actually processed (see above).
 
-  nsOnStopRequestEvent* ev = new nsOnStopRequestEvent(this, request);
-  if (!ev) return NS_ERROR_OUT_OF_MEMORY;
+  RefPtr<nsOnStopRequestEvent> ev = new nsOnStopRequestEvent(this, request);
 
-  LOG(("post stopevent=%p\n", ev));
-  nsresult rv = FireEvent(ev);
-  if (NS_FAILED(rv)) delete ev;
-  return rv;
+  LOG(("post stopevent=%p\n", ev.get()));
+  return FireEvent(ev);
 }
 
 //-----------------------------------------------------------------------------
 // nsRequestObserverProxy::nsIRequestObserverProxy implementation...
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 nsRequestObserverProxy::Init(nsIRequestObserver* observer,