ResourceLoadStatisticsClassifier.cpp [plain text]
#include "config.h"
#include "ResourceLoadStatisticsClassifier.h"
#include "Logging.h"
#include <WebCore/ResourceLoadStatistics.h>
namespace WebKit {
using namespace WebCore;
static double vectorLength(unsigned a, unsigned b, unsigned c)
{
return std::hypot(a, b, c);
}
static const auto featureVectorLengthThresholdHigh = 3;
static const auto featureVectorLengthThresholdVeryHigh = 30;
ResourceLoadPrevalence ResourceLoadStatisticsClassifier::calculateResourcePrevalence(const ResourceLoadStatistics& resourceStatistic, ResourceLoadPrevalence currentPrevalence)
{
ASSERT(currentPrevalence != VeryHigh);
auto subresourceUnderTopFrameDomainsCount = resourceStatistic.subresourceUnderTopFrameDomains.size();
auto subresourceUniqueRedirectsToCount = resourceStatistic.subresourceUniqueRedirectsTo.size();
auto subframeUnderTopFrameDomainsCount = resourceStatistic.subframeUnderTopFrameDomains.size();
auto topFrameUniqueRedirectsToCount = resourceStatistic.topFrameUniqueRedirectsTo.size();
return calculateResourcePrevalence(subresourceUnderTopFrameDomainsCount, subresourceUniqueRedirectsToCount, subframeUnderTopFrameDomainsCount, topFrameUniqueRedirectsToCount, currentPrevalence);
}
ResourceLoadPrevalence ResourceLoadStatisticsClassifier::calculateResourcePrevalence(unsigned subresourceUnderTopFrameDomainsCount, unsigned subresourceUniqueRedirectsToCount, unsigned subframeUnderTopFrameDomainsCount, unsigned topFrameUniqueRedirectsToCount, ResourceLoadPrevalence currentPrevalence)
{
if (!subresourceUnderTopFrameDomainsCount
&& !subresourceUniqueRedirectsToCount
&& !subframeUnderTopFrameDomainsCount
&& !topFrameUniqueRedirectsToCount) {
return Low;
}
if (vectorLength(subresourceUnderTopFrameDomainsCount, subresourceUniqueRedirectsToCount, subframeUnderTopFrameDomainsCount) > featureVectorLengthThresholdVeryHigh)
return VeryHigh;
if (currentPrevalence == High
|| subresourceUnderTopFrameDomainsCount > featureVectorLengthThresholdHigh
|| subresourceUniqueRedirectsToCount > featureVectorLengthThresholdHigh
|| subframeUnderTopFrameDomainsCount > featureVectorLengthThresholdHigh
|| topFrameUniqueRedirectsToCount > featureVectorLengthThresholdHigh
|| classify(subresourceUnderTopFrameDomainsCount, subresourceUniqueRedirectsToCount, subframeUnderTopFrameDomainsCount))
return High;
return Low;
}
bool ResourceLoadStatisticsClassifier::classifyWithVectorThreshold(unsigned a, unsigned b, unsigned c)
{
LOG(ResourceLoadStatistics, "ResourceLoadStatisticsClassifier::classifyWithVectorThreshold(): Classified with threshold.");
return vectorLength(a, b, c) > featureVectorLengthThresholdHigh;
}
}