Files
sousa-gecko/dom/workers/remoteworkers/RemoteWorkerNonLifeCycleOpControllerChild.cpp
T
serge-sans-paille 7662b3abdc Bug 1994397 - Remove obsolete Unused.h header r=emilio,tschuster,geckoview-reviewers,extension-reviewers,application-update-reviewers,media-playback-reviewers,webrtc-reviewers,cookie-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,permissions-reviewers,profiles-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,firefox-svg-reviewers,layout-reviewers,timhuang,gstoll,TravisLong,bytesized,mstange,karlt,robwu,pehrsons,m_kato,jari,jhirsch
It is replaced by a standard-conforming cast to (void) which is
understood the same by the compiler.

In some cases this could be replaced by `[[maybe_unused]]` but for
expression whose value is ignored, this requires storing to a temporary
variable first, so not going that way.

One notable change is that marking an object of type already_AddRefed as
unused used to implicitly leak memory. This is now made explicit.

Most of the heavy lifting was done through:

    $ git grep -l '\<Unused\> <<' | xargs sed -i -e 's/Unused << /(void)/g'
    $ git grep -l mozilla/Unused.h | xargs sed -i -e '/mozilla\/Unused.h/ d'

Differential Revision: https://phabricator.services.mozilla.com/D268706
2025-10-21 19:36:01 +00:00

107 lines
3.1 KiB
C++

/* 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 "RemoteWorkerNonLifeCycleOpControllerChild.h"
#include "mozilla/dom/ServiceWorkerOp.h"
#include "mozilla/dom/SharedWorkerOp.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerRef.h"
namespace mozilla::dom {
using remoteworker::Canceled;
using remoteworker::Killed;
using remoteworker::Running;
/* static */
RefPtr<RemoteWorkerNonLifeCycleOpControllerChild>
RemoteWorkerNonLifeCycleOpControllerChild::Create() {
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(GetCurrentThreadWorkerPrivate());
RefPtr<RemoteWorkerNonLifeCycleOpControllerChild> actor =
MakeAndAddRef<RemoteWorkerNonLifeCycleOpControllerChild>();
return actor;
}
RemoteWorkerNonLifeCycleOpControllerChild::
RemoteWorkerNonLifeCycleOpControllerChild()
: mState(VariantType<remoteworker::Running>(),
"RemoteWorkerNonLifeCycleOpControllerChild") {}
RemoteWorkerNonLifeCycleOpControllerChild::
~RemoteWorkerNonLifeCycleOpControllerChild() = default;
void RemoteWorkerNonLifeCycleOpControllerChild::TransistionStateToCanceled() {
auto lock = mState.Lock();
MOZ_ASSERT(lock->is<Running>());
*lock = VariantType<Canceled>();
}
void RemoteWorkerNonLifeCycleOpControllerChild::TransistionStateToKilled() {
auto lock = mState.Lock();
MOZ_ASSERT(lock->is<Canceled>());
*lock = VariantType<Killed>();
if (!CanSend()) {
return;
}
(void)SendTerminated();
if (GetIPCChannel()) {
GetIPCChannel()->Close();
}
}
void RemoteWorkerNonLifeCycleOpControllerChild::ErrorPropagation(
nsresult aError) {
if (!CanSend()) {
return;
}
(void)SendError(aError);
}
void RemoteWorkerNonLifeCycleOpControllerChild::StartOp(
RefPtr<RemoteWorkerOp>&& aOp) {
MOZ_ASSERT(aOp);
auto lock = mState.Lock();
// ServiceWorkerOp/SharedWorkerOp handles the Canceled/Killed state cases.
aOp->Start(this, lock.ref());
}
IPCResult RemoteWorkerNonLifeCycleOpControllerChild::RecvExecOp(
SharedWorkerOpArgs&& aOpArgs) {
MOZ_ASSERT(aOpArgs.type() ==
SharedWorkerOpArgs::TSharedWorkerPortIdentifierOpArgs);
StartOp(new SharedWorkerOp(std::move(aOpArgs)));
return IPC_OK();
}
IPCResult RemoteWorkerNonLifeCycleOpControllerChild::RecvExecServiceWorkerOp(
ServiceWorkerOpArgs&& aOpArgs, ExecServiceWorkerOpResolver&& aResolve) {
MOZ_ASSERT(
aOpArgs.type() !=
ServiceWorkerOpArgs::TParentToChildServiceWorkerFetchEventOpArgs,
"FetchEvent operations should be sent via PFetchEventOp(Proxy) actors!");
MOZ_ASSERT(aOpArgs.type() !=
ServiceWorkerOpArgs::TServiceWorkerTerminateWorkerOpArgs,
"Terminate operations should be sent via PRemoteWorker actros!");
StartOp(ServiceWorkerOp::Create(std::move(aOpArgs), std::move(aResolve)));
return IPC_OK();
}
IPCResult RemoteWorkerNonLifeCycleOpControllerChild::RecvShutdown() {
if (GetIPCChannel()) {
GetIPCChannel()->Close();
}
return IPC_OK();
}
} // namespace mozilla::dom