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

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

Issue 2742913002: PVer4: Filter out the safe crxs before calling OnCheckExtensionsResult (Closed)
Patch Set: Fix date format Created 3 years, 9 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 } // namespace 105 } // namespace
106 106
107 V4LocalDatabaseManager::PendingCheck::PendingCheck( 107 V4LocalDatabaseManager::PendingCheck::PendingCheck(
108 Client* client, 108 Client* client,
109 ClientCallbackType client_callback_type, 109 ClientCallbackType client_callback_type,
110 const StoresToCheck& stores_to_check, 110 const StoresToCheck& stores_to_check,
111 const std::vector<GURL>& urls) 111 const std::vector<GURL>& urls)
112 : client(client), 112 : client(client),
113 client_callback_type(client_callback_type), 113 client_callback_type(client_callback_type),
114 result_threat_type(SB_THREAT_TYPE_SAFE), 114 most_severe_threat_type(SB_THREAT_TYPE_SAFE),
115 stores_to_check(stores_to_check), 115 stores_to_check(stores_to_check),
116 urls(urls) { 116 urls(urls) {
117 for (const auto& url : urls) { 117 for (const auto& url : urls) {
118 V4ProtocolManagerUtil::UrlToFullHashes(url, &full_hashes); 118 V4ProtocolManagerUtil::UrlToFullHashes(url, &full_hashes);
119 } 119 }
120 DCHECK(full_hashes.size());
121 full_hash_threat_types.assign(full_hashes.size(), SB_THREAT_TYPE_SAFE);
120 } 122 }
121 123
122 V4LocalDatabaseManager::PendingCheck::PendingCheck( 124 V4LocalDatabaseManager::PendingCheck::PendingCheck(
123 Client* client, 125 Client* client,
124 ClientCallbackType client_callback_type, 126 ClientCallbackType client_callback_type,
125 const StoresToCheck& stores_to_check, 127 const StoresToCheck& stores_to_check,
126 const std::set<FullHash>& full_hashes_set) 128 const std::set<FullHash>& full_hashes_set)
127 : client(client), 129 : client(client),
128 client_callback_type(client_callback_type), 130 client_callback_type(client_callback_type),
129 result_threat_type(SB_THREAT_TYPE_SAFE), 131 most_severe_threat_type(SB_THREAT_TYPE_SAFE),
130 stores_to_check(stores_to_check) { 132 stores_to_check(stores_to_check) {
131 full_hashes.assign(full_hashes_set.begin(), full_hashes_set.end()); 133 full_hashes.assign(full_hashes_set.begin(), full_hashes_set.end());
134 DCHECK(full_hashes.size());
135 full_hash_threat_types.assign(full_hashes.size(), SB_THREAT_TYPE_SAFE);
132 } 136 }
133 137
134 V4LocalDatabaseManager::PendingCheck::~PendingCheck() {} 138 V4LocalDatabaseManager::PendingCheck::~PendingCheck() {}
135 139
136 // static 140 // static
137 scoped_refptr<V4LocalDatabaseManager> V4LocalDatabaseManager::Create( 141 scoped_refptr<V4LocalDatabaseManager> V4LocalDatabaseManager::Create(
138 const base::FilePath& base_path, 142 const base::FilePath& base_path,
139 ExtendedReportingLevelCallback extended_reporting_level_callback) { 143 ExtendedReportingLevelCallback extended_reporting_level_callback) {
140 return make_scoped_refptr( 144 return make_scoped_refptr(
141 new V4LocalDatabaseManager(base_path, extended_reporting_level_callback)); 145 new V4LocalDatabaseManager(base_path, extended_reporting_level_callback));
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 // searching the three CHECK_BROWSE_URL stores. 500 // searching the three CHECK_BROWSE_URL stores.
497 base::TimeDelta diff = TimeTicks::Now() - before; 501 base::TimeDelta diff = TimeTicks::Now() - before;
498 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", diff); 502 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", diff);
499 UMA_HISTOGRAM_CUSTOM_TIMES("SafeBrowsing.V4GetPrefixMatches.Time", diff, 503 UMA_HISTOGRAM_CUSTOM_TIMES("SafeBrowsing.V4GetPrefixMatches.Time", diff,
500 base::TimeDelta::FromMicroseconds(20), 504 base::TimeDelta::FromMicroseconds(20),
501 base::TimeDelta::FromSeconds(1), 50); 505 base::TimeDelta::FromSeconds(1), 50);
502 return !full_hash_to_store_and_hash_prefixes->empty(); 506 return !full_hash_to_store_and_hash_prefixes->empty();
503 } 507 }
504 508
505 void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata( 509 void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata(
506 SBThreatType* result_threat_type, 510 const std::vector<FullHashInfo>& full_hash_infos,
511 const std::vector<FullHash>& full_hashes,
512 std::vector<SBThreatType>* full_hash_threat_types,
513 SBThreatType* most_severe_threat_type,
507 ThreatMetadata* metadata, 514 ThreatMetadata* metadata,
508 FullHash* matching_full_hash, 515 FullHash* matching_full_hash) {
509 const std::vector<FullHashInfo>& full_hash_infos) {
510 DCHECK(result_threat_type);
511 DCHECK(metadata);
512 DCHECK(matching_full_hash);
513
514 ThreatSeverity most_severe_yet = kLeastSeverity; 516 ThreatSeverity most_severe_yet = kLeastSeverity;
515 for (const FullHashInfo& fhi : full_hash_infos) { 517 for (const FullHashInfo& fhi : full_hash_infos) {
516 ThreatSeverity severity = GetThreatSeverity(fhi.list_id); 518 ThreatSeverity severity = GetThreatSeverity(fhi.list_id);
519 SBThreatType threat_type = GetSBThreatTypeForList(fhi.list_id);
520
521 const auto& it =
522 std::find(full_hashes.begin(), full_hashes.end(), fhi.full_hash);
523 DCHECK(it != full_hashes.end());
524 (*full_hash_threat_types)[it - full_hashes.begin()] = threat_type;
525
517 if (severity < most_severe_yet) { 526 if (severity < most_severe_yet) {
518 most_severe_yet = severity; 527 most_severe_yet = severity;
519 *result_threat_type = GetSBThreatTypeForList(fhi.list_id); 528 *most_severe_threat_type = threat_type;
520 *metadata = fhi.metadata; 529 *metadata = fhi.metadata;
521 *matching_full_hash = fhi.full_hash; 530 *matching_full_hash = fhi.full_hash;
522 } 531 }
523 } 532 }
524 } 533 }
525 534
526 StoresToCheck V4LocalDatabaseManager::GetStoresForFullHashRequests() { 535 StoresToCheck V4LocalDatabaseManager::GetStoresForFullHashRequests() {
527 StoresToCheck stores_for_full_hash; 536 StoresToCheck stores_for_full_hash;
528 for (auto it : list_infos_) { 537 for (auto it : list_infos_) {
529 stores_for_full_hash.insert(it.list_id()); 538 stores_for_full_hash.insert(it.list_id());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 return; 614 return;
606 } 615 }
607 616
608 const auto it = pending_checks_.find(check.get()); 617 const auto it = pending_checks_.find(check.get());
609 if (it == pending_checks_.end()) { 618 if (it == pending_checks_.end()) {
610 // The check has since been cancelled. 619 // The check has since been cancelled.
611 return; 620 return;
612 } 621 }
613 622
614 // Find out the most severe threat, if any, to report to the client. 623 // Find out the most severe threat, if any, to report to the client.
615 GetSeverestThreatTypeAndMetadata(&check->result_threat_type, 624 GetSeverestThreatTypeAndMetadata(
616 &check->url_metadata, 625 full_hash_infos, check->full_hashes, &check->full_hash_threat_types,
617 &check->matching_full_hash, full_hash_infos); 626 &check->most_severe_threat_type, &check->url_metadata,
627 &check->matching_full_hash);
618 pending_checks_.erase(it); 628 pending_checks_.erase(it);
619 RespondToClient(std::move(check)); 629 RespondToClient(std::move(check));
620 } 630 }
621 631
622 void V4LocalDatabaseManager::PerformFullHashCheck( 632 void V4LocalDatabaseManager::PerformFullHashCheck(
623 std::unique_ptr<PendingCheck> check, 633 std::unique_ptr<PendingCheck> check,
624 const FullHashToStoreAndHashPrefixesMap& 634 const FullHashToStoreAndHashPrefixesMap&
625 full_hash_to_store_and_hash_prefixes) { 635 full_hash_to_store_and_hash_prefixes) {
626 DCHECK_CURRENTLY_ON(BrowserThread::IO); 636 DCHECK_CURRENTLY_ON(BrowserThread::IO);
627 637
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 676
667 void V4LocalDatabaseManager::RespondToClient( 677 void V4LocalDatabaseManager::RespondToClient(
668 std::unique_ptr<PendingCheck> check) { 678 std::unique_ptr<PendingCheck> check) {
669 DCHECK(check.get()); 679 DCHECK(check.get());
670 680
671 switch (check->client_callback_type) { 681 switch (check->client_callback_type) {
672 case ClientCallbackType::CHECK_BROWSE_URL: 682 case ClientCallbackType::CHECK_BROWSE_URL:
673 case ClientCallbackType::CHECK_URL_FOR_SUBRESOURCE_FILTER: 683 case ClientCallbackType::CHECK_URL_FOR_SUBRESOURCE_FILTER:
674 DCHECK_EQ(1u, check->urls.size()); 684 DCHECK_EQ(1u, check->urls.size());
675 check->client->OnCheckBrowseUrlResult( 685 check->client->OnCheckBrowseUrlResult(
676 check->urls[0], check->result_threat_type, check->url_metadata); 686 check->urls[0], check->most_severe_threat_type, check->url_metadata);
677 break; 687 break;
678 688
679 case ClientCallbackType::CHECK_DOWNLOAD_URLS: 689 case ClientCallbackType::CHECK_DOWNLOAD_URLS:
680 check->client->OnCheckDownloadUrlResult(check->urls, 690 check->client->OnCheckDownloadUrlResult(check->urls,
681 check->result_threat_type); 691 check->most_severe_threat_type);
682 break; 692 break;
683 693
684 case ClientCallbackType::CHECK_RESOURCE_URL: 694 case ClientCallbackType::CHECK_RESOURCE_URL:
685 DCHECK_EQ(1u, check->urls.size()); 695 DCHECK_EQ(1u, check->urls.size());
686 check->client->OnCheckResourceUrlResult( 696 check->client->OnCheckResourceUrlResult(check->urls[0],
687 check->urls[0], check->result_threat_type, check->matching_full_hash); 697 check->most_severe_threat_type,
698 check->matching_full_hash);
688 break; 699 break;
689 700
690 case ClientCallbackType::CHECK_EXTENSION_IDS: { 701 case ClientCallbackType::CHECK_EXTENSION_IDS: {
691 const std::set<FullHash> extension_ids(check->full_hashes.begin(), 702 DCHECK_EQ(check->full_hash_threat_types.size(),
692 check->full_hashes.end()); 703 check->full_hashes.size());
693 check->client->OnCheckExtensionsResult(extension_ids); 704 std::set<FullHash> unsafe_extension_ids;
705 for (size_t i = 0; i < check->full_hash_threat_types.size(); i++) {
706 if (check->full_hash_threat_types[i] == SB_THREAT_TYPE_EXTENSION) {
707 unsafe_extension_ids.insert(check->full_hashes[i]);
708 }
709 }
710 check->client->OnCheckExtensionsResult(unsafe_extension_ids);
694 break; 711 break;
695 } 712 }
696 case ClientCallbackType::CHECK_OTHER: 713 case ClientCallbackType::CHECK_OTHER:
697 NOTREACHED() << "Unexpected client_callback_type encountered"; 714 NOTREACHED() << "Unexpected client_callback_type encountered";
698 } 715 }
699 } 716 }
700 717
701 void V4LocalDatabaseManager::SetupDatabase() { 718 void V4LocalDatabaseManager::SetupDatabase() {
702 DCHECK(!base_path_.empty()); 719 DCHECK(!base_path_.empty());
703 DCHECK(!list_infos_.empty()); 720 DCHECK(!list_infos_.empty());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 db_updated_callback_); 756 db_updated_callback_);
740 } 757 }
741 758
742 bool V4LocalDatabaseManager::AreStoresAvailableNow( 759 bool V4LocalDatabaseManager::AreStoresAvailableNow(
743 const StoresToCheck& stores_to_check) const { 760 const StoresToCheck& stores_to_check) const {
744 return enabled_ && v4_database_ && 761 return enabled_ && v4_database_ &&
745 v4_database_->AreStoresAvailable(stores_to_check); 762 v4_database_->AreStoresAvailable(stores_to_check);
746 } 763 }
747 764
748 } // namespace safe_browsing 765 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698