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 "PendingIPCBlobParent.h"
8 #include "mozilla/ipc/PBackgroundParent.h"
9 
10 namespace mozilla {
11 
12 using namespace ipc;
13 
14 namespace dom {
15 
16 /* static */
Create(PBackgroundParent * aManager,BlobImpl * aBlobImpl)17 PendingIPCBlobParent* PendingIPCBlobParent::Create(PBackgroundParent* aManager,
18                                                    BlobImpl* aBlobImpl) {
19   MOZ_ASSERT(aManager);
20   MOZ_ASSERT(aBlobImpl);
21 
22   IPCBlob ipcBlob;
23   nsresult rv = IPCBlobUtils::Serialize(aBlobImpl, aManager, ipcBlob);
24   if (NS_WARN_IF(NS_FAILED(rv))) {
25     return nullptr;
26   }
27 
28   PendingIPCBlobParent* actor = new PendingIPCBlobParent(aBlobImpl);
29   if (!aManager->SendPPendingIPCBlobConstructor(actor, ipcBlob)) {
30     // The actor will be deleted by the manager.
31     return nullptr;
32   }
33 
34   return actor;
35 }
36 
PendingIPCBlobParent(BlobImpl * aBlobImpl)37 PendingIPCBlobParent::PendingIPCBlobParent(BlobImpl* aBlobImpl)
38     : mBlobImpl(aBlobImpl) {}
39 
Recv__delete__(const PendingIPCBlobData & aData)40 IPCResult PendingIPCBlobParent::Recv__delete__(
41     const PendingIPCBlobData& aData) {
42   if (aData.file().type() == PendingIPCFileUnion::Tvoid_t) {
43     mBlobImpl->SetLazyData(VoidString(), aData.type(), aData.size(), INT64_MAX);
44   } else {
45     const PendingIPCFileData& fileData = aData.file().get_PendingIPCFileData();
46     mBlobImpl->SetLazyData(fileData.name(), aData.type(), aData.size(),
47                            fileData.lastModified());
48   }
49 
50   return IPC_OK();
51 }
52 
53 }  // namespace dom
54 }  // namespace mozilla
55