Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / ipc / glue / BackgroundChild.h
blob89de00795f6dfeb0a19278eef8644b48fa2f3f57
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 ipc {
26 class PBackgroundChild;
27 class PBackgroundStarterChild;
29 // This class allows access to the PBackground protocol. PBackground allows
30 // communication between any thread (in the parent or a child process) and a
31 // single background thread in the parent process. Each PBackgroundChild
32 // instance is tied to the thread on which it is created and must not be shared
33 // across threads. Each PBackgroundChild is unique and valid as long as its
34 // designated thread lives.
36 // Creation of PBackground is synchronous. GetOrCreateForCurrentThread will
37 // create the actor if it doesn't exist yet. Thereafter (assuming success)
38 // GetForCurrentThread() will return the same actor every time.
40 // CloseForCurrentThread() will close the current PBackground actor. Subsequent
41 // calls to GetForCurrentThread will return null. CloseForCurrentThread() may
42 // only be called exactly once for each thread-specific actor. Currently it is
43 // illegal to call this before the PBackground actor has been created.
45 // The PBackgroundChild actor and all its sub-protocol actors will be
46 // automatically destroyed when its designated thread completes.
48 // InitContentStarter must be called on the main thread
49 // with an actor bridging to the relevant target process type before these
50 // methods can be used.
51 class BackgroundChild final {
52 friend class mozilla::dom::ContentParent;
53 friend class mozilla::dom::ContentProcess;
55 public:
56 // See above.
57 static PBackgroundChild* GetForCurrentThread();
59 // See above.
60 static PBackgroundChild* GetOrCreateForCurrentThread();
62 // See above.
63 static void CloseForCurrentThread();
65 // See above.
66 static void InitContentStarter(mozilla::dom::ContentChild* aContent);
68 private:
69 // Only called by this class's friends.
70 static void Startup();
73 } // namespace ipc
74 } // namespace mozilla
76 #endif // mozilla_ipc_backgroundchild_h__