RemoteQuotaObjectParent.cpp (1995B)
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 "RemoteQuotaObjectParent.h" 8 9 #include "CanonicalQuotaObject.h" 10 #include "mozilla/dom/quota/RemoteQuotaObjectParentTracker.h" 11 #include "mozilla/dom/quota/ResultExtensions.h" 12 #include "mozilla/ipc/BackgroundParent.h" 13 14 namespace mozilla::dom::quota { 15 16 RemoteQuotaObjectParent::RemoteQuotaObjectParent( 17 RefPtr<CanonicalQuotaObject> aCanonicalQuotaObject, 18 nsCOMPtr<RemoteQuotaObjectParentTracker> aTracker) 19 : mCanonicalQuotaObject(std::move(aCanonicalQuotaObject)), 20 mTracker(std::move(aTracker)) {} 21 22 RemoteQuotaObjectParent::~RemoteQuotaObjectParent() { MOZ_ASSERT(!CanSend()); } 23 24 mozilla::ipc::IPCResult RemoteQuotaObjectParent::RecvMaybeUpdateSize( 25 int64_t aSize, bool aTruncate, bool* aResult) { 26 MOZ_ASSERT(!NS_IsMainThread()); 27 MOZ_ASSERT(!mozilla::ipc::IsOnBackgroundThread()); 28 MOZ_ASSERT(!GetCurrentThreadWorkerPrivate()); 29 30 *aResult = mCanonicalQuotaObject->MaybeUpdateSize(aSize, aTruncate); 31 return IPC_OK(); 32 } 33 34 void RemoteQuotaObjectParent::ActorDestroy(ActorDestroyReason aWhy) { 35 QM_WARNONLY_TRY(MOZ_TO_RESULT(CheckFileAfterClose())); 36 37 mCanonicalQuotaObject = nullptr; 38 39 if (mTracker) { 40 mTracker->UnregisterRemoteQuotaObjectParent(WrapNotNullUnchecked(this)); 41 } 42 } 43 44 nsresult RemoteQuotaObjectParent::CheckFileAfterClose() { 45 MOZ_ASSERT(mCanonicalQuotaObject); 46 47 QM_TRY_INSPECT(const auto& file, 48 QM_NewLocalFile(mCanonicalQuotaObject->Path())); 49 50 QM_TRY_UNWRAP(auto size, MOZ_TO_RESULT_INVOKE_MEMBER(file, GetFileSize)); 51 52 DebugOnly<bool> res = 53 mCanonicalQuotaObject->MaybeUpdateSize(size, /* aTruncate */ true); 54 MOZ_ASSERT(res); 55 56 return NS_OK; 57 } 58 59 } // namespace mozilla::dom::quota