FileSystemWritableFileStreamParent.cpp (2444B)
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 "FileSystemWritableFileStreamParent.h" 8 9 #include "FileSystemDataManager.h" 10 #include "FileSystemStreamCallbacks.h" 11 #include "mozilla/dom/FileSystemLog.h" 12 #include "mozilla/dom/FileSystemManagerParent.h" 13 #include "mozilla/dom/quota/RemoteQuotaObjectParent.h" 14 15 namespace mozilla::dom { 16 17 class FileSystemWritableFileStreamParent::FileSystemWritableFileStreamCallbacks 18 : public FileSystemStreamCallbacks { 19 public: 20 void CloseRemoteQuotaObjectParent() { 21 if (mRemoteQuotaObjectParent) { 22 mRemoteQuotaObjectParent->Close(); 23 } 24 } 25 }; 26 27 FileSystemWritableFileStreamParent::FileSystemWritableFileStreamParent( 28 RefPtr<FileSystemManagerParent> aManager, const fs::EntryId& aEntryId, 29 const fs::FileId& aTemporaryFileId, bool aIsExclusive) 30 : mManager(std::move(aManager)), 31 mEntryId(aEntryId), 32 mTemporaryFileId(aTemporaryFileId), 33 mIsExclusive(aIsExclusive) {} 34 35 FileSystemWritableFileStreamParent::~FileSystemWritableFileStreamParent() { 36 MOZ_ASSERT(mClosed); 37 } 38 39 mozilla::ipc::IPCResult FileSystemWritableFileStreamParent::RecvClose( 40 bool aAbort, CloseResolver&& aResolver) { 41 Close(aAbort); 42 43 aResolver(void_t()); 44 45 return IPC_OK(); 46 } 47 48 void FileSystemWritableFileStreamParent::ActorDestroy(ActorDestroyReason aWhy) { 49 if (mStreamCallbacks) { 50 mStreamCallbacks->CloseRemoteQuotaObjectParent(); 51 mStreamCallbacks = nullptr; 52 } 53 54 if (!IsClosed()) { 55 Close(/* aAbort */ true); 56 } 57 } 58 59 nsIInterfaceRequestor* 60 FileSystemWritableFileStreamParent::GetOrCreateStreamCallbacks() { 61 if (!mStreamCallbacks) { 62 if (mClosed) { 63 return nullptr; 64 } 65 66 mStreamCallbacks = MakeRefPtr<FileSystemWritableFileStreamCallbacks>(); 67 } 68 69 return mStreamCallbacks.get(); 70 } 71 72 void FileSystemWritableFileStreamParent::Close(bool aAbort) { 73 LOG(("Closing WritableFileStream")); 74 75 mClosed.Flip(); 76 77 if (mIsExclusive) { 78 mManager->DataManagerStrongRef()->UnlockExclusive(mEntryId); 79 } else { 80 mManager->DataManagerStrongRef()->UnlockShared(mEntryId, mTemporaryFileId, 81 aAbort); 82 } 83 } 84 85 } // namespace mozilla::dom