PerformanceEntry.h (3148B)
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_dom_PerformanceEntry_h___ 8 #define mozilla_dom_PerformanceEntry_h___ 9 10 #include "mozilla/dom/PerformanceObserverBinding.h" 11 #include "nsAtom.h" 12 #include "nsDOMNavigationTiming.h" 13 #include "nsString.h" 14 #include "nsWrapperCache.h" 15 16 class nsISupports; 17 18 namespace mozilla::dom { 19 class PerformanceResourceTiming; 20 21 // http://www.w3.org/TR/performance-timeline/#performanceentry 22 class PerformanceEntry : public nsISupports, public nsWrapperCache { 23 protected: 24 virtual ~PerformanceEntry(); 25 26 public: 27 PerformanceEntry(nsISupports* aParent, const nsAString& aName, 28 const nsStaticAtom* aEntryType); 29 30 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 31 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(PerformanceEntry) 32 33 nsISupports* GetParentObject() const { return mParent; } 34 35 void GetName(nsAString& aName) const { 36 if (mName) { 37 mName->ToString(aName); 38 } 39 } 40 41 const nsAtom* GetName() const { return mName; } 42 43 void GetEntryType(nsAString& aEntryType) const { 44 if (mEntryType) { 45 mEntryType->ToString(aEntryType); 46 } 47 } 48 49 const nsAtom* GetEntryType() const { return mEntryType; } 50 const nsStaticAtom* GetEntryTypeAsStaticAtom() const { return mEntryType; } 51 52 void SetEntryType(nsStaticAtom* aEntryType) { mEntryType = aEntryType; } 53 54 virtual DOMHighResTimeStamp StartTime() const { return 0; } 55 56 // This is used by the Gecko Profiler only for adding precise markers. 57 // It's not exposed to JS. 58 virtual DOMHighResTimeStamp UnclampedStartTime() const { 59 MOZ_ASSERT(false, "UnclampedStartTime should not be called on this class."); 60 return 0; 61 } 62 63 virtual DOMHighResTimeStamp Duration() const { return 0; } 64 65 virtual const PerformanceResourceTiming* ToResourceTiming() const { 66 return nullptr; 67 } 68 69 virtual bool ShouldAddEntryToObserverBuffer( 70 PerformanceObserverInit& aOption) const; 71 72 virtual void BufferEntryIfNeeded() {} 73 74 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; 75 76 protected: 77 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; 78 79 private: 80 nsCOMPtr<nsISupports> mParent; 81 RefPtr<nsAtom> mName; 82 const nsStaticAtom* mEntryType; 83 }; 84 85 // Helper classes 86 class MOZ_STACK_CLASS PerformanceEntryComparator final { 87 public: 88 bool Equals(const PerformanceEntry* aElem1, 89 const PerformanceEntry* aElem2) const { 90 MOZ_ASSERT(aElem1 && aElem2, "Trying to compare null performance entries"); 91 return aElem1->StartTime() == aElem2->StartTime(); 92 } 93 94 bool LessThan(const PerformanceEntry* aElem1, 95 const PerformanceEntry* aElem2) const { 96 MOZ_ASSERT(aElem1 && aElem2, "Trying to compare null performance entries"); 97 return aElem1->StartTime() < aElem2->StartTime(); 98 } 99 }; 100 101 } // namespace mozilla::dom 102 103 #endif /* mozilla_dom_PerformanceEntry_h___ */