Bug 1843230 - Remove IsWin8OrLater checks from dom/geolocation/ r=emk
[gecko.git] / dom / cache / CacheStorageParent.cpp
blob5a7c5774cb12a40c7481b4cdac639c5090e405b3
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 already_AddRefed<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 MakeAndAddRef<CacheStorageParent>(aManagingActor, aNamespace,
32 aPrincipalInfo);
35 // declared in ActorUtils.h
36 void DeallocPCacheStorageParent(PCacheStorageParent* aActor) { delete aActor; }
38 CacheStorageParent::CacheStorageParent(PBackgroundParent* aManagingActor,
39 Namespace aNamespace,
40 const PrincipalInfo& aPrincipalInfo)
41 : mNamespace(aNamespace), mVerifiedStatus(NS_OK) {
42 MOZ_COUNT_CTOR(cache::CacheStorageParent);
43 MOZ_DIAGNOSTIC_ASSERT(aManagingActor);
45 // Start the async principal verification process immediately.
46 mVerifier = PrincipalVerifier::CreateAndDispatch(*this, aManagingActor,
47 aPrincipalInfo);
48 MOZ_DIAGNOSTIC_ASSERT(mVerifier);
51 CacheStorageParent::~CacheStorageParent() {
52 MOZ_COUNT_DTOR(cache::CacheStorageParent);
53 MOZ_DIAGNOSTIC_ASSERT(!mVerifier);
56 void CacheStorageParent::ActorDestroy(ActorDestroyReason aReason) {
57 if (mVerifier) {
58 mVerifier->RemoveListener(*this);
59 mVerifier = nullptr;
63 PCacheOpParent* CacheStorageParent::AllocPCacheOpParent(
64 const CacheOpArgs& aOpArgs) {
65 if (aOpArgs.type() != CacheOpArgs::TStorageMatchArgs &&
66 aOpArgs.type() != CacheOpArgs::TStorageHasArgs &&
67 aOpArgs.type() != CacheOpArgs::TStorageOpenArgs &&
68 aOpArgs.type() != CacheOpArgs::TStorageDeleteArgs &&
69 aOpArgs.type() != CacheOpArgs::TStorageKeysArgs) {
70 MOZ_CRASH("Invalid operation sent to CacheStorage actor!");
73 return new CacheOpParent(Manager(), mNamespace, aOpArgs);
76 bool CacheStorageParent::DeallocPCacheOpParent(PCacheOpParent* aActor) {
77 delete aActor;
78 return true;
81 mozilla::ipc::IPCResult CacheStorageParent::RecvPCacheOpConstructor(
82 PCacheOpParent* aActor, const CacheOpArgs& aOpArgs) {
83 auto actor = static_cast<CacheOpParent*>(aActor);
85 if (mVerifier) {
86 MOZ_DIAGNOSTIC_ASSERT(!mManagerId);
87 actor->WaitForVerification(mVerifier);
88 return IPC_OK();
91 if (NS_WARN_IF(NS_FAILED(mVerifiedStatus))) {
92 ErrorResult result(mVerifiedStatus);
94 QM_WARNONLY_TRY(OkIf(
95 CacheOpParent::Send__delete__(actor, std::move(result), void_t())));
96 return IPC_OK();
99 MOZ_DIAGNOSTIC_ASSERT(mManagerId);
100 actor->Execute(mManagerId);
101 return IPC_OK();
104 mozilla::ipc::IPCResult CacheStorageParent::RecvTeardown() {
105 // If child process is gone, warn and allow actor to clean up normally
106 QM_WARNONLY_TRY(OkIf(Send__delete__(this)));
107 return IPC_OK();
110 void CacheStorageParent::OnPrincipalVerified(
111 nsresult aRv, const SafeRefPtr<ManagerId>& aManagerId) {
112 MOZ_DIAGNOSTIC_ASSERT(mVerifier);
113 MOZ_DIAGNOSTIC_ASSERT(!mManagerId);
114 MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(mVerifiedStatus));
116 if (NS_WARN_IF(NS_FAILED(aRv))) {
117 mVerifiedStatus = aRv;
120 mManagerId = aManagerId.clonePtr();
121 mVerifier->RemoveListener(*this);
122 mVerifier = nullptr;
125 } // namespace mozilla::dom::cache