Bug 1231213 - Support IPCStreamSource on the Worker Launcher thread. r=asuth
authorPerry Jiang <perry@mozilla.com>
Thu, 15 Aug 2019 17:25:58 +0000
changeset 488295 448714db54b31cf1bcd3af13c15883f59a8c4d02
parent 488294 f9e8d4068c06c1339efddad1d558e32a87f8ead6
child 488296 49091733782ab828c1f124f57c4a5bf58f598a24
push id36440
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 03:57:48 +0000
treeherdermozilla-central@a58b7dc85887 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1231213
milestone70.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 1231213 - Support IPCStreamSource on the Worker Launcher thread. r=asuth Differential Revision: https://phabricator.services.mozilla.com/D26160
ipc/glue/IPCStreamSource.cpp
--- a/ipc/glue/IPCStreamSource.cpp
+++ b/ipc/glue/IPCStreamSource.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "IPCStreamSource.h"
 #include "BackgroundParent.h"  // for AssertIsOnBackgroundThread
+#include "mozilla/dom/RemoteWorkerService.h"
 #include "mozilla/webrender/WebRenderTypes.h"
 #include "nsIAsyncInputStream.h"
 #include "nsICancelableRunnable.h"
 #include "nsIRunnable.h"
 #include "nsISerialEventTarget.h"
 #include "nsStreamUtils.h"
 #include "nsThreadUtils.h"
 
@@ -108,33 +109,36 @@ bool IPCStreamSource::Initialize() {
   MOZ_ALWAYS_TRUE(NS_SUCCEEDED(mStream->IsNonBlocking(&nonBlocking)));
   // IPCStreamChild reads in the current thread, so it is only supported on
   // non-blocking, async channels
   if (!nonBlocking) {
     return false;
   }
 
   // A source can be used on any thread, but we only support IPCStream on
-  // main thread, Workers and PBackground thread right now.  This is due
-  // to the requirement  that the thread be guaranteed to live long enough to
-  // receive messages. We can enforce this guarantee with a StrongWorkerRef on
-  // worker threads, but not other threads. Main-thread and PBackground thread
-  // do not need anything special in order to be kept alive.
+  // main thread, Workers, Worker Launcher, and PBackground thread right now.
+  // This is due to the requirement  that the thread be guaranteed to live long
+  // enough to receive messages. We can enforce this guarantee with a
+  // StrongWorkerRef on worker threads, but not other threads. Main-thread,
+  // PBackground, and Worker Launcher threads do not need anything special in
+  // order to be kept alive.
   if (!NS_IsMainThread()) {
     if (const auto workerPrivate = dom::GetCurrentThreadWorkerPrivate()) {
       RefPtr<dom::StrongWorkerRef> workerRef =
           dom::StrongWorkerRef::CreateForcibly(workerPrivate,
                                                "IPCStreamSource");
       if (NS_WARN_IF(!workerRef)) {
         return false;
       }
 
       mWorkerRef = std::move(workerRef);
     } else {
-      AssertIsOnBackgroundThread();
+      MOZ_DIAGNOSTIC_ASSERT(
+          IsOnBackgroundThread() ||
+          dom::RemoteWorkerService::Thread()->IsOnCurrentThread());
     }
   }
 
   return true;
 }
 
 void IPCStreamSource::ActorConstructed() {
   MOZ_ASSERT(mState == ePending);