/src/mozilla-central/dom/quota/ActorsChild.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 file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "ActorsChild.h" |
8 | | |
9 | | #include "nsVariant.h" |
10 | | #include "QuotaManagerService.h" |
11 | | #include "QuotaRequests.h" |
12 | | #include "QuotaResults.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | namespace quota { |
17 | | |
18 | | /******************************************************************************* |
19 | | * QuotaChild |
20 | | ******************************************************************************/ |
21 | | |
22 | | QuotaChild::QuotaChild(QuotaManagerService* aService) |
23 | | : mService(aService) |
24 | | #ifdef DEBUG |
25 | | , mOwningThread(GetCurrentThreadEventTarget()) |
26 | | #endif |
27 | 0 | { |
28 | 0 | AssertIsOnOwningThread(); |
29 | 0 | MOZ_ASSERT(aService); |
30 | 0 |
|
31 | 0 | MOZ_COUNT_CTOR(quota::QuotaChild); |
32 | 0 | } |
33 | | |
34 | | QuotaChild::~QuotaChild() |
35 | 0 | { |
36 | 0 | AssertIsOnOwningThread(); |
37 | 0 |
|
38 | 0 | MOZ_COUNT_DTOR(quota::QuotaChild); |
39 | 0 | } |
40 | | |
41 | | #ifdef DEBUG |
42 | | |
43 | | void |
44 | | QuotaChild::AssertIsOnOwningThread() const |
45 | | { |
46 | | MOZ_ASSERT(mOwningThread); |
47 | | |
48 | | bool current; |
49 | | MOZ_ASSERT(NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(¤t))); |
50 | | MOZ_ASSERT(current); |
51 | | } |
52 | | |
53 | | #endif // DEBUG |
54 | | |
55 | | void |
56 | | QuotaChild::ActorDestroy(ActorDestroyReason aWhy) |
57 | 0 | { |
58 | 0 | AssertIsOnOwningThread(); |
59 | 0 |
|
60 | 0 | if (mService) { |
61 | 0 | mService->ClearBackgroundActor(); |
62 | | #ifdef DEBUG |
63 | | mService = nullptr; |
64 | | #endif |
65 | | } |
66 | 0 | } |
67 | | |
68 | | PQuotaUsageRequestChild* |
69 | | QuotaChild::AllocPQuotaUsageRequestChild(const UsageRequestParams& aParams) |
70 | 0 | { |
71 | 0 | AssertIsOnOwningThread(); |
72 | 0 |
|
73 | 0 | MOZ_CRASH("PQuotaUsageRequestChild actors should be manually constructed!"); |
74 | 0 | } |
75 | | |
76 | | bool |
77 | | QuotaChild::DeallocPQuotaUsageRequestChild(PQuotaUsageRequestChild* aActor) |
78 | 0 | { |
79 | 0 | AssertIsOnOwningThread(); |
80 | 0 | MOZ_ASSERT(aActor); |
81 | 0 |
|
82 | 0 | delete static_cast<QuotaUsageRequestChild*>(aActor); |
83 | 0 | return true; |
84 | 0 | } |
85 | | |
86 | | PQuotaRequestChild* |
87 | | QuotaChild::AllocPQuotaRequestChild(const RequestParams& aParams) |
88 | 0 | { |
89 | 0 | AssertIsOnOwningThread(); |
90 | 0 |
|
91 | 0 | MOZ_CRASH("PQuotaRequestChild actors should be manually constructed!"); |
92 | 0 | } |
93 | | |
94 | | bool |
95 | | QuotaChild::DeallocPQuotaRequestChild(PQuotaRequestChild* aActor) |
96 | 0 | { |
97 | 0 | AssertIsOnOwningThread(); |
98 | 0 | MOZ_ASSERT(aActor); |
99 | 0 |
|
100 | 0 | delete static_cast<QuotaRequestChild*>(aActor); |
101 | 0 | return true; |
102 | 0 | } |
103 | | |
104 | | /******************************************************************************* |
105 | | * QuotaUsageRequestChild |
106 | | ******************************************************************************/ |
107 | | |
108 | | QuotaUsageRequestChild::QuotaUsageRequestChild(UsageRequest* aRequest) |
109 | | : mRequest(aRequest) |
110 | 0 | { |
111 | 0 | AssertIsOnOwningThread(); |
112 | 0 |
|
113 | 0 | MOZ_COUNT_CTOR(quota::QuotaUsageRequestChild); |
114 | 0 | } |
115 | | |
116 | | QuotaUsageRequestChild::~QuotaUsageRequestChild() |
117 | 0 | { |
118 | 0 | // Can't assert owning thread here because the request is cleared. |
119 | 0 |
|
120 | 0 | MOZ_COUNT_DTOR(quota::QuotaUsageRequestChild); |
121 | 0 | } |
122 | | |
123 | | #ifdef DEBUG |
124 | | |
125 | | void |
126 | | QuotaUsageRequestChild::AssertIsOnOwningThread() const |
127 | | { |
128 | | MOZ_ASSERT(mRequest); |
129 | | mRequest->AssertIsOnOwningThread(); |
130 | | } |
131 | | |
132 | | #endif // DEBUG |
133 | | |
134 | | void |
135 | | QuotaUsageRequestChild::HandleResponse(nsresult aResponse) |
136 | 0 | { |
137 | 0 | AssertIsOnOwningThread(); |
138 | 0 | MOZ_ASSERT(NS_FAILED(aResponse)); |
139 | 0 | MOZ_ASSERT(mRequest); |
140 | 0 |
|
141 | 0 | mRequest->SetError(aResponse); |
142 | 0 | } |
143 | | |
144 | | void |
145 | | QuotaUsageRequestChild::HandleResponse(const nsTArray<OriginUsage>& aResponse) |
146 | 0 | { |
147 | 0 | AssertIsOnOwningThread(); |
148 | 0 | MOZ_ASSERT(mRequest); |
149 | 0 |
|
150 | 0 | RefPtr<nsVariant> variant = new nsVariant(); |
151 | 0 |
|
152 | 0 | if (aResponse.IsEmpty()) { |
153 | 0 | variant->SetAsEmptyArray(); |
154 | 0 | } else { |
155 | 0 | nsTArray<RefPtr<UsageResult>> usageResults; |
156 | 0 |
|
157 | 0 | const uint32_t count = aResponse.Length(); |
158 | 0 |
|
159 | 0 | usageResults.SetCapacity(count); |
160 | 0 |
|
161 | 0 | for (uint32_t index = 0; index < count; index++) { |
162 | 0 | auto& originUsage = aResponse[index]; |
163 | 0 |
|
164 | 0 | RefPtr<UsageResult> usageResult = new UsageResult(originUsage.origin(), |
165 | 0 | originUsage.persisted(), |
166 | 0 | originUsage.usage(), |
167 | 0 | originUsage.lastAccessed()); |
168 | 0 |
|
169 | 0 | usageResults.AppendElement(usageResult.forget()); |
170 | 0 | } |
171 | 0 |
|
172 | 0 | variant->SetAsArray(nsIDataType::VTYPE_INTERFACE_IS, |
173 | 0 | &NS_GET_IID(nsIQuotaUsageResult), |
174 | 0 | usageResults.Length(), |
175 | 0 | static_cast<void*>(usageResults.Elements())); |
176 | 0 | } |
177 | 0 |
|
178 | 0 | mRequest->SetResult(variant); |
179 | 0 | } |
180 | | |
181 | | void |
182 | | QuotaUsageRequestChild::HandleResponse(const OriginUsageResponse& aResponse) |
183 | 0 | { |
184 | 0 | AssertIsOnOwningThread(); |
185 | 0 | MOZ_ASSERT(mRequest); |
186 | 0 |
|
187 | 0 | RefPtr<OriginUsageResult> result = |
188 | 0 | new OriginUsageResult(aResponse.usage(), |
189 | 0 | aResponse.fileUsage(), |
190 | 0 | aResponse.limit()); |
191 | 0 |
|
192 | 0 | RefPtr<nsVariant> variant = new nsVariant(); |
193 | 0 | variant->SetAsInterface(NS_GET_IID(nsIQuotaOriginUsageResult), result); |
194 | 0 |
|
195 | 0 | mRequest->SetResult(variant); |
196 | 0 | } |
197 | | |
198 | | void |
199 | | QuotaUsageRequestChild::ActorDestroy(ActorDestroyReason aWhy) |
200 | 0 | { |
201 | 0 | AssertIsOnOwningThread(); |
202 | 0 |
|
203 | 0 | if (mRequest) { |
204 | 0 | mRequest->ClearBackgroundActor(); |
205 | | #ifdef DEBUG |
206 | | mRequest = nullptr; |
207 | | #endif |
208 | | } |
209 | 0 | } |
210 | | |
211 | | mozilla::ipc::IPCResult |
212 | | QuotaUsageRequestChild::Recv__delete__(const UsageRequestResponse& aResponse) |
213 | 0 | { |
214 | 0 | AssertIsOnOwningThread(); |
215 | 0 | MOZ_ASSERT(mRequest); |
216 | 0 |
|
217 | 0 | switch (aResponse.type()) { |
218 | 0 | case UsageRequestResponse::Tnsresult: |
219 | 0 | HandleResponse(aResponse.get_nsresult()); |
220 | 0 | break; |
221 | 0 |
|
222 | 0 | case UsageRequestResponse::TAllUsageResponse: |
223 | 0 | HandleResponse(aResponse.get_AllUsageResponse().originUsages()); |
224 | 0 | break; |
225 | 0 |
|
226 | 0 | case UsageRequestResponse::TOriginUsageResponse: |
227 | 0 | HandleResponse(aResponse.get_OriginUsageResponse()); |
228 | 0 | break; |
229 | 0 |
|
230 | 0 | default: |
231 | 0 | MOZ_CRASH("Unknown response type!"); |
232 | 0 | } |
233 | 0 |
|
234 | 0 | return IPC_OK(); |
235 | 0 | } |
236 | | |
237 | | /******************************************************************************* |
238 | | * QuotaRequestChild |
239 | | ******************************************************************************/ |
240 | | |
241 | | QuotaRequestChild::QuotaRequestChild(Request* aRequest) |
242 | | : mRequest(aRequest) |
243 | 0 | { |
244 | 0 | AssertIsOnOwningThread(); |
245 | 0 |
|
246 | 0 | MOZ_COUNT_CTOR(quota::QuotaRequestChild); |
247 | 0 | } |
248 | | |
249 | | QuotaRequestChild::~QuotaRequestChild() |
250 | 0 | { |
251 | 0 | AssertIsOnOwningThread(); |
252 | 0 |
|
253 | 0 | MOZ_COUNT_DTOR(quota::QuotaRequestChild); |
254 | 0 | } |
255 | | |
256 | | #ifdef DEBUG |
257 | | |
258 | | void |
259 | | QuotaRequestChild::AssertIsOnOwningThread() const |
260 | | { |
261 | | MOZ_ASSERT(mRequest); |
262 | | mRequest->AssertIsOnOwningThread(); |
263 | | } |
264 | | |
265 | | #endif // DEBUG |
266 | | |
267 | | void |
268 | | QuotaRequestChild::HandleResponse(nsresult aResponse) |
269 | 0 | { |
270 | 0 | AssertIsOnOwningThread(); |
271 | 0 | MOZ_ASSERT(NS_FAILED(aResponse)); |
272 | 0 | MOZ_ASSERT(mRequest); |
273 | 0 |
|
274 | 0 | mRequest->SetError(aResponse); |
275 | 0 | } |
276 | | |
277 | | void |
278 | | QuotaRequestChild::HandleResponse() |
279 | 0 | { |
280 | 0 | AssertIsOnOwningThread(); |
281 | 0 | MOZ_ASSERT(mRequest); |
282 | 0 |
|
283 | 0 | RefPtr<nsVariant> variant = new nsVariant(); |
284 | 0 | variant->SetAsVoid(); |
285 | 0 |
|
286 | 0 | mRequest->SetResult(variant); |
287 | 0 | } |
288 | | |
289 | | void |
290 | | QuotaRequestChild::HandleResponse(bool aResponse) |
291 | 0 | { |
292 | 0 | AssertIsOnOwningThread(); |
293 | 0 | MOZ_ASSERT(mRequest); |
294 | 0 |
|
295 | 0 | RefPtr<nsVariant> variant = new nsVariant(); |
296 | 0 | variant->SetAsBool(aResponse); |
297 | 0 |
|
298 | 0 | mRequest->SetResult(variant); |
299 | 0 | } |
300 | | |
301 | | void |
302 | | QuotaRequestChild::ActorDestroy(ActorDestroyReason aWhy) |
303 | 0 | { |
304 | 0 | AssertIsOnOwningThread(); |
305 | 0 | } |
306 | | |
307 | | mozilla::ipc::IPCResult |
308 | | QuotaRequestChild::Recv__delete__(const RequestResponse& aResponse) |
309 | 0 | { |
310 | 0 | AssertIsOnOwningThread(); |
311 | 0 | MOZ_ASSERT(mRequest); |
312 | 0 |
|
313 | 0 | switch (aResponse.type()) { |
314 | 0 | case RequestResponse::Tnsresult: |
315 | 0 | HandleResponse(aResponse.get_nsresult()); |
316 | 0 | break; |
317 | 0 |
|
318 | 0 | case RequestResponse::TInitResponse: |
319 | 0 | case RequestResponse::TClearOriginResponse: |
320 | 0 | case RequestResponse::TClearDataResponse: |
321 | 0 | case RequestResponse::TClearAllResponse: |
322 | 0 | case RequestResponse::TResetAllResponse: |
323 | 0 | case RequestResponse::TPersistResponse: |
324 | 0 | HandleResponse(); |
325 | 0 | break; |
326 | 0 |
|
327 | 0 | case RequestResponse::TInitOriginResponse: |
328 | 0 | HandleResponse(aResponse.get_InitOriginResponse().created()); |
329 | 0 | break; |
330 | 0 |
|
331 | 0 | case RequestResponse::TPersistedResponse: |
332 | 0 | HandleResponse(aResponse.get_PersistedResponse().persisted()); |
333 | 0 | break; |
334 | 0 |
|
335 | 0 | default: |
336 | 0 | MOZ_CRASH("Unknown response type!"); |
337 | 0 | } |
338 | 0 |
|
339 | 0 | return IPC_OK(); |
340 | 0 | } |
341 | | |
342 | | } // namespace quota |
343 | | } // namespace dom |
344 | | } // namespace mozilla |