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"
17 # include "nsXULAppAPI.h"
21 struct already_AddRefed
;
27 class SocketProcessBridgeParent
;
28 class SocketProcessParent
;
41 class BackgroundStarterParent
;
42 class PBackgroundParent
;
43 class PBackgroundStarterParent
;
45 template <class PFooSide
>
48 // This class is not designed for public consumption beyond the few static
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
;
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
);
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();
95 // Implemented in BackgroundImpl.cpp.
96 void AssertIsOnBackgroundThread();
100 inline void AssertIsOnBackgroundThread() {}
104 inline void AssertIsInMainProcess() { MOZ_ASSERT(XRE_IsParentProcess()); }
106 inline void AssertIsInMainOrSocketProcess() {
107 MOZ_ASSERT(XRE_IsParentProcess() || XRE_IsSocketProcess());
111 } // namespace mozilla
113 #endif // mozilla_ipc_backgroundparent_h__