Bug 1797433 [wpt PR 36660] - [anchor-position] Add tests for fixed position in multic...
[gecko.git] / ipc / glue / BackgroundParent.h
blob6e4e72210028e8172755f15f9e58edcfacdc8d17
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"
14 #ifdef DEBUG
15 # include "nsXULAppAPI.h"
16 #endif
18 template <class>
19 struct already_AddRefed;
21 namespace mozilla {
23 namespace net {
25 class SocketProcessBridgeParent;
26 class SocketProcessParent;
28 } // namespace net
30 namespace dom {
32 class BlobImpl;
33 class ContentParent;
35 } // namespace dom
37 namespace ipc {
39 class BackgroundStarterParent;
40 class PBackgroundParent;
41 class PBackgroundStarterParent;
43 template <class PFooSide>
44 class Endpoint;
46 // This class is not designed for public consumption beyond the few static
47 // member functions.
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;
58 public:
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);
85 private:
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();
98 #ifdef DEBUG
100 // Implemented in BackgroundImpl.cpp.
101 void AssertIsOnBackgroundThread();
103 #else
105 inline void AssertIsOnBackgroundThread() {}
107 #endif // DEBUG
109 inline void AssertIsInMainProcess() { MOZ_ASSERT(XRE_IsParentProcess()); }
111 inline void AssertIsInMainOrSocketProcess() {
112 MOZ_ASSERT(XRE_IsParentProcess() || XRE_IsSocketProcess());
115 } // namespace ipc
116 } // namespace mozilla
118 #endif // mozilla_ipc_backgroundparent_h__