Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/TimelineConsumers.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
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_TimelineConsumers_h_
8
#define mozilla_TimelineConsumers_h_
9
10
#include "nsIObserver.h"
11
#include "mozilla/StaticPtr.h"
12
#include "mozilla/UniquePtr.h"
13
#include "mozilla/LinkedList.h"
14
#include "mozilla/StaticMutex.h"
15
#include "TimelineMarkerEnums.h" // for MarkerTracingType
16
17
class nsDocShell;
18
class nsIDocShell;
19
struct JSContext;
20
21
namespace mozilla {
22
class TimeStamp;
23
class MarkersStorage;
24
class AbstractTimelineMarker;
25
26
namespace dom {
27
struct ProfileTimelineMarker;
28
}
29
30
class TimelineConsumers : public nsIObserver
31
{
32
public:
33
  NS_DECL_THREADSAFE_ISUPPORTS
34
  NS_DECL_NSIOBSERVER
35
36
private:
37
  TimelineConsumers();
38
  TimelineConsumers(const TimelineConsumers& aOther) = delete;
39
  void operator=(const TimelineConsumers& aOther) = delete;
40
0
  virtual ~TimelineConsumers() = default;
41
42
  bool Init();
43
  bool RemoveObservers();
44
45
public:
46
  static already_AddRefed<TimelineConsumers> Get();
47
48
  // Methods for registering interested consumers (i.e. "devtools toolboxes").
49
  // Each consumer should be directly focused on a particular docshell, but
50
  // timeline markers don't necessarily have to be tied to that docshell.
51
  // See the public `AddMarker*` methods below.
52
  // Main thread only.
53
  void AddConsumer(nsDocShell* aDocShell);
54
  void RemoveConsumer(nsDocShell* aDocShell);
55
56
  bool HasConsumer(nsIDocShell* aDocShell);
57
58
  // Checks if there's any existing interested consumer.
59
  // May be called from any thread.
60
  bool IsEmpty();
61
62
  // Methods for adding markers relevant for particular docshells, or generic
63
  // (meaning that they either can't be tied to a particular docshell, or one
64
  // wasn't accessible in the part of the codebase where they're instantiated).
65
  // These will only add markers if at least one docshell is currently being
66
  // observed by a timeline. Markers tied to a particular docshell won't be
67
  // created unless that docshell is specifically being currently observed.
68
  // See nsIDocShell::recordProfileTimelineMarkers
69
70
  // These methods create a basic TimelineMarker from a name and some metadata,
71
  // relevant for a specific docshell.
72
  // Main thread only.
73
  void AddMarkerForDocShell(nsDocShell* aDocShell,
74
                            const char* aName,
75
                            MarkerTracingType aTracingType,
76
                            MarkerStackRequest aStackRequest = MarkerStackRequest::STACK);
77
  void AddMarkerForDocShell(nsIDocShell* aDocShell,
78
                            const char* aName,
79
                            MarkerTracingType aTracingType,
80
                            MarkerStackRequest aStackRequest = MarkerStackRequest::STACK);
81
82
  void AddMarkerForDocShell(nsDocShell* aDocShell,
83
                            const char* aName,
84
                            const TimeStamp& aTime,
85
                            MarkerTracingType aTracingType,
86
                            MarkerStackRequest aStackRequest = MarkerStackRequest::STACK);
87
  void AddMarkerForDocShell(nsIDocShell* aDocShell,
88
                            const char* aName,
89
                            const TimeStamp& aTime,
90
                            MarkerTracingType aTracingType,
91
                            MarkerStackRequest aStackRequest = MarkerStackRequest::STACK);
92
93
  // These methods register and receive ownership of an already created marker,
94
  // relevant for a specific docshell.
95
  // Main thread only.
96
  void AddMarkerForDocShell(nsDocShell* aDocShell,
97
                            UniquePtr<AbstractTimelineMarker>&& aMarker);
98
  void AddMarkerForDocShell(nsIDocShell* aDocShell,
99
                            UniquePtr<AbstractTimelineMarker>&& aMarker);
100
101
  // These methods create a basic marker from a name and some metadata,
102
  // which doesn't have to be relevant to a specific docshell.
103
  // May be called from any thread.
104
  void AddMarkerForAllObservedDocShells(const char* aName,
105
                                        MarkerTracingType aTracingType,
106
                                        MarkerStackRequest aStackRequest = MarkerStackRequest::STACK);
107
  void AddMarkerForAllObservedDocShells(const char* aName,
108
                                        const TimeStamp& aTime,
109
                                        MarkerTracingType aTracingType,
110
                                        MarkerStackRequest aStackRequest = MarkerStackRequest::STACK);
111
112
  // This method clones and registers an already instantiated marker,
113
  // which doesn't have to be relevant to a specific docshell.
114
  // May be called from any thread.
115
  void AddMarkerForAllObservedDocShells(UniquePtr<AbstractTimelineMarker>& aMarker);
116
117
  void PopMarkers(nsDocShell* aDocShell,
118
                  JSContext* aCx,
119
                  nsTArray<dom::ProfileTimelineMarker>& aStore);
120
121
private:
122
  static StaticRefPtr<TimelineConsumers> sInstance;
123
  static bool sInShutdown;
124
125
  // Counter for how many timelines are currently interested in markers,
126
  // and a list of the MarkersStorage interfaces representing them.
127
  unsigned long mActiveConsumers;
128
  LinkedList<MarkersStorage> mMarkersStores;
129
130
  // Protects this class's data structures.
131
  static StaticMutex sMutex;
132
};
133
134
} // namespace mozilla
135
136
#endif /* mozilla_TimelineConsumers_h_ */