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

Side by Side Diff: components/safe_browsing_db/v4_local_database_manager.cc

Issue 2622063002: Add the missing callback to client for CheckResourceUrl. (Closed)
Patch Set: nit: fix mistake in rebase Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file should not be build on Android but is currently getting built. 5 // This file should not be build on Android but is currently getting built.
6 // TODO(vakh): Fix that: http://crbug.com/621647 6 // TODO(vakh): Fix that: http://crbug.com/621647
7 7
8 #include "components/safe_browsing_db/v4_local_database_manager.h" 8 #include "components/safe_browsing_db/v4_local_database_manager.h"
9 9
10 #include <vector> 10 #include <vector>
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return true; 232 return true;
233 } 233 }
234 234
235 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( 235 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>(
236 client, ClientCallbackType::CHECK_EXTENSION_IDS, 236 client, ClientCallbackType::CHECK_EXTENSION_IDS,
237 StoresToCheck({GetChromeExtMalwareId()}), extension_ids); 237 StoresToCheck({GetChromeExtMalwareId()}), extension_ids);
238 238
239 return HandleCheck(std::move(check)); 239 return HandleCheck(std::move(check));
240 } 240 }
241 241
242 bool V4LocalDatabaseManager::CheckResourceUrl(const GURL& url, Client* client) { 242 bool V4LocalDatabaseManager::CheckResourceUrl(const GURL& url, Client* client) {
Nathan Parker 2017/01/11 00:13:35 How about a unit test for this?
vakh (use Gerrit instead) 2017/01/11 20:54:34 Done.
243 DCHECK_CURRENTLY_ON(BrowserThread::IO); 243 DCHECK_CURRENTLY_ON(BrowserThread::IO);
244 244
245 StoresToCheck stores_to_check({GetChromeUrlClientIncidentId()}); 245 StoresToCheck stores_to_check({GetChromeUrlClientIncidentId()});
246 246
247 if (!CanCheckUrl(url) || !AreStoresAvailableNow(stores_to_check)) { 247 if (!CanCheckUrl(url) || !AreStoresAvailableNow(stores_to_check)) {
248 // Fail open: Mark resource as safe immediately. 248 // Fail open: Mark resource as safe immediately.
249 // TODO(nparker): This should queue the request if the DB isn't yet 249 // TODO(nparker): This should queue the request if the DB isn't yet
250 // loaded, and later decide if this store is available. 250 // loaded, and later decide if this store is available.
251 // Currently this is the only store that requires full-hash-checks 251 // Currently this is the only store that requires full-hash-checks
252 // AND isn't supported on Chromium, so it's unique. 252 // AND isn't supported on Chromium, so it's unique.
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", diff); 483 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", diff);
484 UMA_HISTOGRAM_CUSTOM_TIMES("SafeBrowsing.V4GetPrefixMatches.Time", diff, 484 UMA_HISTOGRAM_CUSTOM_TIMES("SafeBrowsing.V4GetPrefixMatches.Time", diff,
485 base::TimeDelta::FromMicroseconds(20), 485 base::TimeDelta::FromMicroseconds(20),
486 base::TimeDelta::FromSeconds(1), 50); 486 base::TimeDelta::FromSeconds(1), 50);
487 return !full_hash_to_store_and_hash_prefixes->empty(); 487 return !full_hash_to_store_and_hash_prefixes->empty();
488 } 488 }
489 489
490 void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata( 490 void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata(
491 SBThreatType* result_threat_type, 491 SBThreatType* result_threat_type,
492 ThreatMetadata* metadata, 492 ThreatMetadata* metadata,
493 FullHash* matching_full_hash,
493 const std::vector<FullHashInfo>& full_hash_infos) { 494 const std::vector<FullHashInfo>& full_hash_infos) {
494 DCHECK(result_threat_type); 495 DCHECK(result_threat_type);
495 DCHECK(metadata); 496 DCHECK(metadata);
497 DCHECK(matching_full_hash);
496 498
497 ThreatSeverity most_severe_yet = kLeastSeverity; 499 ThreatSeverity most_severe_yet = kLeastSeverity;
498 for (const FullHashInfo& fhi : full_hash_infos) { 500 for (const FullHashInfo& fhi : full_hash_infos) {
499 ThreatSeverity severity = GetThreatSeverity(fhi.list_id); 501 ThreatSeverity severity = GetThreatSeverity(fhi.list_id);
500 if (severity < most_severe_yet) { 502 if (severity < most_severe_yet) {
501 most_severe_yet = severity; 503 most_severe_yet = severity;
502 *result_threat_type = GetSBThreatTypeForList(fhi.list_id); 504 *result_threat_type = GetSBThreatTypeForList(fhi.list_id);
503 *metadata = fhi.metadata; 505 *metadata = fhi.metadata;
506 *matching_full_hash = fhi.full_hash;
504 } 507 }
505 } 508 }
506 } 509 }
507 510
508 StoresToCheck V4LocalDatabaseManager::GetStoresForFullHashRequests() { 511 StoresToCheck V4LocalDatabaseManager::GetStoresForFullHashRequests() {
509 StoresToCheck stores_for_full_hash; 512 StoresToCheck stores_for_full_hash;
510 for (auto it : list_infos_) { 513 for (auto it : list_infos_) {
511 stores_for_full_hash.insert(it.list_id()); 514 stores_for_full_hash.insert(it.list_id());
512 } 515 }
513 return stores_for_full_hash; 516 return stores_for_full_hash;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 591 }
589 592
590 const auto it = pending_checks_.find(check.get()); 593 const auto it = pending_checks_.find(check.get());
591 if (it == pending_checks_.end()) { 594 if (it == pending_checks_.end()) {
592 // The check has since been cancelled. 595 // The check has since been cancelled.
593 return; 596 return;
594 } 597 }
595 598
596 // Find out the most severe threat, if any, to report to the client. 599 // Find out the most severe threat, if any, to report to the client.
597 GetSeverestThreatTypeAndMetadata(&check->result_threat_type, 600 GetSeverestThreatTypeAndMetadata(&check->result_threat_type,
598 &check->url_metadata, full_hash_infos); 601 &check->url_metadata,
602 &check->matching_full_hash, full_hash_infos);
599 pending_checks_.erase(it); 603 pending_checks_.erase(it);
600 RespondToClient(std::move(check)); 604 RespondToClient(std::move(check));
601 } 605 }
602 606
603 void V4LocalDatabaseManager::PerformFullHashCheck( 607 void V4LocalDatabaseManager::PerformFullHashCheck(
604 std::unique_ptr<PendingCheck> check, 608 std::unique_ptr<PendingCheck> check,
605 const FullHashToStoreAndHashPrefixesMap& 609 const FullHashToStoreAndHashPrefixesMap&
606 full_hash_to_store_and_hash_prefixes) { 610 full_hash_to_store_and_hash_prefixes) {
607 DCHECK_CURRENTLY_ON(BrowserThread::IO); 611 DCHECK_CURRENTLY_ON(BrowserThread::IO);
608 612
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 check->urls[0], check->result_threat_type, check->url_metadata); 659 check->urls[0], check->result_threat_type, check->url_metadata);
656 } else if (check->client_callback_type == 660 } else if (check->client_callback_type ==
657 ClientCallbackType::CHECK_DOWNLOAD_URLS) { 661 ClientCallbackType::CHECK_DOWNLOAD_URLS) {
658 check->client->OnCheckDownloadUrlResult(check->urls, 662 check->client->OnCheckDownloadUrlResult(check->urls,
659 check->result_threat_type); 663 check->result_threat_type);
660 } else if (check->client_callback_type == 664 } else if (check->client_callback_type ==
661 ClientCallbackType::CHECK_EXTENSION_IDS) { 665 ClientCallbackType::CHECK_EXTENSION_IDS) {
662 const std::set<FullHash> extension_ids(check->full_hashes.begin(), 666 const std::set<FullHash> extension_ids(check->full_hashes.begin(),
663 check->full_hashes.end()); 667 check->full_hashes.end());
664 check->client->OnCheckExtensionsResult(extension_ids); 668 check->client->OnCheckExtensionsResult(extension_ids);
669 } else if (check->client_callback_type ==
670 ClientCallbackType::CHECK_RESOURCE_URL) {
671 DCHECK_EQ(1u, check->urls.size());
672 check->client->OnCheckResourceUrlResult(
673 check->urls[0], check->result_threat_type, check->matching_full_hash);
665 } else { 674 } else {
666 NOTREACHED() << "Unexpected client_callback_type encountered"; 675 NOTREACHED() << "Unexpected client_callback_type encountered";
667 } 676 }
668 } 677 }
669 678
670 void V4LocalDatabaseManager::SetupDatabase() { 679 void V4LocalDatabaseManager::SetupDatabase() {
671 DCHECK(!base_path_.empty()); 680 DCHECK(!base_path_.empty());
672 DCHECK(!list_infos_.empty()); 681 DCHECK(!list_infos_.empty());
673 DCHECK_CURRENTLY_ON(BrowserThread::IO); 682 DCHECK_CURRENTLY_ON(BrowserThread::IO);
674 683
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 db_updated_callback_); 716 db_updated_callback_);
708 } 717 }
709 718
710 bool V4LocalDatabaseManager::AreStoresAvailableNow( 719 bool V4LocalDatabaseManager::AreStoresAvailableNow(
711 const StoresToCheck& stores_to_check) const { 720 const StoresToCheck& stores_to_check) const {
712 return enabled_ && v4_database_ && 721 return enabled_ && v4_database_ &&
713 v4_database_->AreStoresAvailable(stores_to_check); 722 v4_database_->AreStoresAvailable(stores_to_check);
714 } 723 }
715 724
716 } // namespace safe_browsing 725 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698