Commit d57c9498 authored by Nika Layzell's avatar Nika Layzell
Browse files

Bug 1825360 - Remove the NS_DISPATCH_SYNC flag,...

Bug 1825360 - Remove the NS_DISPATCH_SYNC flag, r=necko-reviewers,geckoview-reviewers,media-playback-reviewers,karlt,jesup,m_kato,emilio

This flag is not supported by most event targets and can have unexpected
side effects (namely spinning a nested event loop). All consumers have
been replaced with a new function which is more explicit about this side
effect.

Differential Revision: https://phabricator.services.mozilla.com/D173985
parent 1118f48c
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "nsIEventTarget.h"
#include "nsISerialEventTarget.h"
#include "nsIURIMutator.h"
#include "nsNetUtil.h"
#include "nsPrintfCString.h"
@@ -18,10 +19,13 @@ namespace mozilla {

template <typename F>
void RunOnBackgroundThread(F&& aFunction) {
  ASSERT_NS_SUCCEEDED(NS_DispatchBackgroundTask(
  nsCOMPtr<nsISerialEventTarget> backgroundQueue;
  ASSERT_NS_SUCCEEDED(NS_CreateBackgroundTaskQueue(
      "RunOnBackgroundThread", getter_AddRefs(backgroundQueue)));
  ASSERT_NS_SUCCEEDED(NS_DispatchAndSpinEventLoopUntilComplete(
      "RunOnBackgroundThread"_ns, backgroundQueue,
      NS_NewRunnableFunction("RunOnBackgroundThread",
                             std::forward<F>(aFunction)),
      NS_DISPATCH_SYNC));
                             std::forward<F>(aFunction))));
}

TEST(BackgroundThreadPrincipal, CreateContent)
+16 −18
Original line number Diff line number Diff line
@@ -60,10 +60,9 @@ class TestFileSystemQuotaClient
      quota::QuotaManager* quotaManager = quota::QuotaManager::Get();
      ASSERT_TRUE(quotaManager);

      quotaManager->IOThread()->Dispatch(
          NS_NewRunnableFunction(
              "TestFileSystemQuotaClient",
              []() {
      NS_DispatchAndSpinEventLoopUntilComplete(
          "TestFileSystemQuotaClient"_ns, quotaManager->IOThread(),
          NS_NewRunnableFunction("TestFileSystemQuotaClient", []() {
            quota::QuotaManager* qm = quota::QuotaManager::Get();
            ASSERT_TRUE(qm);

@@ -81,8 +80,7 @@ class TestFileSystemQuotaClient
            }

            qm->EnsureQuotaForOrigin(testOriginMeta);
              }),
          NS_DISPATCH_SYNC);
          }));
    };

    PerformOnBackgroundThread(std::move(backgroundTask));
+2 −1
Original line number Diff line number Diff line
@@ -6377,7 +6377,8 @@ nsresult DispatchAndReturnFileReferences(
  QuotaManager* const quotaManager = QuotaManager::Get();
  MOZ_ASSERT(quotaManager);
  // XXX can't we simply use NS_DISPATCH_SYNC instead of using a monitor?
  // XXX can't we simply use NS_DispatchAndSpinEventLoopUntilComplete instead of
  // using a monitor?
  QM_TRY(MOZ_TO_RESULT(quotaManager->IOThread()->Dispatch(
      NS_NewRunnableFunction("GetFileReferences", std::move(lambda)),
      NS_DISPATCH_NORMAL)));
+2 −1
Original line number Diff line number Diff line
@@ -799,7 +799,8 @@ void AudioCallbackDriver::Shutdown() {

  RefPtr<AsyncCubebTask> releaseEvent =
      new AsyncCubebTask(this, AsyncCubebOperation::SHUTDOWN);
  releaseEvent->Dispatch(NS_DISPATCH_SYNC);
  releaseEvent->DispatchAndSpinEventLoopUntilComplete(
      "AudioCallbackDriver::Shutdown"_ns);
}

/* static */
+6 −0
Original line number Diff line number Diff line
@@ -808,6 +808,12 @@ class AsyncCubebTask : public Runnable {
    return mDriver->mInitShutdownThread->Dispatch(this, aFlags);
  }

  nsresult DispatchAndSpinEventLoopUntilComplete(
      const nsACString& aVeryGoodReasonToDoThis) {
    return NS_DispatchAndSpinEventLoopUntilComplete(
        aVeryGoodReasonToDoThis, mDriver->mInitShutdownThread, do_AddRef(this));
  }

 protected:
  virtual ~AsyncCubebTask();

Loading