QuotaObject.cpp (2507B)
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 "QuotaObject.h" 8 9 #include "CanonicalQuotaObject.h" 10 #include "RemoteQuotaObject.h" 11 #include "mozilla/dom/quota/IPCQuotaObject.h" 12 #include "mozilla/dom/quota/PRemoteQuotaObject.h" 13 #include "mozilla/dom/quota/RemoteQuotaObjectChild.h" 14 #include "mozilla/dom/quota/RemoteQuotaObjectParent.h" 15 #include "mozilla/dom/quota/RemoteQuotaObjectParentTracker.h" 16 #include "mozilla/ipc/BackgroundParent.h" 17 #include "nsIInterfaceRequestor.h" 18 #include "nsIInterfaceRequestorUtils.h" 19 20 namespace mozilla::dom::quota { 21 22 CanonicalQuotaObject* QuotaObject::AsCanonicalQuotaObject() { 23 return mIsRemote ? nullptr : static_cast<CanonicalQuotaObject*>(this); 24 } 25 26 RemoteQuotaObject* QuotaObject::AsRemoteQuotaObject() { 27 return mIsRemote ? static_cast<RemoteQuotaObject*>(this) : nullptr; 28 } 29 30 IPCQuotaObject QuotaObject::Serialize(nsIInterfaceRequestor* aCallbacks) { 31 MOZ_RELEASE_ASSERT(XRE_IsParentProcess()); 32 MOZ_RELEASE_ASSERT(!NS_IsMainThread()); 33 MOZ_RELEASE_ASSERT(!mozilla::ipc::IsOnBackgroundThread()); 34 MOZ_RELEASE_ASSERT(!GetCurrentThreadWorkerPrivate()); 35 MOZ_RELEASE_ASSERT(!mIsRemote); 36 37 mozilla::ipc::Endpoint<PRemoteQuotaObjectParent> parentEndpoint; 38 mozilla::ipc::Endpoint<PRemoteQuotaObjectChild> childEndpoint; 39 MOZ_ALWAYS_SUCCEEDS( 40 PRemoteQuotaObject::CreateEndpoints(&parentEndpoint, &childEndpoint)); 41 42 nsCOMPtr<RemoteQuotaObjectParentTracker> tracker = 43 do_GetInterface(aCallbacks); 44 45 auto actor = 46 MakeRefPtr<RemoteQuotaObjectParent>(AsCanonicalQuotaObject(), tracker); 47 48 if (tracker) { 49 tracker->RegisterRemoteQuotaObjectParent(WrapNotNull(actor)); 50 } 51 52 parentEndpoint.Bind(actor); 53 54 IPCQuotaObject ipcQuotaObject; 55 ipcQuotaObject.childEndpoint() = std::move(childEndpoint); 56 57 return ipcQuotaObject; 58 } 59 60 // static 61 RefPtr<QuotaObject> QuotaObject::Deserialize(IPCQuotaObject& aQuotaObject) { 62 MOZ_RELEASE_ASSERT(!NS_IsMainThread()); 63 MOZ_RELEASE_ASSERT(!mozilla::ipc::IsOnBackgroundThread()); 64 MOZ_RELEASE_ASSERT(!GetCurrentThreadWorkerPrivate()); 65 66 auto actor = MakeRefPtr<RemoteQuotaObjectChild>(); 67 68 aQuotaObject.childEndpoint().Bind(actor); 69 70 return MakeRefPtr<RemoteQuotaObject>(actor); 71 } 72 73 } // namespace mozilla::dom::quota