Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / quota / RemoteQuotaObjectParent.cpp
blobc9ba59785cfe7d908dac83a733ec7feab57b5de9
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/. */
7 #include "RemoteQuotaObjectParent.h"
9 #include "CanonicalQuotaObject.h"
10 #include "mozilla/dom/quota/RemoteQuotaObjectParentTracker.h"
11 #include "mozilla/dom/quota/ResultExtensions.h"
12 #include "mozilla/ipc/BackgroundParent.h"
14 namespace mozilla::dom::quota {
16 RemoteQuotaObjectParent::RemoteQuotaObjectParent(
17 RefPtr<CanonicalQuotaObject> aCanonicalQuotaObject,
18 nsCOMPtr<RemoteQuotaObjectParentTracker> aTracker)
19 : mCanonicalQuotaObject(std::move(aCanonicalQuotaObject)),
20 mTracker(std::move(aTracker)) {}
22 RemoteQuotaObjectParent::~RemoteQuotaObjectParent() { MOZ_ASSERT(!CanSend()); }
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());
30 *aResult = mCanonicalQuotaObject->MaybeUpdateSize(aSize, aTruncate);
31 return IPC_OK();
34 void RemoteQuotaObjectParent::ActorDestroy(ActorDestroyReason aWhy) {
35 QM_WARNONLY_TRY(MOZ_TO_RESULT(CheckFileAfterClose()));
37 mCanonicalQuotaObject = nullptr;
39 if (mTracker) {
40 mTracker->UnregisterRemoteQuotaObjectParent(WrapNotNullUnchecked(this));
44 nsresult RemoteQuotaObjectParent::CheckFileAfterClose() {
45 MOZ_ASSERT(mCanonicalQuotaObject);
47 QM_TRY_INSPECT(const auto& file,
48 QM_NewLocalFile(mCanonicalQuotaObject->Path()));
50 QM_TRY_UNWRAP(auto size, MOZ_TO_RESULT_INVOKE_MEMBER(file, GetFileSize));
52 DebugOnly<bool> res =
53 mCanonicalQuotaObject->MaybeUpdateSize(size, /* aTruncate */ true);
54 MOZ_ASSERT(res);
56 return NS_OK;
59 } // namespace mozilla::dom::quota