1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/glue/BackgroundParentImpl.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "BackgroundParentImpl.h" 1.9 + 1.10 +#include "mozilla/Assertions.h" 1.11 +#include "mozilla/ipc/BackgroundParent.h" 1.12 +#include "mozilla/ipc/PBackgroundTestParent.h" 1.13 +#include "nsThreadUtils.h" 1.14 +#include "nsTraceRefcnt.h" 1.15 +#include "nsXULAppAPI.h" 1.16 + 1.17 +using mozilla::ipc::AssertIsOnBackgroundThread; 1.18 + 1.19 +namespace { 1.20 + 1.21 +void 1.22 +AssertIsInMainProcess() 1.23 +{ 1.24 + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); 1.25 +} 1.26 + 1.27 +void 1.28 +AssertIsOnMainThread() 1.29 +{ 1.30 + MOZ_ASSERT(NS_IsMainThread()); 1.31 +} 1.32 + 1.33 +class TestParent MOZ_FINAL : public mozilla::ipc::PBackgroundTestParent 1.34 +{ 1.35 + friend class mozilla::ipc::BackgroundParentImpl; 1.36 + 1.37 + TestParent() 1.38 + { 1.39 + MOZ_COUNT_CTOR(mozilla::ipc::BackgroundTestParent); 1.40 + } 1.41 + 1.42 + ~TestParent() 1.43 + { 1.44 + MOZ_COUNT_DTOR(mozilla::ipc::BackgroundTestParent); 1.45 + } 1.46 + 1.47 + virtual void 1.48 + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; 1.49 +}; 1.50 + 1.51 +} // anonymous namespace 1.52 + 1.53 +namespace mozilla { 1.54 +namespace ipc { 1.55 + 1.56 +BackgroundParentImpl::BackgroundParentImpl() 1.57 +{ 1.58 + AssertIsInMainProcess(); 1.59 + AssertIsOnMainThread(); 1.60 + 1.61 + MOZ_COUNT_CTOR(mozilla::ipc::BackgroundParentImpl); 1.62 +} 1.63 + 1.64 +BackgroundParentImpl::~BackgroundParentImpl() 1.65 +{ 1.66 + AssertIsInMainProcess(); 1.67 + AssertIsOnMainThread(); 1.68 + 1.69 + MOZ_COUNT_DTOR(mozilla::ipc::BackgroundParentImpl); 1.70 +} 1.71 + 1.72 +void 1.73 +BackgroundParentImpl::ActorDestroy(ActorDestroyReason aWhy) 1.74 +{ 1.75 + AssertIsInMainProcess(); 1.76 + AssertIsOnBackgroundThread(); 1.77 +} 1.78 + 1.79 +PBackgroundTestParent* 1.80 +BackgroundParentImpl::AllocPBackgroundTestParent(const nsCString& aTestArg) 1.81 +{ 1.82 + AssertIsInMainProcess(); 1.83 + AssertIsOnBackgroundThread(); 1.84 + 1.85 + return new TestParent(); 1.86 +} 1.87 + 1.88 +bool 1.89 +BackgroundParentImpl::RecvPBackgroundTestConstructor( 1.90 + PBackgroundTestParent* aActor, 1.91 + const nsCString& aTestArg) 1.92 +{ 1.93 + AssertIsInMainProcess(); 1.94 + AssertIsOnBackgroundThread(); 1.95 + MOZ_ASSERT(aActor); 1.96 + 1.97 + return PBackgroundTestParent::Send__delete__(aActor, aTestArg); 1.98 +} 1.99 + 1.100 +bool 1.101 +BackgroundParentImpl::DeallocPBackgroundTestParent( 1.102 + PBackgroundTestParent* aActor) 1.103 +{ 1.104 + AssertIsInMainProcess(); 1.105 + AssertIsOnBackgroundThread(); 1.106 + MOZ_ASSERT(aActor); 1.107 + 1.108 + delete static_cast<TestParent*>(aActor); 1.109 + return true; 1.110 +} 1.111 + 1.112 +} // namespace ipc 1.113 +} // namespace mozilla 1.114 + 1.115 +void 1.116 +TestParent::ActorDestroy(ActorDestroyReason aWhy) 1.117 +{ 1.118 + AssertIsInMainProcess(); 1.119 + AssertIsOnBackgroundThread(); 1.120 +}