/src/mozilla-central/dom/cache/CacheStorageParent.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "mozilla/dom/cache/CacheStorageParent.h" |
8 | | |
9 | | #include "mozilla/Unused.h" |
10 | | #include "mozilla/dom/ContentParent.h" |
11 | | #include "mozilla/dom/cache/ActorUtils.h" |
12 | | #include "mozilla/dom/cache/CacheOpParent.h" |
13 | | #include "mozilla/dom/cache/ManagerId.h" |
14 | | #include "mozilla/ipc/PBackgroundParent.h" |
15 | | |
16 | | namespace mozilla { |
17 | | namespace dom { |
18 | | namespace cache { |
19 | | |
20 | | using mozilla::ipc::PBackgroundParent; |
21 | | using mozilla::ipc::PrincipalInfo; |
22 | | |
23 | | // declared in ActorUtils.h |
24 | | PCacheStorageParent* |
25 | | AllocPCacheStorageParent(PBackgroundParent* aManagingActor, |
26 | | Namespace aNamespace, |
27 | | const mozilla::ipc::PrincipalInfo& aPrincipalInfo) |
28 | 0 | { |
29 | 0 | return new CacheStorageParent(aManagingActor, aNamespace, aPrincipalInfo); |
30 | 0 | } |
31 | | |
32 | | // declared in ActorUtils.h |
33 | | void |
34 | | DeallocPCacheStorageParent(PCacheStorageParent* aActor) |
35 | 0 | { |
36 | 0 | delete aActor; |
37 | 0 | } |
38 | | |
39 | | CacheStorageParent::CacheStorageParent(PBackgroundParent* aManagingActor, |
40 | | Namespace aNamespace, |
41 | | const PrincipalInfo& aPrincipalInfo) |
42 | | : mNamespace(aNamespace) |
43 | | , mVerifiedStatus(NS_OK) |
44 | 0 | { |
45 | 0 | MOZ_COUNT_CTOR(cache::CacheStorageParent); |
46 | 0 | MOZ_DIAGNOSTIC_ASSERT(aManagingActor); |
47 | 0 |
|
48 | 0 | // Start the async principal verification process immediately. |
49 | 0 | mVerifier = PrincipalVerifier::CreateAndDispatch(this, aManagingActor, |
50 | 0 | aPrincipalInfo); |
51 | 0 | MOZ_DIAGNOSTIC_ASSERT(mVerifier); |
52 | 0 | } |
53 | | |
54 | | CacheStorageParent::~CacheStorageParent() |
55 | 0 | { |
56 | 0 | MOZ_COUNT_DTOR(cache::CacheStorageParent); |
57 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mVerifier); |
58 | 0 | } |
59 | | |
60 | | void |
61 | | CacheStorageParent::ActorDestroy(ActorDestroyReason aReason) |
62 | 0 | { |
63 | 0 | if (mVerifier) { |
64 | 0 | mVerifier->RemoveListener(this); |
65 | 0 | mVerifier = nullptr; |
66 | 0 | } |
67 | 0 | } |
68 | | |
69 | | PCacheOpParent* |
70 | | CacheStorageParent::AllocPCacheOpParent(const CacheOpArgs& aOpArgs) |
71 | 0 | { |
72 | 0 | if (aOpArgs.type() != CacheOpArgs::TStorageMatchArgs && |
73 | 0 | aOpArgs.type() != CacheOpArgs::TStorageHasArgs && |
74 | 0 | aOpArgs.type() != CacheOpArgs::TStorageOpenArgs && |
75 | 0 | aOpArgs.type() != CacheOpArgs::TStorageDeleteArgs && |
76 | 0 | aOpArgs.type() != CacheOpArgs::TStorageKeysArgs) |
77 | 0 | { |
78 | 0 | MOZ_CRASH("Invalid operation sent to CacheStorage actor!"); |
79 | 0 | } |
80 | 0 |
|
81 | 0 | return new CacheOpParent(Manager(), mNamespace, aOpArgs); |
82 | 0 | } |
83 | | |
84 | | bool |
85 | | CacheStorageParent::DeallocPCacheOpParent(PCacheOpParent* aActor) |
86 | 0 | { |
87 | 0 | delete aActor; |
88 | 0 | return true; |
89 | 0 | } |
90 | | |
91 | | mozilla::ipc::IPCResult |
92 | | CacheStorageParent::RecvPCacheOpConstructor(PCacheOpParent* aActor, |
93 | | const CacheOpArgs& aOpArgs) |
94 | 0 | { |
95 | 0 | auto actor = static_cast<CacheOpParent*>(aActor); |
96 | 0 |
|
97 | 0 | if (mVerifier) { |
98 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mManagerId); |
99 | 0 | actor->WaitForVerification(mVerifier); |
100 | 0 | return IPC_OK(); |
101 | 0 | } |
102 | 0 | |
103 | 0 | if (NS_WARN_IF(NS_FAILED(mVerifiedStatus))) { |
104 | 0 | ErrorResult result(mVerifiedStatus); |
105 | 0 | Unused << CacheOpParent::Send__delete__(actor, result, void_t()); |
106 | 0 | result.SuppressException(); |
107 | 0 | return IPC_OK(); |
108 | 0 | } |
109 | 0 |
|
110 | 0 | MOZ_DIAGNOSTIC_ASSERT(mManagerId); |
111 | 0 | actor->Execute(mManagerId); |
112 | 0 | return IPC_OK(); |
113 | 0 | } |
114 | | |
115 | | mozilla::ipc::IPCResult |
116 | | CacheStorageParent::RecvTeardown() |
117 | 0 | { |
118 | 0 | if (!Send__delete__(this)) { |
119 | 0 | // child process is gone, warn and allow actor to clean up normally |
120 | 0 | NS_WARNING("CacheStorage failed to delete actor."); |
121 | 0 | } |
122 | 0 | return IPC_OK(); |
123 | 0 | } |
124 | | |
125 | | void |
126 | | CacheStorageParent::OnPrincipalVerified(nsresult aRv, ManagerId* aManagerId) |
127 | 0 | { |
128 | 0 | MOZ_DIAGNOSTIC_ASSERT(mVerifier); |
129 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mManagerId); |
130 | 0 | MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(mVerifiedStatus)); |
131 | 0 |
|
132 | 0 | if (NS_WARN_IF(NS_FAILED(aRv))) { |
133 | 0 | mVerifiedStatus = aRv; |
134 | 0 | } |
135 | 0 |
|
136 | 0 | mManagerId = aManagerId; |
137 | 0 | mVerifier->RemoveListener(this); |
138 | 0 | mVerifier = nullptr; |
139 | 0 | } |
140 | | |
141 | | } // namespace cache |
142 | | } // namespace dom |
143 | | } // namespace mozilla |