Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3376)

Unified Diff: chrome/browser/safe_browsing/database_manager.cc

Issue 586793003: Safebrowsing: Honor the metadata from malware fullhash results in SB API 3.0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes for sky Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/database_manager.cc
diff --git a/chrome/browser/safe_browsing/database_manager.cc b/chrome/browser/safe_browsing/database_manager.cc
index 92bf351aff0f0d9be52f0c936a4d607b4e79ba8c..712271ba657f0c31e19fc9bbd71aed6ef6fae19d 100644
--- a/chrome/browser/safe_browsing/database_manager.cc
+++ b/chrome/browser/safe_browsing/database_manager.cc
@@ -72,10 +72,14 @@ bool IsExpectedThreat(
// |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;
}
@@ -85,7 +89,8 @@ safe_browsing_util::ListType GetHashThreatListType(
// |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;
@@ -93,8 +98,8 @@ safe_browsing_util::ListType GetUrlThreatListType(
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;
}
@@ -123,14 +128,17 @@ SBThreatType GetThreatTypeFromListType(safe_browsing_util::ListType list_type) {
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(
@@ -141,6 +149,7 @@ 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),
@@ -163,7 +172,8 @@ void SafeBrowsingDatabaseManager::Client::OnSafeBrowsingResult(
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());
@@ -942,10 +952,13 @@ bool SafeBrowsingDatabaseManager::HandleOneCheck(
// 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;
}
}
« no previous file with comments | « chrome/browser/safe_browsing/database_manager.h ('k') | chrome/browser/safe_browsing/database_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698