|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #include "BackgroundParentImpl.h" |
|
6 |
|
7 #include "mozilla/Assertions.h" |
|
8 #include "mozilla/ipc/BackgroundParent.h" |
|
9 #include "mozilla/ipc/PBackgroundTestParent.h" |
|
10 #include "nsThreadUtils.h" |
|
11 #include "nsTraceRefcnt.h" |
|
12 #include "nsXULAppAPI.h" |
|
13 |
|
14 using mozilla::ipc::AssertIsOnBackgroundThread; |
|
15 |
|
16 namespace { |
|
17 |
|
18 void |
|
19 AssertIsInMainProcess() |
|
20 { |
|
21 MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); |
|
22 } |
|
23 |
|
24 void |
|
25 AssertIsOnMainThread() |
|
26 { |
|
27 MOZ_ASSERT(NS_IsMainThread()); |
|
28 } |
|
29 |
|
30 class TestParent MOZ_FINAL : public mozilla::ipc::PBackgroundTestParent |
|
31 { |
|
32 friend class mozilla::ipc::BackgroundParentImpl; |
|
33 |
|
34 TestParent() |
|
35 { |
|
36 MOZ_COUNT_CTOR(mozilla::ipc::BackgroundTestParent); |
|
37 } |
|
38 |
|
39 ~TestParent() |
|
40 { |
|
41 MOZ_COUNT_DTOR(mozilla::ipc::BackgroundTestParent); |
|
42 } |
|
43 |
|
44 virtual void |
|
45 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
46 }; |
|
47 |
|
48 } // anonymous namespace |
|
49 |
|
50 namespace mozilla { |
|
51 namespace ipc { |
|
52 |
|
53 BackgroundParentImpl::BackgroundParentImpl() |
|
54 { |
|
55 AssertIsInMainProcess(); |
|
56 AssertIsOnMainThread(); |
|
57 |
|
58 MOZ_COUNT_CTOR(mozilla::ipc::BackgroundParentImpl); |
|
59 } |
|
60 |
|
61 BackgroundParentImpl::~BackgroundParentImpl() |
|
62 { |
|
63 AssertIsInMainProcess(); |
|
64 AssertIsOnMainThread(); |
|
65 |
|
66 MOZ_COUNT_DTOR(mozilla::ipc::BackgroundParentImpl); |
|
67 } |
|
68 |
|
69 void |
|
70 BackgroundParentImpl::ActorDestroy(ActorDestroyReason aWhy) |
|
71 { |
|
72 AssertIsInMainProcess(); |
|
73 AssertIsOnBackgroundThread(); |
|
74 } |
|
75 |
|
76 PBackgroundTestParent* |
|
77 BackgroundParentImpl::AllocPBackgroundTestParent(const nsCString& aTestArg) |
|
78 { |
|
79 AssertIsInMainProcess(); |
|
80 AssertIsOnBackgroundThread(); |
|
81 |
|
82 return new TestParent(); |
|
83 } |
|
84 |
|
85 bool |
|
86 BackgroundParentImpl::RecvPBackgroundTestConstructor( |
|
87 PBackgroundTestParent* aActor, |
|
88 const nsCString& aTestArg) |
|
89 { |
|
90 AssertIsInMainProcess(); |
|
91 AssertIsOnBackgroundThread(); |
|
92 MOZ_ASSERT(aActor); |
|
93 |
|
94 return PBackgroundTestParent::Send__delete__(aActor, aTestArg); |
|
95 } |
|
96 |
|
97 bool |
|
98 BackgroundParentImpl::DeallocPBackgroundTestParent( |
|
99 PBackgroundTestParent* aActor) |
|
100 { |
|
101 AssertIsInMainProcess(); |
|
102 AssertIsOnBackgroundThread(); |
|
103 MOZ_ASSERT(aActor); |
|
104 |
|
105 delete static_cast<TestParent*>(aActor); |
|
106 return true; |
|
107 } |
|
108 |
|
109 } // namespace ipc |
|
110 } // namespace mozilla |
|
111 |
|
112 void |
|
113 TestParent::ActorDestroy(ActorDestroyReason aWhy) |
|
114 { |
|
115 AssertIsInMainProcess(); |
|
116 AssertIsOnBackgroundThread(); |
|
117 } |