PerformanceEntry.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_PerformanceEntry_h___
  6. #define mozilla_dom_PerformanceEntry_h___
  7. #include "nsDOMNavigationTiming.h"
  8. #include "nsString.h"
  9. #include "nsWrapperCache.h"
  10. class nsISupports;
  11. namespace mozilla {
  12. namespace dom {
  13. class PerformanceResourceTiming;
  14. // http://www.w3.org/TR/performance-timeline/#performanceentry
  15. class PerformanceEntry : public nsISupports,
  16. public nsWrapperCache
  17. {
  18. protected:
  19. virtual ~PerformanceEntry();
  20. public:
  21. PerformanceEntry(nsISupports* aParent,
  22. const nsAString& aName,
  23. const nsAString& aEntryType);
  24. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  25. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PerformanceEntry)
  26. virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  27. nsISupports* GetParentObject() const
  28. {
  29. return mParent;
  30. }
  31. void GetName(nsAString& aName) const
  32. {
  33. aName = mName;
  34. }
  35. const nsAString& GetName() const
  36. {
  37. return mName;
  38. }
  39. void SetName(const nsAString& aName)
  40. {
  41. mName = aName;
  42. }
  43. void GetEntryType(nsAString& aEntryType) const
  44. {
  45. aEntryType = mEntryType;
  46. }
  47. const nsAString& GetEntryType()
  48. {
  49. return mEntryType;
  50. }
  51. void SetEntryType(const nsAString& aEntryType)
  52. {
  53. mEntryType = aEntryType;
  54. }
  55. virtual DOMHighResTimeStamp StartTime() const
  56. {
  57. return 0;
  58. }
  59. virtual DOMHighResTimeStamp Duration() const
  60. {
  61. return 0;
  62. }
  63. virtual const PerformanceResourceTiming* ToResourceTiming() const
  64. {
  65. return nullptr;
  66. }
  67. protected:
  68. nsCOMPtr<nsISupports> mParent;
  69. nsString mName;
  70. nsString mEntryType;
  71. };
  72. // Helper classes
  73. class MOZ_STACK_CLASS PerformanceEntryComparator final
  74. {
  75. public:
  76. bool Equals(const PerformanceEntry* aElem1,
  77. const PerformanceEntry* aElem2) const
  78. {
  79. MOZ_ASSERT(aElem1 && aElem2,
  80. "Trying to compare null performance entries");
  81. return aElem1->StartTime() == aElem2->StartTime();
  82. }
  83. bool LessThan(const PerformanceEntry* aElem1,
  84. const PerformanceEntry* aElem2) const
  85. {
  86. MOZ_ASSERT(aElem1 && aElem2,
  87. "Trying to compare null performance entries");
  88. return aElem1->StartTime() < aElem2->StartTime();
  89. }
  90. };
  91. } // namespace dom
  92. } // namespace mozilla
  93. #endif /* mozilla_dom_PerformanceEntry_h___ */