Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / ipc / glue / BackgroundParent.h
blob7857165d9456f210a162fc11e88464e971fafb15
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_backgroundparent_h__
8 #define mozilla_ipc_backgroundparent_h__
10 #include "base/process.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/dom/ContentParent.h"
13 #include "nsStringFwd.h"
14 #include "nsTArrayForwardDeclare.h"
16 #ifdef DEBUG
17 # include "nsXULAppAPI.h"
18 #endif
20 template <class>
21 struct already_AddRefed;
23 namespace mozilla {
25 namespace net {
27 class SocketProcessBridgeParent;
28 class SocketProcessParent;
30 } // namespace net
32 namespace dom {
34 class BlobImpl;
35 class ContentParent;
37 } // namespace dom
39 namespace ipc {
41 class BackgroundStarterParent;
42 class PBackgroundParent;
43 class PBackgroundStarterParent;
45 template <class PFooSide>
46 class Endpoint;
48 // This class is not designed for public consumption beyond the few static
49 // member functions.
50 class BackgroundParent final {
51 friend class mozilla::ipc::BackgroundStarterParent;
52 friend class mozilla::dom::ContentParent;
53 friend class mozilla::net::SocketProcessBridgeParent;
54 friend class mozilla::net::SocketProcessParent;
56 using ProcessId = base::ProcessId;
57 using BlobImpl = mozilla::dom::BlobImpl;
58 using ContentParent = mozilla::dom::ContentParent;
59 using ThreadsafeContentParentHandle =
60 mozilla::dom::ThreadsafeContentParentHandle;
62 public:
63 // Get the nsISerialEventTarget used to handle messages from BackgroundParent
64 // actors, if it is running.
66 // This function may only be called on the background or main thread.
67 static already_AddRefed<nsISerialEventTarget> GetBackgroundThread();
69 // This function allows the caller to determine if the given parent actor
70 // corresponds to a child actor from another process or a child actor from a
71 // different thread in the same process.
72 // This function may only be called on the background thread.
73 static bool IsOtherProcessActor(PBackgroundParent* aBackgroundActor);
75 // This function returns a handle to the ContentParent associated with the
76 // parent actor if the parent actor corresponds to a child actor from another
77 // content process. If the parent actor corresponds to a child actor from a
78 // different thread in the same process then this function returns null.
80 // This function may only be called on the background thread.
81 static ThreadsafeContentParentHandle* GetContentParentHandle(
82 PBackgroundParent* aBackgroundActor);
84 static uint64_t GetChildID(PBackgroundParent* aBackgroundActor);
86 static void KillHardAsync(PBackgroundParent* aBackgroundActor,
87 const nsACString& aReason);
89 private:
90 // Only called by ContentParent for cross-process actors.
91 static bool AllocStarter(ContentParent* aContent,
92 Endpoint<PBackgroundStarterParent>&& aEndpoint);
94 // Called by SocketProcessBridgeParent and SocketProcessParent for
95 // cross-process actors.
96 static bool AllocStarter(Endpoint<PBackgroundStarterParent>&& aEndpoint);
99 // Implemented in BackgroundImpl.cpp.
100 bool IsOnBackgroundThread();
102 #ifdef DEBUG
104 // Implemented in BackgroundImpl.cpp.
105 void AssertIsOnBackgroundThread();
107 #else
109 inline void AssertIsOnBackgroundThread() {}
111 #endif // DEBUG
113 inline void AssertIsInMainProcess() { MOZ_ASSERT(XRE_IsParentProcess()); }
115 } // namespace ipc
116 } // namespace mozilla
118 #endif // mozilla_ipc_backgroundparent_h__