Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
5 #ifndef mozilla_ipc_backgroundchild_h__
6 #define mozilla_ipc_backgroundchild_h__
8 #include "base/process.h"
9 #include "mozilla/Attributes.h"
10 #include "mozilla/ipc/Transport.h"
12 class nsIIPCBackgroundChildCreateCallback;
14 namespace mozilla {
15 namespace dom {
17 class ContentChild;
18 class ContentParent;
20 } // namespace dom
22 namespace ipc {
24 class PBackgroundChild;
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;
47 typedef base::ProcessId ProcessId;
48 typedef mozilla::ipc::Transport Transport;
50 public:
51 // See above.
52 static PBackgroundChild*
53 GetForCurrentThread();
55 // See above.
56 static bool
57 GetOrCreateForCurrentThread(nsIIPCBackgroundChildCreateCallback* aCallback);
59 private:
60 // Only called by ContentChild or ContentParent.
61 static void
62 Startup();
64 // Only called by ContentChild.
65 static PBackgroundChild*
66 Alloc(Transport* aTransport, ProcessId aOtherProcess);
67 };
69 } // namespace ipc
70 } // namespace mozilla
72 #endif // mozilla_ipc_backgroundchild_h__