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

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

Issue 2675063002: Browser tests for using the new SafeBrowsing protocol (v4) (Closed)
Patch Set: Simplify V4DB creation in product code and tests Created 3 years, 10 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 stores_to_check(stores_to_check) { 123 stores_to_check(stores_to_check) {
124 full_hashes.assign(full_hashes_set.begin(), full_hashes_set.end()); 124 full_hashes.assign(full_hashes_set.begin(), full_hashes_set.end());
125 } 125 }
126 126
127 V4LocalDatabaseManager::PendingCheck::~PendingCheck() {} 127 V4LocalDatabaseManager::PendingCheck::~PendingCheck() {}
128 128
129 // static 129 // static
130 scoped_refptr<V4LocalDatabaseManager> V4LocalDatabaseManager::Create( 130 scoped_refptr<V4LocalDatabaseManager> V4LocalDatabaseManager::Create(
131 const base::FilePath& base_path, 131 const base::FilePath& base_path,
132 ExtendedReportingLevelCallback extended_reporting_level_callback) { 132 ExtendedReportingLevelCallback extended_reporting_level_callback) {
133 if (!V4FeatureList::IsLocalDatabaseManagerEnabled()) {
134 return nullptr;
135 }
136
137 return make_scoped_refptr( 133 return make_scoped_refptr(
138 new V4LocalDatabaseManager(base_path, extended_reporting_level_callback)); 134 new V4LocalDatabaseManager(base_path, extended_reporting_level_callback));
139 } 135 }
140 136
141 V4LocalDatabaseManager::V4LocalDatabaseManager( 137 V4LocalDatabaseManager::V4LocalDatabaseManager(
142 const base::FilePath& base_path, 138 const base::FilePath& base_path,
143 ExtendedReportingLevelCallback extended_reporting_level_callback) 139 ExtendedReportingLevelCallback extended_reporting_level_callback)
144 : base_path_(base_path), 140 : base_path_(base_path),
145 extended_reporting_level_callback_(extended_reporting_level_callback), 141 extended_reporting_level_callback_(extended_reporting_level_callback),
146 list_infos_(GetListInfos()), 142 list_infos_(GetListInfos()),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 url.SchemeIs(url::kFtpScheme); 188 url.SchemeIs(url::kFtpScheme);
193 } 189 }
194 190
195 bool V4LocalDatabaseManager::ChecksAreAlwaysAsync() const { 191 bool V4LocalDatabaseManager::ChecksAreAlwaysAsync() const {
196 return false; 192 return false;
197 } 193 }
198 194
199 bool V4LocalDatabaseManager::CheckBrowseUrl(const GURL& url, Client* client) { 195 bool V4LocalDatabaseManager::CheckBrowseUrl(const GURL& url, Client* client) {
200 DCHECK_CURRENTLY_ON(BrowserThread::IO); 196 DCHECK_CURRENTLY_ON(BrowserThread::IO);
201 197
198 LOG(ERROR) << "V4LocalDatabaseManager::CheckBrowseUrl: url: " << url.spec();
Scott Hess - ex-Googler 2017/02/06 22:46:36 Does everyone need to see these logs?
vakh (use Gerrit instead) 2017/02/06 23:30:13 No, got uploaded by mistake. Removed.
199
202 if (!enabled_ || !CanCheckUrl(url)) { 200 if (!enabled_ || !CanCheckUrl(url)) {
203 return true; 201 return true;
204 } 202 }
205 203
204 LOG(ERROR) << "V4LocalDatabaseManager::CheckBrowseUrl: url: " << url.spec();
206 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( 205 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>(
207 client, ClientCallbackType::CHECK_BROWSE_URL, 206 client, ClientCallbackType::CHECK_BROWSE_URL,
208 StoresToCheck({GetUrlMalwareId(), GetUrlSocEngId(), GetUrlUwsId()}), 207 StoresToCheck({GetUrlMalwareId(), GetUrlSocEngId(), GetUrlUwsId()}),
209 std::vector<GURL>(1, url)); 208 std::vector<GURL>(1, url));
210 209
211 return HandleCheck(std::move(check)); 210 return HandleCheck(std::move(check));
212 } 211 }
213 212
214 bool V4LocalDatabaseManager::CheckDownloadUrl( 213 bool V4LocalDatabaseManager::CheckDownloadUrl(
215 const std::vector<GURL>& url_chain, 214 const std::vector<GURL>& url_chain,
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 check->client_callback_type == ClientCallbackType::CHECK_RESOURCE_URL || 461 check->client_callback_type == ClientCallbackType::CHECK_RESOURCE_URL ||
463 check->client_callback_type == ClientCallbackType::CHECK_EXTENSION_IDS || 462 check->client_callback_type == ClientCallbackType::CHECK_EXTENSION_IDS ||
464 check->client_callback_type == ClientCallbackType::CHECK_OTHER) { 463 check->client_callback_type == ClientCallbackType::CHECK_OTHER) {
465 DCHECK(!check->full_hashes.empty()); 464 DCHECK(!check->full_hashes.empty());
466 465
467 full_hash_to_store_and_hash_prefixes->clear(); 466 full_hash_to_store_and_hash_prefixes->clear();
468 for (const auto& full_hash : check->full_hashes) { 467 for (const auto& full_hash : check->full_hashes) {
469 StoreAndHashPrefixes matched_store_and_hash_prefixes; 468 StoreAndHashPrefixes matched_store_and_hash_prefixes;
470 v4_database_->GetStoresMatchingFullHash(full_hash, check->stores_to_check, 469 v4_database_->GetStoresMatchingFullHash(full_hash, check->stores_to_check,
471 &matched_store_and_hash_prefixes); 470 &matched_store_and_hash_prefixes);
471 LOG(ERROR) << "V4LocalDatabaseManager::GetPrefixMatches: matched: "
472 << !matched_store_and_hash_prefixes.empty();
472 if (!matched_store_and_hash_prefixes.empty()) { 473 if (!matched_store_and_hash_prefixes.empty()) {
473 (*full_hash_to_store_and_hash_prefixes)[full_hash] = 474 (*full_hash_to_store_and_hash_prefixes)[full_hash] =
474 matched_store_and_hash_prefixes; 475 matched_store_and_hash_prefixes;
475 } 476 }
476 } 477 }
477 } else { 478 } else {
478 NOTREACHED() << "Unexpected client_callback_type encountered."; 479 NOTREACHED() << "Unexpected client_callback_type encountered.";
479 } 480 }
480 481
481 // TODO(vakh): Only log SafeBrowsing.V4GetPrefixMatches.Time once PVer3 code 482 // TODO(vakh): Only log SafeBrowsing.V4GetPrefixMatches.Time once PVer3 code
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 auto it = std::find_if( 527 auto it = std::find_if(
527 std::begin(list_infos_), std::end(list_infos_), 528 std::begin(list_infos_), std::end(list_infos_),
528 [&list_id](ListInfo const& li) { return li.list_id() == list_id; }); 529 [&list_id](ListInfo const& li) { return li.list_id() == list_id; });
529 DCHECK(list_infos_.end() != it); 530 DCHECK(list_infos_.end() != it);
530 DCHECK_NE(SB_THREAT_TYPE_SAFE, it->sb_threat_type()); 531 DCHECK_NE(SB_THREAT_TYPE_SAFE, it->sb_threat_type());
531 DCHECK_NE(SB_THREAT_TYPE_UNUSED, it->sb_threat_type()); 532 DCHECK_NE(SB_THREAT_TYPE_UNUSED, it->sb_threat_type());
532 return it->sb_threat_type(); 533 return it->sb_threat_type();
533 } 534 }
534 535
535 bool V4LocalDatabaseManager::HandleCheck(std::unique_ptr<PendingCheck> check) { 536 bool V4LocalDatabaseManager::HandleCheck(std::unique_ptr<PendingCheck> check) {
537 LOG(ERROR) << "V4LocalDatabaseManager::HandleCheck: v4_database_: "
538 << v4_database_.get();
536 if (!v4_database_) { 539 if (!v4_database_) {
537 queued_checks_.push_back(std::move(check)); 540 queued_checks_.push_back(std::move(check));
538 return false; 541 return false;
539 } 542 }
540 543
541 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; 544 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes;
542 if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) { 545 if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) {
546 LOG(ERROR) << "V4LocalDatabaseManager::HandleCheck: No prefix match!";
543 return true; 547 return true;
544 } 548 }
545 549
550 LOG(ERROR) << "V4LocalDatabaseManager::HandleCheck: Prefix(es) matched!";
546 // Add check to pending_checks_ before scheduling PerformFullHashCheck so that 551 // Add check to pending_checks_ before scheduling PerformFullHashCheck so that
547 // even if the client calls CancelCheck before PerformFullHashCheck gets 552 // even if the client calls CancelCheck before PerformFullHashCheck gets
548 // called, the check can be found in pending_checks_. 553 // called, the check can be found in pending_checks_.
549 pending_checks_.insert(check.get()); 554 pending_checks_.insert(check.get());
550 555
551 // Post on the IO thread to enforce async behavior. 556 // Post on the IO thread to enforce async behavior.
552 BrowserThread::PostTask( 557 BrowserThread::PostTask(
553 BrowserThread::IO, FROM_HERE, 558 BrowserThread::IO, FROM_HERE,
554 base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this, 559 base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this,
555 base::Passed(std::move(check)), 560 base::Passed(std::move(check)),
(...skipping 26 matching lines...) Expand all
582 587
583 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; 588 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes;
584 return GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes); 589 return GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes);
585 } 590 }
586 591
587 void V4LocalDatabaseManager::OnFullHashResponse( 592 void V4LocalDatabaseManager::OnFullHashResponse(
588 std::unique_ptr<PendingCheck> check, 593 std::unique_ptr<PendingCheck> check,
589 const std::vector<FullHashInfo>& full_hash_infos) { 594 const std::vector<FullHashInfo>& full_hash_infos) {
590 DCHECK_CURRENTLY_ON(BrowserThread::IO); 595 DCHECK_CURRENTLY_ON(BrowserThread::IO);
591 596
597 LOG(ERROR)
598 << "V4LocalDatabaseManager::OnFullHashResponse: full_hash_infos.size(): "
599 << full_hash_infos.size();
600 LOG(ERROR) << "V4LocalDatabaseManager::OnFullHashResponse: enabled_: "
601 << enabled_;
602
592 if (!enabled_) { 603 if (!enabled_) {
593 DCHECK(pending_checks_.empty()); 604 DCHECK(pending_checks_.empty());
594 return; 605 return;
595 } 606 }
596 607
597 const auto it = pending_checks_.find(check.get()); 608 const auto it = pending_checks_.find(check.get());
598 if (it == pending_checks_.end()) { 609 if (it == pending_checks_.end()) {
599 // The check has since been cancelled. 610 // The check has since been cancelled.
600 return; 611 return;
601 } 612 }
602 613
603 // Find out the most severe threat, if any, to report to the client. 614 // Find out the most severe threat, if any, to report to the client.
604 GetSeverestThreatTypeAndMetadata(&check->result_threat_type, 615 GetSeverestThreatTypeAndMetadata(&check->result_threat_type,
605 &check->url_metadata, 616 &check->url_metadata,
606 &check->matching_full_hash, full_hash_infos); 617 &check->matching_full_hash, full_hash_infos);
618 LOG(ERROR) << "V4LocalDatabaseManager::OnFullHashResponse: "
619 "check->result_threat_type: "
620 << check->result_threat_type;
607 pending_checks_.erase(it); 621 pending_checks_.erase(it);
608 RespondToClient(std::move(check)); 622 RespondToClient(std::move(check));
609 } 623 }
610 624
611 void V4LocalDatabaseManager::PerformFullHashCheck( 625 void V4LocalDatabaseManager::PerformFullHashCheck(
612 std::unique_ptr<PendingCheck> check, 626 std::unique_ptr<PendingCheck> check,
613 const FullHashToStoreAndHashPrefixesMap& 627 const FullHashToStoreAndHashPrefixesMap&
614 full_hash_to_store_and_hash_prefixes) { 628 full_hash_to_store_and_hash_prefixes) {
615 DCHECK_CURRENTLY_ON(BrowserThread::IO); 629 DCHECK_CURRENTLY_ON(BrowserThread::IO);
616 630
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 db_updated_callback_); 742 db_updated_callback_);
729 } 743 }
730 744
731 bool V4LocalDatabaseManager::AreStoresAvailableNow( 745 bool V4LocalDatabaseManager::AreStoresAvailableNow(
732 const StoresToCheck& stores_to_check) const { 746 const StoresToCheck& stores_to_check) const {
733 return enabled_ && v4_database_ && 747 return enabled_ && v4_database_ &&
734 v4_database_->AreStoresAvailable(stores_to_check); 748 v4_database_->AreStoresAvailable(stores_to_check);
735 } 749 }
736 750
737 } // namespace safe_browsing 751 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698