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

Unified Diff: components/safe_browsing_db/v4_local_database_manager.cc

Issue 2450633003: Small: Implement CheckDownloadUrls -- not called yet. (Closed)
Patch Set: Remove histograms change. Will send that as a separate CL. Remove an unused variable. Created 4 years, 2 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: components/safe_browsing_db/v4_local_database_manager.cc
diff --git a/components/safe_browsing_db/v4_local_database_manager.cc b/components/safe_browsing_db/v4_local_database_manager.cc
index 8235225a81ab2b3d9a8a548023a5d3a95249218a..9944d61b5ab60f9acd8548e127200baa02c5cec3 100644
--- a/components/safe_browsing_db/v4_local_database_manager.cc
+++ b/components/safe_browsing_db/v4_local_database_manager.cc
@@ -63,14 +63,12 @@ V4LocalDatabaseManager::PendingCheck::PendingCheck(
Client* client,
ClientCallbackType client_callback_type,
const StoresToCheck& stores_to_check,
- const GURL& url)
+ const std::vector<GURL>& urls)
: client(client),
client_callback_type(client_callback_type),
result_threat_type(SB_THREAT_TYPE_SAFE),
stores_to_check(stores_to_check),
- url(url) {
- DCHECK_GT(ClientCallbackType::CHECK_MAX, client_callback_type);
-}
+ urls(urls) {}
V4LocalDatabaseManager::PendingCheck::~PendingCheck() {}
@@ -147,33 +145,26 @@ bool V4LocalDatabaseManager::CheckBrowseUrl(const GURL& url, Client* client) {
std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>(
client, ClientCallbackType::CHECK_BROWSE_URL,
- StoresToCheck({GetUrlMalwareId(), GetUrlSocEngId(), GetUrlUwsId()}), url);
- if (!v4_database_) {
- queued_checks_.push_back(std::move(check));
- return false;
- }
+ StoresToCheck({GetUrlMalwareId(), GetUrlSocEngId(), GetUrlUwsId()}),
+ std::vector<GURL>(1, url));
- FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes;
- if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) {
- return true;
- }
-
- // Post the task to check full hashes back on the IO thread to follow the
- // documented behavior of CheckBrowseUrl.
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this,
- base::Passed(std::move(check)),
- full_hash_to_store_and_hash_prefixes));
- return false;
+ return HandleCheck(std::move(check));
}
bool V4LocalDatabaseManager::CheckDownloadUrl(
const std::vector<GURL>& url_chain,
Client* client) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- // TODO(vakh): Implement this skeleton.
- return true;
+
+ if (!enabled_ || url_chain.empty()) {
+ return true;
+ }
+
+ std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>(
+ client, ClientCallbackType::CHECK_DOWNLOAD_URLS,
+ StoresToCheck({GetUrlMalBinId()}), url_chain);
+
+ return HandleCheck(std::move(check));
}
bool V4LocalDatabaseManager::CheckExtensionIDs(
@@ -338,13 +329,15 @@ bool V4LocalDatabaseManager::GetPrefixMatches(
DCHECK(enabled_);
DCHECK(v4_database_);
- DCHECK_GT(ClientCallbackType::CHECK_MAX, check->client_callback_type);
full_hash_to_store_and_hash_prefixes->clear();
const base::TimeTicks before = TimeTicks::Now();
- if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) {
+ if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL ||
+ check->client_callback_type == ClientCallbackType::CHECK_DOWNLOAD_URLS) {
std::unordered_set<FullHash> full_hashes;
- V4ProtocolManagerUtil::UrlToFullHashes(check->url, &full_hashes);
+ for (const auto& url : check->urls) {
+ V4ProtocolManagerUtil::UrlToFullHashes(url, &full_hashes);
+ }
StoreAndHashPrefixes matched_store_and_hash_prefixes;
for (const auto& full_hash : full_hashes) {
@@ -410,6 +403,26 @@ SBThreatType V4LocalDatabaseManager::GetSBThreatTypeForList(
return it->sb_threat_type();
}
+bool V4LocalDatabaseManager::HandleCheck(std::unique_ptr<PendingCheck> check) {
+ if (!v4_database_) {
+ queued_checks_.push_back(std::move(check));
+ return false;
+ }
+
+ FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes;
+ if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) {
+ return true;
+ }
+
+ // Post on the IO thread to enforce async behavior.
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this,
+ base::Passed(std::move(check)),
+ full_hash_to_store_and_hash_prefixes));
+ return false;
+}
+
void V4LocalDatabaseManager::OnFullHashResponse(
std::unique_ptr<PendingCheck> pending_check,
const std::vector<FullHashInfo>& full_hash_infos) {
@@ -420,7 +433,7 @@ void V4LocalDatabaseManager::OnFullHashResponse(
return;
}
- auto it = pending_clients_.find(pending_check->client);
+ const auto it = pending_clients_.find(pending_check->client);
if (it == pending_clients_.end()) {
// The check has since been cancelled.
return;
@@ -475,11 +488,15 @@ void V4LocalDatabaseManager::RespondSafeToQueuedChecks() {
void V4LocalDatabaseManager::RespondToClient(
std::unique_ptr<PendingCheck> check) {
DCHECK(check.get());
- DCHECK_GT(ClientCallbackType::CHECK_MAX, check->client_callback_type);
if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) {
- check->client->OnCheckBrowseUrlResult(check->url, check->result_threat_type,
- check->url_metadata);
+ DCHECK_EQ(1u, check->urls.size());
+ check->client->OnCheckBrowseUrlResult(
+ check->urls[0], check->result_threat_type, check->url_metadata);
+ } else if (check->client_callback_type ==
+ ClientCallbackType::CHECK_DOWNLOAD_URLS) {
+ check->client->OnCheckDownloadUrlResult(check->urls,
+ check->result_threat_type);
} else {
NOTREACHED() << "Unexpected client_callback_type encountered";
}
« no previous file with comments | « components/safe_browsing_db/v4_local_database_manager.h ('k') | components/safe_browsing_db/v4_protocol_manager_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698