ResourceLoadObserver.h [plain text]
#pragma once
#include "Timer.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/text/WTFString.h>
namespace WTF {
class Lock;
class WorkQueue;
class WallTime;
}
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();
void logFrameNavigation(const Frame&, const Frame& topFrame, const ResourceRequest& newRequest, const URL& redirectUrl);
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>&&)>&&);
WEBCORE_EXPORT void notifyObserver();
WEBCORE_EXPORT void clearState();
private:
ResourceLoadObserver();
bool shouldLog(Page*) const;
ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
void scheduleNotificationIfNeeded();
Vector<ResourceLoadStatistics> takeStatistics();
HashMap<String, ResourceLoadStatistics> m_resourceStatisticsMap;
HashMap<String, WTF::WallTime> m_lastReportedUserInteractionMap;
WTF::Function<void (Vector<ResourceLoadStatistics>&&)> m_notificationCallback;
Timer m_notificationTimer;
URL nonNullOwnerURL(const Document&) const;
};
}