Line data Source code
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/. */
6 :
7 : #ifndef mozilla_ipc_backgroundparent_h__
8 : #define mozilla_ipc_backgroundparent_h__
9 :
10 : #include "base/process.h"
11 : #include "mozilla/Attributes.h"
12 : #include "mozilla/ipc/Transport.h"
13 :
14 : template <class> struct already_AddRefed;
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : class BlobImpl;
20 : class ContentParent;
21 :
22 : } // namespace dom
23 :
24 : namespace ipc {
25 :
26 : class PBackgroundParent;
27 :
28 : template<class PFooSide> class Endpoint;
29 :
30 : // This class is not designed for public consumption beyond the few static
31 : // member functions.
32 : class BackgroundParent final
33 : {
34 : friend class mozilla::dom::ContentParent;
35 :
36 : typedef base::ProcessId ProcessId;
37 : typedef mozilla::dom::BlobImpl BlobImpl;
38 : typedef mozilla::dom::ContentParent ContentParent;
39 : typedef mozilla::ipc::Transport Transport;
40 :
41 : public:
42 : // This function allows the caller to determine if the given parent actor
43 : // corresponds to a child actor from another process or a child actor from a
44 : // different thread in the same process.
45 : // This function may only be called on the background thread.
46 : static bool
47 : IsOtherProcessActor(PBackgroundParent* aBackgroundActor);
48 :
49 : // This function returns the ContentParent associated with the parent actor if
50 : // the parent actor corresponds to a child actor from another process. If the
51 : // parent actor corresponds to a child actor from a different thread in the
52 : // same process then this function returns null.
53 : // This function may only be called on the background thread. However,
54 : // ContentParent is not threadsafe and the returned pointer may not be used on
55 : // any thread other than the main thread. Callers must take care to use (and
56 : // release) the returned pointer appropriately.
57 : static already_AddRefed<ContentParent>
58 : GetContentParent(PBackgroundParent* aBackgroundActor);
59 :
60 : // Get a value that represents the ContentParent associated with the parent
61 : // actor for comparison. The value is not guaranteed to uniquely identify the
62 : // ContentParent after the ContentParent has died. This function may only be
63 : // called on the background thread.
64 : static intptr_t
65 : GetRawContentParentForComparison(PBackgroundParent* aBackgroundActor);
66 :
67 : static uint64_t
68 : GetChildID(PBackgroundParent* aBackgroundActor);
69 :
70 : private:
71 : // Only called by ContentParent for cross-process actors.
72 : static bool
73 : Alloc(ContentParent* aContent,
74 : Endpoint<PBackgroundParent>&& aEndpoint);
75 : };
76 :
77 : // Implemented in BackgroundImpl.cpp.
78 : bool
79 : IsOnBackgroundThread();
80 :
81 : #ifdef DEBUG
82 :
83 : // Implemented in BackgroundImpl.cpp.
84 : void
85 : AssertIsOnBackgroundThread();
86 :
87 : #else
88 :
89 : inline void
90 : AssertIsOnBackgroundThread()
91 : { }
92 :
93 : #endif // DEBUG
94 :
95 : inline void
96 65 : AssertIsInMainProcess()
97 : {
98 65 : MOZ_ASSERT(XRE_IsParentProcess());
99 65 : }
100 :
101 : } // namespace ipc
102 : } // namespace mozilla
103 :
104 : #endif // mozilla_ipc_backgroundparent_h__
|