Loading dom/performance/Performance.cpp +10 −145 Original line number Diff line number Diff line Loading @@ -41,8 +41,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Performance) NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) NS_IMPL_CYCLE_COLLECTION_INHERITED(Performance, DOMEventTargetHelper, mUserEntries, mResourceEntries, mSecondaryResourceEntries); mUserEntries, mResourceEntries); NS_IMPL_ADDREF_INHERITED(Performance, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(Performance, DOMEventTargetHelper) Loading Loading @@ -72,7 +71,6 @@ already_AddRefed<Performance> Performance::CreateForWorker( Performance::Performance(bool aSystemPrincipal) : mResourceTimingBufferSize(kDefaultResourceTimingBufferSize), mPendingNotificationObserversTask(false), mPendingResourceTimingBufferFullEvent(false), mSystemPrincipal(aSystemPrincipal) { MOZ_ASSERT(!NS_IsMainThread()); } Loading @@ -81,7 +79,6 @@ Performance::Performance(nsPIDOMWindowInner* aWindow, bool aSystemPrincipal) : DOMEventTargetHelper(aWindow), mResourceTimingBufferSize(kDefaultResourceTimingBufferSize), mPendingNotificationObserversTask(false), mPendingResourceTimingBufferFullEvent(false), mSystemPrincipal(aSystemPrincipal) { MOZ_ASSERT(NS_IsMainThread()); } Loading Loading @@ -376,161 +373,29 @@ void Performance::InsertUserEntry(PerformanceEntry* aEntry) { QueueEntry(aEntry); } /* * Steps are labeled according to the description found at * https://w3c.github.io/resource-timing/#sec-extensions-performance-interface. * * Buffer Full Event */ void Performance::BufferEvent() { /* * While resource timing secondary buffer is not empty, * run the following substeps: */ while (!mSecondaryResourceEntries.IsEmpty()) { uint32_t secondaryResourceEntriesBeforeCount = 0; uint32_t secondaryResourceEntriesAfterCount = 0; /* * Let number of excess entries before be resource * timing secondary buffer current size. */ secondaryResourceEntriesBeforeCount = mSecondaryResourceEntries.Length(); /* * If can add resource timing entry returns false, * then fire an event named resourcetimingbufferfull * at the Performance object. */ if (!CanAddResourceTimingEntry()) { DispatchBufferFullEvent(); } /* * Run copy secondary buffer. * * While resource timing secondary buffer is not * empty and can add resource timing entry returns * true ... */ while (!mSecondaryResourceEntries.IsEmpty() && CanAddResourceTimingEntry()) { /* * Let entry be the oldest PerformanceResourceTiming * in resource timing secondary buffer. Add entry to * the end of performance entry buffer. Increment * resource timing buffer current size by 1. */ mResourceEntries.InsertElementSorted( mSecondaryResourceEntries.ElementAt(0), PerformanceEntryComparator()); /* * Remove entry from resource timing secondary buffer. * Decrement resource timing secondary buffer current * size by 1. */ mSecondaryResourceEntries.RemoveElementAt(0); } /* * Let number of excess entries after be resource * timing secondary buffer current size. */ secondaryResourceEntriesAfterCount = mSecondaryResourceEntries.Length(); /* * If number of excess entries before is lower than * or equals number of excess entries after, then * remove all entries from resource timing secondary * buffer, set resource timing secondary buffer current * size to 0, and abort these steps. */ if (secondaryResourceEntriesBeforeCount <= secondaryResourceEntriesAfterCount) { mSecondaryResourceEntries.Clear(); break; } } /* * Set resource timing buffer full event pending flag * to false. */ mPendingResourceTimingBufferFullEvent = false; } void Performance::SetResourceTimingBufferSize(uint64_t aMaxSize) { mResourceTimingBufferSize = aMaxSize; } /* * Steps are labeled according to the description found at * https://w3c.github.io/resource-timing/#sec-extensions-performance-interface. * * Can Add Resource Timing Entry */ MOZ_ALWAYS_INLINE bool Performance::CanAddResourceTimingEntry() { /* * If resource timing buffer current size is smaller than resource timing * buffer size limit, return true. [Otherwise,] [r]eturn false. */ return mResourceEntries.Length() < mResourceTimingBufferSize; } /* * Steps are labeled according to the description found at * https://w3c.github.io/resource-timing/#sec-extensions-performance-interface. * * Add a PerformanceResourceTiming Entry */ void Performance::InsertResourceEntry(PerformanceEntry* aEntry) { MOZ_ASSERT(aEntry); // We won't add an entry when 'privacy.resistFingerprint' is true. if (nsContentUtils::ShouldResistFingerprinting()) { return; } /* * Let new entry be the input PerformanceEntry to be added. * * If can add resource timing entry returns true and resource * timing buffer full event pending flag is false ... */ if (CanAddResourceTimingEntry() && !mPendingResourceTimingBufferFullEvent) { /* * Add new entry to the performance entry buffer. * Increase resource timing buffer current size by 1. */ mResourceEntries.InsertElementSorted(aEntry, PerformanceEntryComparator()); QueueEntry(aEntry); /* * Return. */ // Don't add the entry if the buffer is full if (mResourceEntries.Length() >= mResourceTimingBufferSize) { return; } /* * If resource timing buffer full event pending flag is * false ... */ if (!mPendingResourceTimingBufferFullEvent) { /* * Set resource timing buffer full event pending flag * to true. */ mPendingResourceTimingBufferFullEvent = true; /* * Queue a task to run fire a buffer full event. */ NS_DispatchToCurrentThread(NewCancelableRunnableMethod( "Performance::BufferEvent", this, &Performance::BufferEvent)); } /* * Add new entry to the resource timing secondary buffer. * Increase resource timing secondary buffer current size * by 1. */ mSecondaryResourceEntries.InsertElementSorted(aEntry, PerformanceEntryComparator()); mResourceEntries.InsertElementSorted(aEntry, PerformanceEntryComparator()); if (mResourceEntries.Length() == mResourceTimingBufferSize) { // call onresourcetimingbufferfull DispatchBufferFullEvent(); } QueueEntry(aEntry); } void Performance::AddObserver(PerformanceObserver* aObserver) { Loading dom/performance/Performance.h +0 −8 Original line number Diff line number Diff line Loading @@ -155,21 +155,13 @@ class Performance : public DOMEventTargetHelper { mUserEntries; AutoTArray<RefPtr<PerformanceEntry>, kDefaultResourceTimingBufferSize> mResourceEntries; AutoTArray<RefPtr<PerformanceEntry>, kDefaultResourceTimingBufferSize> mSecondaryResourceEntries; uint64_t mResourceTimingBufferSize; bool mPendingNotificationObserversTask; bool mPendingResourceTimingBufferFullEvent; RefPtr<PerformanceService> mPerformanceService; bool mSystemPrincipal; private: MOZ_ALWAYS_INLINE bool CanAddResourceTimingEntry(); void BufferEvent(); }; } // namespace dom Loading testing/web-platform/meta/resource-timing/buffer-full-add-after-full-event.html.ini +4 −1 Original line number Diff line number Diff line [buffer-full-add-after-full-event.html] disabled: Bug 1535466: https://bugzilla.mozilla.org/show_bug.cgi?id=1535466 expected: TIMEOUT [Test that entry was added to the buffer after a buffer full event] expected: TIMEOUT testing/web-platform/meta/resource-timing/buffer-full-add-entries-during-callback-that-drop.html.ini 0 → 100644 +5 −0 Original line number Diff line number Diff line [buffer-full-add-entries-during-callback-that-drop.html] expected: TIMEOUT [Test that entries synchronously added to the buffer during the callback are dropped] expected: TIMEOUT testing/web-platform/meta/resource-timing/buffer-full-add-entries-during-callback.html.ini 0 → 100644 +5 −0 Original line number Diff line number Diff line [buffer-full-add-entries-during-callback.html] expected: TIMEOUT [Test that entries synchronously added to the buffer during the callback don't get dropped if the buffer is increased] expected: TIMEOUT Loading
dom/performance/Performance.cpp +10 −145 Original line number Diff line number Diff line Loading @@ -41,8 +41,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Performance) NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) NS_IMPL_CYCLE_COLLECTION_INHERITED(Performance, DOMEventTargetHelper, mUserEntries, mResourceEntries, mSecondaryResourceEntries); mUserEntries, mResourceEntries); NS_IMPL_ADDREF_INHERITED(Performance, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(Performance, DOMEventTargetHelper) Loading Loading @@ -72,7 +71,6 @@ already_AddRefed<Performance> Performance::CreateForWorker( Performance::Performance(bool aSystemPrincipal) : mResourceTimingBufferSize(kDefaultResourceTimingBufferSize), mPendingNotificationObserversTask(false), mPendingResourceTimingBufferFullEvent(false), mSystemPrincipal(aSystemPrincipal) { MOZ_ASSERT(!NS_IsMainThread()); } Loading @@ -81,7 +79,6 @@ Performance::Performance(nsPIDOMWindowInner* aWindow, bool aSystemPrincipal) : DOMEventTargetHelper(aWindow), mResourceTimingBufferSize(kDefaultResourceTimingBufferSize), mPendingNotificationObserversTask(false), mPendingResourceTimingBufferFullEvent(false), mSystemPrincipal(aSystemPrincipal) { MOZ_ASSERT(NS_IsMainThread()); } Loading Loading @@ -376,161 +373,29 @@ void Performance::InsertUserEntry(PerformanceEntry* aEntry) { QueueEntry(aEntry); } /* * Steps are labeled according to the description found at * https://w3c.github.io/resource-timing/#sec-extensions-performance-interface. * * Buffer Full Event */ void Performance::BufferEvent() { /* * While resource timing secondary buffer is not empty, * run the following substeps: */ while (!mSecondaryResourceEntries.IsEmpty()) { uint32_t secondaryResourceEntriesBeforeCount = 0; uint32_t secondaryResourceEntriesAfterCount = 0; /* * Let number of excess entries before be resource * timing secondary buffer current size. */ secondaryResourceEntriesBeforeCount = mSecondaryResourceEntries.Length(); /* * If can add resource timing entry returns false, * then fire an event named resourcetimingbufferfull * at the Performance object. */ if (!CanAddResourceTimingEntry()) { DispatchBufferFullEvent(); } /* * Run copy secondary buffer. * * While resource timing secondary buffer is not * empty and can add resource timing entry returns * true ... */ while (!mSecondaryResourceEntries.IsEmpty() && CanAddResourceTimingEntry()) { /* * Let entry be the oldest PerformanceResourceTiming * in resource timing secondary buffer. Add entry to * the end of performance entry buffer. Increment * resource timing buffer current size by 1. */ mResourceEntries.InsertElementSorted( mSecondaryResourceEntries.ElementAt(0), PerformanceEntryComparator()); /* * Remove entry from resource timing secondary buffer. * Decrement resource timing secondary buffer current * size by 1. */ mSecondaryResourceEntries.RemoveElementAt(0); } /* * Let number of excess entries after be resource * timing secondary buffer current size. */ secondaryResourceEntriesAfterCount = mSecondaryResourceEntries.Length(); /* * If number of excess entries before is lower than * or equals number of excess entries after, then * remove all entries from resource timing secondary * buffer, set resource timing secondary buffer current * size to 0, and abort these steps. */ if (secondaryResourceEntriesBeforeCount <= secondaryResourceEntriesAfterCount) { mSecondaryResourceEntries.Clear(); break; } } /* * Set resource timing buffer full event pending flag * to false. */ mPendingResourceTimingBufferFullEvent = false; } void Performance::SetResourceTimingBufferSize(uint64_t aMaxSize) { mResourceTimingBufferSize = aMaxSize; } /* * Steps are labeled according to the description found at * https://w3c.github.io/resource-timing/#sec-extensions-performance-interface. * * Can Add Resource Timing Entry */ MOZ_ALWAYS_INLINE bool Performance::CanAddResourceTimingEntry() { /* * If resource timing buffer current size is smaller than resource timing * buffer size limit, return true. [Otherwise,] [r]eturn false. */ return mResourceEntries.Length() < mResourceTimingBufferSize; } /* * Steps are labeled according to the description found at * https://w3c.github.io/resource-timing/#sec-extensions-performance-interface. * * Add a PerformanceResourceTiming Entry */ void Performance::InsertResourceEntry(PerformanceEntry* aEntry) { MOZ_ASSERT(aEntry); // We won't add an entry when 'privacy.resistFingerprint' is true. if (nsContentUtils::ShouldResistFingerprinting()) { return; } /* * Let new entry be the input PerformanceEntry to be added. * * If can add resource timing entry returns true and resource * timing buffer full event pending flag is false ... */ if (CanAddResourceTimingEntry() && !mPendingResourceTimingBufferFullEvent) { /* * Add new entry to the performance entry buffer. * Increase resource timing buffer current size by 1. */ mResourceEntries.InsertElementSorted(aEntry, PerformanceEntryComparator()); QueueEntry(aEntry); /* * Return. */ // Don't add the entry if the buffer is full if (mResourceEntries.Length() >= mResourceTimingBufferSize) { return; } /* * If resource timing buffer full event pending flag is * false ... */ if (!mPendingResourceTimingBufferFullEvent) { /* * Set resource timing buffer full event pending flag * to true. */ mPendingResourceTimingBufferFullEvent = true; /* * Queue a task to run fire a buffer full event. */ NS_DispatchToCurrentThread(NewCancelableRunnableMethod( "Performance::BufferEvent", this, &Performance::BufferEvent)); } /* * Add new entry to the resource timing secondary buffer. * Increase resource timing secondary buffer current size * by 1. */ mSecondaryResourceEntries.InsertElementSorted(aEntry, PerformanceEntryComparator()); mResourceEntries.InsertElementSorted(aEntry, PerformanceEntryComparator()); if (mResourceEntries.Length() == mResourceTimingBufferSize) { // call onresourcetimingbufferfull DispatchBufferFullEvent(); } QueueEntry(aEntry); } void Performance::AddObserver(PerformanceObserver* aObserver) { Loading
dom/performance/Performance.h +0 −8 Original line number Diff line number Diff line Loading @@ -155,21 +155,13 @@ class Performance : public DOMEventTargetHelper { mUserEntries; AutoTArray<RefPtr<PerformanceEntry>, kDefaultResourceTimingBufferSize> mResourceEntries; AutoTArray<RefPtr<PerformanceEntry>, kDefaultResourceTimingBufferSize> mSecondaryResourceEntries; uint64_t mResourceTimingBufferSize; bool mPendingNotificationObserversTask; bool mPendingResourceTimingBufferFullEvent; RefPtr<PerformanceService> mPerformanceService; bool mSystemPrincipal; private: MOZ_ALWAYS_INLINE bool CanAddResourceTimingEntry(); void BufferEvent(); }; } // namespace dom Loading
testing/web-platform/meta/resource-timing/buffer-full-add-after-full-event.html.ini +4 −1 Original line number Diff line number Diff line [buffer-full-add-after-full-event.html] disabled: Bug 1535466: https://bugzilla.mozilla.org/show_bug.cgi?id=1535466 expected: TIMEOUT [Test that entry was added to the buffer after a buffer full event] expected: TIMEOUT
testing/web-platform/meta/resource-timing/buffer-full-add-entries-during-callback-that-drop.html.ini 0 → 100644 +5 −0 Original line number Diff line number Diff line [buffer-full-add-entries-during-callback-that-drop.html] expected: TIMEOUT [Test that entries synchronously added to the buffer during the callback are dropped] expected: TIMEOUT
testing/web-platform/meta/resource-timing/buffer-full-add-entries-during-callback.html.ini 0 → 100644 +5 −0 Original line number Diff line number Diff line [buffer-full-add-entries-during-callback.html] expected: TIMEOUT [Test that entries synchronously added to the buffer during the callback don't get dropped if the buffer is increased] expected: TIMEOUT