#pragma once
#include "ContextDestructionObserver.h"
#include "DOMHighResTimeStamp.h"
#include "EventTarget.h"
#include "ExceptionOr.h"
#include "GenericTaskQueue.h"
#include <wtf/ListHashSet.h>
namespace WebCore {
class LoadTiming;
class PerformanceEntry;
class PerformanceNavigation;
class PerformanceObserver;
class PerformanceTiming;
class ResourceResponse;
class ResourceTiming;
class ScriptExecutionContext;
class URL;
class UserTiming;
class Performance final : public RefCounted<Performance>, public ContextDestructionObserver, public EventTargetWithInlineData {
public:
static Ref<Performance> create(ScriptExecutionContext& context, MonotonicTime timeOrigin) { return adoptRef(*new Performance(context, timeOrigin)); }
~Performance();
DOMHighResTimeStamp now() const;
PerformanceNavigation* navigation();
PerformanceTiming* timing();
Vector<RefPtr<PerformanceEntry>> getEntries() const;
Vector<RefPtr<PerformanceEntry>> getEntriesByType(const String& entryType) const;
Vector<RefPtr<PerformanceEntry>> getEntriesByName(const String& name, const String& entryType) const;
void clearResourceTimings();
void setResourceTimingBufferSize(unsigned);
ExceptionOr<void> mark(const String& markName);
void clearMarks(const String& markName);
ExceptionOr<void> measure(const String& measureName, const String& startMark, const String& endMark);
void clearMeasures(const String& measureName);
void addResourceTiming(ResourceTiming&&);
void removeAllObservers();
void registerPerformanceObserver(PerformanceObserver&);
void unregisterPerformanceObserver(PerformanceObserver&);
static Seconds reduceTimeResolution(Seconds);
DOMHighResTimeStamp relativeTimeFromTimeOriginInReducedResolution(MonotonicTime) const;
ScriptExecutionContext* scriptExecutionContext() const final { return ContextDestructionObserver::scriptExecutionContext(); }
using RefCounted::ref;
using RefCounted::deref;
private:
Performance(ScriptExecutionContext&, MonotonicTime timeOrigin);
void contextDestroyed() override;
EventTargetInterface eventTargetInterface() const final { return PerformanceEventTargetInterfaceType; }
void refEventTarget() final { ref(); }
void derefEventTarget() final { deref(); }
bool isResourceTimingBufferFull() const;
void resourceTimingBufferFullTimerFired();
void queueEntry(PerformanceEntry&);
mutable RefPtr<PerformanceNavigation> m_navigation;
mutable RefPtr<PerformanceTiming> m_timing;
Vector<RefPtr<PerformanceEntry>> m_resourceTimingBuffer;
unsigned m_resourceTimingBufferSize { 150 };
Timer m_resourceTimingBufferFullTimer;
Vector<RefPtr<PerformanceEntry>> m_backupResourceTimingBuffer;
bool m_resourceTimingBufferFullFlag { false };
bool m_waitingForBackupBufferToBeProcessed { false };
MonotonicTime m_timeOrigin;
std::unique_ptr<UserTiming> m_userTiming;
GenericTaskQueue<ScriptExecutionContext> m_performanceTimelineTaskQueue;
ListHashSet<RefPtr<PerformanceObserver>> m_observers;
};
}