diff -r 000000000000 -r 6474c204b198 ipc/glue/BackgroundParentImpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ipc/glue/BackgroundParentImpl.cpp Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,117 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "BackgroundParentImpl.h" + +#include "mozilla/Assertions.h" +#include "mozilla/ipc/BackgroundParent.h" +#include "mozilla/ipc/PBackgroundTestParent.h" +#include "nsThreadUtils.h" +#include "nsTraceRefcnt.h" +#include "nsXULAppAPI.h" + +using mozilla::ipc::AssertIsOnBackgroundThread; + +namespace { + +void +AssertIsInMainProcess() +{ + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); +} + +void +AssertIsOnMainThread() +{ + MOZ_ASSERT(NS_IsMainThread()); +} + +class TestParent MOZ_FINAL : public mozilla::ipc::PBackgroundTestParent +{ + friend class mozilla::ipc::BackgroundParentImpl; + + TestParent() + { + MOZ_COUNT_CTOR(mozilla::ipc::BackgroundTestParent); + } + + ~TestParent() + { + MOZ_COUNT_DTOR(mozilla::ipc::BackgroundTestParent); + } + + virtual void + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; +}; + +} // anonymous namespace + +namespace mozilla { +namespace ipc { + +BackgroundParentImpl::BackgroundParentImpl() +{ + AssertIsInMainProcess(); + AssertIsOnMainThread(); + + MOZ_COUNT_CTOR(mozilla::ipc::BackgroundParentImpl); +} + +BackgroundParentImpl::~BackgroundParentImpl() +{ + AssertIsInMainProcess(); + AssertIsOnMainThread(); + + MOZ_COUNT_DTOR(mozilla::ipc::BackgroundParentImpl); +} + +void +BackgroundParentImpl::ActorDestroy(ActorDestroyReason aWhy) +{ + AssertIsInMainProcess(); + AssertIsOnBackgroundThread(); +} + +PBackgroundTestParent* +BackgroundParentImpl::AllocPBackgroundTestParent(const nsCString& aTestArg) +{ + AssertIsInMainProcess(); + AssertIsOnBackgroundThread(); + + return new TestParent(); +} + +bool +BackgroundParentImpl::RecvPBackgroundTestConstructor( + PBackgroundTestParent* aActor, + const nsCString& aTestArg) +{ + AssertIsInMainProcess(); + AssertIsOnBackgroundThread(); + MOZ_ASSERT(aActor); + + return PBackgroundTestParent::Send__delete__(aActor, aTestArg); +} + +bool +BackgroundParentImpl::DeallocPBackgroundTestParent( + PBackgroundTestParent* aActor) +{ + AssertIsInMainProcess(); + AssertIsOnBackgroundThread(); + MOZ_ASSERT(aActor); + + delete static_cast(aActor); + return true; +} + +} // namespace ipc +} // namespace mozilla + +void +TestParent::ActorDestroy(ActorDestroyReason aWhy) +{ + AssertIsInMainProcess(); + AssertIsOnBackgroundThread(); +}