Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / ipc / glue / BackgroundParent.h
blob650cf2ea29f4e67b18b993e964bb1fb2d4969b49
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 // This function allows the caller to determine if the given parent actor
64 // corresponds to a child actor from another process or a child actor from a
65 // different thread in the same process.
66 // This function may only be called on the background thread.
67 static bool IsOtherProcessActor(PBackgroundParent* aBackgroundActor);
69 // This function returns a handle to the ContentParent associated with the
70 // parent actor if the parent actor corresponds to a child actor from another
71 // content process. If the parent actor corresponds to a child actor from a
72 // different thread in the same process then this function returns null.
74 // This function may only be called on the background thread.
75 static ThreadsafeContentParentHandle* GetContentParentHandle(
76 PBackgroundParent* aBackgroundActor);
78 static uint64_t GetChildID(PBackgroundParent* aBackgroundActor);
80 private:
81 // Only called by ContentParent for cross-process actors.
82 static bool AllocStarter(ContentParent* aContent,
83 Endpoint<PBackgroundStarterParent>&& aEndpoint);
85 // Called by SocketProcessBridgeParent and SocketProcessParent for
86 // cross-process actors.
87 static bool AllocStarter(Endpoint<PBackgroundStarterParent>&& aEndpoint);
90 // Implemented in BackgroundImpl.cpp.
91 bool IsOnBackgroundThread();
93 #ifdef DEBUG
95 // Implemented in BackgroundImpl.cpp.
96 void AssertIsOnBackgroundThread();
98 #else
100 inline void AssertIsOnBackgroundThread() {}
102 #endif // DEBUG
104 inline void AssertIsInMainProcess() { MOZ_ASSERT(XRE_IsParentProcess()); }
106 inline void AssertIsInMainOrSocketProcess() {
107 MOZ_ASSERT(XRE_IsParentProcess() || XRE_IsSocketProcess());
110 } // namespace ipc
111 } // namespace mozilla
113 #endif // mozilla_ipc_backgroundparent_h__