Bug 1688354 [wpt PR 27298] - Treat 'rem' as an absolute unit for font size, a=testonly
[gecko.git] / dom / cache / CacheStorageParent.cpp
blobb05e1c26681a0d632427d246580da7ed9e12271f
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 "mozilla/dom/cache/CacheStorageParent.h"
9 #include "mozilla/Unused.h"
10 #include "mozilla/dom/cache/ActorUtils.h"
11 #include "mozilla/dom/cache/CacheOpParent.h"
12 #include "mozilla/dom/cache/ManagerId.h"
13 #include "mozilla/dom/quota/QuotaManager.h"
14 #include "mozilla/ipc/PBackgroundParent.h"
16 namespace mozilla::dom::cache {
18 using mozilla::dom::quota::QuotaManager;
19 using mozilla::ipc::PBackgroundParent;
20 using mozilla::ipc::PrincipalInfo;
22 // declared in ActorUtils.h
23 PCacheStorageParent* AllocPCacheStorageParent(
24 PBackgroundParent* aManagingActor, Namespace aNamespace,
25 const mozilla::ipc::PrincipalInfo& aPrincipalInfo) {
26 if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(aPrincipalInfo))) {
27 MOZ_ASSERT(false);
28 return nullptr;
31 return new CacheStorageParent(aManagingActor, aNamespace, aPrincipalInfo);
34 // declared in ActorUtils.h
35 void DeallocPCacheStorageParent(PCacheStorageParent* aActor) { delete aActor; }
37 CacheStorageParent::CacheStorageParent(PBackgroundParent* aManagingActor,
38 Namespace aNamespace,
39 const PrincipalInfo& aPrincipalInfo)
40 : mNamespace(aNamespace), mVerifiedStatus(NS_OK) {
41 MOZ_COUNT_CTOR(cache::CacheStorageParent);
42 MOZ_DIAGNOSTIC_ASSERT(aManagingActor);
44 // Start the async principal verification process immediately.
45 mVerifier = PrincipalVerifier::CreateAndDispatch(*this, aManagingActor,
46 aPrincipalInfo);
47 MOZ_DIAGNOSTIC_ASSERT(mVerifier);
50 CacheStorageParent::~CacheStorageParent() {
51 MOZ_COUNT_DTOR(cache::CacheStorageParent);
52 MOZ_DIAGNOSTIC_ASSERT(!mVerifier);
55 void CacheStorageParent::ActorDestroy(ActorDestroyReason aReason) {
56 if (mVerifier) {
57 mVerifier->RemoveListener(*this);
58 mVerifier = nullptr;
62 PCacheOpParent* CacheStorageParent::AllocPCacheOpParent(
63 const CacheOpArgs& aOpArgs) {
64 if (aOpArgs.type() != CacheOpArgs::TStorageMatchArgs &&
65 aOpArgs.type() != CacheOpArgs::TStorageHasArgs &&
66 aOpArgs.type() != CacheOpArgs::TStorageOpenArgs &&
67 aOpArgs.type() != CacheOpArgs::TStorageDeleteArgs &&
68 aOpArgs.type() != CacheOpArgs::TStorageKeysArgs) {
69 MOZ_CRASH("Invalid operation sent to CacheStorage actor!");
72 return new CacheOpParent(Manager(), mNamespace, aOpArgs);
75 bool CacheStorageParent::DeallocPCacheOpParent(PCacheOpParent* aActor) {
76 delete aActor;
77 return true;
80 mozilla::ipc::IPCResult CacheStorageParent::RecvPCacheOpConstructor(
81 PCacheOpParent* aActor, const CacheOpArgs& aOpArgs) {
82 auto actor = static_cast<CacheOpParent*>(aActor);
84 if (mVerifier) {
85 MOZ_DIAGNOSTIC_ASSERT(!mManagerId);
86 actor->WaitForVerification(mVerifier);
87 return IPC_OK();
90 if (NS_WARN_IF(NS_FAILED(mVerifiedStatus))) {
91 ErrorResult result(mVerifiedStatus);
92 Unused << CacheOpParent::Send__delete__(actor, std::move(result), void_t());
93 return IPC_OK();
96 MOZ_DIAGNOSTIC_ASSERT(mManagerId);
97 actor->Execute(mManagerId);
98 return IPC_OK();
101 mozilla::ipc::IPCResult CacheStorageParent::RecvTeardown() {
102 if (!Send__delete__(this)) {
103 // child process is gone, warn and allow actor to clean up normally
104 NS_WARNING("CacheStorage failed to delete actor.");
106 return IPC_OK();
109 void CacheStorageParent::OnPrincipalVerified(
110 nsresult aRv, const SafeRefPtr<ManagerId>& aManagerId) {
111 MOZ_DIAGNOSTIC_ASSERT(mVerifier);
112 MOZ_DIAGNOSTIC_ASSERT(!mManagerId);
113 MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(mVerifiedStatus));
115 if (NS_WARN_IF(NS_FAILED(aRv))) {
116 mVerifiedStatus = aRv;
119 mManagerId = aManagerId.clonePtr();
120 mVerifier->RemoveListener(*this);
121 mVerifier = nullptr;
124 } // namespace mozilla::dom::cache