Skip to content

Commit

Permalink
Bug 1809753 - Part 1: Remove quantum-dom nsIThread::EventTarget metho…
Browse files Browse the repository at this point in the history
…ds, r=mccr8

We aren't likely to try to make these changes any time soon, so cleaning out
these unnecessary methods which just return `this` will simplify things.

I was unable to find any calls to the `.eventTarget` getter in JS, which makes
sense, as the nsIThread type is only really used in JS as a wrapper around the
main thread in older code. Because of that, it has been removed as well.

Differential Revision: https://phabricator.services.mozilla.com/D166605
  • Loading branch information
mystor committed Jan 16, 2023
1 parent 2da9764 commit 3888410
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 67 deletions.
3 changes: 1 addition & 2 deletions dom/cache/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1959,8 +1959,7 @@ void Manager::Init(Maybe<Manager&> aOldManager) {
// per Manager now, this lets us cleanly call Factory::Remove() once the
// Context goes away.
SafeRefPtr<Context> ref = Context::Create(
SafeRefPtrFromThis(), mIOThread->SerialEventTarget(),
MakeSafeRefPtr<SetupAction>(),
SafeRefPtrFromThis(), mIOThread, MakeSafeRefPtr<SetupAction>(),
aOldManager ? SomeRef(*aOldManager->mContext) : Nothing());
mContext = ref.unsafeGetRawPtr();
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/GraphDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void ThreadedDriver::Start() {
// See AudioInitTask
nsresult rv = NS_NewNamedThread("MediaTrackGrph", getter_AddRefs(mThread));
if (NS_SUCCEEDED(rv)) {
mThread->EventTarget()->Dispatch(event.forget(), NS_DISPATCH_NORMAL);
mThread->Dispatch(event.forget(), NS_DISPATCH_NORMAL);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dom/media/GraphDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ class ThreadedDriver : public GraphDriver {
nsIThread* Thread() const { return mThread; }

bool OnThread() const override {
return !mThread || mThread->EventTarget()->IsOnCurrentThread();
return !mThread || mThread->IsOnCurrentThread();
}

bool ThreadRunning() const override { return mThreadRunning; }
Expand Down
4 changes: 1 addition & 3 deletions dom/media/GraphRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ NS_IMETHODIMP GraphRunner::Run() {
return NS_OK;
}

bool GraphRunner::OnThread() const {
return mThread->EventTarget()->IsOnCurrentThread();
}
bool GraphRunner::OnThread() const { return mThread->IsOnCurrentThread(); }

#ifdef DEBUG
bool GraphRunner::InDriverIteration(const GraphDriver* aDriver) const {
Expand Down
2 changes: 1 addition & 1 deletion dom/media/gmp/GMPContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ nsCOMPtr<nsISerialEventTarget> GMPContentParent::GMPEventTarget() {
mps->GetThread(getter_AddRefs(gmpThread));
MOZ_ASSERT(gmpThread);

mGMPEventTarget = gmpThread->SerialEventTarget();
mGMPEventTarget = gmpThread;
}

return mGMPEventTarget;
Expand Down
2 changes: 1 addition & 1 deletion dom/media/gmp/GMPParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ nsCOMPtr<nsISerialEventTarget> GMPParent::GMPEventTarget() {
// nullptr if the GeckoMediaPluginService has started shutdown.
nsCOMPtr<nsIThread> gmpThread;
mps->GetThread(getter_AddRefs(gmpThread));
return gmpThread ? gmpThread->SerialEventTarget() : nullptr;
return gmpThread;
}

/* static */
Expand Down
3 changes: 2 additions & 1 deletion gfx/vr/service/OpenVRSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,8 @@ void OpenVRSession::StartHapticTimer() {
if (!mHapticTimer && mHapticThread) {
mLastHapticUpdate = TimeStamp();
mHapticTimer = NS_NewTimer();
mHapticTimer->SetTarget(mHapticThread->GetThread()->EventTarget());
nsCOMPtr<nsIThread> thread = mHapticThread->GetThread();
mHapticTimer->SetTarget(thread);
mHapticTimer->InitWithNamedFuncCallback(
HapticTimerCallback, this, kVRHapticUpdateInterval,
nsITimer::TYPE_REPEATING_PRECISE_CAN_SKIP,
Expand Down
3 changes: 1 addition & 2 deletions ipc/mscom/EnsureMTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ RefPtr<EnsureMTA::CreateInstanceAgileRefPromise> EnsureMTA::CreateInstance(

nsCOMPtr<nsIThread> mtaThread(GetPersistentMTAThread());

return InvokeAsync(mtaThread->SerialEventTarget(), __func__,
std::move(invoker));
return InvokeAsync(mtaThread, __func__, std::move(invoker));
}

/* static */
Expand Down
5 changes: 2 additions & 3 deletions parser/html/nsHtml5Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,13 @@ already_AddRefed<nsISerialEventTarget>
nsHtml5Module::GetStreamParserEventTarget() {
MOZ_ASSERT(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
if (sStreamParserThread) {
nsCOMPtr<nsISerialEventTarget> target =
sStreamParserThread->SerialEventTarget();
nsCOMPtr<nsISerialEventTarget> target = sStreamParserThread;
return target.forget();
}
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));
MOZ_RELEASE_ASSERT(mainThread); // Unrecoverable situation
nsCOMPtr<nsISerialEventTarget> target = mainThread->SerialEventTarget();
nsCOMPtr<nsISerialEventTarget> target = mainThread;
return target.forget();
}

Expand Down
14 changes: 7 additions & 7 deletions toolkit/xre/dllservices/UntrustedModulesProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ RefPtr<UntrustedModulesPromise> UntrustedModulesProcessor::GetProcessedData() {
BackgroundPriorityRegion::Clear(mThread);

RefPtr<UntrustedModulesProcessor> self(this);
return InvokeAsync(
mThread->SerialEventTarget(), __func__,
[self = std::move(self)]() { return self->GetProcessedDataInternal(); });
return InvokeAsync(mThread, __func__, [self = std::move(self)]() {
return self->GetProcessedDataInternal();
});
}

RefPtr<ModulesTrustPromise> UntrustedModulesProcessor::GetModulesTrust(
Expand All @@ -377,12 +377,12 @@ RefPtr<ModulesTrustPromise> UntrustedModulesProcessor::GetModulesTrust(
// Clear any background priority in case background processing is running.
BackgroundPriorityRegion::Clear(mThread);

return InvokeAsync(mThread->SerialEventTarget(), __func__, std::move(run));
return InvokeAsync(mThread, __func__, std::move(run));
}

RefPtr<ModulesTrustPromise::Private> p(
new ModulesTrustPromise::Private(__func__));
nsCOMPtr<nsISerialEventTarget> evtTarget(mThread->SerialEventTarget());
nsCOMPtr<nsISerialEventTarget> evtTarget(mThread);
const char* source = __func__;

auto runWrap = [evtTarget = std::move(evtTarget), p, source,
Expand Down Expand Up @@ -443,7 +443,7 @@ UntrustedModulesProcessor::GetProcessedDataInternalChildProcess() {
RefPtr<UntrustedModulesProcessor> self(this);
RefPtr<UntrustedModulesPromise::Private> p(
new UntrustedModulesPromise::Private(__func__));
nsCOMPtr<nsISerialEventTarget> evtTarget(mThread->SerialEventTarget());
nsCOMPtr<nsISerialEventTarget> evtTarget(mThread);

const char* source = __func__;
auto completionRoutine = [evtTarget = std::move(evtTarget), p,
Expand Down Expand Up @@ -542,7 +542,7 @@ void UntrustedModulesProcessor::BackgroundProcessModuleLoadQueueChildProcess() {
ProcessModuleLoadQueueChildProcess(Priority::Background));

RefPtr<UntrustedModulesProcessor> self(this);
nsCOMPtr<nsISerialEventTarget> evtTarget(mThread->SerialEventTarget());
nsCOMPtr<nsISerialEventTarget> evtTarget(mThread);

const char* source = __func__;
auto completionRoutine = [evtTarget = std::move(evtTarget),
Expand Down
11 changes: 0 additions & 11 deletions xpcom/threads/LazyIdleThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,15 +635,4 @@ LazyIdleThread::Observe(nsISupports* /* aSubject */, const char* aTopic,
return NS_OK;
}

NS_IMETHODIMP
LazyIdleThread::GetEventTarget(nsIEventTarget** aEventTarget) {
nsCOMPtr<nsIEventTarget> target = this;
target.forget(aEventTarget);
return NS_OK;
}

nsIEventTarget* LazyIdleThread::EventTarget() { return this; }

nsISerialEventTarget* LazyIdleThread::SerialEventTarget() { return this; }

} // namespace mozilla
4 changes: 1 addition & 3 deletions xpcom/threads/TimerThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ class TimerThread final : public mozilla::Runnable, public nsIObserver {
void DoBeforeSleep();
void DoAfterSleep();

bool IsOnTimerThread() const {
return mThread->SerialEventTarget()->IsOnCurrentThread();
}
bool IsOnTimerThread() const { return mThread->IsOnCurrentThread(); }

uint32_t AllowedEarlyFiringMicroseconds();

Expand Down
18 changes: 0 additions & 18 deletions xpcom/threads/nsIThread.idl
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,6 @@ interface nsIThread : nsISerialEventTarget
[noscript] void dispatchToQueue(in alreadyAddRefed_nsIRunnable event,
in EventQueuePriority queue);

/**
* Use this attribute to dispatch runnables to the thread. Eventually, the
* eventTarget attribute will be the only way to dispatch events to a
* thread--nsIThread will no longer inherit from nsIEventTarget.
*/
readonly attribute nsIEventTarget eventTarget;

/**
* A fast C++ getter for the eventTarget.
*/
[noscript,notxpcom] nsIEventTargetPtr EventTarget();

/**
* A fast C++ getter for the eventTarget. It asserts that the thread's event
* target is an nsISerialEventTarget and then returns it.
*/
[noscript,notxpcom] nsISerialEventTargetPtr SerialEventTarget();

/**
* This is set to the end of the last 50+ms event that was executed on
* this thread (for MainThread only). Otherwise returns a null TimeStamp.
Expand Down
11 changes: 0 additions & 11 deletions xpcom/threads/nsThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,13 +1375,6 @@ void nsThread::DoMainThreadSpecificProcessing() const {
}
}

NS_IMETHODIMP
nsThread::GetEventTarget(nsIEventTarget** aEventTarget) {
nsCOMPtr<nsIEventTarget> target = this;
target.forget(aEventTarget);
return NS_OK;
}

//-----------------------------------------------------------------------------
// nsIDirectTaskDispatcher

Expand Down Expand Up @@ -1411,10 +1404,6 @@ NS_IMETHODIMP nsThread::HaveDirectTasks(bool* aValue) {
return NS_OK;
}

nsIEventTarget* nsThread::EventTarget() { return this; }

nsISerialEventTarget* nsThread::SerialEventTarget() { return this; }

NS_IMPL_ISUPPORTS(nsThreadShutdownContext, nsIThreadShutdown)

NS_IMETHODIMP
Expand Down
4 changes: 2 additions & 2 deletions xpcom/threads/nsThreadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ nsIEventTarget* GetCurrentEventTarget() {
return nullptr;
}

return thread->EventTarget();
return thread;
}

nsIEventTarget* GetMainThreadEventTarget() {
Expand All @@ -574,7 +574,7 @@ nsISerialEventTarget* GetCurrentSerialEventTarget() {
return nullptr;
}

return thread->SerialEventTarget();
return thread;
}

nsISerialEventTarget* GetMainThreadSerialEventTarget() {
Expand Down

0 comments on commit 3888410

Please sign in to comment.