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

Unified Diff: components/safe_browsing_db/v4_local_database_manager.cc

Issue 2450633003: Small: Implement CheckDownloadUrls -- not called yet. (Closed)
Patch Set: DRY: Don't repeat yourself 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 7b024d35fa4eb52687a5c0c7621fe963bbdbc5b0..141bd35c6b6833ec7bd1047d2d4d04db9fc77183 100644
--- a/components/safe_browsing_db/v4_local_database_manager.cc
+++ b/components/safe_browsing_db/v4_local_database_manager.cc
@@ -65,12 +65,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) {
+ urls(urls) {
DCHECK_GT(ClientCallbackType::CHECK_MAX, client_callback_type);
}
@@ -149,33 +149,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));
Nathan Parker 2016/10/26 00:45:45 nit: Does {url} work here? I'm not sure if that wi
vakh (use Gerrit instead) 2016/10/26 19:53:21 Tried it. MakeUnique doesn't like it very much.
- 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(
@@ -344,9 +337,12 @@ bool V4LocalDatabaseManager::GetPrefixMatches(
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) {
@@ -412,6 +408,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) {
@@ -422,7 +438,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;
@@ -480,8 +496,13 @@ void V4LocalDatabaseManager::RespondToClient(
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";
}

Powered by Google App Engine
This is Rietveld 408576698