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 sqrt(a * a + b * b + c * c);
}
static const auto featureVectorLengthThresholdHigh = 3;
static const auto featureVectorLengthThresholdVeryHigh = 30;
ResourceLoadPrevalence ResourceLoadStatisticsClassifier::calculateResourcePrevalence(const ResourceLoadStatistics& resourceStatistic, ResourceLoadPrevalence currentPrevalence)
{
ASSERT(currentPrevalence != VeryHigh);
auto subresourceUnderTopFrameOriginsCount = resourceStatistic.subresourceUnderTopFrameOrigins.size();
auto subresourceUniqueRedirectsToCount = resourceStatistic.subresourceUniqueRedirectsTo.size();
auto subframeUnderTopFrameOriginsCount = resourceStatistic.subframeUnderTopFrameOrigins.size();
auto topFrameUniqueRedirectsToCount = resourceStatistic.topFrameUniqueRedirectsTo.size();
if (!subresourceUnderTopFrameOriginsCount
&& !subresourceUniqueRedirectsToCount
&& !subframeUnderTopFrameOriginsCount
&& !topFrameUniqueRedirectsToCount) {
return Low;
}
if (vectorLength(subresourceUnderTopFrameOriginsCount, subresourceUniqueRedirectsToCount, subframeUnderTopFrameOriginsCount) > featureVectorLengthThresholdVeryHigh)
return VeryHigh;
if (currentPrevalence == High
|| subresourceUnderTopFrameOriginsCount > featureVectorLengthThresholdHigh
|| subresourceUniqueRedirectsToCount > featureVectorLengthThresholdHigh
|| subframeUnderTopFrameOriginsCount > featureVectorLengthThresholdHigh
|| topFrameUniqueRedirectsToCount > featureVectorLengthThresholdHigh
|| classify(subresourceUnderTopFrameOriginsCount, subresourceUniqueRedirectsToCount, subframeUnderTopFrameOriginsCount))
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;
}
}