Bug 1517601, part 2 - Create and use a new WebSocketEvent base class instead of ChannelEvent. r=mayhemer
authorAndrew McCreight <continuation@gmail.com>
Wed, 13 Feb 2019 16:57:58 +0000
changeset 458930 57206fca017df883b2580c6c5e0eb109cd926c27
parent 458929 8f6fc796dca278262341cbf33174c65823f84b55
child 458931 56f7fee6d13916f70dc1991c1e3c0fdc64325b25
push id35551
push usershindli@mozilla.com
push dateWed, 13 Feb 2019 21:34:09 +0000
treeherdermozilla-central@08f794a4928e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1517601
milestone67.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 1517601, part 2 - Create and use a new WebSocketEvent base class instead of ChannelEvent. r=mayhemer In the next patch, I want to change the signature of Run(), so I need to create a new base class for these inner WebSocket events. For now, this class is the same as ChannelEvent, except that it does not have the GetEventTarget method, which is never called. Depends on D19585 Differential Revision: https://phabricator.services.mozilla.com/D19586
netwerk/protocol/websocket/WebSocketChannelChild.cpp
--- a/netwerk/protocol/websocket/WebSocketChannelChild.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannelChild.cpp
@@ -114,79 +114,84 @@ void WebSocketChannelChild::MaybeRelease
 }
 
 void WebSocketChannelChild::GetEffectiveURL(nsAString& aEffectiveURL) const {
   aEffectiveURL = mEffectiveURL;
 }
 
 bool WebSocketChannelChild::IsEncrypted() const { return mEncrypted; }
 
-class WrappedChannelEvent : public Runnable {
+class WebSocketEvent {
  public:
-  explicit WrappedChannelEvent(ChannelEvent* aChannelEvent)
-      : Runnable("net::WrappedChannelEvent"), mChannelEvent(aChannelEvent) {
-    MOZ_RELEASE_ASSERT(aChannelEvent);
+  WebSocketEvent() { MOZ_COUNT_CTOR(WebSocketEvent); }
+  virtual ~WebSocketEvent() { MOZ_COUNT_DTOR(WebSocketEvent); }
+  virtual void Run() = 0;
+};
+
+class WrappedWebSocketEvent : public Runnable {
+ public:
+  explicit WrappedWebSocketEvent(WebSocketEvent* aWebSocketEvent)
+      : Runnable("net::WrappedWebSocketEvent"),
+        mWebSocketEvent(aWebSocketEvent) {
+    MOZ_RELEASE_ASSERT(aWebSocketEvent);
   }
   NS_IMETHOD Run() override {
-    mChannelEvent->Run();
+    mWebSocketEvent->Run();
     return NS_OK;
   }
 
  private:
-  nsAutoPtr<ChannelEvent> mChannelEvent;
+  nsAutoPtr<WebSocketEvent> mWebSocketEvent;
 };
 
 class EventTargetDispatcher : public ChannelEvent {
  public:
-  EventTargetDispatcher(ChannelEvent* aChannelEvent,
+  EventTargetDispatcher(WebSocketEvent* aWebSocketEvent,
                         nsIEventTarget* aEventTarget)
-      : mChannelEvent(aChannelEvent), mEventTarget(aEventTarget) {}
+      : mWebSocketEvent(aWebSocketEvent), mEventTarget(aEventTarget) {}
 
   void Run() override {
     if (mEventTarget) {
-      mEventTarget->Dispatch(new WrappedChannelEvent(mChannelEvent.forget()),
-                             NS_DISPATCH_NORMAL);
+      mEventTarget->Dispatch(
+          new WrappedWebSocketEvent(mWebSocketEvent.forget()),
+          NS_DISPATCH_NORMAL);
       return;
     }
 
-    mChannelEvent->Run();
+    mWebSocketEvent->Run();
   }
 
   already_AddRefed<nsIEventTarget> GetEventTarget() override {
     nsCOMPtr<nsIEventTarget> target = mEventTarget;
     if (!target) {
       target = GetMainThreadEventTarget();
     }
     return target.forget();
   }
 
  private:
-  nsAutoPtr<ChannelEvent> mChannelEvent;
+  nsAutoPtr<WebSocketEvent> mWebSocketEvent;
   nsCOMPtr<nsIEventTarget> mEventTarget;
 };
 
-class StartEvent : public ChannelEvent {
+class StartEvent : public WebSocketEvent {
  public:
   StartEvent(WebSocketChannelChild* aChild, const nsCString& aProtocol,
              const nsCString& aExtensions, const nsString& aEffectiveURL,
              bool aEncrypted)
       : mChild(aChild),
         mProtocol(aProtocol),
         mExtensions(aExtensions),
         mEffectiveURL(aEffectiveURL),
         mEncrypted(aEncrypted) {}
 
   void Run() override {
     mChild->OnStart(mProtocol, mExtensions, mEffectiveURL, mEncrypted);
   }
 
-  already_AddRefed<nsIEventTarget> GetEventTarget() override {
-    return do_AddRef(GetCurrentThreadEventTarget());
-  }
-
  private:
   RefPtr<WebSocketChannelChild> mChild;
   nsCString mProtocol;
   nsCString mExtensions;
   nsString mEffectiveURL;
   bool mEncrypted;
 };
 
@@ -217,27 +222,23 @@ void WebSocketChannelChild::OnStart(cons
       LOG(
           ("WebSocketChannelChild::OnStart "
            "mListenerMT->mListener->OnStart() failed with error 0x%08" PRIx32,
            static_cast<uint32_t>(rv)));
     }
   }
 }
 
-class StopEvent : public ChannelEvent {
+class StopEvent : public WebSocketEvent {
  public:
   StopEvent(WebSocketChannelChild* aChild, const nsresult& aStatusCode)
       : mChild(aChild), mStatusCode(aStatusCode) {}
 
   void Run() override { mChild->OnStop(mStatusCode); }
 
-  already_AddRefed<nsIEventTarget> GetEventTarget() override {
-    return do_AddRef(GetCurrentThreadEventTarget());
-  }
-
  private:
   RefPtr<WebSocketChannelChild> mChild;
   nsresult mStatusCode;
 };
 
 mozilla::ipc::IPCResult WebSocketChannelChild::RecvOnStop(
     const nsresult& aStatusCode) {
   mEventQ->RunOrEnqueue(new EventTargetDispatcher(
@@ -256,34 +257,30 @@ void WebSocketChannelChild::OnStop(const
       LOG(
           ("WebSocketChannel::OnStop "
            "mListenerMT->mListener->OnStop() failed with error 0x%08" PRIx32,
            static_cast<uint32_t>(rv)));
     }
   }
 }
 
-class MessageEvent : public ChannelEvent {
+class MessageEvent : public WebSocketEvent {
  public:
   MessageEvent(WebSocketChannelChild* aChild, const nsCString& aMessage,
                bool aBinary)
       : mChild(aChild), mMessage(aMessage), mBinary(aBinary) {}
 
   void Run() override {
     if (!mBinary) {
       mChild->OnMessageAvailable(mMessage);
     } else {
       mChild->OnBinaryMessageAvailable(mMessage);
     }
   }
 
-  already_AddRefed<nsIEventTarget> GetEventTarget() override {
-    return do_AddRef(GetCurrentThreadEventTarget());
-  }
-
  private:
   RefPtr<WebSocketChannelChild> mChild;
   nsCString mMessage;
   bool mBinary;
 };
 
 mozilla::ipc::IPCResult WebSocketChannelChild::RecvOnMessageAvailable(
     const nsCString& aMsg) {
@@ -328,27 +325,23 @@ void WebSocketChannelChild::OnBinaryMess
           ("WebSocketChannelChild::OnBinaryMessageAvailable "
            "mListenerMT->mListener->OnBinaryMessageAvailable() "
            "failed with error 0x%08" PRIx32,
            static_cast<uint32_t>(rv)));
     }
   }
 }
 
-class AcknowledgeEvent : public ChannelEvent {
+class AcknowledgeEvent : public WebSocketEvent {
  public:
   AcknowledgeEvent(WebSocketChannelChild* aChild, const uint32_t& aSize)
       : mChild(aChild), mSize(aSize) {}
 
   void Run() override { mChild->OnAcknowledge(mSize); }
 
-  already_AddRefed<nsIEventTarget> GetEventTarget() override {
-    return do_AddRef(GetCurrentThreadEventTarget());
-  }
-
  private:
   RefPtr<WebSocketChannelChild> mChild;
   uint32_t mSize;
 };
 
 mozilla::ipc::IPCResult WebSocketChannelChild::RecvOnAcknowledge(
     const uint32_t& aSize) {
   mEventQ->RunOrEnqueue(new EventTargetDispatcher(
@@ -368,28 +361,24 @@ void WebSocketChannelChild::OnAcknowledg
           ("WebSocketChannel::OnAcknowledge "
            "mListenerMT->mListener->OnAcknowledge() "
            "failed with error 0x%08" PRIx32,
            static_cast<uint32_t>(rv)));
     }
   }
 }
 
-class ServerCloseEvent : public ChannelEvent {
+class ServerCloseEvent : public WebSocketEvent {
  public:
   ServerCloseEvent(WebSocketChannelChild* aChild, const uint16_t aCode,
                    const nsCString& aReason)
       : mChild(aChild), mCode(aCode), mReason(aReason) {}
 
   void Run() override { mChild->OnServerClose(mCode, mReason); }
 
-  already_AddRefed<nsIEventTarget> GetEventTarget() override {
-    return do_AddRef(GetCurrentThreadEventTarget());
-  }
-
  private:
   RefPtr<WebSocketChannelChild> mChild;
   uint16_t mCode;
   nsCString mReason;
 };
 
 mozilla::ipc::IPCResult WebSocketChannelChild::RecvOnServerClose(
     const uint16_t& aCode, const nsCString& aReason) {