OLD | NEW |
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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 646 |
643 for (std::unique_ptr<PendingCheck>& it : checks) { | 647 for (std::unique_ptr<PendingCheck>& it : checks) { |
644 RespondToClient(std::move(it)); | 648 RespondToClient(std::move(it)); |
645 } | 649 } |
646 } | 650 } |
647 | 651 |
648 void V4LocalDatabaseManager::RespondToClient( | 652 void V4LocalDatabaseManager::RespondToClient( |
649 std::unique_ptr<PendingCheck> check) { | 653 std::unique_ptr<PendingCheck> check) { |
650 DCHECK(check.get()); | 654 DCHECK(check.get()); |
651 | 655 |
652 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) { | 656 switch (check->client_callback_type) { |
653 DCHECK_EQ(1u, check->urls.size()); | 657 case ClientCallbackType::CHECK_BROWSE_URL: |
654 check->client->OnCheckBrowseUrlResult( | 658 DCHECK_EQ(1u, check->urls.size()); |
655 check->urls[0], check->result_threat_type, check->url_metadata); | 659 check->client->OnCheckBrowseUrlResult( |
656 } else if (check->client_callback_type == | 660 check->urls[0], check->result_threat_type, check->url_metadata); |
657 ClientCallbackType::CHECK_DOWNLOAD_URLS) { | 661 break; |
658 check->client->OnCheckDownloadUrlResult(check->urls, | 662 |
659 check->result_threat_type); | 663 case ClientCallbackType::CHECK_DOWNLOAD_URLS: |
660 } else if (check->client_callback_type == | 664 check->client->OnCheckDownloadUrlResult(check->urls, |
661 ClientCallbackType::CHECK_EXTENSION_IDS) { | 665 check->result_threat_type); |
662 const std::set<FullHash> extension_ids(check->full_hashes.begin(), | 666 break; |
663 check->full_hashes.end()); | 667 |
664 check->client->OnCheckExtensionsResult(extension_ids); | 668 case ClientCallbackType::CHECK_RESOURCE_URL: |
665 } else { | 669 DCHECK_EQ(1u, check->urls.size()); |
666 NOTREACHED() << "Unexpected client_callback_type encountered"; | 670 check->client->OnCheckResourceUrlResult( |
| 671 check->urls[0], check->result_threat_type, check->matching_full_hash); |
| 672 break; |
| 673 |
| 674 case ClientCallbackType::CHECK_EXTENSION_IDS: { |
| 675 const std::set<FullHash> extension_ids(check->full_hashes.begin(), |
| 676 check->full_hashes.end()); |
| 677 check->client->OnCheckExtensionsResult(extension_ids); |
| 678 break; |
| 679 } |
| 680 |
| 681 case ClientCallbackType::CHECK_OTHER: |
| 682 NOTREACHED() << "Unexpected client_callback_type encountered"; |
667 } | 683 } |
668 } | 684 } |
669 | 685 |
670 void V4LocalDatabaseManager::SetupDatabase() { | 686 void V4LocalDatabaseManager::SetupDatabase() { |
671 DCHECK(!base_path_.empty()); | 687 DCHECK(!base_path_.empty()); |
672 DCHECK(!list_infos_.empty()); | 688 DCHECK(!list_infos_.empty()); |
673 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 689 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
674 | 690 |
675 // Only get a new task runner if there isn't one already. If the service has | 691 // Only get a new task runner if there isn't one already. If the service has |
676 // previously been started and stopped, a task runner could already exist. | 692 // previously been started and stopped, a task runner could already exist. |
(...skipping 30 matching lines...) Expand all Loading... |
707 db_updated_callback_); | 723 db_updated_callback_); |
708 } | 724 } |
709 | 725 |
710 bool V4LocalDatabaseManager::AreStoresAvailableNow( | 726 bool V4LocalDatabaseManager::AreStoresAvailableNow( |
711 const StoresToCheck& stores_to_check) const { | 727 const StoresToCheck& stores_to_check) const { |
712 return enabled_ && v4_database_ && | 728 return enabled_ && v4_database_ && |
713 v4_database_->AreStoresAvailable(stores_to_check); | 729 v4_database_->AreStoresAvailable(stores_to_check); |
714 } | 730 } |
715 | 731 |
716 } // namespace safe_browsing | 732 } // namespace safe_browsing |
OLD | NEW |