|
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_backgroundchild_h__ |
|
6 #define mozilla_ipc_backgroundchild_h__ |
|
7 |
|
8 #include "base/process.h" |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "mozilla/ipc/Transport.h" |
|
11 |
|
12 class nsIIPCBackgroundChildCreateCallback; |
|
13 |
|
14 namespace mozilla { |
|
15 namespace dom { |
|
16 |
|
17 class ContentChild; |
|
18 class ContentParent; |
|
19 |
|
20 } // namespace dom |
|
21 |
|
22 namespace ipc { |
|
23 |
|
24 class PBackgroundChild; |
|
25 |
|
26 // This class allows access to the PBackground protocol. PBackground allows |
|
27 // communication between any thread (in the parent or a child process) and a |
|
28 // single background thread in the parent process. Each PBackgroundChild |
|
29 // instance is tied to the thread on which it is created and must not be shared |
|
30 // across threads. Each PBackgroundChild is unique and valid as long as its |
|
31 // designated thread lives. |
|
32 // |
|
33 // Creation of PBackground is asynchronous. GetForCurrentThread() will return |
|
34 // null until the sequence is complete. GetOrCreateForCurrentThread() will start |
|
35 // the creation sequence and will call back via the |
|
36 // nsIIPCBackgroundChildCreateCallback interface when completed. Thereafter |
|
37 // (assuming success) GetForCurrentThread() will return the same actor every |
|
38 // time. |
|
39 // |
|
40 // The PBackgroundChild actor and all its sub-protocol actors will be |
|
41 // automatically destroyed when its designated thread completes. |
|
42 class BackgroundChild MOZ_FINAL |
|
43 { |
|
44 friend class mozilla::dom::ContentChild; |
|
45 friend class mozilla::dom::ContentParent; |
|
46 |
|
47 typedef base::ProcessId ProcessId; |
|
48 typedef mozilla::ipc::Transport Transport; |
|
49 |
|
50 public: |
|
51 // See above. |
|
52 static PBackgroundChild* |
|
53 GetForCurrentThread(); |
|
54 |
|
55 // See above. |
|
56 static bool |
|
57 GetOrCreateForCurrentThread(nsIIPCBackgroundChildCreateCallback* aCallback); |
|
58 |
|
59 private: |
|
60 // Only called by ContentChild or ContentParent. |
|
61 static void |
|
62 Startup(); |
|
63 |
|
64 // Only called by ContentChild. |
|
65 static PBackgroundChild* |
|
66 Alloc(Transport* aTransport, ProcessId aOtherProcess); |
|
67 }; |
|
68 |
|
69 } // namespace ipc |
|
70 } // namespace mozilla |
|
71 |
|
72 #endif // mozilla_ipc_backgroundchild_h__ |