Chromium Code Reviews| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 } | 153 } |
| 154 | 154 |
| 155 // | 155 // |
| 156 // Start: SafeBrowsingDatabaseManager implementation | 156 // Start: SafeBrowsingDatabaseManager implementation |
| 157 // | 157 // |
| 158 | 158 |
| 159 void V4LocalDatabaseManager::CancelCheck(Client* client) { | 159 void V4LocalDatabaseManager::CancelCheck(Client* client) { |
| 160 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 160 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 161 DCHECK(enabled_); | 161 DCHECK(enabled_); |
| 162 | 162 |
| 163 auto it = pending_clients_.find(client); | 163 auto pending_it = std::find_if( |
| 164 if (it != pending_clients_.end()) { | 164 std::begin(pending_checks_), std::end(pending_checks_), |
| 165 pending_clients_.erase(it); | 165 [&client](const PendingCheck* check) { return check->client == client; }); |
|
Scott Hess - ex-Googler
2017/01/06 00:42:02
Does capture-by-value (no &) work fine for client,
vakh (use Gerrit instead)
2017/01/09 19:21:32
Done.
| |
| 166 if (pending_it != pending_checks_.end()) { | |
| 167 pending_checks_.erase(pending_it); | |
| 166 } | 168 } |
| 167 | 169 |
| 168 auto queued_it = | 170 auto queued_it = |
| 169 std::find_if(std::begin(queued_checks_), std::end(queued_checks_), | 171 std::find_if(std::begin(queued_checks_), std::end(queued_checks_), |
| 170 [&client](const std::unique_ptr<PendingCheck>& check) { | 172 [&client](const std::unique_ptr<PendingCheck>& check) { |
| 171 return check->client == client; | 173 return check->client == client; |
| 172 }); | 174 }); |
| 173 if (queued_it != queued_checks_.end()) { | 175 if (queued_it != queued_checks_.end()) { |
| 174 queued_checks_.erase(queued_it); | 176 queued_checks_.erase(queued_it); |
| 175 } | 177 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 SetupDatabase(); | 370 SetupDatabase(); |
| 369 | 371 |
| 370 enabled_ = true; | 372 enabled_ = true; |
| 371 } | 373 } |
| 372 | 374 |
| 373 void V4LocalDatabaseManager::StopOnIOThread(bool shutdown) { | 375 void V4LocalDatabaseManager::StopOnIOThread(bool shutdown) { |
| 374 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 376 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 375 | 377 |
| 376 enabled_ = false; | 378 enabled_ = false; |
| 377 | 379 |
| 378 pending_clients_.clear(); | 380 pending_checks_.clear(); |
| 379 | 381 |
| 380 RespondSafeToQueuedChecks(); | 382 RespondSafeToQueuedChecks(); |
| 381 | 383 |
| 382 // Delete the V4Database. Any pending writes to disk are completed. | 384 // Delete the V4Database. Any pending writes to disk are completed. |
| 383 // This operation happens on the task_runner on which v4_database_ operates | 385 // This operation happens on the task_runner on which v4_database_ operates |
| 384 // and doesn't block the IO thread. | 386 // and doesn't block the IO thread. |
| 385 V4Database::Destroy(std::move(v4_database_)); | 387 V4Database::Destroy(std::move(v4_database_)); |
| 386 | 388 |
| 387 // Delete the V4UpdateProtocolManager. | 389 // Delete the V4UpdateProtocolManager. |
| 388 // This cancels any in-flight update request. | 390 // This cancels any in-flight update request. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 if (!v4_database_) { | 529 if (!v4_database_) { |
| 528 queued_checks_.push_back(std::move(check)); | 530 queued_checks_.push_back(std::move(check)); |
| 529 return false; | 531 return false; |
| 530 } | 532 } |
| 531 | 533 |
| 532 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; | 534 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; |
| 533 if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) { | 535 if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) { |
| 534 return true; | 536 return true; |
| 535 } | 537 } |
| 536 | 538 |
| 539 pending_clients_.insert(check->client); | |
|
Scott Hess - ex-Googler
2017/01/06 00:42:02
Something going wrong, here. Perhaps a merge issu
vakh (use Gerrit instead)
2017/01/06 00:43:49
Yup, bad merge. See new patch.
| |
| 537 // Post on the IO thread to enforce async behavior. | 540 // Post on the IO thread to enforce async behavior. |
| 538 pending_clients_.insert(check->client); | |
| 539 BrowserThread::PostTask( | 541 BrowserThread::PostTask( |
| 540 BrowserThread::IO, FROM_HERE, | 542 BrowserThread::IO, FROM_HERE, |
| 541 base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this, | 543 base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this, |
| 542 base::Passed(std::move(check)), | 544 base::Passed(std::move(check)), |
| 543 full_hash_to_store_and_hash_prefixes)); | 545 full_hash_to_store_and_hash_prefixes)); |
| 544 | 546 |
| 545 return false; | 547 return false; |
| 546 } | 548 } |
| 547 | 549 |
| 548 bool V4LocalDatabaseManager::HandleHashSynchronously( | 550 bool V4LocalDatabaseManager::HandleHashSynchronously( |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 565 | 567 |
| 566 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( | 568 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( |
| 567 nullptr, ClientCallbackType::CHECK_OTHER, stores_to_check, | 569 nullptr, ClientCallbackType::CHECK_OTHER, stores_to_check, |
| 568 std::vector<GURL>(1, url)); | 570 std::vector<GURL>(1, url)); |
| 569 | 571 |
| 570 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; | 572 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; |
| 571 return GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes); | 573 return GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes); |
| 572 } | 574 } |
| 573 | 575 |
| 574 void V4LocalDatabaseManager::OnFullHashResponse( | 576 void V4LocalDatabaseManager::OnFullHashResponse( |
| 575 std::unique_ptr<PendingCheck> pending_check, | 577 std::unique_ptr<PendingCheck> check, |
| 576 const std::vector<FullHashInfo>& full_hash_infos) { | 578 const std::vector<FullHashInfo>& full_hash_infos) { |
| 577 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 579 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 578 | 580 |
| 579 if (!enabled_) { | 581 if (!enabled_) { |
| 580 DCHECK(pending_clients_.empty()); | 582 DCHECK(pending_checks_.empty()); |
| 581 return; | 583 return; |
| 582 } | 584 } |
| 583 | 585 |
| 584 const auto it = pending_clients_.find(pending_check->client); | 586 const auto it = pending_checks_.find(check.get()); |
| 585 if (it == pending_clients_.end()) { | 587 if (it == pending_checks_.end()) { |
| 586 // The check has since been cancelled. | 588 // The check has since been cancelled. |
| 587 return; | 589 return; |
| 588 } | 590 } |
| 589 | 591 |
| 590 // Find out the most severe threat, if any, to report to the client. | 592 // Find out the most severe threat, if any, to report to the client. |
| 591 GetSeverestThreatTypeAndMetadata(&pending_check->result_threat_type, | 593 GetSeverestThreatTypeAndMetadata(&check->result_threat_type, |
| 592 &pending_check->url_metadata, | 594 &check->url_metadata, full_hash_infos); |
| 593 full_hash_infos); | 595 pending_checks_.erase(it); |
| 594 pending_clients_.erase(it); | 596 RespondToClient(std::move(check)); |
| 595 RespondToClient(std::move(pending_check)); | |
| 596 } | 597 } |
| 597 | 598 |
| 598 void V4LocalDatabaseManager::PerformFullHashCheck( | 599 void V4LocalDatabaseManager::PerformFullHashCheck( |
| 599 std::unique_ptr<PendingCheck> check, | 600 std::unique_ptr<PendingCheck> check, |
| 600 const FullHashToStoreAndHashPrefixesMap& | 601 const FullHashToStoreAndHashPrefixesMap& |
| 601 full_hash_to_store_and_hash_prefixes) { | 602 full_hash_to_store_and_hash_prefixes) { |
| 602 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 603 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 603 | 604 |
| 604 DCHECK(enabled_); | 605 DCHECK(enabled_); |
| 605 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); | 606 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); |
| 606 | 607 |
| 608 pending_checks_.insert(check.get()); | |
| 609 | |
| 607 v4_get_hash_protocol_manager_->GetFullHashes( | 610 v4_get_hash_protocol_manager_->GetFullHashes( |
| 608 full_hash_to_store_and_hash_prefixes, | 611 full_hash_to_store_and_hash_prefixes, |
| 609 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, | 612 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, |
| 610 weak_factory_.GetWeakPtr(), base::Passed(std::move(check)))); | 613 weak_factory_.GetWeakPtr(), base::Passed(std::move(check)))); |
| 611 } | 614 } |
| 612 | 615 |
| 613 void V4LocalDatabaseManager::ProcessQueuedChecks() { | 616 void V4LocalDatabaseManager::ProcessQueuedChecks() { |
| 614 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 617 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 615 | 618 |
| 616 // Steal the queue to protect against reentrant CancelCheck() calls. | 619 // Steal the queue to protect against reentrant CancelCheck() calls. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 639 RespondToClient(std::move(it)); | 642 RespondToClient(std::move(it)); |
| 640 } | 643 } |
| 641 } | 644 } |
| 642 | 645 |
| 643 void V4LocalDatabaseManager::RespondToClient( | 646 void V4LocalDatabaseManager::RespondToClient( |
| 644 std::unique_ptr<PendingCheck> check) { | 647 std::unique_ptr<PendingCheck> check) { |
| 645 DCHECK(check.get()); | 648 DCHECK(check.get()); |
| 646 | 649 |
| 647 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) { | 650 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) { |
| 648 DCHECK_EQ(1u, check->urls.size()); | 651 DCHECK_EQ(1u, check->urls.size()); |
| 649 // TODO(vakh): Remove these CHECKs after fixing bugs 660293, 660359. | |
| 650 CHECK(check.get()); | |
| 651 CHECK(check->client); | |
| 652 CHECK_LE(1u, check->urls.size()); | |
| 653 CHECK(check->urls[0].is_valid()); | |
| 654 check->client->OnCheckBrowseUrlResult( | 652 check->client->OnCheckBrowseUrlResult( |
| 655 check->urls[0], check->result_threat_type, check->url_metadata); | 653 check->urls[0], check->result_threat_type, check->url_metadata); |
| 656 } else if (check->client_callback_type == | 654 } else if (check->client_callback_type == |
| 657 ClientCallbackType::CHECK_DOWNLOAD_URLS) { | 655 ClientCallbackType::CHECK_DOWNLOAD_URLS) { |
| 658 check->client->OnCheckDownloadUrlResult(check->urls, | 656 check->client->OnCheckDownloadUrlResult(check->urls, |
| 659 check->result_threat_type); | 657 check->result_threat_type); |
| 660 } else if (check->client_callback_type == | 658 } else if (check->client_callback_type == |
| 661 ClientCallbackType::CHECK_EXTENSION_IDS) { | 659 ClientCallbackType::CHECK_EXTENSION_IDS) { |
| 662 const std::set<FullHash> extension_ids(check->full_hashes.begin(), | 660 const std::set<FullHash> extension_ids(check->full_hashes.begin(), |
| 663 check->full_hashes.end()); | 661 check->full_hashes.end()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 db_updated_callback_); | 705 db_updated_callback_); |
| 708 } | 706 } |
| 709 | 707 |
| 710 bool V4LocalDatabaseManager::AreStoresAvailableNow( | 708 bool V4LocalDatabaseManager::AreStoresAvailableNow( |
| 711 const StoresToCheck& stores_to_check) const { | 709 const StoresToCheck& stores_to_check) const { |
| 712 return enabled_ && v4_database_ && | 710 return enabled_ && v4_database_ && |
| 713 v4_database_->AreStoresAvailable(stores_to_check); | 711 v4_database_->AreStoresAvailable(stores_to_check); |
| 714 } | 712 } |
| 715 | 713 |
| 716 } // namespace safe_browsing | 714 } // namespace safe_browsing |
| OLD | NEW |