This source file includes following definitions.
- AddBooleanFeature
- AddRealFeature
- Clear
#include "chrome/renderer/safe_browsing/features.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
namespace safe_browsing {
const size_t FeatureMap::kMaxFeatureMapSize = 10000;
FeatureMap::FeatureMap() {}
FeatureMap::~FeatureMap() {}
bool FeatureMap::AddBooleanFeature(const std::string& name) {
return AddRealFeature(name, 1.0);
}
bool FeatureMap::AddRealFeature(const std::string& name, double value) {
if (features_.size() >= kMaxFeatureMapSize) {
LOG(ERROR) << "Not adding feature: " << name << " because the "
<< "feature map is too large.";
UMA_HISTOGRAM_COUNTS("SBClientPhishing.TooManyFeatures", 1);
return false;
}
if (value < 0.0 || value > 1.0) {
LOG(ERROR) << "Not adding feature: " << name << " because the value "
<< value << " is not in the range [0.0, 1.0].";
UMA_HISTOGRAM_COUNTS("SBClientPhishing.IllegalFeatureValue", 1);
return false;
}
features_[name] = value;
return true;
}
void FeatureMap::Clear() {
features_.clear();
}
namespace features {
const char kUrlHostIsIpAddress[] = "UrlHostIsIpAddress";
const char kUrlTldToken[] = "UrlTld=";
const char kUrlDomainToken[] = "UrlDomain=";
const char kUrlOtherHostToken[] = "UrlOtherHostToken=";
const char kUrlNumOtherHostTokensGTOne[] = "UrlNumOtherHostTokens>1";
const char kUrlNumOtherHostTokensGTThree[] = "UrlNumOtherHostTokens>3";
const char kUrlPathToken[] = "UrlPathToken=";
const char kPageHasForms[] = "PageHasForms";
const char kPageActionOtherDomainFreq[] = "PageActionOtherDomainFreq";
const char kPageHasTextInputs[] = "PageHasTextInputs";
const char kPageHasPswdInputs[] = "PageHasPswdInputs";
const char kPageHasRadioInputs[] = "PageHasRadioInputs";
const char kPageHasCheckInputs[] = "PageHasCheckInputs";
const char kPageExternalLinksFreq[] = "PageExternalLinksFreq";
const char kPageLinkDomain[] = "PageLinkDomain=";
const char kPageSecureLinksFreq[] = "PageSecureLinksFreq";
const char kPageNumScriptTagsGTOne[] = "PageNumScriptTags>1";
const char kPageNumScriptTagsGTSix[] = "PageNumScriptTags>6";
const char kPageImgOtherDomainFreq[] = "PageImgOtherDomainFreq";
const char kPageTerm[] = "PageTerm=";
}
}