Bug 1806483 - Enable TSAN cppunittests by default. r=jmaher
[gecko.git] / dom / serviceworkers / ServiceWorkerParent.cpp
blob4e31344e92dd7b12d74723131c868097b2118c71
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "ServiceWorkerParent.h"
9 #include "ServiceWorkerCloneData.h"
10 #include "ServiceWorkerProxy.h"
11 #include "mozilla/dom/ClientInfo.h"
12 #include "mozilla/dom/ClientState.h"
13 #include "mozilla/dom/ipc/StructuredCloneData.h"
15 namespace mozilla::dom {
17 using mozilla::dom::ipc::StructuredCloneData;
18 using mozilla::ipc::IPCResult;
20 void ServiceWorkerParent::ActorDestroy(ActorDestroyReason aReason) {
21 if (mProxy) {
22 mProxy->RevokeActor(this);
23 mProxy = nullptr;
27 IPCResult ServiceWorkerParent::RecvTeardown() {
28 MaybeSendDelete();
29 return IPC_OK();
32 IPCResult ServiceWorkerParent::RecvPostMessage(
33 const ClonedOrErrorMessageData& aClonedData,
34 const ClientInfoAndState& aSource) {
35 RefPtr<ServiceWorkerCloneData> data = new ServiceWorkerCloneData();
36 data->CopyFromClonedMessageData(aClonedData);
38 mProxy->PostMessage(std::move(data), ClientInfo(aSource.info()),
39 ClientState::FromIPC(aSource.state()));
41 return IPC_OK();
44 ServiceWorkerParent::ServiceWorkerParent() : mDeleteSent(false) {}
46 ServiceWorkerParent::~ServiceWorkerParent() { MOZ_DIAGNOSTIC_ASSERT(!mProxy); }
48 void ServiceWorkerParent::Init(const IPCServiceWorkerDescriptor& aDescriptor) {
49 MOZ_DIAGNOSTIC_ASSERT(!mProxy);
50 mProxy = new ServiceWorkerProxy(ServiceWorkerDescriptor(aDescriptor));
51 mProxy->Init(this);
54 void ServiceWorkerParent::MaybeSendDelete() {
55 if (mDeleteSent) {
56 return;
58 mDeleteSent = true;
59 Unused << Send__delete__(this);
62 } // namespace mozilla::dom