Bug 1809753 - Part 4: Remove unnecessary GetMainThreadEventTarget, r=mccr8

This method always returned GetMainThreadSerialEventTarget(). This patch
switches all callers over to use that method instead.

We can't easily switch all calls to be calls to NS_GetMainThread(), as there is
no version of that method returning a bare nsIThread* instance.

I didn't introduce one, as we may want to add a lock around mMainThread in the
future, which would require removing nsThreadManager::GetMainThreadWeak. As
this method only returns nsISerialEventTarget, it method could remain
implemented, however, by returning a statically allocated fake event target
which forwards dispatches (and QIs to nsIThread) to the real main thread.

Differential Revision: https://phabricator.services.mozilla.com/D166608
This commit is contained in:
Nika Layzell 2023-01-16 23:14:12 +00:00
Родитель 852d02ec16
Коммит 9d6bb19c23
60 изменённых файлов: 97 добавлений и 102 удалений

Просмотреть файл

@ -52,7 +52,7 @@ class SurfaceHelper : public Runnable {
}
already_AddRefed<gfx::DataSourceSurface> GetDataSurfaceSafe() {
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadSerialEventTarget();
MOZ_ASSERT(mainTarget);
SyncRunnable::DispatchToThread(mainTarget, this, false);
@ -90,7 +90,7 @@ class EncodingCompleteEvent final : public DiscardableRunnable {
if (!NS_IsMainThread() && IsCurrentThreadRunningWorker()) {
mCreationEventTarget = GetCurrentSerialEventTarget();
} else {
mCreationEventTarget = GetMainThreadEventTarget();
mCreationEventTarget = GetMainThreadSerialEventTarget();
}
}

Просмотреть файл

@ -183,7 +183,7 @@ Nullable<WindowProxyHolder> InProcessBrowserChildMessageManager::GetContent(
already_AddRefed<nsIEventTarget>
InProcessBrowserChildMessageManager::GetTabEventTarget() {
nsCOMPtr<nsIEventTarget> target = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> target = GetMainThreadSerialEventTarget();
return target.forget();
}

Просмотреть файл

@ -1977,7 +1977,7 @@ static bool DispatchToEventLoop(void* closure,
// simply NS_DispatchToMainThread. Failure during shutdown is expected and
// properly handled by the JS engine.
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadSerialEventTarget();
if (!mainTarget) {
return false;
}

Просмотреть файл

@ -161,13 +161,13 @@ RefPtr<FetchServicePromises> FetchService::FetchInstance::Fetch() {
// Create a FetchDriver instance
mFetchDriver = MakeRefPtr<FetchDriver>(
mRequest.clonePtr(), // Fetch Request
mPrincipal, // Principal
mLoadGroup, // LoadGroup
GetMainThreadEventTarget(), // MainThreadEventTarget
mCookieJarSettings, // CookieJarSettings
mPerformanceStorage, // PerformanceStorage
false // IsTrackingFetch
mRequest.clonePtr(), // Fetch Request
mPrincipal, // Principal
mLoadGroup, // LoadGroup
GetMainThreadSerialEventTarget(), // MainThreadEventTarget
mCookieJarSettings, // CookieJarSettings
mPerformanceStorage, // PerformanceStorage
false // IsTrackingFetch
);
// Call FetchDriver::Fetch to start fetching.

Просмотреть файл

@ -288,7 +288,7 @@ MutableBlobStorage::MutableBlobStorage(MutableBlobStorageType aType,
MOZ_ASSERT(NS_IsMainThread());
if (!mEventTarget) {
mEventTarget = GetMainThreadEventTarget();
mEventTarget = GetMainThreadSerialEventTarget();
}
if (aMaxMemory == 0 && aType == eCouldBeInTemporaryFile) {

Просмотреть файл

@ -23,7 +23,7 @@ MutableBlobStreamListener::MutableBlobStreamListener(
MOZ_ASSERT(aCallback);
if (!mEventTarget) {
mEventTarget = GetMainThreadEventTarget();
mEventTarget = GetMainThreadSerialEventTarget();
}
MOZ_ASSERT(mEventTarget);

Просмотреть файл

@ -1017,7 +1017,7 @@ void Geolocation::GetCurrentPosition(PositionCallback& aCallback,
static nsIEventTarget* MainThreadTarget(Geolocation* geo) {
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryReferent(geo->GetOwner());
if (!window) {
return GetMainThreadEventTarget();
return GetMainThreadSerialEventTarget();
}
return nsGlobalWindowInner::Cast(window)->EventTargetFor(
mozilla::TaskCategory::Other);

Просмотреть файл

@ -827,7 +827,7 @@ nsresult SimpleTimer::Init(nsIRunnable* aTask, uint32_t aTimeoutMs,
if (aTarget) {
target = aTarget;
} else {
target = GetMainThreadEventTarget();
target = GetMainThreadSerialEventTarget();
if (!target) {
return NS_ERROR_NOT_AVAILABLE;
}

Просмотреть файл

@ -158,7 +158,7 @@ void MediaKeys::OnInnerWindowDestroy() {
// Don't call shutdown directly because (at time of writing) mProxy can
// spin the event loop when it's shutdown. This can change the world state
// in the middle of window destruction, which we do not want.
GetMainThreadEventTarget()->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NewRunnableMethod("MediaKeys::Shutdown", this, &MediaKeys::Shutdown));
}

Просмотреть файл

@ -406,7 +406,7 @@ class CDMStorageTest {
nsCString failureReason;
self->mCDM
->Init(self->mCallback.get(), false, true,
GetMainThreadEventTarget())
GetMainThreadSerialEventTarget())
->Then(
thread, __func__,
[self, updates = std::move(updates)] {

Просмотреть файл

@ -233,7 +233,7 @@ void DecoderBenchmark::CheckVersion(const nsACString& aDecoderName) {
}
DebugOnly<nsresult> rv =
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"DecoderBenchmark::CheckVersion", [name, version]() {
BenchmarkStorageChild::Instance()->SendCheckVersion(name, version);
}));

Просмотреть файл

@ -334,7 +334,7 @@ void PDMFactory::EnsureInit() {
initalization();
return;
}
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadSerialEventTarget();
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction(
"PDMFactory::EnsureInit", std::move(initalization));
SyncRunnable::DispatchToThread(mainTarget, runnable);

Просмотреть файл

@ -253,7 +253,8 @@ bool WMFDecoderModule::CanCreateMFTDecoder(const WMFStreamType& aType) {
} else {
nsCOMPtr<nsIRunnable> runnable =
NS_NewRunnableFunction("WMFDecoderModule::Init", [&]() { Init(); });
SyncRunnable::DispatchToThread(GetMainThreadEventTarget(), runnable);
SyncRunnable::DispatchToThread(GetMainThreadSerialEventTarget(),
runnable);
}
}

Просмотреть файл

@ -123,7 +123,7 @@ class HRTFDatabaseLoader::ProxyReleaseEvent final : public Runnable {
};
void HRTFDatabaseLoader::ProxyRelease() {
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadSerialEventTarget();
if (MOZ_LIKELY(mainTarget)) {
RefPtr<ProxyReleaseEvent> event = new ProxyReleaseEvent(this);
DebugOnly<nsresult> rv = mainTarget->Dispatch(event, NS_DISPATCH_NORMAL);

Просмотреть файл

@ -695,7 +695,7 @@ void MediaTransportHandlerSTS::Destroy() {
CSFLogDebug(LOGTAG, "%s %p", __func__, this);
// Our "destruction tour" starts on main, because we need to deregister.
if (!NS_IsMainThread()) {
GetMainThreadEventTarget()->Dispatch(NewNonOwningRunnableMethod(
GetMainThreadSerialEventTarget()->Dispatch(NewNonOwningRunnableMethod(
__func__, this, &MediaTransportHandlerSTS::Destroy));
return;
}

Просмотреть файл

@ -532,8 +532,8 @@ static void GMPReady_m() {
};
static void GMPReady() {
GetMainThreadEventTarget()->Dispatch(WrapRunnableNM(&GMPReady_m),
NS_DISPATCH_NORMAL);
GetMainThreadSerialEventTarget()->Dispatch(WrapRunnableNM(&GMPReady_m),
NS_DISPATCH_NORMAL);
};
void PeerConnectionCtx::initGMP() {

Просмотреть файл

@ -1406,7 +1406,7 @@ void PeerConnectionImpl::UpdateNegotiationNeeded() {
}
// Queue a task to run the following steps:
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
__func__, [this, self = RefPtr<PeerConnectionImpl>(this)] {
// If connection.[[IsClosed]] is true, abort these steps.
if (IsClosed()) {
@ -1530,7 +1530,7 @@ PeerConnectionImpl::CreateOffer(const JsepOfferOptions& aOptions) {
STAMP_TIMECARD(mTimeCard, "Create Offer");
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
__func__, [this, self = RefPtr<PeerConnectionImpl>(this), aOptions] {
std::string offer;
@ -1570,7 +1570,7 @@ PeerConnectionImpl::CreateAnswer() {
// add it as a param to CreateAnswer, and convert it here.
JsepAnswerOptions options;
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
__func__, [this, self = RefPtr<PeerConnectionImpl>(this), options] {
std::string answer;
SyncToJsep();
@ -1889,7 +1889,7 @@ PeerConnectionImpl::AddIceCandidate(
mRawTrickledCandidates.push_back(aCandidate);
}
// Spec says we queue a task for these updates
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
__func__, [this, self = RefPtr<PeerConnectionImpl>(this)] {
if (IsClosed()) {
return;
@ -1910,7 +1910,7 @@ PeerConnectionImpl::AddIceCandidate(
static_cast<unsigned>(*result.mError), aCandidate,
level.valueOr(-1), errorString.c_str());
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
__func__,
[this, self = RefPtr<PeerConnectionImpl>(this), errorString, result] {
if (IsClosed()) {
@ -2577,7 +2577,7 @@ already_AddRefed<dom::Promise> PeerConnectionImpl::OnSetDescriptionSuccess(
void PeerConnectionImpl::DoSetDescriptionSuccessPostProcessing(
dom::RTCSdpType aSdpType, bool aRemote, const RefPtr<dom::Promise>& aP) {
// Spec says we queue a task for all the stuff that ends up back in JS
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
__func__,
[this, self = RefPtr<PeerConnectionImpl>(this), aSdpType, aRemote, aP] {
if (IsClosed()) {
@ -3829,7 +3829,7 @@ void PeerConnectionImpl::AddIceCandidate(const std::string& aCandidate,
cand.mUfrag = aUfrag;
mQueriedMDNSHostnames[addr].push_back(cand);
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"PeerConnectionImpl::SendQueryMDNSHostname",
[self = RefPtr<PeerConnectionImpl>(this), addr]() mutable {
if (self->mStunAddrsRequest) {
@ -4033,7 +4033,7 @@ void PeerConnectionImpl::SignalHandler::IceGatheringStateChange_s(
dom::RTCIceGatheringState aState) {
ASSERT_ON_THREAD(mSTSThread);
GetMainThreadEventTarget()->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NS_NewRunnableFunction(__func__,
[handle = mHandle, aState] {
PeerConnectionWrapper wrapper(handle);
@ -4049,7 +4049,7 @@ void PeerConnectionImpl::SignalHandler::IceConnectionStateChange_s(
dom::RTCIceConnectionState aState) {
ASSERT_ON_THREAD(mSTSThread);
GetMainThreadEventTarget()->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NS_NewRunnableFunction(__func__,
[handle = mHandle, aState] {
PeerConnectionWrapper wrapper(handle);
@ -4068,7 +4068,7 @@ void PeerConnectionImpl::SignalHandler::OnCandidateFound_s(
MOZ_ASSERT(!aCandidateInfo.mUfrag.empty());
GetMainThreadEventTarget()->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NS_NewRunnableFunction(__func__,
[handle = mHandle, aTransportId, aCandidateInfo] {
PeerConnectionWrapper wrapper(handle);
@ -4083,7 +4083,7 @@ void PeerConnectionImpl::SignalHandler::OnCandidateFound_s(
void PeerConnectionImpl::SignalHandler::AlpnNegotiated_s(
const std::string& aAlpn, bool aPrivacyRequested) {
MOZ_DIAGNOSTIC_ASSERT((aAlpn == "c-webrtc") == aPrivacyRequested);
GetMainThreadEventTarget()->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NS_NewRunnableFunction(__func__,
[handle = mHandle, aPrivacyRequested] {
PeerConnectionWrapper wrapper(handle);

Просмотреть файл

@ -686,7 +686,7 @@ already_AddRefed<Promise> RTCRtpSender::SetParameters(
// If the media stack is successfully configured with parameters,
// queue a task to run the following steps:
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
__func__,
[this, self = RefPtr<RTCRtpSender>(this), p, paramsCopy, serialNumber] {
// Set sender.[[LastReturnedParameters]] to null.
@ -853,7 +853,7 @@ void RTCRtpSender::GetParameters(RTCRtpSendParameters& aParameters) {
mLastReturnedParameters = Some(aParameters);
// Queue a task that sets sender.[[LastReturnedParameters]] to null.
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
__func__, [this, self = RefPtr<RTCRtpSender>(this)] {
mLastReturnedParameters = Nothing();
}));
@ -1068,7 +1068,7 @@ RefPtr<dom::Promise> ReplaceTrackOperation::CallImpl(ErrorResult& aError) {
}
// Queue a task that runs the following steps:
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
__func__, [p, sender, track = mNewTrack]() MOZ_CAN_RUN_SCRIPT_BOUNDARY {
// If connection.[[IsClosed]] is true, abort these steps.
// Set sender.[[SenderTrack]] to withTrack.

Просмотреть файл

@ -254,8 +254,8 @@ void RTCRtpTransceiver::RollbackToStableDtlsTransport() {
void RTCRtpTransceiver::UpdateDtlsTransportState(
const std::string& aTransportId, TransportLayer::State aState) {
if (!GetMainThreadEventTarget()->IsOnCurrentThread()) {
GetMainThreadEventTarget()->Dispatch(
if (!GetMainThreadSerialEventTarget()->IsOnCurrentThread()) {
GetMainThreadSerialEventTarget()->Dispatch(
WrapRunnable(this, &RTCRtpTransceiver::UpdateDtlsTransportState,
aTransportId, aState),
NS_DISPATCH_NORMAL);

Просмотреть файл

@ -24,7 +24,7 @@ WebrtcTCPSocketWrapper::WebrtcTCPSocketWrapper(
mWebrtcTCPSocket(nullptr),
mMainThread(nullptr),
mSocketThread(nullptr) {
mMainThread = GetMainThreadEventTarget();
mMainThread = GetMainThreadSerialEventTarget();
mSocketThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID);
MOZ_RELEASE_ASSERT(mMainThread, "no main thread");
MOZ_RELEASE_ASSERT(mSocketThread, "no socket thread");

Просмотреть файл

@ -58,7 +58,7 @@ WebrtcTCPSocket::WebrtcTCPSocket(WebrtcTCPSocketCallback* aCallbacks)
mSocketIn(nullptr),
mSocketOut(nullptr) {
LOG(("WebrtcTCPSocket::WebrtcTCPSocket %p\n", this));
mMainThread = GetMainThreadEventTarget();
mMainThread = GetMainThreadSerialEventTarget();
mSocketThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID);
MOZ_RELEASE_ASSERT(mMainThread, "no main thread");
MOZ_RELEASE_ASSERT(mSocketThread, "no socket thread");

Просмотреть файл

@ -1201,7 +1201,7 @@ class GenericReceiveListener : public MediaTrackListener {
void OnRtpReceived() {
if (mMaybeTrackNeedsUnmute) {
mMaybeTrackNeedsUnmute = false;
GetMainThreadEventTarget()->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NewRunnableMethod("GenericReceiveListener::OnRtpReceived_m", this,
&GenericReceiveListener::OnRtpReceived_m));
}
@ -1224,7 +1224,7 @@ class GenericReceiveListener : public MediaTrackListener {
mSource->Destroy();
}
GetMainThreadEventTarget()->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NewRunnableMethod("RemoteTrackSource::ForceEnded", mTrackSource.get(),
&RemoteTrackSource::ForceEnded));
}
@ -1288,7 +1288,7 @@ class MediaPipelineReceiveAudio::PipelineListener
void MakePrincipalPrivate_s() {
mForceSilence = true;
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"MediaPipelineReceiveAudio::PipelineListener::MakePrincipalPrivate_s",
[self = RefPtr<PipelineListener>(this), this] {
class Message : public ControlMessage {
@ -1494,7 +1494,7 @@ class MediaPipelineReceiveVideo::PipelineListener
mForceDropFrames = true;
}
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
__func__, [self = RefPtr<PipelineListener>(this), this] {
RefPtr<nsIPrincipal> privatePrincipal =
NullPrincipal::CreateWithInheritedAttributes(

Просмотреть файл

@ -139,7 +139,7 @@ void TextTrackList::CreateAndDispatchChangeEvent() {
void TextTrackList::CreateAndDispatchTrackEventRunner(
TextTrack* aTrack, const nsAString& aEventName) {
DebugOnly<nsresult> rv;
nsCOMPtr<nsIEventTarget> target = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> target = GetMainThreadSerialEventTarget();
if (!target) {
// If we are not able to get the main-thread object we are shutting down.
return;

Просмотреть файл

@ -2322,7 +2322,7 @@ nsresult Notification::DispatchToMainThread(
nsIEventTarget::DISPATCH_NORMAL);
}
}
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadSerialEventTarget();
MOZ_ASSERT(mainTarget);
return mainTarget->Dispatch(std::move(aRunnable),
nsIEventTarget::DISPATCH_NORMAL);

Просмотреть файл

@ -93,7 +93,7 @@ RefPtr<U2FRegisterPromise> AndroidWebAuthnTokenManager::Register(
ClearPromises();
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"java::WebAuthnTokenManager::WebAuthnMakeCredential",
[self = RefPtr{this}, aInfo, aForceNoneAttestation]() {
AssertIsOnMainThread();
@ -282,7 +282,7 @@ RefPtr<U2FSignPromise> AndroidWebAuthnTokenManager::Sign(
ClearPromises();
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"java::WebAuthnTokenManager::WebAuthnGetAssertion",
[self = RefPtr{this}, aInfo]() {
AssertIsOnMainThread();

Просмотреть файл

@ -195,7 +195,7 @@ nsresult U2FSoftTokenManager::GetOrCreateWrappingKey(
MOZ_LOG(gNSSTokenLog, LogLevel::Debug,
("Key stored, nickname set to %s.", mSecretNickname.get()));
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"dom::U2FSoftTokenManager::GetOrCreateWrappingKey", []() {
MOZ_ASSERT(NS_IsMainThread());
Preferences::SetUint(PREF_U2F_NSSTOKEN_COUNTER, 0);
@ -885,7 +885,7 @@ RefPtr<U2FSignPromise> U2FSoftTokenManager::Sign(
counterItem.data[2] = (mCounter >> 8) & 0xFF;
counterItem.data[3] = (mCounter >> 0) & 0xFF;
uint32_t counter = mCounter;
GetMainThreadEventTarget()->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NS_NewRunnableFunction("dom::U2FSoftTokenManager::Sign", [counter]() {
MOZ_ASSERT(NS_IsMainThread());
Preferences::SetUint(PREF_U2F_NSSTOKEN_COUNTER, counter);

Просмотреть файл

@ -273,8 +273,8 @@ void U2FTokenManager::SendPromptNotification(const char16_t* aFormat,
"U2FTokenManager::RunSendPromptNotification", this,
&U2FTokenManager::RunSendPromptNotification, json));
MOZ_ALWAYS_SUCCEEDS(
GetMainThreadEventTarget()->Dispatch(r.forget(), NS_DISPATCH_NORMAL));
MOZ_ALWAYS_SUCCEEDS(GetMainThreadSerialEventTarget()->Dispatch(
r.forget(), NS_DISPATCH_NORMAL));
}
void U2FTokenManager::RunSendPromptNotification(const nsString& aJSON) {
@ -390,8 +390,8 @@ static void status_callback(rust_ctap2_status_update_res* status) {
nsCOMPtr<nsIRunnable> r(NewRunnableMethod<nsString>(
"U2FTokenManager::RunSendPromptNotification", gInstance,
&U2FTokenManager::RunSendPromptNotification, notification_json));
MOZ_ALWAYS_SUCCEEDS(
GetMainThreadEventTarget()->Dispatch(r.forget(), NS_DISPATCH_NORMAL));
MOZ_ALWAYS_SUCCEEDS(GetMainThreadSerialEventTarget()->Dispatch(
r.forget(), NS_DISPATCH_NORMAL));
}
}

Просмотреть файл

@ -2755,7 +2755,7 @@ WebSocketImpl::Dispatch(already_AddRefed<nsIRunnable> aEvent, uint32_t aFlags) {
if (mIsMainThread) {
return mMainThreadEventTarget
? mMainThreadEventTarget->Dispatch(event_ref.forget())
: GetMainThreadEventTarget()->Dispatch(event_ref.forget());
: GetMainThreadSerialEventTarget()->Dispatch(event_ref.forget());
}
MutexAutoLock lock(mMutex);

Просмотреть файл

@ -2133,7 +2133,7 @@ WorkerThreadPrimaryRunnable::Run() {
mWorkerPrivate = nullptr;
// Now recycle this thread.
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadSerialEventTarget();
MOZ_ASSERT(mainTarget);
RefPtr<FinishedRunnable> finishedRunnable =

Просмотреть файл

@ -405,7 +405,7 @@ bool CanvasTranslator::CheckForFreshCanvasDevice(int aLineNumber) {
// It is safe to wait here because only the Compositor thread waits on us and
// the main thread doesn't wait on the compositor thread in the GPU process.
SyncRunnable::DispatchToThread(GetMainThreadEventTarget(), runnable,
SyncRunnable::DispatchToThread(GetMainThreadSerialEventTarget(), runnable,
/*aForceDispatch*/ true);
mDevice = gfx::DeviceManagerDx::Get()->GetCanvasDevice();

Просмотреть файл

@ -105,7 +105,7 @@ void nsFontFaceLoader::StartedLoading(nsIStreamLoader* aStreamLoader) {
if (doc) {
target = doc->EventTargetFor(TaskCategory::Other);
} else {
target = GetMainThreadEventTarget();
target = GetMainThreadSerialEventTarget();
}
NS_NewTimerWithFuncCallback(
getter_AddRefs(mLoadTimer), LoadTimerCallback, static_cast<void*>(this),

Просмотреть файл

@ -43,7 +43,7 @@ class MainAsCurrent : public TaskQueueWrapper<DeletionPolicy::NonBlocking> {
public:
MainAsCurrent()
: TaskQueueWrapper(
TaskQueue::Create(do_AddRef(GetMainThreadEventTarget()),
TaskQueue::Create(do_AddRef(GetMainThreadSerialEventTarget()),
"MainAsCurrentTaskQueue"),
"MainAsCurrent"_ns),
mSetter(this) {

Просмотреть файл

@ -81,7 +81,7 @@ nsresult nsAsyncRedirectVerifyHelper::Init(
nsresult rv;
rv = mainThreadEventTarget
? mainThreadEventTarget->Dispatch(runnable.forget())
: GetMainThreadEventTarget()->Dispatch(runnable.forget());
: GetMainThreadSerialEventTarget()->Dispatch(runnable.forget());
NS_ENSURE_SUCCESS(rv, rv);
if (synchronize) {

Просмотреть файл

@ -100,8 +100,9 @@ nsresult nsInputStreamPump::EnsureWaiting() {
// created on main thread.
if (mState == STATE_STOP && !mOffMainThread) {
nsCOMPtr<nsIEventTarget> mainThread =
mLabeledMainThreadTarget ? mLabeledMainThreadTarget
: do_AddRef(GetMainThreadEventTarget());
mLabeledMainThreadTarget
? mLabeledMainThreadTarget
: do_AddRef(GetMainThreadSerialEventTarget());
if (mTargetThread != mainThread) {
mTargetThread = mainThread;
}

Просмотреть файл

@ -167,7 +167,7 @@ nsRequestObserverProxy::Init(nsIRequestObserver* observer,
//-----------------------------------------------------------------------------
nsresult nsRequestObserverProxy::FireEvent(nsARequestObserverEvent* event) {
nsCOMPtr<nsIEventTarget> mainThread(GetMainThreadEventTarget());
nsCOMPtr<nsIEventTarget> mainThread(GetMainThreadSerialEventTarget());
return mainThread->Dispatch(event, NS_DISPATCH_NORMAL);
}

Просмотреть файл

@ -28,7 +28,7 @@
// - CacheFile is still waiting for the handle
// - the chunk is preloaded
//#define CACHE_CHUNKS
// #define CACHE_CHUNKS
namespace mozilla::net {
@ -2189,7 +2189,7 @@ void CacheFile::QueueChunkListener(uint32_t aIndex,
LOG(
("CacheFile::QueueChunkListener() - Cannot get Cache I/O thread! Using "
"main thread for callback."));
item->mTarget = GetMainThreadEventTarget();
item->mTarget = GetMainThreadSerialEventTarget();
}
item->mCallback = aCallback;

Просмотреть файл

@ -432,7 +432,7 @@ void CacheFileChunk::WaitForUpdate(CacheFileChunkListener* aCallback) {
LOG(
("CacheFileChunk::WaitForUpdate() - Cannot get Cache I/O thread! Using "
"main thread for callback."));
item->mTarget = GetMainThreadEventTarget();
item->mTarget = GetMainThreadSerialEventTarget();
}
item->mCallback = aCallback;
MOZ_ASSERT(item->mTarget);

Просмотреть файл

@ -635,7 +635,7 @@ void CacheFileInputStream::NotifyListener() {
LOG(
("CacheFileInputStream::NotifyListener() - Cannot get Cache I/O "
"thread! Using main thread for callback."));
mCallbackTarget = GetMainThreadEventTarget();
mCallbackTarget = GetMainThreadSerialEventTarget();
}
}

Просмотреть файл

@ -440,7 +440,7 @@ void CacheFileOutputStream::NotifyListener() {
LOG(
("CacheFileOutputStream::NotifyListener() - Cannot get Cache I/O "
"thread! Using main thread for callback."));
mCallbackTarget = GetMainThreadEventTarget();
mCallbackTarget = GetMainThreadSerialEventTarget();
}
}

Просмотреть файл

@ -429,7 +429,7 @@ void ProxyRelease(const char* aName, nsCOMPtr<T>& object,
template <class T>
void ProxyReleaseMainThread(const char* aName, nsCOMPtr<T>& object) {
ProxyRelease(aName, object, GetMainThreadEventTarget());
ProxyRelease(aName, object, GetMainThreadSerialEventTarget());
}
} // namespace net

Просмотреть файл

@ -45,7 +45,7 @@ void DNSRequestHandler::DoAsyncResolve(const nsACString& hostname,
mFlags = flags;
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIEventTarget> main = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> main = GetMainThreadSerialEventTarget();
nsCOMPtr<nsICancelable> unused;
RefPtr<DNSAdditionalInfo> info;
if (!trrServer.IsEmpty() || port != -1) {

Просмотреть файл

@ -54,7 +54,7 @@ nsresult DNSUtils::CreateChannelHelper(nsIURI* aUri, nsIChannel** aResult) {
// Unfortunately, we can only initialize gHttpHandler on main thread.
if (!gHttpHandler) {
nsCOMPtr<nsIEventTarget> main = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> main = GetMainThreadSerialEventTarget();
if (main) {
// Forward to the main thread synchronously.
SyncRunnable::DispatchToThread(

Просмотреть файл

@ -1039,7 +1039,7 @@ nsresult nsDNSService::AsyncResolveInternal(
// make sure JS callers get notification on the main thread
nsCOMPtr<nsIXPConnectWrappedJS> wrappedListener = do_QueryInterface(listener);
if (wrappedListener && !target) {
target = GetMainThreadEventTarget();
target = GetMainThreadSerialEventTarget();
}
if (target) {

Просмотреть файл

@ -40,7 +40,7 @@ class MainThreadChannelEvent : public ChannelEvent {
already_AddRefed<nsIEventTarget> GetEventTarget() override {
MOZ_ASSERT(XRE_IsParentProcess());
return do_AddRef(GetMainThreadEventTarget());
return do_AddRef(GetMainThreadSerialEventTarget());
}
};

Просмотреть файл

@ -350,8 +350,9 @@ IPCResult DocumentChannelChild::RecvRedirectToRealChannel(
mRedirectChannel = newChannel;
mStreamFilterEndpoints = std::move(aEndpoints);
rv = gHttpHandler->AsyncOnChannelRedirect(
this, newChannel, aArgs.redirectFlags(), GetMainThreadEventTarget());
rv = gHttpHandler->AsyncOnChannelRedirect(this, newChannel,
aArgs.redirectFlags(),
GetMainThreadSerialEventTarget());
if (NS_SUCCEEDED(rv)) {
scopeExit.release();

Просмотреть файл

@ -180,7 +180,7 @@ void AltDataOutputStreamChild::NotifyListener() {
MOZ_ASSERT(mCallback);
if (!mCallbackTarget) {
mCallbackTarget = GetMainThreadEventTarget();
mCallbackTarget = GetMainThreadSerialEventTarget();
}
nsCOMPtr<nsIOutputStreamCallback> asyncCallback =

Просмотреть файл

@ -892,7 +892,7 @@ void AltSvcCache::EnsureStorageInited() {
return;
}
nsCOMPtr<nsIEventTarget> main = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> main = GetMainThreadSerialEventTarget();
if (!main) {
return;
}

Просмотреть файл

@ -2125,7 +2125,7 @@ already_AddRefed<nsIEventTarget> HttpChannelChild::GetODATarget() {
}
if (!target) {
target = GetMainThreadEventTarget();
target = GetMainThreadSerialEventTarget();
}
return target.forget();
}

Просмотреть файл

@ -220,7 +220,7 @@ already_AddRefed<nsIEventTarget> HttpTransactionParent::GetODATarget() {
}
if (!target) {
target = GetMainThreadEventTarget();
target = GetMainThreadSerialEventTarget();
}
return target.forget();
}
@ -400,7 +400,7 @@ already_AddRefed<nsHttpConnectionInfo> HttpTransactionParent::GetConnInfo()
}
already_AddRefed<nsIEventTarget> HttpTransactionParent::GetNeckoTarget() {
nsCOMPtr<nsIEventTarget> target = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> target = GetMainThreadSerialEventTarget();
return target.forget();
}

Просмотреть файл

@ -7971,7 +7971,7 @@ nsHttpChannel::RetargetDeliveryTo(nsIEventTarget* aNewTarget) {
// If retarget fails for transaction pump, we must restore mCachePump.
if (NS_FAILED(rv) && retargetableCachePump) {
nsCOMPtr<nsIEventTarget> main = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> main = GetMainThreadSerialEventTarget();
NS_ENSURE_TRUE(main, NS_ERROR_UNEXPECTED);
rv = retargetableCachePump->RetargetDeliveryTo(main);
}

Просмотреть файл

@ -2853,7 +2853,7 @@ nsresult WebSocketChannel::DoAdmissionDNS() {
if (mPort == -1) mPort = (mEncrypted ? kDefaultWSSPort : kDefaultWSPort);
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIEventTarget> main = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> main = GetMainThreadSerialEventTarget();
nsCOMPtr<nsICancelable> cancelable;
rv = dns->AsyncResolveNative(hostName, nsIDNSService::RESOLVE_TYPE_DEFAULT,
nsIDNSService::RESOLVE_DEFAULT_FLAGS, nullptr,
@ -3405,7 +3405,7 @@ WebSocketChannel::AsyncOpenNative(nsIURI* aURI, const nsACString& aOrigin,
{
auto lock = mTargetThread.Lock();
if (!lock.ref()) {
lock.ref() = GetMainThreadEventTarget();
lock.ref() = GetMainThreadSerialEventTarget();
}
}

Просмотреть файл

@ -169,7 +169,7 @@ class EventTargetDispatcher : public ChannelEvent {
already_AddRefed<nsIEventTarget> GetEventTarget() override {
nsCOMPtr<nsIEventTarget> target = mEventTarget;
if (!target) {
target = GetMainThreadEventTarget();
target = GetMainThreadSerialEventTarget();
}
return target.forget();
}

Просмотреть файл

@ -410,7 +410,7 @@ void DataChannelConnection::DestroyOnSTS(struct socket* aMasterSocket,
disconnect_all();
mTransportHandler = nullptr;
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"DataChannelConnection::Destroy",
[id = mId]() { DataChannelRegistry::Deregister(id); }));
}

Просмотреть файл

@ -179,7 +179,7 @@ NS_IMETHODIMP nsWifiMonitor::Run() {
}
if (doError) {
nsCOMPtr<nsIEventTarget> target = GetMainThreadEventTarget();
nsCOMPtr<nsIEventTarget> target = GetMainThreadSerialEventTarget();
if (!target) return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIRunnable> runnable(

Просмотреть файл

@ -118,7 +118,7 @@ mozilla::ipc::IPCResult SandboxTestingParent::RecvGetSpecialDirectory(
dir->GetPath(*aDirPath);
}
});
SyncRunnable::DispatchToThread(GetMainThreadEventTarget(), runnable,
SyncRunnable::DispatchToThread(GetMainThreadSerialEventTarget(), runnable,
/*aForceDispatch*/ true);
return IPC_OK();
}

Просмотреть файл

@ -15,7 +15,7 @@ using namespace mozilla;
//-----------------------------------------------------------------------------
nsBrowserStatusFilter::nsBrowserStatusFilter()
: mTarget(GetMainThreadEventTarget()),
: mTarget(GetMainThreadSerialEventTarget()),
mCurProgress(0),
mMaxProgress(0),
mCurrentPercentage(0),

Просмотреть файл

@ -33,13 +33,13 @@ using namespace mozilla::ipc;
// IPC between other processes will interfere with our fuzzing in the meantime
// but blocking could also cause hangs when such IPC is required during the
// fuzzing runtime for some reason.
//#define MOZ_FUZZ_IPC_SYNC_INJECT 1
// #define MOZ_FUZZ_IPC_SYNC_INJECT 1
// For debugging purposes, it can be helpful to synchronize after each message
// rather than after each iteration, to see which messages are particularly
// slow or cause a hang. Without this, synchronization will occur at the end
// of each iteration as well as after each constructor message.
//#define MOZ_FUZZ_IPC_SYNC_AFTER_EACH_MSG
// #define MOZ_FUZZ_IPC_SYNC_AFTER_EACH_MSG
namespace mozilla {
namespace fuzzing {
@ -621,7 +621,7 @@ NS_IMETHODIMP IPCFuzzController::IPCFuzzLoop::Run() {
IPCFuzzController::instance().runnableDone = false;
SyncRunnable::DispatchToThread(
GetMainThreadEventTarget(),
GetMainThreadSerialEventTarget(),
NS_NewRunnableFunction("IPCFuzzController::StartFuzzing", [&]() -> void {
MOZ_FUZZING_NYX_PRINT("INFO: Main thread runnable start.\n");
NS_ProcessPendingEvents(NS_GetCurrentThread());

Просмотреть файл

@ -32,7 +32,7 @@ void RLBoxSandboxPool::StartTimer() {
}
DebugOnly<nsresult> rv = NS_NewTimerWithCallback(
getter_AddRefs(mTimer), this, mDelaySeconds * 1000,
nsITimer::TYPE_ONE_SHOT, GetMainThreadEventTarget());
nsITimer::TYPE_ONE_SHOT, GetMainThreadSerialEventTarget());
MOZ_ASSERT(NS_SUCCEEDED(rv), "failed to create timer");
}

Просмотреть файл

@ -547,10 +547,6 @@ nsAutoLowPriorityIO::~nsAutoLowPriorityIO() {
namespace mozilla {
nsIEventTarget* GetMainThreadEventTarget() {
return GetMainThreadSerialEventTarget();
}
nsISerialEventTarget* GetCurrentSerialEventTarget() {
if (nsISerialEventTarget* current =
SerialEventTargetGuard::GetCurrentSerialEventTarget()) {

Просмотреть файл

@ -1797,10 +1797,6 @@ class SerialEventTargetGuard {
nsISerialEventTarget* mLastCurrentThread;
};
// See GetMainThreadSerialEventTarget()
nsIEventTarget* GetMainThreadEventTarget();
// Get the serial event target corresponding to the currently executing task
// queue or thread. This method will assert if called on a thread pool without
// an active task queue.