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"
26 class SocketProcessChild
;
27 class SocketProcessBridgeChild
;
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
;
69 static PBackgroundChild
* GetForCurrentThread();
72 static PBackgroundChild
* GetOrCreateForCurrentThread();
75 static PBackgroundChild
* GetOrCreateSocketActorForCurrentThread();
78 static PBackgroundChild
* GetOrCreateForSocketParentBridgeForCurrentThread();
81 static void CloseForCurrentThread();
84 static void InitContentStarter(mozilla::dom::ContentChild
* aContent
);
87 static void InitSocketStarter(mozilla::net::SocketProcessChild
* aSocket
);
90 static void InitSocketBridgeStarter(
91 mozilla::net::SocketProcessBridgeChild
* aSocketBridge
);
94 // Only called by this class's friends.
95 static void Startup();
99 } // namespace mozilla
101 #endif // mozilla_ipc_backgroundchild_h__