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_dom_PerformanceEntry_h___
8 #define mozilla_dom_PerformanceEntry_h___
10 #include "nsDOMNavigationTiming.h"
12 #include "nsWrapperCache.h"
14 #include "mozilla/dom/PerformanceObserverBinding.h"
18 namespace mozilla::dom
{
19 class PerformanceResourceTiming
;
21 // http://www.w3.org/TR/performance-timeline/#performanceentry
22 class PerformanceEntry
: public nsISupports
, public nsWrapperCache
{
24 virtual ~PerformanceEntry();
27 PerformanceEntry(nsISupports
* aParent
, const nsAString
& aName
,
28 const nsAString
& aEntryType
);
30 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
31 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(PerformanceEntry
)
33 nsISupports
* GetParentObject() const { return mParent
; }
35 void GetName(nsAString
& aName
) const {
37 mName
->ToString(aName
);
41 const nsAtom
* GetName() const { return mName
; }
43 void GetEntryType(nsAString
& aEntryType
) const {
45 mEntryType
->ToString(aEntryType
);
49 const nsAtom
* GetEntryType() const { return mEntryType
; }
51 void SetEntryType(const nsAString
& aEntryType
) {
52 mEntryType
= NS_Atomize(aEntryType
);
55 virtual DOMHighResTimeStamp
StartTime() const { return 0; }
57 // This is used by the Gecko Profiler only for adding precise markers.
58 // It's not exposed to JS.
59 virtual DOMHighResTimeStamp
UnclampedStartTime() const {
60 MOZ_ASSERT(false, "UnclampedStartTime should not be called on this class.");
64 virtual DOMHighResTimeStamp
Duration() const { return 0; }
66 virtual const PerformanceResourceTiming
* ToResourceTiming() const {
70 virtual bool ShouldAddEntryToObserverBuffer(
71 PerformanceObserverInit
& aOption
) const;
73 virtual void BufferEntryIfNeeded() {}
75 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
78 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
81 nsCOMPtr
<nsISupports
> mParent
;
83 RefPtr
<nsAtom
> mEntryType
;
87 class MOZ_STACK_CLASS PerformanceEntryComparator final
{
89 bool Equals(const PerformanceEntry
* aElem1
,
90 const PerformanceEntry
* aElem2
) const {
91 MOZ_ASSERT(aElem1
&& aElem2
, "Trying to compare null performance entries");
92 return aElem1
->StartTime() == aElem2
->StartTime();
95 bool LessThan(const PerformanceEntry
* aElem1
,
96 const PerformanceEntry
* aElem2
) const {
97 MOZ_ASSERT(aElem1
&& aElem2
, "Trying to compare null performance entries");
98 return aElem1
->StartTime() < aElem2
->StartTime();
102 } // namespace mozilla::dom
104 #endif /* mozilla_dom_PerformanceEntry_h___ */