| 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 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 queued_checks_.push_back(std::move(check)); | 528 queued_checks_.push_back(std::move(check)); |
| 529 return false; | 529 return false; |
| 530 } | 530 } |
| 531 | 531 |
| 532 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; | 532 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; |
| 533 if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) { | 533 if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) { |
| 534 return true; | 534 return true; |
| 535 } | 535 } |
| 536 | 536 |
| 537 // Post on the IO thread to enforce async behavior. | 537 // Post on the IO thread to enforce async behavior. |
| 538 pending_clients_.insert(check->client); |
| 538 BrowserThread::PostTask( | 539 BrowserThread::PostTask( |
| 539 BrowserThread::IO, FROM_HERE, | 540 BrowserThread::IO, FROM_HERE, |
| 540 base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this, | 541 base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this, |
| 541 base::Passed(std::move(check)), | 542 base::Passed(std::move(check)), |
| 542 full_hash_to_store_and_hash_prefixes)); | 543 full_hash_to_store_and_hash_prefixes)); |
| 543 | 544 |
| 544 return false; | 545 return false; |
| 545 } | 546 } |
| 546 | 547 |
| 547 bool V4LocalDatabaseManager::HandleHashSynchronously( | 548 bool V4LocalDatabaseManager::HandleHashSynchronously( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 | 597 |
| 597 void V4LocalDatabaseManager::PerformFullHashCheck( | 598 void V4LocalDatabaseManager::PerformFullHashCheck( |
| 598 std::unique_ptr<PendingCheck> check, | 599 std::unique_ptr<PendingCheck> check, |
| 599 const FullHashToStoreAndHashPrefixesMap& | 600 const FullHashToStoreAndHashPrefixesMap& |
| 600 full_hash_to_store_and_hash_prefixes) { | 601 full_hash_to_store_and_hash_prefixes) { |
| 601 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 602 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 602 | 603 |
| 603 DCHECK(enabled_); | 604 DCHECK(enabled_); |
| 604 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); | 605 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); |
| 605 | 606 |
| 606 pending_clients_.insert(check->client); | |
| 607 | |
| 608 v4_get_hash_protocol_manager_->GetFullHashes( | 607 v4_get_hash_protocol_manager_->GetFullHashes( |
| 609 full_hash_to_store_and_hash_prefixes, | 608 full_hash_to_store_and_hash_prefixes, |
| 610 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, | 609 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, |
| 611 weak_factory_.GetWeakPtr(), base::Passed(std::move(check)))); | 610 weak_factory_.GetWeakPtr(), base::Passed(std::move(check)))); |
| 612 } | 611 } |
| 613 | 612 |
| 614 void V4LocalDatabaseManager::ProcessQueuedChecks() { | 613 void V4LocalDatabaseManager::ProcessQueuedChecks() { |
| 615 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 614 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 616 for (auto& it : queued_checks_) { | 615 |
| 616 // Steal the queue to protect against reentrant CancelCheck() calls. |
| 617 QueuedChecks checks; |
| 618 checks.swap(queued_checks_); |
| 619 |
| 620 for (auto& it : checks) { |
| 617 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; | 621 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; |
| 618 if (!GetPrefixMatches(it, &full_hash_to_store_and_hash_prefixes)) { | 622 if (!GetPrefixMatches(it, &full_hash_to_store_and_hash_prefixes)) { |
| 619 RespondToClient(std::move(it)); | 623 RespondToClient(std::move(it)); |
| 620 } else { | 624 } else { |
| 625 pending_clients_.insert(it->client); |
| 621 PerformFullHashCheck(std::move(it), full_hash_to_store_and_hash_prefixes); | 626 PerformFullHashCheck(std::move(it), full_hash_to_store_and_hash_prefixes); |
| 622 } | 627 } |
| 623 } | 628 } |
| 624 queued_checks_.clear(); | |
| 625 } | 629 } |
| 626 | 630 |
| 627 void V4LocalDatabaseManager::RespondSafeToQueuedChecks() { | 631 void V4LocalDatabaseManager::RespondSafeToQueuedChecks() { |
| 628 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 632 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 629 for (std::unique_ptr<PendingCheck>& it : queued_checks_) { | 633 |
| 634 // Steal the queue to protect against reentrant CancelCheck() calls. |
| 635 QueuedChecks checks; |
| 636 checks.swap(queued_checks_); |
| 637 |
| 638 for (std::unique_ptr<PendingCheck>& it : checks) { |
| 630 RespondToClient(std::move(it)); | 639 RespondToClient(std::move(it)); |
| 631 } | 640 } |
| 632 queued_checks_.clear(); | |
| 633 } | 641 } |
| 634 | 642 |
| 635 void V4LocalDatabaseManager::RespondToClient( | 643 void V4LocalDatabaseManager::RespondToClient( |
| 636 std::unique_ptr<PendingCheck> check) { | 644 std::unique_ptr<PendingCheck> check) { |
| 637 DCHECK(check.get()); | 645 DCHECK(check.get()); |
| 638 | 646 |
| 639 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) { | 647 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) { |
| 640 DCHECK_EQ(1u, check->urls.size()); | 648 DCHECK_EQ(1u, check->urls.size()); |
| 641 // TODO(vakh): Remove these CHECKs after fixing bugs 660293, 660359. | 649 // TODO(vakh): Remove these CHECKs after fixing bugs 660293, 660359. |
| 642 CHECK(check.get()); | 650 CHECK(check.get()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 db_updated_callback_); | 707 db_updated_callback_); |
| 700 } | 708 } |
| 701 | 709 |
| 702 bool V4LocalDatabaseManager::AreStoresAvailableNow( | 710 bool V4LocalDatabaseManager::AreStoresAvailableNow( |
| 703 const StoresToCheck& stores_to_check) const { | 711 const StoresToCheck& stores_to_check) const { |
| 704 return enabled_ && v4_database_ && | 712 return enabled_ && v4_database_ && |
| 705 v4_database_->AreStoresAvailable(stores_to_check); | 713 v4_database_->AreStoresAvailable(stores_to_check); |
| 706 } | 714 } |
| 707 | 715 |
| 708 } // namespace safe_browsing | 716 } // namespace safe_browsing |
| OLD | NEW |