Bug 1314833 - Part 3: Factor out AbstractThread::MainThread() used in FlyWeb. r=billm
authorBevis Tseng <btseng@mozilla.com>
Tue, 22 Nov 2016 14:15:04 +0800
changeset 375619 d3cfaafedb4339897fcede34a67125a4d16a7b98
parent 375618 02e5708a75fcdd9e8e4b065995f00b29896fb4b5
child 375620 66e7178c31542d5cc6f893c3998ad17bf6845075
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1314833
milestone53.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 1314833 - Part 3: Factor out AbstractThread::MainThread() used in FlyWeb. r=billm MozReview-Commit-ID: 4wVykPwuDS9
dom/base/Navigator.cpp
dom/flyweb/FlyWebPublishedServer.cpp
dom/flyweb/HttpServer.cpp
dom/flyweb/HttpServer.h
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1538,17 +1538,17 @@ Navigator::PublishServer(const nsAString
   nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
   ErrorResult result;
   RefPtr<Promise> domPromise = Promise::Create(global, result);
   if (result.Failed()) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  mozPromise->Then(AbstractThread::MainThread(),
+  mozPromise->Then(global->AbstractMainThreadFor(TaskCategory::Other),
                    __func__,
                    [domPromise] (FlyWebPublishedServer* aServer) {
                      domPromise->MaybeResolve(aServer);
                    },
                    [domPromise] (nsresult aStatus) {
                      domPromise->MaybeReject(aStatus);
                    });
 
--- a/dom/flyweb/FlyWebPublishedServer.cpp
+++ b/dom/flyweb/FlyWebPublishedServer.cpp
@@ -2,24 +2,26 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/FlyWebPublishedServerIPC.h"
 #include "mozilla/dom/FlyWebPublishBinding.h"
 #include "mozilla/dom/FlyWebService.h"
+#include "mozilla/dom/DocGroup.h"
 #include "mozilla/dom/Request.h"
 #include "mozilla/dom/FlyWebServerEvents.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/InternalResponse.h"
 #include "mozilla/ipc/IPCStreamUtils.h"
 #include "mozilla/net/NeckoParent.h"
 #include "mozilla/net/IPCTransportProvider.h"
+#include "mozilla/AbstractThread.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Unused.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsGlobalWindow.h"
 #include "WebSocketChannel.h"
 
 namespace mozilla {
@@ -163,17 +165,17 @@ FlyWebPublishedServer::OnWebSocketAccept
 /******** FlyWebPublishedServerImpl ********/
 
 NS_IMPL_ISUPPORTS_INHERITED0(FlyWebPublishedServerImpl, mozilla::DOMEventTargetHelper)
 
 FlyWebPublishedServerImpl::FlyWebPublishedServerImpl(nsPIDOMWindowInner* aOwner,
                                                      const nsAString& aName,
                                                      const FlyWebPublishOptions& aOptions)
   : FlyWebPublishedServer(aOwner, aName, aOptions)
-  , mHttpServer(new HttpServer())
+  , mHttpServer(new HttpServer(aOwner->GetDocGroup()->AbstractMainThreadFor(TaskCategory::Other)))
 {
   LOG_I("FlyWebPublishedServerImpl::FlyWebPublishedServerImpl(%p)", this);
 }
 
 void
 FlyWebPublishedServerImpl::PermissionGranted(bool aGranted)
 {
   LOG_I("FlyWebPublishedServerImpl::PermissionGranted(%b)", aGranted);
@@ -481,16 +483,17 @@ FlyWebPublishedServerParent::FlyWebPubli
   if (!mozPromise) {
     Unused << SendServerReady(NS_ERROR_FAILURE);
     return;
   }
 
   RefPtr<FlyWebPublishedServerParent> self = this;
 
   mozPromise->Then(
+    // Non DocGroup-version of AbstractThread::MainThread() for the task in parent.
     AbstractThread::MainThread(),
     __func__,
     [this, self] (FlyWebPublishedServer* aServer) {
       mPublishedServer = static_cast<FlyWebPublishedServerImpl*>(aServer);
       if (mActorDestroyed) {
         mPublishedServer->Close();
         return;
       }
--- a/dom/flyweb/HttpServer.cpp
+++ b/dom/flyweb/HttpServer.cpp
@@ -31,19 +31,20 @@ static LazyLogModule gHttpServerLog("Htt
 #undef LOG_E
 #define LOG_E(...) MOZ_LOG(gHttpServerLog, mozilla::LogLevel::Error, (__VA_ARGS__))
 
 
 NS_IMPL_ISUPPORTS(HttpServer,
                   nsIServerSocketListener,
                   nsILocalCertGetCallback)
 
-HttpServer::HttpServer()
+HttpServer::HttpServer(AbstractThread* aMainThread)
   : mPort()
   , mHttps()
+  , mAbstractMainThread(aMainThread)
 {
 }
 
 HttpServer::~HttpServer()
 {
 }
 
 void
@@ -1248,17 +1249,17 @@ HttpServer::Connection::OnOutputStreamRe
       mOutputCopy =
         StreamCopier::Copy(mOutputBuffers[0].mStream,
                            mOutput,
                            mOutputBuffers[0].mChunked);
 
       RefPtr<Connection> self = this;
 
       mOutputCopy->
-        Then(AbstractThread::MainThread(),
+        Then(mServer->mAbstractMainThread,
              __func__,
              [self, this] (nsresult aStatus) {
                MOZ_ASSERT(mOutputBuffers[0].mStream);
                LOG_V("HttpServer::Connection::OnOutputStreamReady(%p) - "
                      "Sent body. Status 0x%lx",
                      this, aStatus);
 
                mOutputBuffers.RemoveElementAt(0);
--- a/dom/flyweb/HttpServer.h
+++ b/dom/flyweb/HttpServer.h
@@ -16,16 +16,19 @@
 #include "nsIRequestObserver.h"
 #include "mozilla/MozPromise.h"
 #include "nsITransportProvider.h"
 #include "nsILocalCertService.h"
 
 class nsIX509Cert;
 
 namespace mozilla {
+
+class AbstractThread;
+
 namespace dom {
 
 extern bool
 ContainsToken(const nsCString& aList, const nsCString& aToken);
 
 class InternalRequest;
 class InternalResponse;
 
@@ -41,17 +44,17 @@ public:
   virtual void OnWebSocket(InternalRequest* aConnectRequest) = 0;
   virtual void OnServerClose() = 0;
 };
 
 class HttpServer final : public nsIServerSocketListener,
                          public nsILocalCertGetCallback
 {
 public:
-  HttpServer();
+  explicit HttpServer(AbstractThread* aMainThread);
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSISERVERSOCKETLISTENER
   NS_DECL_NSILOCALCERTGETCALLBACK
 
   void Init(int32_t aPort, bool aHttps, HttpServerListener* aListener);
 
   void SendResponse(InternalRequest* aRequest, InternalResponse* aResponse);
@@ -180,14 +183,16 @@ private:
   RefPtr<HttpServerListener> mListener;
   nsCOMPtr<nsIServerSocket> mServerSocket;
   nsCOMPtr<nsIX509Cert> mCert;
 
   nsTArray<RefPtr<Connection>> mConnections;
 
   int32_t mPort;
   bool mHttps;
+
+  const RefPtr<AbstractThread> mAbstractMainThread;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_HttpServer_h