Bug 1588241 - P9. Make ChannelEventQueue::PrependEvents infallible. r=mattwoodrow
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 15 Nov 2019 05:35:28 +0000
changeset 502322 2909f92bb59434929217c1510b991ef7ed88314c
parent 502321 ab0b99b9fbe77e8494816e20472ea593a29b598a
child 502323 05f4ac2d6dd6beb54482ce138d36cf3226f2464c
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1588241
milestone72.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 1588241 - P9. Make ChannelEventQueue::PrependEvents infallible. r=mattwoodrow nsTArray::InsertElementsAt is infallible. So the test checking that nullptr wasn't returned would always be false. Seeing that queuing an event is also an infallible operation, there's no point for prepentEvents to be. Differential Revision: https://phabricator.services.mozilla.com/D53115
netwerk/ipc/ChannelEventQueue.h
netwerk/protocol/ftp/FTPChannelChild.cpp
netwerk/protocol/http/HttpChannelChild.cpp
--- a/netwerk/ipc/ChannelEventQueue.h
+++ b/netwerk/ipc/ChannelEventQueue.h
@@ -149,18 +149,18 @@ class ChannelEventQueue final {
   //
   // @param aCallback - the ChannelEvent
   // @param aAssertionWhenNotQueued - this optional param will be used in an
   //   assertion when the event is executed directly.
   inline void RunOrEnqueue(ChannelEvent* aCallback,
                            bool aAssertionWhenNotQueued = false);
 
   // Append ChannelEvent in front of the event queue.
-  inline nsresult PrependEvent(UniquePtr<ChannelEvent>&& aEvent);
-  inline nsresult PrependEvents(nsTArray<UniquePtr<ChannelEvent>>& aEvents);
+  inline void PrependEvent(UniquePtr<ChannelEvent>&& aEvent);
+  inline void PrependEvents(nsTArray<UniquePtr<ChannelEvent>>& aEvents);
 
   // After StartForcedQueueing is called, RunOrEnqueue() will start enqueuing
   // events that will be run/flushed when EndForcedQueueing is called.
   // - Note: queueing may still be required after EndForcedQueueing() (if the
   //   queue is suspended, etc):  always call RunOrEnqueue() to avoid race
   //   conditions.
   inline void StartForcedQueueing();
   inline void EndForcedQueueing();
@@ -277,57 +277,44 @@ inline void ChannelEventQueue::EndForced
     }
   }
 
   if (tryFlush) {
     MaybeFlushQueue();
   }
 }
 
-inline nsresult ChannelEventQueue::PrependEvent(
+inline void ChannelEventQueue::PrependEvent(
     UniquePtr<ChannelEvent>&& aEvent) {
   MutexAutoLock lock(mMutex);
 
   // Prepending event while no queue flush foreseen might cause the following
   // channel events not run. This assertion here guarantee there must be a
   // queue flush, either triggered by Resume or EndForcedQueueing, to execute
   // the added event.
   MOZ_ASSERT(mSuspended || !!mForcedCount);
 
-  UniquePtr<ChannelEvent>* newEvent =
-      mEventQueue.InsertElementAt(0, std::move(aEvent));
-
-  if (!newEvent) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  return NS_OK;
+  mEventQueue.InsertElementAt(0, std::move(aEvent));
 }
 
-inline nsresult ChannelEventQueue::PrependEvents(
+inline void ChannelEventQueue::PrependEvents(
     nsTArray<UniquePtr<ChannelEvent>>& aEvents) {
   MutexAutoLock lock(mMutex);
 
   // Prepending event while no queue flush foreseen might cause the following
   // channel events not run. This assertion here guarantee there must be a
   // queue flush, either triggered by Resume or EndForcedQueueing, to execute
   // the added events.
   MOZ_ASSERT(mSuspended || !!mForcedCount);
 
-  UniquePtr<ChannelEvent>* newEvents =
-      mEventQueue.InsertElementsAt(0, aEvents.Length());
-  if (!newEvents) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  mEventQueue.InsertElementsAt(0, aEvents.Length());
 
   for (uint32_t i = 0; i < aEvents.Length(); i++) {
-    newEvents[i] = std::move(aEvents[i]);
+    mEventQueue[i] = std::move(aEvents[i]);
   }
-
-  return NS_OK;
 }
 
 inline void ChannelEventQueue::CompleteResume() {
   bool tryFlush = false;
   {
     MutexAutoLock lock(mMutex);
 
     // channel may have been suspended again since Resume fired event to call
--- a/netwerk/protocol/ftp/FTPChannelChild.cpp
+++ b/netwerk/protocol/ftp/FTPChannelChild.cpp
@@ -687,24 +687,22 @@ FTPChannelChild::UnknownDecoderInvolvedK
   mUnknownDecoderInvolved = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 FTPChannelChild::UnknownDecoderInvolvedOnStartRequestCalled() {
   mUnknownDecoderInvolved = false;
 
-  nsresult rv = NS_OK;
-
   if (mDivertingToParent) {
-    rv = mEventQ->PrependEvents(mUnknownDecoderEventQ);
+    mEventQ->PrependEvents(mUnknownDecoderEventQ);
   }
   mUnknownDecoderEventQ.Clear();
 
-  return rv;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 FTPChannelChild::GetDivertingToParent(bool* aDiverting) {
   NS_ENSURE_ARG_POINTER(aDiverting);
   *aDiverting = mDivertingToParent;
   return NS_OK;
 }
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -3337,24 +3337,22 @@ HttpChannelChild::UnknownDecoderInvolved
   LOG(
       ("HttpChannelChild::UnknownDecoderInvolvedOnStartRequestCalled "
        "[this=%p, mDivertingToParent=%d]",
        this, static_cast<bool>(mDivertingToParent)));
   MOZ_ASSERT(NS_IsMainThread());
 
   mUnknownDecoderInvolved = false;
 
-  nsresult rv = NS_OK;
-
   if (mDivertingToParent) {
-    rv = mEventQ->PrependEvents(mUnknownDecoderEventQ);
+    mEventQ->PrependEvents(mUnknownDecoderEventQ);
   }
   mUnknownDecoderEventQ.Clear();
 
-  return rv;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpChannelChild::GetDivertingToParent(bool* aDiverting) {
   NS_ENSURE_ARG_POINTER(aDiverting);
   *aDiverting = mDivertingToParent;
   return NS_OK;
 }