|
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 #ifndef mozilla_ipc_backgroundparent_h__ |
|
6 #define mozilla_ipc_backgroundparent_h__ |
|
7 |
|
8 #include "base/process.h" |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "mozilla/ipc/Transport.h" |
|
11 |
|
12 template <class> class already_AddRefed; |
|
13 |
|
14 namespace mozilla { |
|
15 namespace dom { |
|
16 |
|
17 class ContentParent; |
|
18 |
|
19 } // namespace dom |
|
20 |
|
21 namespace ipc { |
|
22 |
|
23 class PBackgroundParent; |
|
24 |
|
25 // This class is not designed for public consumption beyond the few static |
|
26 // member functions. |
|
27 class BackgroundParent MOZ_FINAL |
|
28 { |
|
29 friend class mozilla::dom::ContentParent; |
|
30 |
|
31 typedef base::ProcessId ProcessId; |
|
32 typedef mozilla::dom::ContentParent ContentParent; |
|
33 typedef mozilla::ipc::Transport Transport; |
|
34 |
|
35 public: |
|
36 // This function allows the caller to determine if the given parent actor |
|
37 // corresponds to a child actor from another process or a child actor from a |
|
38 // different thread in the same process. |
|
39 // This function may only be called on the background thread. |
|
40 static bool |
|
41 IsOtherProcessActor(PBackgroundParent* aBackgroundActor); |
|
42 |
|
43 // This function returns the ContentParent associated with the parent actor if |
|
44 // the parent actor corresponds to a child actor from another process. If the |
|
45 // parent actor corresponds to a child actor from a different thread in the |
|
46 // same process then this function returns null. |
|
47 // This function may only be called on the background thread. However, |
|
48 // ContentParent is not threadsafe and the returned pointer may not be used on |
|
49 // any thread other than the main thread. Callers must take care to use (and |
|
50 // release) the returned pointer appropriately. |
|
51 static already_AddRefed<ContentParent> |
|
52 GetContentParent(PBackgroundParent* aBackgroundActor); |
|
53 |
|
54 private: |
|
55 // Only called by ContentParent for cross-process actors. |
|
56 static PBackgroundParent* |
|
57 Alloc(ContentParent* aContent, |
|
58 Transport* aTransport, |
|
59 ProcessId aOtherProcess); |
|
60 }; |
|
61 |
|
62 // Implemented in BackgroundImpl.cpp. |
|
63 bool |
|
64 IsOnBackgroundThread(); |
|
65 |
|
66 #ifdef DEBUG |
|
67 |
|
68 // Implemented in BackgroundImpl.cpp. |
|
69 void |
|
70 AssertIsOnBackgroundThread(); |
|
71 |
|
72 #else |
|
73 |
|
74 inline void |
|
75 AssertIsOnBackgroundThread() |
|
76 { } |
|
77 |
|
78 #endif // DEBUG |
|
79 |
|
80 } // namespace ipc |
|
81 } // namespace mozilla |
|
82 |
|
83 #endif // mozilla_ipc_backgroundparent_h__ |