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