Bug 1407415 - Add a using statement to reduce word wrapping. r=dminor
authorJan-Ivar Bruaroey <jib@mozilla.com>
Fri, 03 May 2019 21:08:40 +0000
changeset 531420 5edef21b353c2e30553f8302affa971ae10d2542
parent 531419 7f0dd201e0593edb157189e0952f8def5e387f11
child 531421 5dbc2ba75388af17e059b91bf235826ef94d6485
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdminor
bugs1407415
milestone68.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 1407415 - Add a using statement to reduce word wrapping. r=dminor Differential Revision: https://phabricator.services.mozilla.com/D29699
dom/media/systemservices/CamerasParent.cpp
--- a/dom/media/systemservices/CamerasParent.cpp
+++ b/dom/media/systemservices/CamerasParent.cpp
@@ -33,16 +33,18 @@
 #undef LOG_ENABLED
 mozilla::LazyLogModule gCamerasParentLog("CamerasParent");
 #define LOG(args) MOZ_LOG(gCamerasParentLog, mozilla::LogLevel::Debug, args)
 #define LOG_VERBOSE(args) \
   MOZ_LOG(gCamerasParentLog, mozilla::LogLevel::Verbose, args)
 #define LOG_ENABLED() MOZ_LOG_TEST(gCamerasParentLog, mozilla::LogLevel::Debug)
 
 namespace mozilla {
+using media::NewRunnableFrom;
+
 namespace camera {
 
 std::map<uint32_t, const char*> sDeviceUniqueIDs;
 std::map<uint32_t, webrtc::VideoCaptureCapability> sAllRequestedCapabilities;
 
 uint32_t ResolutionFeasibilityDistance(int32_t candidate, int32_t requested) {
   // The purpose of this function is to find a smallest resolution
   // which is larger than all requested capabilities.
@@ -100,24 +102,23 @@ StaticMutex CamerasParent::sMutex;
 //   suitable for UI access.
 
 // InputObserver is owned by CamerasParent, and it has a ref to CamerasParent
 void InputObserver::OnDeviceChange() {
   LOG((__PRETTY_FUNCTION__));
   MOZ_ASSERT(mParent);
 
   RefPtr<InputObserver> self(this);
-  RefPtr<nsIRunnable> ipc_runnable =
-      media::NewRunnableFrom([self]() -> nsresult {
-        if (self->mParent->IsShuttingDown()) {
-          return NS_ERROR_FAILURE;
-        }
-        Unused << self->mParent->SendDeviceChange();
-        return NS_OK;
-      });
+  RefPtr<nsIRunnable> ipc_runnable = NewRunnableFrom([self]() {
+    if (self->mParent->IsShuttingDown()) {
+      return NS_ERROR_FAILURE;
+    }
+    Unused << self->mParent->SendDeviceChange();
+    return NS_OK;
+  });
 
   nsIEventTarget* target = mParent->GetBackgroundEventTarget();
   MOZ_ASSERT(target != nullptr);
   target->Dispatch(ipc_runnable, NS_DISPATCH_NORMAL);
 };
 
 class DeliverFrameRunnable : public mozilla::Runnable {
  public:
@@ -213,23 +214,22 @@ nsresult CamerasParent::DispatchToVideoC
 }
 
 void CamerasParent::StopVideoCapture() {
   LOG((__PRETTY_FUNCTION__));
   // We are called from the main thread (xpcom-shutdown) or
   // from PBackground (when the Actor shuts down).
   // Shut down the WebRTC stack (on the capture thread)
   RefPtr<CamerasParent> self(this);
-  RefPtr<Runnable> webrtc_runnable =
-      media::NewRunnableFrom([self]() -> nsresult {
-        MonitorAutoLock lock(*(self->sThreadMonitor));
-        self->CloseEngines();
-        self->sThreadMonitor->NotifyAll();
-        return NS_OK;
-      });
+  RefPtr<Runnable> webrtc_runnable = NewRunnableFrom([self]() {
+    MonitorAutoLock lock(*(self->sThreadMonitor));
+    self->CloseEngines();
+    self->sThreadMonitor->NotifyAll();
+    return NS_OK;
+  });
   DebugOnly<nsresult> rv = DispatchToVideoCaptureThread(webrtc_runnable);
 #ifdef DEBUG
   // It's ok for the dispatch to fail if the cleanup it has to do
   // has been done already.
   MOZ_ASSERT(NS_SUCCEEDED(rv) || !mWebRTCAlive);
 #endif
   // Hold here until the WebRTC thread is gone. We need to dispatch
   // the thread deletion *now*, or there will be no more possibility
@@ -238,24 +238,23 @@ void CamerasParent::StopVideoCapture() {
   while (mWebRTCAlive) {
     sThreadMonitor->Wait();
   }
   // After closing the WebRTC stack, clean up the
   // VideoCapture thread.
   if (sNumOfOpenCamerasParentEngines == 0 && self->sVideoCaptureThread) {
     base::Thread* thread = self->sVideoCaptureThread;
     self->sVideoCaptureThread = nullptr;
-    RefPtr<Runnable> threadShutdown =
-        media::NewRunnableFrom([thread]() -> nsresult {
-          if (thread->IsRunning()) {
-            thread->Stop();
-          }
-          delete thread;
-          return NS_OK;
-        });
+    RefPtr<Runnable> threadShutdown = NewRunnableFrom([thread]() {
+      if (thread->IsRunning()) {
+        thread->Stop();
+      }
+      delete thread;
+      return NS_OK;
+    });
     if (NS_FAILED(NS_DispatchToMainThread(threadShutdown))) {
       LOG(("Could not dispatch VideoCaptureThread destruction"));
     }
   }
 }
 
 int CamerasParent::DeliverFrameOverIPC(CaptureEngine capEng, uint32_t aStreamId,
                                        ShmemBuffer buffer,
@@ -446,221 +445,209 @@ VideoEngine* CamerasParent::EnsureInitia
 // chain a runnable to send back the result on the IPC thread.
 // It would be nice to get rid of the code duplication here,
 // perhaps via Promises.
 mozilla::ipc::IPCResult CamerasParent::RecvNumberOfCaptureDevices(
     const CaptureEngine& aCapEngine) {
   LOG((__PRETTY_FUNCTION__));
   LOG(("CaptureEngine=%d", aCapEngine));
   RefPtr<CamerasParent> self(this);
-  RefPtr<Runnable> webrtc_runnable =
-      media::NewRunnableFrom([self, aCapEngine]() -> nsresult {
-        int num = -1;
-        if (auto engine = self->EnsureInitialized(aCapEngine)) {
-          if (auto devInfo = engine->GetOrCreateVideoCaptureDeviceInfo()) {
-            num = devInfo->NumberOfDevices();
-          }
-        }
-        RefPtr<nsIRunnable> ipc_runnable =
-            media::NewRunnableFrom([self, num]() -> nsresult {
-              if (!self->mChildIsAlive) {
-                return NS_ERROR_FAILURE;
-              }
+  RefPtr<Runnable> webrtc_runnable = NewRunnableFrom([self, aCapEngine]() {
+    int num = -1;
+    if (auto engine = self->EnsureInitialized(aCapEngine)) {
+      if (auto devInfo = engine->GetOrCreateVideoCaptureDeviceInfo()) {
+        num = devInfo->NumberOfDevices();
+      }
+    }
+    RefPtr<nsIRunnable> ipc_runnable = NewRunnableFrom([self, num]() {
+      if (!self->mChildIsAlive) {
+        return NS_ERROR_FAILURE;
+      }
 
-              if (num < 0) {
-                LOG(("RecvNumberOfCaptureDevices couldn't find devices"));
-                Unused << self->SendReplyFailure();
-                return NS_ERROR_FAILURE;
-              }
+      if (num < 0) {
+        LOG(("RecvNumberOfCaptureDevices couldn't find devices"));
+        Unused << self->SendReplyFailure();
+        return NS_ERROR_FAILURE;
+      }
 
-              LOG(("RecvNumberOfCaptureDevices: %d", num));
-              Unused << self->SendReplyNumberOfCaptureDevices(num);
-              return NS_OK;
-            });
-        self->mPBackgroundEventTarget->Dispatch(ipc_runnable,
-                                                NS_DISPATCH_NORMAL);
-        return NS_OK;
-      });
+      LOG(("RecvNumberOfCaptureDevices: %d", num));
+      Unused << self->SendReplyNumberOfCaptureDevices(num);
+      return NS_OK;
+    });
+    self->mPBackgroundEventTarget->Dispatch(ipc_runnable, NS_DISPATCH_NORMAL);
+    return NS_OK;
+  });
   DispatchToVideoCaptureThread(webrtc_runnable);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult CamerasParent::RecvEnsureInitialized(
     const CaptureEngine& aCapEngine) {
   LOG((__PRETTY_FUNCTION__));
 
   RefPtr<CamerasParent> self(this);
-  RefPtr<Runnable> webrtc_runnable =
-      media::NewRunnableFrom([self, aCapEngine]() -> nsresult {
-        bool result = self->EnsureInitialized(aCapEngine);
+  RefPtr<Runnable> webrtc_runnable = NewRunnableFrom([self, aCapEngine]() {
+    bool result = self->EnsureInitialized(aCapEngine);
 
-        RefPtr<nsIRunnable> ipc_runnable =
-            media::NewRunnableFrom([self, result]() -> nsresult {
-              if (!self->mChildIsAlive) {
-                return NS_ERROR_FAILURE;
-              }
+    RefPtr<nsIRunnable> ipc_runnable = NewRunnableFrom([self, result]() {
+      if (!self->mChildIsAlive) {
+        return NS_ERROR_FAILURE;
+      }
 
-              if (!result) {
-                LOG(("RecvEnsureInitialized failed"));
-                Unused << self->SendReplyFailure();
-                return NS_ERROR_FAILURE;
-              }
+      if (!result) {
+        LOG(("RecvEnsureInitialized failed"));
+        Unused << self->SendReplyFailure();
+        return NS_ERROR_FAILURE;
+      }
 
-              LOG(("RecvEnsureInitialized succeeded"));
-              Unused << self->SendReplySuccess();
-              return NS_OK;
-            });
-        self->mPBackgroundEventTarget->Dispatch(ipc_runnable,
-                                                NS_DISPATCH_NORMAL);
-        return NS_OK;
-      });
+      LOG(("RecvEnsureInitialized succeeded"));
+      Unused << self->SendReplySuccess();
+      return NS_OK;
+    });
+    self->mPBackgroundEventTarget->Dispatch(ipc_runnable, NS_DISPATCH_NORMAL);
+    return NS_OK;
+  });
   DispatchToVideoCaptureThread(webrtc_runnable);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult CamerasParent::RecvNumberOfCapabilities(
     const CaptureEngine& aCapEngine, const nsCString& unique_id) {
   LOG((__PRETTY_FUNCTION__));
   LOG(("Getting caps for %s", unique_id.get()));
 
   RefPtr<CamerasParent> self(this);
-  RefPtr<Runnable> webrtc_runnable =
-      media::NewRunnableFrom([self, unique_id, aCapEngine]() -> nsresult {
-        int num = -1;
-        if (auto engine = self->EnsureInitialized(aCapEngine)) {
-          if (auto devInfo = engine->GetOrCreateVideoCaptureDeviceInfo()) {
-            num = devInfo->NumberOfCapabilities(unique_id.get());
-          }
-        }
-        RefPtr<nsIRunnable> ipc_runnable =
-            media::NewRunnableFrom([self, num]() -> nsresult {
-              if (!self->mChildIsAlive) {
-                return NS_ERROR_FAILURE;
-              }
+  RefPtr<Runnable> webrtc_runnable = NewRunnableFrom([self, unique_id,
+                                                      aCapEngine]() {
+    int num = -1;
+    if (auto engine = self->EnsureInitialized(aCapEngine)) {
+      if (auto devInfo = engine->GetOrCreateVideoCaptureDeviceInfo()) {
+        num = devInfo->NumberOfCapabilities(unique_id.get());
+      }
+    }
+    RefPtr<nsIRunnable> ipc_runnable = NewRunnableFrom([self, num]() {
+      if (!self->mChildIsAlive) {
+        return NS_ERROR_FAILURE;
+      }
 
-              if (num < 0) {
-                LOG(("RecvNumberOfCapabilities couldn't find capabilities"));
-                Unused << self->SendReplyFailure();
-                return NS_ERROR_FAILURE;
-              }
+      if (num < 0) {
+        LOG(("RecvNumberOfCapabilities couldn't find capabilities"));
+        Unused << self->SendReplyFailure();
+        return NS_ERROR_FAILURE;
+      }
 
-              LOG(("RecvNumberOfCapabilities: %d", num));
-              Unused << self->SendReplyNumberOfCapabilities(num);
-              return NS_OK;
-            });
-        self->mPBackgroundEventTarget->Dispatch(ipc_runnable,
-                                                NS_DISPATCH_NORMAL);
-        return NS_OK;
-      });
+      LOG(("RecvNumberOfCapabilities: %d", num));
+      Unused << self->SendReplyNumberOfCapabilities(num);
+      return NS_OK;
+    });
+    self->mPBackgroundEventTarget->Dispatch(ipc_runnable, NS_DISPATCH_NORMAL);
+    return NS_OK;
+  });
   DispatchToVideoCaptureThread(webrtc_runnable);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult CamerasParent::RecvGetCaptureCapability(
     const CaptureEngine& aCapEngine, const nsCString& unique_id,
     const int& num) {
   LOG((__PRETTY_FUNCTION__));
   LOG(("RecvGetCaptureCapability: %s %d", unique_id.get(), num));
 
   RefPtr<CamerasParent> self(this);
-  RefPtr<Runnable> webrtc_runnable =
-      media::NewRunnableFrom([self, unique_id, aCapEngine, num]() -> nsresult {
-        webrtc::VideoCaptureCapability webrtcCaps;
-        int error = -1;
-        if (auto engine = self->EnsureInitialized(aCapEngine)) {
-          if (auto devInfo = engine->GetOrCreateVideoCaptureDeviceInfo()) {
-            error = devInfo->GetCapability(unique_id.get(), num, webrtcCaps);
-          }
+  RefPtr<Runnable> webrtc_runnable = NewRunnableFrom([self, unique_id,
+                                                      aCapEngine, num]() {
+    webrtc::VideoCaptureCapability webrtcCaps;
+    int error = -1;
+    if (auto engine = self->EnsureInitialized(aCapEngine)) {
+      if (auto devInfo = engine->GetOrCreateVideoCaptureDeviceInfo()) {
+        error = devInfo->GetCapability(unique_id.get(), num, webrtcCaps);
+      }
 
-          if (!error && aCapEngine == CameraEngine) {
-            auto iter = self->mAllCandidateCapabilities.find(unique_id);
-            if (iter == self->mAllCandidateCapabilities.end()) {
-              std::map<uint32_t, webrtc::VideoCaptureCapability>
-                  candidateCapabilities;
-              candidateCapabilities.emplace(num, webrtcCaps);
-              self->mAllCandidateCapabilities.emplace(nsCString(unique_id),
-                                                      candidateCapabilities);
-            } else {
-              (iter->second).emplace(num, webrtcCaps);
-            }
-          }
+      if (!error && aCapEngine == CameraEngine) {
+        auto iter = self->mAllCandidateCapabilities.find(unique_id);
+        if (iter == self->mAllCandidateCapabilities.end()) {
+          std::map<uint32_t, webrtc::VideoCaptureCapability>
+              candidateCapabilities;
+          candidateCapabilities.emplace(num, webrtcCaps);
+          self->mAllCandidateCapabilities.emplace(nsCString(unique_id),
+                                                  candidateCapabilities);
+        } else {
+          (iter->second).emplace(num, webrtcCaps);
         }
-        RefPtr<nsIRunnable> ipc_runnable =
-            media::NewRunnableFrom([self, webrtcCaps, error]() -> nsresult {
-              if (!self->mChildIsAlive) {
-                return NS_ERROR_FAILURE;
-              }
-              VideoCaptureCapability capCap(
-                  webrtcCaps.width, webrtcCaps.height, webrtcCaps.maxFPS,
-                  static_cast<int>(webrtcCaps.videoType),
-                  webrtcCaps.interlaced);
-              LOG(("Capability: %u %u %u %d %d", webrtcCaps.width,
-                   webrtcCaps.height, webrtcCaps.maxFPS,
-                   static_cast<int>(webrtcCaps.videoType),
-                   webrtcCaps.interlaced));
-              if (error) {
-                Unused << self->SendReplyFailure();
-                return NS_ERROR_FAILURE;
-              }
-              Unused << self->SendReplyGetCaptureCapability(capCap);
-              return NS_OK;
-            });
-        self->mPBackgroundEventTarget->Dispatch(ipc_runnable,
-                                                NS_DISPATCH_NORMAL);
-        return NS_OK;
-      });
+      }
+    }
+    RefPtr<nsIRunnable> ipc_runnable =
+        NewRunnableFrom([self, webrtcCaps, error]() {
+          if (!self->mChildIsAlive) {
+            return NS_ERROR_FAILURE;
+          }
+          VideoCaptureCapability capCap(
+              webrtcCaps.width, webrtcCaps.height, webrtcCaps.maxFPS,
+              static_cast<int>(webrtcCaps.videoType), webrtcCaps.interlaced);
+          LOG(("Capability: %u %u %u %d %d", webrtcCaps.width,
+               webrtcCaps.height, webrtcCaps.maxFPS,
+               static_cast<int>(webrtcCaps.videoType), webrtcCaps.interlaced));
+          if (error) {
+            Unused << self->SendReplyFailure();
+            return NS_ERROR_FAILURE;
+          }
+          Unused << self->SendReplyGetCaptureCapability(capCap);
+          return NS_OK;
+        });
+    self->mPBackgroundEventTarget->Dispatch(ipc_runnable, NS_DISPATCH_NORMAL);
+    return NS_OK;
+  });
   DispatchToVideoCaptureThread(webrtc_runnable);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult CamerasParent::RecvGetCaptureDevice(
     const CaptureEngine& aCapEngine, const int& aListNumber) {
   LOG((__PRETTY_FUNCTION__));
 
   RefPtr<CamerasParent> self(this);
-  RefPtr<Runnable> webrtc_runnable =
-      media::NewRunnableFrom([self, aCapEngine, aListNumber]() -> nsresult {
-        char deviceName[MediaEngineSource::kMaxDeviceNameLength];
-        char deviceUniqueId[MediaEngineSource::kMaxUniqueIdLength];
-        nsCString name;
-        nsCString uniqueId;
-        pid_t devicePid = 0;
-        int error = -1;
-        if (auto engine = self->EnsureInitialized(aCapEngine)) {
-          if (auto devInfo = engine->GetOrCreateVideoCaptureDeviceInfo()) {
-            error = devInfo->GetDeviceName(
-                aListNumber, deviceName, sizeof(deviceName), deviceUniqueId,
-                sizeof(deviceUniqueId), nullptr, 0, &devicePid);
+  RefPtr<Runnable> webrtc_runnable = NewRunnableFrom([self, aCapEngine,
+                                                      aListNumber]() {
+    char deviceName[MediaEngineSource::kMaxDeviceNameLength];
+    char deviceUniqueId[MediaEngineSource::kMaxUniqueIdLength];
+    nsCString name;
+    nsCString uniqueId;
+    pid_t devicePid = 0;
+    int error = -1;
+    if (auto engine = self->EnsureInitialized(aCapEngine)) {
+      if (auto devInfo = engine->GetOrCreateVideoCaptureDeviceInfo()) {
+        error = devInfo->GetDeviceName(
+            aListNumber, deviceName, sizeof(deviceName), deviceUniqueId,
+            sizeof(deviceUniqueId), nullptr, 0, &devicePid);
+      }
+    }
+    if (!error) {
+      name.Assign(deviceName);
+      uniqueId.Assign(deviceUniqueId);
+    }
+    RefPtr<nsIRunnable> ipc_runnable =
+        NewRunnableFrom([self, error, name, uniqueId, devicePid]() {
+          if (!self->mChildIsAlive) {
+            return NS_ERROR_FAILURE;
           }
-        }
-        if (!error) {
-          name.Assign(deviceName);
-          uniqueId.Assign(deviceUniqueId);
-        }
-        RefPtr<nsIRunnable> ipc_runnable =
-            media::NewRunnableFrom([self, error, name, uniqueId, devicePid]() {
-              if (!self->mChildIsAlive) {
-                return NS_ERROR_FAILURE;
-              }
-              if (error) {
-                LOG(("GetCaptureDevice failed: %d", error));
-                Unused << self->SendReplyFailure();
-                return NS_ERROR_FAILURE;
-              }
-              bool scary = (devicePid == getpid());
+          if (error) {
+            LOG(("GetCaptureDevice failed: %d", error));
+            Unused << self->SendReplyFailure();
+            return NS_ERROR_FAILURE;
+          }
+          bool scary = (devicePid == getpid());
 
-              LOG(("Returning %s name %s id (pid = %d)%s", name.get(),
-                   uniqueId.get(), devicePid, (scary ? " (scary)" : "")));
-              Unused << self->SendReplyGetCaptureDevice(name, uniqueId, scary);
-              return NS_OK;
-            });
-        self->mPBackgroundEventTarget->Dispatch(ipc_runnable,
-                                                NS_DISPATCH_NORMAL);
-        return NS_OK;
-      });
+          LOG(("Returning %s name %s id (pid = %d)%s", name.get(),
+               uniqueId.get(), devicePid, (scary ? " (scary)" : "")));
+          Unused << self->SendReplyGetCaptureDevice(name, uniqueId, scary);
+          return NS_OK;
+        });
+    self->mPBackgroundEventTarget->Dispatch(ipc_runnable, NS_DISPATCH_NORMAL);
+    return NS_OK;
+  });
   DispatchToVideoCaptureThread(webrtc_runnable);
   return IPC_OK();
 }
 
 // Find out whether the given principal has permission to use the
 // camera. If the permission is not persistent, we'll make it
 // a one-shot by removing the (session) permission.
 static bool HasCameraPermission(const ipc::PrincipalInfo& aPrincipalInfo) {
@@ -708,73 +695,72 @@ static bool HasCameraPermission(const ip
   return allowed;
 }
 
 mozilla::ipc::IPCResult CamerasParent::RecvAllocateCaptureDevice(
     const CaptureEngine& aCapEngine, const nsCString& unique_id,
     const PrincipalInfo& aPrincipalInfo) {
   LOG(("%s: Verifying permissions", __PRETTY_FUNCTION__));
   RefPtr<CamerasParent> self(this);
-  RefPtr<Runnable> mainthread_runnable = media::NewRunnableFrom(
-      [self, aCapEngine, unique_id, aPrincipalInfo]() -> nsresult {
-        // Verify whether the claimed origin has received permission
-        // to use the camera, either persistently or this session (one shot).
-        bool allowed = HasCameraPermission(aPrincipalInfo);
-        if (!allowed) {
-          // Developer preference for turning off permission check.
-          if (Preferences::GetBool("media.navigator.permission.disabled",
-                                   false) ||
-              Preferences::GetBool("media.navigator.permission.fake")) {
-            allowed = true;
-            LOG(
-                ("No permission but checks are disabled or fake sources "
-                 "active"));
-          } else {
-            LOG(("No camera permission for this origin"));
+  RefPtr<Runnable> mainthread_runnable = NewRunnableFrom([self, aCapEngine,
+                                                          unique_id,
+                                                          aPrincipalInfo]() {
+    // Verify whether the claimed origin has received permission
+    // to use the camera, either persistently or this session (one shot).
+    bool allowed = HasCameraPermission(aPrincipalInfo);
+    if (!allowed) {
+      // Developer preference for turning off permission check.
+      if (Preferences::GetBool("media.navigator.permission.disabled", false) ||
+          Preferences::GetBool("media.navigator.permission.fake")) {
+        allowed = true;
+        LOG(
+            ("No permission but checks are disabled or fake sources "
+             "active"));
+      } else {
+        LOG(("No camera permission for this origin"));
+      }
+    }
+    // After retrieving the permission (or not) on the main thread,
+    // bounce to the WebRTC thread to allocate the device (or not),
+    // then bounce back to the IPC thread for the reply to content.
+    RefPtr<Runnable> webrtc_runnable =
+        NewRunnableFrom([self, allowed, aCapEngine, unique_id]() {
+          int numdev = -1;
+          int error = -1;
+          if (allowed && self->EnsureInitialized(aCapEngine)) {
+            StaticRefPtr<VideoEngine>& engine = self->sEngines[aCapEngine];
+            engine->CreateVideoCapture(numdev, unique_id.get());
+            engine->WithEntry(numdev, [&error](VideoEngine::CaptureEntry& cap) {
+              if (cap.VideoCapture()) {
+                error = 0;
+              }
+            });
           }
-        }
-        // After retrieving the permission (or not) on the main thread,
-        // bounce to the WebRTC thread to allocate the device (or not),
-        // then bounce back to the IPC thread for the reply to content.
-        RefPtr<Runnable> webrtc_runnable = media::NewRunnableFrom(
-            [self, allowed, aCapEngine, unique_id]() -> nsresult {
-              int numdev = -1;
-              int error = -1;
-              if (allowed && self->EnsureInitialized(aCapEngine)) {
-                StaticRefPtr<VideoEngine>& engine = self->sEngines[aCapEngine];
-                engine->CreateVideoCapture(numdev, unique_id.get());
-                engine->WithEntry(numdev,
-                                  [&error](VideoEngine::CaptureEntry& cap) {
-                                    if (cap.VideoCapture()) {
-                                      error = 0;
-                                    }
-                                  });
-              }
-              RefPtr<nsIRunnable> ipc_runnable =
-                  media::NewRunnableFrom([self, numdev, error]() -> nsresult {
-                    if (!self->mChildIsAlive) {
-                      return NS_ERROR_FAILURE;
-                    }
+          RefPtr<nsIRunnable> ipc_runnable =
+              NewRunnableFrom([self, numdev, error]() {
+                if (!self->mChildIsAlive) {
+                  return NS_ERROR_FAILURE;
+                }
+
+                if (error) {
+                  Unused << self->SendReplyFailure();
+                  return NS_ERROR_FAILURE;
+                }
 
-                    if (error) {
-                      Unused << self->SendReplyFailure();
-                      return NS_ERROR_FAILURE;
-                    }
-
-                    LOG(("Allocated device nr %d", numdev));
-                    Unused << self->SendReplyAllocateCaptureDevice(numdev);
-                    return NS_OK;
-                  });
-              self->mPBackgroundEventTarget->Dispatch(ipc_runnable,
-                                                      NS_DISPATCH_NORMAL);
-              return NS_OK;
-            });
-        self->DispatchToVideoCaptureThread(webrtc_runnable);
-        return NS_OK;
-      });
+                LOG(("Allocated device nr %d", numdev));
+                Unused << self->SendReplyAllocateCaptureDevice(numdev);
+                return NS_OK;
+              });
+          self->mPBackgroundEventTarget->Dispatch(ipc_runnable,
+                                                  NS_DISPATCH_NORMAL);
+          return NS_OK;
+        });
+    self->DispatchToVideoCaptureThread(webrtc_runnable);
+    return NS_OK;
+  });
   NS_DispatchToMainThread(mainthread_runnable);
   return IPC_OK();
 }
 
 int CamerasParent::ReleaseCaptureDevice(const CaptureEngine& aCapEngine,
                                         const int& capnum) {
   int error = -1;
   if (auto engine = EnsureInitialized(aCapEngine)) {
@@ -784,187 +770,180 @@ int CamerasParent::ReleaseCaptureDevice(
 }
 
 mozilla::ipc::IPCResult CamerasParent::RecvReleaseCaptureDevice(
     const CaptureEngine& aCapEngine, const int& numdev) {
   LOG((__PRETTY_FUNCTION__));
   LOG(("RecvReleaseCamera device nr %d", numdev));
 
   RefPtr<CamerasParent> self(this);
-  RefPtr<Runnable> webrtc_runnable =
-      media::NewRunnableFrom([self, aCapEngine, numdev]() -> nsresult {
-        int error = self->ReleaseCaptureDevice(aCapEngine, numdev);
-        RefPtr<nsIRunnable> ipc_runnable =
-            media::NewRunnableFrom([self, error, numdev]() -> nsresult {
-              if (!self->mChildIsAlive) {
-                return NS_ERROR_FAILURE;
-              }
+  RefPtr<Runnable> webrtc_runnable = NewRunnableFrom([self, aCapEngine,
+                                                      numdev]() {
+    int error = self->ReleaseCaptureDevice(aCapEngine, numdev);
+    RefPtr<nsIRunnable> ipc_runnable = NewRunnableFrom([self, error, numdev]() {
+      if (!self->mChildIsAlive) {
+        return NS_ERROR_FAILURE;
+      }
 
-              if (error) {
-                Unused << self->SendReplyFailure();
-                LOG(("Failed to free device nr %d", numdev));
-                return NS_ERROR_FAILURE;
-              }
+      if (error) {
+        Unused << self->SendReplyFailure();
+        LOG(("Failed to free device nr %d", numdev));
+        return NS_ERROR_FAILURE;
+      }
 
-              Unused << self->SendReplySuccess();
-              LOG(("Freed device nr %d", numdev));
-              return NS_OK;
-            });
-        self->mPBackgroundEventTarget->Dispatch(ipc_runnable,
-                                                NS_DISPATCH_NORMAL);
-        return NS_OK;
-      });
+      Unused << self->SendReplySuccess();
+      LOG(("Freed device nr %d", numdev));
+      return NS_OK;
+    });
+    self->mPBackgroundEventTarget->Dispatch(ipc_runnable, NS_DISPATCH_NORMAL);
+    return NS_OK;
+  });
   DispatchToVideoCaptureThread(webrtc_runnable);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult CamerasParent::RecvStartCapture(
     const CaptureEngine& aCapEngine, const int& capnum,
     const VideoCaptureCapability& ipcCaps) {
   LOG((__PRETTY_FUNCTION__));
 
   RefPtr<CamerasParent> self(this);
-  RefPtr<Runnable> webrtc_runnable =
-      media::NewRunnableFrom([self, aCapEngine, capnum, ipcCaps]() -> nsresult {
-        LOG((__PRETTY_FUNCTION__));
-        CallbackHelper** cbh;
-        int error = -1;
-        if (self->EnsureInitialized(aCapEngine)) {
-          cbh = self->mCallbacks.AppendElement(new CallbackHelper(
-              static_cast<CaptureEngine>(aCapEngine), capnum, self));
-
-          self->sEngines[aCapEngine]->WithEntry(
-              capnum, [&capnum, &aCapEngine, &error, &ipcCaps, &cbh,
-                       self](VideoEngine::CaptureEntry& cap) {
-                webrtc::VideoCaptureCapability capability;
-                capability.width = ipcCaps.width();
-                capability.height = ipcCaps.height();
-                capability.maxFPS = ipcCaps.maxFPS();
-                capability.videoType =
-                    static_cast<webrtc::VideoType>(ipcCaps.videoType());
-                capability.interlaced = ipcCaps.interlaced();
+  RefPtr<Runnable> webrtc_runnable = NewRunnableFrom([self, aCapEngine, capnum,
+                                                      ipcCaps]() {
+    LOG((__PRETTY_FUNCTION__));
+    CallbackHelper** cbh;
+    int error = -1;
+    if (self->EnsureInitialized(aCapEngine)) {
+      cbh = self->mCallbacks.AppendElement(new CallbackHelper(
+          static_cast<CaptureEngine>(aCapEngine), capnum, self));
 
-                MOZ_DIAGNOSTIC_ASSERT(sDeviceUniqueIDs.find(capnum) ==
-                                      sDeviceUniqueIDs.end());
-                sDeviceUniqueIDs.emplace(
-                    capnum, cap.VideoCapture()->CurrentDeviceName());
-
-                MOZ_DIAGNOSTIC_ASSERT(sAllRequestedCapabilities.find(capnum) ==
-                                      sAllRequestedCapabilities.end());
-                sAllRequestedCapabilities.emplace(capnum, capability);
+      self->sEngines[aCapEngine]->WithEntry(
+          capnum, [&capnum, &aCapEngine, &error, &ipcCaps, &cbh,
+                   self](VideoEngine::CaptureEntry& cap) {
+            webrtc::VideoCaptureCapability capability;
+            capability.width = ipcCaps.width();
+            capability.height = ipcCaps.height();
+            capability.maxFPS = ipcCaps.maxFPS();
+            capability.videoType =
+                static_cast<webrtc::VideoType>(ipcCaps.videoType());
+            capability.interlaced = ipcCaps.interlaced();
 
-                if (aCapEngine == CameraEngine) {
-                  for (const auto& it : sDeviceUniqueIDs) {
-                    if (strcmp(it.second,
-                               cap.VideoCapture()->CurrentDeviceName()) == 0) {
-                      capability.width =
-                          std::max(capability.width,
-                                   sAllRequestedCapabilities[it.first].width);
-                      capability.height =
-                          std::max(capability.height,
-                                   sAllRequestedCapabilities[it.first].height);
-                      capability.maxFPS =
-                          std::max(capability.maxFPS,
-                                   sAllRequestedCapabilities[it.first].maxFPS);
-                    }
-                  }
+            MOZ_DIAGNOSTIC_ASSERT(sDeviceUniqueIDs.find(capnum) ==
+                                  sDeviceUniqueIDs.end());
+            sDeviceUniqueIDs.emplace(capnum,
+                                     cap.VideoCapture()->CurrentDeviceName());
+
+            MOZ_DIAGNOSTIC_ASSERT(sAllRequestedCapabilities.find(capnum) ==
+                                  sAllRequestedCapabilities.end());
+            sAllRequestedCapabilities.emplace(capnum, capability);
 
-                  auto candidateCapabilities =
-                      self->mAllCandidateCapabilities.find(
-                          nsCString(cap.VideoCapture()->CurrentDeviceName()));
-                  if ((candidateCapabilities !=
-                       self->mAllCandidateCapabilities.end()) &&
-                      (!candidateCapabilities->second.empty())) {
-                    int32_t minIdx = -1;
-                    uint64_t minDistance = UINT64_MAX;
+            if (aCapEngine == CameraEngine) {
+              for (const auto& it : sDeviceUniqueIDs) {
+                if (strcmp(it.second,
+                           cap.VideoCapture()->CurrentDeviceName()) == 0) {
+                  capability.width =
+                      std::max(capability.width,
+                               sAllRequestedCapabilities[it.first].width);
+                  capability.height =
+                      std::max(capability.height,
+                               sAllRequestedCapabilities[it.first].height);
+                  capability.maxFPS =
+                      std::max(capability.maxFPS,
+                               sAllRequestedCapabilities[it.first].maxFPS);
+                }
+              }
 
-                    for (auto& candidateCapability :
-                         candidateCapabilities->second) {
-                      if (candidateCapability.second.videoType !=
-                          capability.videoType) {
-                        continue;
-                      }
-                      // The first priority is finding a suitable resolution.
-                      // So here we raise the weight of width and height
-                      uint64_t distance =
-                          uint64_t(ResolutionFeasibilityDistance(
-                              candidateCapability.second.width,
-                              capability.width)) +
-                          uint64_t(ResolutionFeasibilityDistance(
-                              candidateCapability.second.height,
-                              capability.height)) +
-                          uint64_t(FeasibilityDistance(
-                              candidateCapability.second.maxFPS,
-                              capability.maxFPS));
-                      if (distance < minDistance) {
-                        minIdx = candidateCapability.first;
-                        minDistance = distance;
-                      }
-                    }
-                    MOZ_ASSERT(minIdx != -1);
-                    capability = candidateCapabilities->second[minIdx];
+              auto candidateCapabilities = self->mAllCandidateCapabilities.find(
+                  nsCString(cap.VideoCapture()->CurrentDeviceName()));
+              if ((candidateCapabilities !=
+                   self->mAllCandidateCapabilities.end()) &&
+                  (!candidateCapabilities->second.empty())) {
+                int32_t minIdx = -1;
+                uint64_t minDistance = UINT64_MAX;
+
+                for (auto& candidateCapability :
+                     candidateCapabilities->second) {
+                  if (candidateCapability.second.videoType !=
+                      capability.videoType) {
+                    continue;
                   }
-                } else if (aCapEngine == ScreenEngine ||
-                           aCapEngine == BrowserEngine ||
-                           aCapEngine == WinEngine) {
-                  for (const auto& it : sDeviceUniqueIDs) {
-                    if (strcmp(it.second,
-                               cap.VideoCapture()->CurrentDeviceName()) == 0) {
-                      capability.maxFPS =
-                          std::max(capability.maxFPS,
-                                   sAllRequestedCapabilities[it.first].maxFPS);
-                    }
+                  // The first priority is finding a suitable resolution.
+                  // So here we raise the weight of width and height
+                  uint64_t distance =
+                      uint64_t(ResolutionFeasibilityDistance(
+                          candidateCapability.second.width, capability.width)) +
+                      uint64_t(ResolutionFeasibilityDistance(
+                          candidateCapability.second.height,
+                          capability.height)) +
+                      uint64_t(
+                          FeasibilityDistance(candidateCapability.second.maxFPS,
+                                              capability.maxFPS));
+                  if (distance < minDistance) {
+                    minIdx = candidateCapability.first;
+                    minDistance = distance;
                   }
                 }
-
-                error = cap.VideoCapture()->StartCapture(capability);
-
-                if (!error) {
-                  cap.VideoCapture()->RegisterCaptureDataCallback(
-                      static_cast<rtc::VideoSinkInterface<webrtc::VideoFrame>*>(
-                          *cbh));
-                } else {
-                  sDeviceUniqueIDs.erase(capnum);
-                  sAllRequestedCapabilities.erase(capnum);
+                MOZ_ASSERT(minIdx != -1);
+                capability = candidateCapabilities->second[minIdx];
+              }
+            } else if (aCapEngine == ScreenEngine ||
+                       aCapEngine == BrowserEngine || aCapEngine == WinEngine) {
+              for (const auto& it : sDeviceUniqueIDs) {
+                if (strcmp(it.second,
+                           cap.VideoCapture()->CurrentDeviceName()) == 0) {
+                  capability.maxFPS =
+                      std::max(capability.maxFPS,
+                               sAllRequestedCapabilities[it.first].maxFPS);
                 }
-              });
-        }
-        RefPtr<nsIRunnable> ipc_runnable =
-            media::NewRunnableFrom([self, error]() -> nsresult {
-              if (!self->mChildIsAlive) {
-                return NS_ERROR_FAILURE;
               }
+            }
+
+            error = cap.VideoCapture()->StartCapture(capability);
 
-              if (!error) {
-                Unused << self->SendReplySuccess();
-                return NS_OK;
-              }
+            if (!error) {
+              cap.VideoCapture()->RegisterCaptureDataCallback(
+                  static_cast<rtc::VideoSinkInterface<webrtc::VideoFrame>*>(
+                      *cbh));
+            } else {
+              sDeviceUniqueIDs.erase(capnum);
+              sAllRequestedCapabilities.erase(capnum);
+            }
+          });
+    }
+    RefPtr<nsIRunnable> ipc_runnable = NewRunnableFrom([self, error]() {
+      if (!self->mChildIsAlive) {
+        return NS_ERROR_FAILURE;
+      }
 
-              Unused << self->SendReplyFailure();
-              return NS_ERROR_FAILURE;
-            });
-        self->mPBackgroundEventTarget->Dispatch(ipc_runnable,
-                                                NS_DISPATCH_NORMAL);
+      if (!error) {
+        Unused << self->SendReplySuccess();
         return NS_OK;
-      });
+      }
+
+      Unused << self->SendReplyFailure();
+      return NS_ERROR_FAILURE;
+    });
+    self->mPBackgroundEventTarget->Dispatch(ipc_runnable, NS_DISPATCH_NORMAL);
+    return NS_OK;
+  });
   DispatchToVideoCaptureThread(webrtc_runnable);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult CamerasParent::RecvFocusOnSelectedSource(
     const CaptureEngine& aCapEngine, const int& aCapNum) {
   LOG((__PRETTY_FUNCTION__));
-  RefPtr<Runnable> webrtc_runnable = media::NewRunnableFrom(
-      [self = RefPtr<CamerasParent>(this), aCapEngine, aCapNum]() -> nsresult {
+  RefPtr<Runnable> webrtc_runnable = NewRunnableFrom(
+      [self = RefPtr<CamerasParent>(this), aCapEngine, aCapNum]() {
         if (auto engine = self->EnsureInitialized(aCapEngine)) {
           engine->WithEntry(aCapNum, [self](VideoEngine::CaptureEntry& cap) {
             if (cap.VideoCapture()) {
               bool result = cap.VideoCapture()->FocusOnSelectedSource();
               RefPtr<nsIRunnable> ipc_runnable =
-                  media::NewRunnableFrom([self, result]() -> nsresult {
+                  NewRunnableFrom([self, result]() {
                     if (!self->mChildIsAlive) {
                       return NS_ERROR_FAILURE;
                     }
 
                     if (result) {
                       Unused << self->SendReplySuccess();
                       return NS_OK;
                     }
@@ -1012,17 +991,17 @@ void CamerasParent::StopCapture(const Ca
 }
 
 mozilla::ipc::IPCResult CamerasParent::RecvStopCapture(
     const CaptureEngine& aCapEngine, const int& capnum) {
   LOG((__PRETTY_FUNCTION__));
 
   RefPtr<CamerasParent> self(this);
   RefPtr<Runnable> webrtc_runnable =
-      media::NewRunnableFrom([self, aCapEngine, capnum]() -> nsresult {
+      NewRunnableFrom([self, aCapEngine, capnum]() {
         self->StopCapture(aCapEngine, capnum);
         return NS_OK;
       });
   nsresult rv = DispatchToVideoCaptureThread(webrtc_runnable);
   if (!self->mChildIsAlive) {
     if (NS_FAILED(rv)) {
       return IPC_FAIL_NO_REASON(this);
     }
@@ -1084,17 +1063,17 @@ CamerasParent::CamerasParent()
 
   mPBackgroundEventTarget = GetCurrentThreadSerialEventTarget();
   MOZ_ASSERT(mPBackgroundEventTarget != nullptr,
              "GetCurrentThreadEventTarget failed");
 
   LOG(("Spinning up WebRTC Cameras Thread"));
 
   RefPtr<CamerasParent> self(this);
-  RefPtr<Runnable> threadStart = media::NewRunnableFrom([self]() -> nsresult {
+  RefPtr<Runnable> threadStart = NewRunnableFrom([self]() {
     // Register thread shutdown observer
     nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
     if (NS_WARN_IF(!obs)) {
       return NS_ERROR_FAILURE;
     }
     nsresult rv =
         obs->AddObserver(self, NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID, false);
     if (NS_WARN_IF(NS_FAILED(rv))) {