// |hash|, or INVALID if none match.
safe_browsing_util::ListType GetHashThreatListType(
const SBFullHash& hash,
- const std::vector<SBFullHashResult>& full_hashes) {
+ const std::vector<SBFullHashResult>& full_hashes,
+ size_t* index) {
for (size_t i = 0; i < full_hashes.size(); ++i) {
- if (SBFullHashEqual(hash, full_hashes[i].hash))
+ if (SBFullHashEqual(hash, full_hashes[i].hash)) {
+ if (index)
+ *index = i;
return static_cast<safe_browsing_util::ListType>(full_hashes[i].list_id);
+ }
}
return safe_browsing_util::INVALID;
}
// |full_hashes|, or INVALID if none match.
safe_browsing_util::ListType GetUrlThreatListType(
const GURL& url,
- const std::vector<SBFullHashResult>& full_hashes) {
+ const std::vector<SBFullHashResult>& full_hashes,
+ size_t* index) {
if (full_hashes.empty())
return safe_browsing_util::INVALID;
safe_browsing_util::GeneratePatternsToCheck(url, &patterns);
for (size_t i = 0; i < patterns.size(); ++i) {
- safe_browsing_util::ListType threat =
- GetHashThreatListType(SBFullHashForString(patterns[i]), full_hashes);
+ safe_browsing_util::ListType threat = GetHashThreatListType(
+ SBFullHashForString(patterns[i]), full_hashes, index);
if (threat != safe_browsing_util::INVALID)
return threat;
}
SBThreatType SafeBrowsingDatabaseManager::GetHashThreatType(
const SBFullHash& hash,
const std::vector<SBFullHashResult>& full_hashes) {
- return GetThreatTypeFromListType(GetHashThreatListType(hash, full_hashes));
+ return GetThreatTypeFromListType(
+ GetHashThreatListType(hash, full_hashes, NULL));
}
// static
SBThreatType SafeBrowsingDatabaseManager::GetUrlThreatType(
const GURL& url,
- const std::vector<SBFullHashResult>& full_hashes) {
- return GetThreatTypeFromListType(GetUrlThreatListType(url, full_hashes));
+ const std::vector<SBFullHashResult>& full_hashes,
+ size_t* index) {
+ return GetThreatTypeFromListType(
+ GetUrlThreatListType(url, full_hashes, index));
}
SafeBrowsingDatabaseManager::SafeBrowsingCheck::SafeBrowsingCheck(
const std::vector<SBThreatType>& expected_threats)
: urls(urls),
url_results(urls.size(), SB_THREAT_TYPE_SAFE),
+ url_metadata(urls.size()),
full_hashes(full_hashes),
full_hash_results(full_hashes.size(), SB_THREAT_TYPE_SAFE),
client(client),
case safe_browsing_util::MALWARE:
case safe_browsing_util::PHISH:
DCHECK_EQ(1u, check.urls.size());
- OnCheckBrowseUrlResult(check.urls[0], check.url_results[0]);
+ OnCheckBrowseUrlResult(
+ check.urls[0], check.url_results[0], check.url_metadata[0]);
break;
case safe_browsing_util::BINURL:
DCHECK_EQ(check.urls.size(), check.url_results.size());
if (!enabled_)
return;
- HISTOGRAM_COUNTS("SB.QueueDepth", queued_checks_.size());
+ LOCAL_HISTOGRAM_COUNTS("SB.QueueDepth", queued_checks_.size());
if (queued_checks_.empty())
return;
while (!queued_checks_.empty()) {
QueuedCheck check = queued_checks_.front();
DCHECK(!check.start.is_null());
- HISTOGRAM_TIMES("SB.QueueDelay", base::TimeTicks::Now() - check.start);
+ LOCAL_HISTOGRAM_TIMES("SB.QueueDelay",
+ base::TimeTicks::Now() - check.start);
// If CheckUrl() determines the URL is safe immediately, it doesn't call the
// client's handler function (because normally it's being directly called by
// the client). Since we're not the client, we have to convey this result.
// interact well with batching the checks here.
for (size_t i = 0; i < check->urls.size(); ++i) {
- SBThreatType threat = GetUrlThreatType(check->urls[i], full_hashes);
+ size_t threat_index;
+ SBThreatType threat =
+ GetUrlThreatType(check->urls[i], full_hashes, &threat_index);
if (threat != SB_THREAT_TYPE_SAFE &&
IsExpectedThreat(threat, check->expected_threats)) {
check->url_results[i] = threat;
+ check->url_metadata[i] = full_hashes[threat_index].metadata;
is_threat = true;
}
}