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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 queued_checks_.push_back(std::move(check)); | 509 queued_checks_.push_back(std::move(check)); |
510 return false; | 510 return false; |
511 } | 511 } |
512 | 512 |
513 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; | 513 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; |
514 if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) { | 514 if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) { |
515 return true; | 515 return true; |
516 } | 516 } |
517 | 517 |
518 // Post on the IO thread to enforce async behavior. | 518 // Post on the IO thread to enforce async behavior. |
| 519 pending_clients_.insert(check->client); |
519 BrowserThread::PostTask( | 520 BrowserThread::PostTask( |
520 BrowserThread::IO, FROM_HERE, | 521 BrowserThread::IO, FROM_HERE, |
521 base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this, | 522 base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this, |
522 base::Passed(std::move(check)), | 523 base::Passed(std::move(check)), |
523 full_hash_to_store_and_hash_prefixes)); | 524 full_hash_to_store_and_hash_prefixes)); |
524 | 525 |
525 return false; | 526 return false; |
526 } | 527 } |
527 | 528 |
528 bool V4LocalDatabaseManager::HandleHashSynchronously( | 529 bool V4LocalDatabaseManager::HandleHashSynchronously( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 578 |
578 void V4LocalDatabaseManager::PerformFullHashCheck( | 579 void V4LocalDatabaseManager::PerformFullHashCheck( |
579 std::unique_ptr<PendingCheck> check, | 580 std::unique_ptr<PendingCheck> check, |
580 const FullHashToStoreAndHashPrefixesMap& | 581 const FullHashToStoreAndHashPrefixesMap& |
581 full_hash_to_store_and_hash_prefixes) { | 582 full_hash_to_store_and_hash_prefixes) { |
582 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 583 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
583 | 584 |
584 DCHECK(enabled_); | 585 DCHECK(enabled_); |
585 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); | 586 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); |
586 | 587 |
587 pending_clients_.insert(check->client); | |
588 | |
589 v4_get_hash_protocol_manager_->GetFullHashes( | 588 v4_get_hash_protocol_manager_->GetFullHashes( |
590 full_hash_to_store_and_hash_prefixes, | 589 full_hash_to_store_and_hash_prefixes, |
591 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, | 590 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, |
592 weak_factory_.GetWeakPtr(), base::Passed(std::move(check)))); | 591 weak_factory_.GetWeakPtr(), base::Passed(std::move(check)))); |
593 } | 592 } |
594 | 593 |
595 void V4LocalDatabaseManager::ProcessQueuedChecks() { | 594 void V4LocalDatabaseManager::ProcessQueuedChecks() { |
596 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 595 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
597 for (auto& it : queued_checks_) { | 596 |
| 597 // Steal the queue to protect against reentrant CancelCheck() calls. |
| 598 QueuedChecks checks; |
| 599 checks.swap(queued_checks_); |
| 600 |
| 601 for (auto& it : checks) { |
598 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; | 602 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; |
599 if (!GetPrefixMatches(it, &full_hash_to_store_and_hash_prefixes)) { | 603 if (!GetPrefixMatches(it, &full_hash_to_store_and_hash_prefixes)) { |
600 RespondToClient(std::move(it)); | 604 RespondToClient(std::move(it)); |
601 } else { | 605 } else { |
| 606 pending_clients_.insert(it->client); |
602 PerformFullHashCheck(std::move(it), full_hash_to_store_and_hash_prefixes); | 607 PerformFullHashCheck(std::move(it), full_hash_to_store_and_hash_prefixes); |
603 } | 608 } |
604 } | 609 } |
605 queued_checks_.clear(); | |
606 } | 610 } |
607 | 611 |
608 void V4LocalDatabaseManager::RespondSafeToQueuedChecks() { | 612 void V4LocalDatabaseManager::RespondSafeToQueuedChecks() { |
609 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 613 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
610 for (std::unique_ptr<PendingCheck>& it : queued_checks_) { | 614 |
| 615 // Steal the queue to protect against reentrant CancelCheck() calls. |
| 616 QueuedChecks checks; |
| 617 checks.swap(queued_checks_); |
| 618 |
| 619 for (std::unique_ptr<PendingCheck>& it : checks) { |
611 RespondToClient(std::move(it)); | 620 RespondToClient(std::move(it)); |
612 } | 621 } |
613 queued_checks_.clear(); | |
614 } | 622 } |
615 | 623 |
616 void V4LocalDatabaseManager::RespondToClient( | 624 void V4LocalDatabaseManager::RespondToClient( |
617 std::unique_ptr<PendingCheck> check) { | 625 std::unique_ptr<PendingCheck> check) { |
618 DCHECK(check.get()); | 626 DCHECK(check.get()); |
619 | 627 |
620 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) { | 628 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) { |
621 DCHECK_EQ(1u, check->urls.size()); | 629 DCHECK_EQ(1u, check->urls.size()); |
622 // TODO(vakh): Remove these CHECKs after fixing bugs 660293, 660359. | 630 // TODO(vakh): Remove these CHECKs after fixing bugs 660293, 660359. |
623 CHECK(check.get()); | 631 CHECK(check.get()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 } | 682 } |
675 | 683 |
676 void V4LocalDatabaseManager::UpdateRequestCompleted( | 684 void V4LocalDatabaseManager::UpdateRequestCompleted( |
677 std::unique_ptr<ParsedServerResponse> parsed_server_response) { | 685 std::unique_ptr<ParsedServerResponse> parsed_server_response) { |
678 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 686 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
679 v4_database_->ApplyUpdate(std::move(parsed_server_response), | 687 v4_database_->ApplyUpdate(std::move(parsed_server_response), |
680 db_updated_callback_); | 688 db_updated_callback_); |
681 } | 689 } |
682 | 690 |
683 } // namespace safe_browsing | 691 } // namespace safe_browsing |
OLD | NEW |