ResourceLoadObserver.h [plain text]
#pragma once
#include "Timer.h"
#include <wtf/HashMap.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/text/WTFString.h>
namespace WTF {
class Lock;
class WorkQueue;
}
namespace WebCore {
class Document;
class Frame;
class Page;
class ResourceRequest;
class ResourceResponse;
class URL;
struct ResourceLoadStatistics;
class ResourceLoadObserver {
friend class WTF::NeverDestroyed<ResourceLoadObserver>;
public:
WEBCORE_EXPORT static ResourceLoadObserver& shared();
WEBCORE_EXPORT void setShouldThrottleObserverNotifications(bool);
void logFrameNavigation(const Frame&, const Frame& topFrame, const ResourceRequest& newRequest);
void logSubresourceLoading(const Frame*, const ResourceRequest& newRequest, const ResourceResponse& redirectResponse);
void logWebSocketLoading(const Frame*, const URL&);
void logUserInteractionWithReducedTimeResolution(const Document&);
WEBCORE_EXPORT String statisticsForOrigin(const String&);
WEBCORE_EXPORT void setNotificationCallback(WTF::Function<void (Vector<ResourceLoadStatistics>&&)>&&);
private:
ResourceLoadObserver();
bool shouldLog(Page*) const;
ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
void scheduleNotificationIfNeeded();
void notificationTimerFired();
Vector<ResourceLoadStatistics> takeStatistics();
HashMap<String, ResourceLoadStatistics> m_resourceStatisticsMap;
WTF::Function<void (Vector<ResourceLoadStatistics>&&)> m_notificationCallback;
Timer m_notificationTimer;
bool m_shouldThrottleNotifications { true };
};
}