Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / ipc / glue / BackgroundChild.h
blob82a28c43d565523ab0d1cc77d40a57f6090ccfb7
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ipc_backgroundchild_h__
8 #define mozilla_ipc_backgroundchild_h__
10 #include "mozilla/Attributes.h"
12 class nsIEventTarget;
14 namespace mozilla {
15 namespace dom {
17 class BlobImpl;
18 class ContentChild;
19 class ContentParent;
20 class ContentProcess;
22 } // namespace dom
24 namespace net {
26 class SocketProcessChild;
27 class SocketProcessBridgeChild;
29 } // namespace net
31 namespace ipc {
33 class PBackgroundChild;
34 class PBackgroundStarterChild;
36 // This class allows access to the PBackground protocol. PBackground allows
37 // communication between any thread (in the parent or a child process) and a
38 // single background thread in the parent process. Each PBackgroundChild
39 // instance is tied to the thread on which it is created and must not be shared
40 // across threads. Each PBackgroundChild is unique and valid as long as its
41 // designated thread lives.
43 // Creation of PBackground is synchronous. GetOrCreateForCurrentThread will
44 // create the actor if it doesn't exist yet. Thereafter (assuming success)
45 // GetForCurrentThread() will return the same actor every time.
47 // GetOrCreateSocketActorForCurrentThread, which is like
48 // GetOrCreateForCurrentThread, is used to get or create PBackground actor
49 // between child process and socket process.
51 // CloseForCurrentThread() will close the current PBackground actor. Subsequent
52 // calls to GetForCurrentThread will return null. CloseForCurrentThread() may
53 // only be called exactly once for each thread-specific actor. Currently it is
54 // illegal to call this before the PBackground actor has been created.
56 // The PBackgroundChild actor and all its sub-protocol actors will be
57 // automatically destroyed when its designated thread completes.
59 // Init{Content,Socket,SocketBridge}Starter must be called on the main thread
60 // with an actor bridging to the relevant target process type before these
61 // methods can be used.
62 class BackgroundChild final {
63 friend class mozilla::dom::ContentParent;
64 friend class mozilla::dom::ContentProcess;
65 friend class mozilla::net::SocketProcessChild;
67 public:
68 // See above.
69 static PBackgroundChild* GetForCurrentThread();
71 // See above.
72 static PBackgroundChild* GetOrCreateForCurrentThread();
74 // See above.
75 static PBackgroundChild* GetOrCreateSocketActorForCurrentThread();
77 // See above.
78 static PBackgroundChild* GetOrCreateForSocketParentBridgeForCurrentThread();
80 // See above.
81 static void CloseForCurrentThread();
83 // See above.
84 static void InitContentStarter(mozilla::dom::ContentChild* aContent);
86 // See above.
87 static void InitSocketStarter(mozilla::net::SocketProcessChild* aSocket);
89 // See above.
90 static void InitSocketBridgeStarter(
91 mozilla::net::SocketProcessBridgeChild* aSocketBridge);
93 private:
94 // Only called by this class's friends.
95 static void Startup();
98 } // namespace ipc
99 } // namespace mozilla
101 #endif // mozilla_ipc_backgroundchild_h__