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"
13 class nsIIPCBackgroundChildCreateCallback
;
26 class PBackgroundChild
;
28 // This class allows access to the PBackground protocol. PBackground allows
29 // communication between any thread (in the parent or a child process) and a
30 // single background thread in the parent process. Each PBackgroundChild
31 // instance is tied to the thread on which it is created and must not be shared
32 // across threads. Each PBackgroundChild is unique and valid as long as its
33 // designated thread lives.
35 // Creation of PBackground is asynchronous. GetForCurrentThread() will return
36 // null until the sequence is complete. GetOrCreateForCurrentThread() will start
37 // the creation sequence and will call back via the
38 // nsIIPCBackgroundChildCreateCallback interface when completed. Thereafter
39 // (assuming success) GetForCurrentThread() will return the same actor every
42 // CloseForCurrentThread() will close the current PBackground actor. Subsequent
43 // calls to GetForCurrentThread will return null. CloseForCurrentThread() may
44 // only be called exactly once for each thread-specific actor. Currently it is
45 // illegal to call this before the PBackground actor has been created.
47 // The PBackgroundChild actor and all its sub-protocol actors will be
48 // automatically destroyed when its designated thread completes.
49 class BackgroundChild final
51 friend class mozilla::dom::ContentChild
;
52 friend class mozilla::dom::ContentParent
;
54 typedef base::ProcessId ProcessId
;
55 typedef mozilla::ipc::Transport Transport
;
59 static PBackgroundChild
*
60 GetForCurrentThread();
64 GetOrCreateForCurrentThread(nsIIPCBackgroundChildCreateCallback
* aCallback
);
66 static mozilla::dom::PBlobChild
*
67 GetOrCreateActorForBlob(PBackgroundChild
* aBackgroundActor
,
72 CloseForCurrentThread();
75 // Only called by ContentChild or ContentParent.
79 // Only called by ContentChild.
80 static PBackgroundChild
*
81 Alloc(Transport
* aTransport
, ProcessId aOtherProcess
);
85 } // namespace mozilla
87 #endif // mozilla_ipc_backgroundchild_h__