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 "nsTArrayForwardDeclare.h"
15 # include "nsXULAppAPI.h"
19 struct already_AddRefed
;
25 class SocketProcessBridgeParent
;
26 class SocketProcessParent
;
39 class BackgroundStarterParent
;
40 class PBackgroundParent
;
41 class PBackgroundStarterParent
;
43 template <class PFooSide
>
46 // This class is not designed for public consumption beyond the few static
48 class BackgroundParent final
{
49 friend class mozilla::ipc::BackgroundStarterParent
;
50 friend class mozilla::dom::ContentParent
;
51 friend class mozilla::net::SocketProcessBridgeParent
;
52 friend class mozilla::net::SocketProcessParent
;
54 typedef base::ProcessId ProcessId
;
55 typedef mozilla::dom::BlobImpl BlobImpl
;
56 typedef mozilla::dom::ContentParent ContentParent
;
59 // This function allows the caller to determine if the given parent actor
60 // corresponds to a child actor from another process or a child actor from a
61 // different thread in the same process.
62 // This function may only be called on the background thread.
63 static bool IsOtherProcessActor(PBackgroundParent
* aBackgroundActor
);
65 // This function returns the ContentParent associated with the parent actor if
66 // the parent actor corresponds to a child actor from another process. If the
67 // parent actor corresponds to a child actor from a different thread in the
68 // same process then this function returns null.
69 // This function may only be called on the background thread. However,
70 // ContentParent is not threadsafe and the returned pointer may not be used on
71 // any thread other than the main thread. Callers must take care to use (and
72 // release) the returned pointer appropriately.
73 static already_AddRefed
<ContentParent
> GetContentParent(
74 PBackgroundParent
* aBackgroundActor
);
76 // Get a value that represents the ContentParent associated with the parent
77 // actor for comparison. The value is not guaranteed to uniquely identify the
78 // ContentParent after the ContentParent has died. This function may only be
79 // called on the background thread.
80 static intptr_t GetRawContentParentForComparison(
81 PBackgroundParent
* aBackgroundActor
);
83 static uint64_t GetChildID(PBackgroundParent
* aBackgroundActor
);
86 // Only called by ContentParent for cross-process actors.
87 static bool AllocStarter(ContentParent
* aContent
,
88 Endpoint
<PBackgroundStarterParent
>&& aEndpoint
);
90 // Called by SocketProcessBridgeParent and SocketProcessParent for
91 // cross-process actors.
92 static bool AllocStarter(Endpoint
<PBackgroundStarterParent
>&& aEndpoint
);
95 // Implemented in BackgroundImpl.cpp.
96 bool IsOnBackgroundThread();
100 // Implemented in BackgroundImpl.cpp.
101 void AssertIsOnBackgroundThread();
105 inline void AssertIsOnBackgroundThread() {}
109 inline void AssertIsInMainProcess() { MOZ_ASSERT(XRE_IsParentProcess()); }
111 inline void AssertIsInMainOrSocketProcess() {
112 MOZ_ASSERT(XRE_IsParentProcess() || XRE_IsSocketProcess());
116 } // namespace mozilla
118 #endif // mozilla_ipc_backgroundparent_h__