no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / ipc / glue / BackgroundParent.h
blob6afad501af73974adbfec8ecaa1718db06100231
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 static void KillHardAsync(PBackgroundParent* aBackgroundActor,
81 const nsACString& aReason);
83 private:
84 // Only called by ContentParent for cross-process actors.
85 static bool AllocStarter(ContentParent* aContent,
86 Endpoint<PBackgroundStarterParent>&& aEndpoint);
88 // Called by SocketProcessBridgeParent and SocketProcessParent for
89 // cross-process actors.
90 static bool AllocStarter(Endpoint<PBackgroundStarterParent>&& aEndpoint);
93 // Implemented in BackgroundImpl.cpp.
94 bool IsOnBackgroundThread();
96 #ifdef DEBUG
98 // Implemented in BackgroundImpl.cpp.
99 void AssertIsOnBackgroundThread();
101 #else
103 inline void AssertIsOnBackgroundThread() {}
105 #endif // DEBUG
107 inline void AssertIsInMainProcess() { MOZ_ASSERT(XRE_IsParentProcess()); }
109 } // namespace ipc
110 } // namespace mozilla
112 #endif // mozilla_ipc_backgroundparent_h__