Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/ipc/BackgroundParent.h
Line
Count
Source (jump to first uncovered line)
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
  static bool
71
  GetLiveActorArray(PBackgroundParent* aBackgroundActor,
72
                    nsTArray<PBackgroundParent*>& aLiveActorArray);
73
74
private:
75
  // Only called by ContentParent for cross-process actors.
76
  static bool
77
  Alloc(ContentParent* aContent,
78
        Endpoint<PBackgroundParent>&& aEndpoint);
79
};
80
81
// Implemented in BackgroundImpl.cpp.
82
bool
83
IsOnBackgroundThread();
84
85
#ifdef DEBUG
86
87
// Implemented in BackgroundImpl.cpp.
88
void
89
AssertIsOnBackgroundThread();
90
91
#else
92
93
inline void
94
AssertIsOnBackgroundThread()
95
0
{ }
96
97
#endif // DEBUG
98
99
inline void
100
AssertIsInMainProcess()
101
0
{
102
0
  MOZ_ASSERT(XRE_IsParentProcess());
103
0
}
104
105
} // namespace ipc
106
} // namespace mozilla
107
108
#endif // mozilla_ipc_backgroundparent_h__