Bug 1408333 Get rid of nsIIPCBackgroundChildCreateCallback - part 17 - HttpBackgroundChannel, r=asuth
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 24 Oct 2017 12:02:41 +0200
changeset 438600 5bd31786c1d492c4f6ac3bf27f956046b7da95fa
parent 438599 7c7bdc0891da86eebd85eb02365ba0b7dac4ea00
child 438601 ef23e447c4fabc816520cd223010c2cb66b0f663
push id8114
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 16:33:21 +0000
treeherdermozilla-beta@73e0d89a540f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1408333
milestone58.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 1408333 Get rid of nsIIPCBackgroundChildCreateCallback - part 17 - HttpBackgroundChannel, r=asuth
netwerk/protocol/http/HttpBackgroundChannelChild.cpp
netwerk/protocol/http/HttpBackgroundChannelChild.h
--- a/netwerk/protocol/http/HttpBackgroundChannelChild.cpp
+++ b/netwerk/protocol/http/HttpBackgroundChannelChild.cpp
@@ -10,85 +10,24 @@
 
 #include "HttpBackgroundChannelChild.h"
 
 #include "HttpChannelChild.h"
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ipc/PBackgroundChild.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Unused.h"
-#include "nsIIPCBackgroundChildCreateCallback.h"
 #include "nsSocketTransportService2.h"
 
 using mozilla::ipc::BackgroundChild;
 using mozilla::ipc::IPCResult;
 
 namespace mozilla {
 namespace net {
 
-// Callbacks for PBackgroundChild creation
-class BackgroundChannelCreateCallback final
-  : public nsIIPCBackgroundChildCreateCallback
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
-
-  explicit BackgroundChannelCreateCallback(HttpBackgroundChannelChild* aBgChild)
-    : mBgChild(aBgChild)
-  {
-    MOZ_ASSERT(OnSocketThread());
-    MOZ_ASSERT(aBgChild);
-  }
-
-private:
-  virtual ~BackgroundChannelCreateCallback() { }
-
-  RefPtr<HttpBackgroundChannelChild> mBgChild;
-};
-
-NS_IMPL_ISUPPORTS(BackgroundChannelCreateCallback,
-                  nsIIPCBackgroundChildCreateCallback)
-
-void
-BackgroundChannelCreateCallback::ActorCreated(PBackgroundChild* aActor)
-{
-  MOZ_ASSERT(OnSocketThread());
-  MOZ_ASSERT(aActor);
-  MOZ_ASSERT(mBgChild);
-
-  if (!mBgChild->mChannelChild) {
-    // HttpChannelChild is closed during PBackground creation,
-    // abort the rest of steps.
-    return;
-  }
-
-  const uint64_t channelId = mBgChild->mChannelChild->ChannelId();
-  if (!aActor->SendPHttpBackgroundChannelConstructor(mBgChild,
-                                                     channelId)) {
-    ActorFailed();
-    return;
-  }
-
-  // hold extra reference for IPDL
-  RefPtr<HttpBackgroundChannelChild> child = mBgChild;
-  Unused << child.forget().take();
-
-  mBgChild->mChannelChild->OnBackgroundChildReady(mBgChild);
-}
-
-void
-BackgroundChannelCreateCallback::ActorFailed()
-{
-  MOZ_ASSERT(OnSocketThread());
-  MOZ_ASSERT(mBgChild);
-
-  mBgChild->OnBackgroundChannelCreationFailed();
-}
-
 // HttpBackgroundChannelChild
 HttpBackgroundChannelChild::HttpBackgroundChannelChild()
 {
 }
 
 HttpBackgroundChannelChild::~HttpBackgroundChannelChild()
 {
 }
@@ -142,39 +81,39 @@ HttpBackgroundChannelChild::OnStartReque
     // but not the Process* methods on HttpChannelChild.
     event->Run();
   }
 
   // Ensure no new message is enqueued.
   MOZ_ASSERT(mQueuedRunnables.IsEmpty());
 }
 
-void
-HttpBackgroundChannelChild::OnBackgroundChannelCreationFailed()
-{
-  LOG(("HttpBackgroundChannelChild::OnBackgroundChannelCreationFailed"
-       " [this=%p]\n", this));
-  MOZ_ASSERT(OnSocketThread());
-
-  if (mChannelChild) {
-    RefPtr<HttpChannelChild> channelChild = mChannelChild.forget();
-    channelChild->OnBackgroundChildDestroyed(this);
-  }
-}
-
 bool
 HttpBackgroundChannelChild::CreateBackgroundChannel()
 {
   LOG(("HttpBackgroundChannelChild::CreateBackgroundChannel [this=%p]\n", this));
   MOZ_ASSERT(OnSocketThread());
+  MOZ_ASSERT(mChannelChild);
 
-  RefPtr<BackgroundChannelCreateCallback> callback =
-    new BackgroundChannelCreateCallback(this);
+  PBackgroundChild* actorChild = BackgroundChild::GetOrCreateForCurrentThread();
+  if (NS_WARN_IF(!actorChild)) {
+    return false;
+  }
 
-  return BackgroundChild::GetOrCreateForCurrentThread(callback);
+  const uint64_t channelId = mChannelChild->ChannelId();
+  if (!actorChild->SendPHttpBackgroundChannelConstructor(this, channelId)) {
+    return false;
+  }
+
+  // hold extra reference for IPDL
+  RefPtr<HttpBackgroundChannelChild> self = this;
+  Unused << self.forget().take();
+
+  mChannelChild->OnBackgroundChildReady(this);
+  return true;
 }
 
 bool
 HttpBackgroundChannelChild::IsWaitingOnStartRequest()
 {
   MOZ_ASSERT(OnSocketThread());
   // Need to wait for OnStartRequest if it is sent by
   // parent process but not received by content process.
--- a/netwerk/protocol/http/HttpBackgroundChannelChild.h
+++ b/netwerk/protocol/http/HttpBackgroundChannelChild.h
@@ -35,19 +35,16 @@ public:
   // Callback while the associated HttpChannelChild is not going to
   // handle any incoming messages over background channel.
   void OnChannelClosed();
 
   // Callback when OnStartRequest is received and handled by HttpChannelChild.
   // Enqueued messages in background channel will be flushed.
   void OnStartRequestReceived();
 
-  // Callback while failed to create PBackground IPC channel.
-  void OnBackgroundChannelCreationFailed();
-
 protected:
   IPCResult RecvOnTransportAndData(const nsresult& aChannelStatus,
                                    const nsresult& aTransportStatus,
                                    const uint64_t& aOffset,
                                    const uint32_t& aCount,
                                    const nsCString& aData) override;
 
   IPCResult RecvOnStopRequest(const nsresult& aChannelStatus,