Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/safe_browsing/database_manager.h" | 5 #include "chrome/browser/safe_browsing/database_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/debug/leak_tracker.h" | 13 #include "base/debug/leak_tracker.h" |
| 14 #include "base/metrics/histogram_macros.h" | |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 17 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/prerender/prerender_field_trial.h" | 21 #include "chrome/browser/prerender/prerender_field_trial.h" |
| 21 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 22 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 22 #include "chrome/browser/safe_browsing/download_protection_service.h" | 23 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 23 #include "chrome/browser/safe_browsing/malware_details.h" | 24 #include "chrome/browser/safe_browsing/malware_details.h" |
| 24 #include "chrome/browser/safe_browsing/protocol_manager.h" | 25 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 25 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 26 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
| 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 27 #include "chrome/browser/safe_browsing/ui_manager.h" | 28 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 28 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
| 29 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 31 #include "components/metrics/metrics_service.h" | |
| 32 #include "components/startup_metric_utils/startup_metric_utils.h" | 32 #include "components/startup_metric_utils/startup_metric_utils.h" |
| 33 #include "components/variations/variations_associated_data.h" | |
| 33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 35 #include "url/url_constants.h" | 36 #include "url/url_constants.h" |
| 36 | 37 |
| 37 using content::BrowserThread; | 38 using content::BrowserThread; |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 // Timeout for match checks, e.g. download URLs, hashes. | 42 // Timeout for match checks, e.g. download URLs, hashes. |
| 42 const int kCheckTimeoutMs = 10000; | 43 const int kCheckTimeoutMs = 10000; |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 | 589 |
| 589 // Cache the GetHash results. | 590 // Cache the GetHash results. |
| 590 if (cache_lifetime != base::TimeDelta() && MakeDatabaseAvailable()) | 591 if (cache_lifetime != base::TimeDelta() && MakeDatabaseAvailable()) |
| 591 database_->CacheHashResults(prefixes, full_hashes, cache_lifetime); | 592 database_->CacheHashResults(prefixes, full_hashes, cache_lifetime); |
| 592 } | 593 } |
| 593 | 594 |
| 594 void SafeBrowsingDatabaseManager::GetChunks(GetChunksCallback callback) { | 595 void SafeBrowsingDatabaseManager::GetChunks(GetChunksCallback callback) { |
| 595 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 596 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 596 DCHECK(enabled_); | 597 DCHECK(enabled_); |
| 597 DCHECK(!callback.is_null()); | 598 DCHECK(!callback.is_null()); |
| 598 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 599 safe_browsing_task_runner_->PostTask( |
| 599 &SafeBrowsingDatabaseManager::GetAllChunksFromDatabase, this, callback)); | 600 FROM_HERE, |
| 601 base::Bind(&SafeBrowsingDatabaseManager::GetAllChunksFromDatabase, this, | |
| 602 callback)); | |
| 600 } | 603 } |
| 601 | 604 |
| 602 void SafeBrowsingDatabaseManager::AddChunks( | 605 void SafeBrowsingDatabaseManager::AddChunks( |
| 603 const std::string& list, | 606 const std::string& list, |
| 604 scoped_ptr<ScopedVector<SBChunkData> > chunks, | 607 scoped_ptr<ScopedVector<SBChunkData> > chunks, |
| 605 AddChunksCallback callback) { | 608 AddChunksCallback callback) { |
| 606 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 609 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 607 DCHECK(enabled_); | 610 DCHECK(enabled_); |
| 608 DCHECK(!callback.is_null()); | 611 DCHECK(!callback.is_null()); |
| 609 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 612 safe_browsing_task_runner_->PostTask( |
| 610 &SafeBrowsingDatabaseManager::AddDatabaseChunks, this, list, | 613 FROM_HERE, base::Bind(&SafeBrowsingDatabaseManager::AddDatabaseChunks, |
| 611 base::Passed(&chunks), callback)); | 614 this, list, base::Passed(&chunks), callback)); |
| 612 } | 615 } |
| 613 | 616 |
| 614 void SafeBrowsingDatabaseManager::DeleteChunks( | 617 void SafeBrowsingDatabaseManager::DeleteChunks( |
| 615 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { | 618 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { |
| 616 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 619 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 617 DCHECK(enabled_); | 620 DCHECK(enabled_); |
| 618 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 621 safe_browsing_task_runner_->PostTask( |
| 619 &SafeBrowsingDatabaseManager::DeleteDatabaseChunks, this, | 622 FROM_HERE, base::Bind(&SafeBrowsingDatabaseManager::DeleteDatabaseChunks, |
| 620 base::Passed(&chunk_deletes))); | 623 this, base::Passed(&chunk_deletes))); |
| 621 } | 624 } |
| 622 | 625 |
| 623 void SafeBrowsingDatabaseManager::UpdateStarted() { | 626 void SafeBrowsingDatabaseManager::UpdateStarted() { |
| 624 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 627 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 625 DCHECK(enabled_); | 628 DCHECK(enabled_); |
| 626 DCHECK(!update_in_progress_); | 629 DCHECK(!update_in_progress_); |
| 627 update_in_progress_ = true; | 630 update_in_progress_ = true; |
| 628 } | 631 } |
| 629 | 632 |
| 630 void SafeBrowsingDatabaseManager::UpdateFinished(bool update_succeeded) { | 633 void SafeBrowsingDatabaseManager::UpdateFinished(bool update_succeeded) { |
| 631 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 634 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 632 DCHECK(enabled_); | 635 DCHECK(enabled_); |
| 633 if (update_in_progress_) { | 636 if (update_in_progress_) { |
| 634 update_in_progress_ = false; | 637 update_in_progress_ = false; |
| 635 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, | 638 safe_browsing_task_runner_->PostTask( |
| 636 base::Bind(&SafeBrowsingDatabaseManager::DatabaseUpdateFinished, | 639 FROM_HERE, |
| 637 this, update_succeeded)); | 640 base::Bind(&SafeBrowsingDatabaseManager::DatabaseUpdateFinished, this, |
| 641 update_succeeded)); | |
| 638 } | 642 } |
| 639 } | 643 } |
| 640 | 644 |
| 641 void SafeBrowsingDatabaseManager::ResetDatabase() { | 645 void SafeBrowsingDatabaseManager::ResetDatabase() { |
| 642 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 646 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 643 DCHECK(enabled_); | 647 DCHECK(enabled_); |
| 644 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 648 safe_browsing_task_runner_->PostTask( |
| 645 &SafeBrowsingDatabaseManager::OnResetDatabase, this)); | 649 FROM_HERE, |
| 650 base::Bind(&SafeBrowsingDatabaseManager::OnResetDatabase, this)); | |
| 646 } | 651 } |
| 647 | 652 |
| 648 void SafeBrowsingDatabaseManager::StartOnIOThread() { | 653 void SafeBrowsingDatabaseManager::StartOnIOThread() { |
| 649 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 654 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 650 if (enabled_) | 655 if (enabled_) |
| 651 return; | 656 return; |
| 652 | 657 |
| 653 DCHECK(!safe_browsing_thread_.get()); | 658 // Use the blocking pool instead of a dedicated thread for safe browsing work, |
|
gab
2015/02/23 16:33:55
This DCHECK ensured StartOnIOThread() was only eve
Alexei Svitkine (slow)
2015/02/23 19:03:27
The "if (enabled_) return;" code suggests that thi
mattm
2015/02/23 19:27:36
Actually the start/stop methods can be called mult
gab
2015/02/23 19:53:32
Right that's what I meant.
gab
2015/02/23 19:53:32
Ah, good point, makes sense to me.
Alexei Svitkine (slow)
2015/02/24 18:08:57
Done.
| |
| 654 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); | 659 // if specified by an experiment. |
| 655 if (!safe_browsing_thread_->Start()) | 660 const std::string sb_threading_mode = |
|
gab
2015/02/23 16:33:55
How about
const bool use_blocking_pool = variati
Alexei Svitkine (slow)
2015/02/23 19:03:27
Done.
| |
| 656 return; | 661 variations::GetVariationParamValue("LightSpeed", "SBThreadingMode"); |
| 662 if (sb_threading_mode == "BlockingPool") { | |
| 663 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | |
| 664 safe_browsing_task_runner_ = | |
| 665 pool->GetSequencedTaskRunnerWithShutdownBehavior( | |
| 666 pool->GetSequenceToken(), | |
| 667 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | |
| 668 } else { | |
| 669 DCHECK(!safe_browsing_thread_.get()); | |
| 670 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); | |
| 671 if (!safe_browsing_thread_->Start()) | |
| 672 return; | |
| 673 safe_browsing_task_runner_ = safe_browsing_thread_->task_runner(); | |
| 674 } | |
| 657 enabled_ = true; | 675 enabled_ = true; |
| 658 | 676 |
| 659 MakeDatabaseAvailable(); | 677 MakeDatabaseAvailable(); |
| 660 } | 678 } |
| 661 | 679 |
| 662 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { | 680 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { |
| 663 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 681 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 664 | 682 |
| 665 DoStopOnIOThread(); | 683 DoStopOnIOThread(); |
| 666 if (shutdown) { | 684 if (shutdown) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 // could start using it on the IO thread and then have the second request | 740 // could start using it on the IO thread and then have the second request |
| 723 // handler delete it out from under us. | 741 // handler delete it out from under us. |
| 724 // * If |database_| is NULL, then either no creation request is in flight, in | 742 // * If |database_| is NULL, then either no creation request is in flight, in |
| 725 // which case we don't need to do anything, or one is in flight, in which | 743 // which case we don't need to do anything, or one is in flight, in which |
| 726 // case the database will be recreated before our deletion request is | 744 // case the database will be recreated before our deletion request is |
| 727 // handled, and could be used on the IO thread in that time period, leading | 745 // handled, and could be used on the IO thread in that time period, leading |
| 728 // to the same problem as above. | 746 // to the same problem as above. |
| 729 // Checking DatabaseAvailable() avoids both of these. | 747 // Checking DatabaseAvailable() avoids both of these. |
| 730 if (DatabaseAvailable()) { | 748 if (DatabaseAvailable()) { |
| 731 closing_database_ = true; | 749 closing_database_ = true; |
| 732 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, | 750 safe_browsing_task_runner_->PostTask( |
| 751 FROM_HERE, | |
| 733 base::Bind(&SafeBrowsingDatabaseManager::OnCloseDatabase, this)); | 752 base::Bind(&SafeBrowsingDatabaseManager::OnCloseDatabase, this)); |
| 734 } | 753 } |
| 735 | 754 |
| 736 // Flush the database thread. Any in-progress database check results will be | 755 // Flush the database thread. Any in-progress database check results will be |
| 737 // ignored and cleaned up below. | 756 // ignored and cleaned up below. |
| 738 // | 757 // |
| 739 // Note that to avoid leaking the database, we rely on the fact that no new | 758 // Note that to avoid leaking the database, we rely on the fact that no new |
| 740 // tasks will be added to the db thread between the call above and this one. | 759 // tasks will be added to the db thread between the call above and this one. |
| 741 // See comments on the declaration of |safe_browsing_thread_|. | 760 // See comments on the declaration of |safe_browsing_thread_|. |
| 742 { | 761 if (safe_browsing_thread_) { |
| 743 // A ScopedAllowIO object is required to join the thread when calling Stop. | 762 // A ScopedAllowIO object is required to join the thread when calling Stop. |
| 744 // See http://crbug.com/72696. Note that we call Stop() first to clear out | 763 // See http://crbug.com/72696. Note that we call Stop() first to clear out |
| 745 // any remaining tasks before clearing safe_browsing_thread_. | 764 // any remaining tasks before clearing safe_browsing_thread_. |
| 746 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; | 765 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; |
| 747 safe_browsing_thread_->Stop(); | 766 safe_browsing_thread_->Stop(); |
| 748 safe_browsing_thread_.reset(); | 767 safe_browsing_thread_.reset(); |
| 749 } | 768 } |
| 750 | 769 |
| 751 // Delete pending checks, calling back any clients with 'SB_THREAT_TYPE_SAFE'. | 770 // Delete pending checks, calling back any clients with 'SB_THREAT_TYPE_SAFE'. |
| 752 // We have to do this after the db thread returns because methods on it can | 771 // We have to do this after the db thread returns because methods on it can |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 766 bool SafeBrowsingDatabaseManager::DatabaseAvailable() const { | 785 bool SafeBrowsingDatabaseManager::DatabaseAvailable() const { |
| 767 base::AutoLock lock(database_lock_); | 786 base::AutoLock lock(database_lock_); |
| 768 return !closing_database_ && (database_ != NULL); | 787 return !closing_database_ && (database_ != NULL); |
| 769 } | 788 } |
| 770 | 789 |
| 771 bool SafeBrowsingDatabaseManager::MakeDatabaseAvailable() { | 790 bool SafeBrowsingDatabaseManager::MakeDatabaseAvailable() { |
| 772 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 791 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 773 DCHECK(enabled_); | 792 DCHECK(enabled_); |
| 774 if (DatabaseAvailable()) | 793 if (DatabaseAvailable()) |
| 775 return true; | 794 return true; |
| 776 safe_browsing_thread_->message_loop()->PostTask( | 795 safe_browsing_task_runner_->PostTask( |
| 777 FROM_HERE, | 796 FROM_HERE, |
| 778 base::Bind(base::IgnoreResult(&SafeBrowsingDatabaseManager::GetDatabase), | 797 base::Bind(base::IgnoreResult(&SafeBrowsingDatabaseManager::GetDatabase), |
| 779 this)); | 798 this)); |
| 780 return false; | 799 return false; |
| 781 } | 800 } |
| 782 | 801 |
| 783 SafeBrowsingDatabase* SafeBrowsingDatabaseManager::GetDatabase() { | 802 SafeBrowsingDatabase* SafeBrowsingDatabaseManager::GetDatabase() { |
| 784 DCHECK_EQ(base::MessageLoop::current(), | 803 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 785 safe_browsing_thread_->message_loop()); | 804 |
| 786 if (database_) | 805 if (database_) |
| 787 return database_; | 806 return database_; |
| 788 startup_metric_utils::ScopedSlowStartupUMA | 807 startup_metric_utils::ScopedSlowStartupUMA |
| 789 scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase"); | 808 scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase"); |
| 790 const base::TimeTicks before = base::TimeTicks::Now(); | 809 const base::TimeTicks before = base::TimeTicks::Now(); |
| 791 | 810 |
| 792 SafeBrowsingDatabase* database = | 811 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create( |
| 793 SafeBrowsingDatabase::Create(enable_download_protection_, | 812 safe_browsing_task_runner_, enable_download_protection_, |
| 794 enable_csd_whitelist_, | 813 enable_csd_whitelist_, enable_download_whitelist_, |
| 795 enable_download_whitelist_, | 814 enable_extension_blacklist_, enable_side_effect_free_whitelist_, |
| 796 enable_extension_blacklist_, | 815 enable_ip_blacklist_, enable_unwanted_software_blacklist_); |
| 797 enable_side_effect_free_whitelist_, | |
| 798 enable_ip_blacklist_, | |
| 799 enable_unwanted_software_blacklist_); | |
| 800 | 816 |
| 801 database->Init(SafeBrowsingService::GetBaseFilename()); | 817 database->Init(SafeBrowsingService::GetBaseFilename()); |
| 802 { | 818 { |
| 803 // Acquiring the lock here guarantees correct ordering between the writes to | 819 // Acquiring the lock here guarantees correct ordering between the writes to |
| 804 // the new database object above, and the setting of |database_| below. | 820 // the new database object above, and the setting of |database_| below. |
| 805 base::AutoLock lock(database_lock_); | 821 base::AutoLock lock(database_lock_); |
| 806 database_ = database; | 822 database_ = database; |
| 807 } | 823 } |
| 808 | 824 |
| 809 BrowserThread::PostTask( | 825 BrowserThread::PostTask( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 is_download); | 877 is_download); |
| 862 } else { | 878 } else { |
| 863 // We may have cached results for previous GetHash queries. Since | 879 // We may have cached results for previous GetHash queries. Since |
| 864 // this data comes from cache, don't histogram hits. | 880 // this data comes from cache, don't histogram hits. |
| 865 HandleOneCheck(check, check->cache_hits); | 881 HandleOneCheck(check, check->cache_hits); |
| 866 } | 882 } |
| 867 } | 883 } |
| 868 | 884 |
| 869 void SafeBrowsingDatabaseManager::GetAllChunksFromDatabase( | 885 void SafeBrowsingDatabaseManager::GetAllChunksFromDatabase( |
| 870 GetChunksCallback callback) { | 886 GetChunksCallback callback) { |
| 871 DCHECK_EQ(base::MessageLoop::current(), | 887 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 872 safe_browsing_thread_->message_loop()); | |
| 873 | 888 |
| 874 bool database_error = true; | 889 bool database_error = true; |
| 875 std::vector<SBListChunkRanges> lists; | 890 std::vector<SBListChunkRanges> lists; |
| 876 DCHECK(!database_update_in_progress_); | 891 DCHECK(!database_update_in_progress_); |
| 877 database_update_in_progress_ = true; | 892 database_update_in_progress_ = true; |
| 878 GetDatabase(); // This guarantees that |database_| is non-NULL. | 893 GetDatabase(); // This guarantees that |database_| is non-NULL. |
| 879 if (database_->UpdateStarted(&lists)) { | 894 if (database_->UpdateStarted(&lists)) { |
| 880 database_error = false; | 895 database_error = false; |
| 881 } else { | 896 } else { |
| 882 database_->UpdateFinished(false); | 897 database_->UpdateFinished(false); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 check.client->OnSafeBrowsingResult(sb_check); | 947 check.client->OnSafeBrowsingResult(sb_check); |
| 933 } | 948 } |
| 934 queued_checks_.pop_front(); | 949 queued_checks_.pop_front(); |
| 935 } | 950 } |
| 936 } | 951 } |
| 937 | 952 |
| 938 void SafeBrowsingDatabaseManager::AddDatabaseChunks( | 953 void SafeBrowsingDatabaseManager::AddDatabaseChunks( |
| 939 const std::string& list_name, | 954 const std::string& list_name, |
| 940 scoped_ptr<ScopedVector<SBChunkData> > chunks, | 955 scoped_ptr<ScopedVector<SBChunkData> > chunks, |
| 941 AddChunksCallback callback) { | 956 AddChunksCallback callback) { |
| 942 DCHECK_EQ(base::MessageLoop::current(), | 957 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 943 safe_browsing_thread_->message_loop()); | |
| 944 if (chunks) | 958 if (chunks) |
| 945 GetDatabase()->InsertChunks(list_name, chunks->get()); | 959 GetDatabase()->InsertChunks(list_name, chunks->get()); |
| 946 BrowserThread::PostTask( | 960 BrowserThread::PostTask( |
| 947 BrowserThread::IO, FROM_HERE, | 961 BrowserThread::IO, FROM_HERE, |
| 948 base::Bind(&SafeBrowsingDatabaseManager::OnAddChunksComplete, this, | 962 base::Bind(&SafeBrowsingDatabaseManager::OnAddChunksComplete, this, |
| 949 callback)); | 963 callback)); |
| 950 } | 964 } |
| 951 | 965 |
| 952 void SafeBrowsingDatabaseManager::DeleteDatabaseChunks( | 966 void SafeBrowsingDatabaseManager::DeleteDatabaseChunks( |
| 953 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { | 967 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { |
| 954 DCHECK_EQ(base::MessageLoop::current(), | 968 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 955 safe_browsing_thread_->message_loop()); | |
| 956 if (chunk_deletes) | 969 if (chunk_deletes) |
| 957 GetDatabase()->DeleteChunks(*chunk_deletes); | 970 GetDatabase()->DeleteChunks(*chunk_deletes); |
| 958 } | 971 } |
| 959 | 972 |
| 960 void SafeBrowsingDatabaseManager::DatabaseUpdateFinished( | 973 void SafeBrowsingDatabaseManager::DatabaseUpdateFinished( |
| 961 bool update_succeeded) { | 974 bool update_succeeded) { |
| 962 DCHECK_EQ(base::MessageLoop::current(), | 975 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 963 safe_browsing_thread_->message_loop()); | |
| 964 GetDatabase()->UpdateFinished(update_succeeded); | 976 GetDatabase()->UpdateFinished(update_succeeded); |
| 965 DCHECK(database_update_in_progress_); | 977 DCHECK(database_update_in_progress_); |
| 966 database_update_in_progress_ = false; | 978 database_update_in_progress_ = false; |
| 967 BrowserThread::PostTask( | 979 BrowserThread::PostTask( |
| 968 BrowserThread::UI, FROM_HERE, | 980 BrowserThread::UI, FROM_HERE, |
| 969 base::Bind(&SafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished, | 981 base::Bind(&SafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished, |
| 970 this, update_succeeded)); | 982 this, update_succeeded)); |
| 971 } | 983 } |
| 972 | 984 |
| 973 void SafeBrowsingDatabaseManager::OnCloseDatabase() { | 985 void SafeBrowsingDatabaseManager::OnCloseDatabase() { |
| 974 DCHECK_EQ(base::MessageLoop::current(), | 986 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 975 safe_browsing_thread_->message_loop()); | |
| 976 DCHECK(closing_database_); | 987 DCHECK(closing_database_); |
| 977 | 988 |
| 978 // Because |closing_database_| is true, nothing on the IO thread will be | 989 // Because |closing_database_| is true, nothing on the IO thread will be |
| 979 // accessing the database, so it's safe to delete and then NULL the pointer. | 990 // accessing the database, so it's safe to delete and then NULL the pointer. |
| 980 delete database_; | 991 delete database_; |
| 981 database_ = NULL; | 992 database_ = NULL; |
| 982 | 993 |
| 983 // Acquiring the lock here guarantees correct ordering between the resetting | 994 // Acquiring the lock here guarantees correct ordering between the resetting |
| 984 // of |database_| above and of |closing_database_| below, which ensures there | 995 // of |database_| above and of |closing_database_| below, which ensures there |
| 985 // won't be a window during which the IO thread falsely believes the database | 996 // won't be a window during which the IO thread falsely believes the database |
| 986 // is available. | 997 // is available. |
| 987 base::AutoLock lock(database_lock_); | 998 base::AutoLock lock(database_lock_); |
| 988 closing_database_ = false; | 999 closing_database_ = false; |
| 989 } | 1000 } |
| 990 | 1001 |
| 991 void SafeBrowsingDatabaseManager::OnResetDatabase() { | 1002 void SafeBrowsingDatabaseManager::OnResetDatabase() { |
| 992 DCHECK_EQ(base::MessageLoop::current(), | 1003 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 993 safe_browsing_thread_->message_loop()); | 1004 |
| 994 GetDatabase()->ResetDatabase(); | 1005 GetDatabase()->ResetDatabase(); |
| 995 } | 1006 } |
| 996 | 1007 |
| 997 void SafeBrowsingDatabaseManager::OnHandleGetHashResults( | 1008 void SafeBrowsingDatabaseManager::OnHandleGetHashResults( |
| 998 SafeBrowsingCheck* check, | 1009 SafeBrowsingCheck* check, |
| 999 const std::vector<SBFullHashResult>& full_hashes) { | 1010 const std::vector<SBFullHashResult>& full_hashes) { |
| 1000 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1011 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1001 safe_browsing_util::ListType check_type = check->check_type; | 1012 safe_browsing_util::ListType check_type = check->check_type; |
| 1002 SBPrefix prefix = check->prefix_hits[0]; | 1013 SBPrefix prefix = check->prefix_hits[0]; |
| 1003 GetHashRequests::iterator it = gethash_requests_.find(prefix); | 1014 GetHashRequests::iterator it = gethash_requests_.find(prefix); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 IsExpectedThreat(threat, check->expected_threats)) { | 1074 IsExpectedThreat(threat, check->expected_threats)) { |
| 1064 check->full_hash_results[i] = threat; | 1075 check->full_hash_results[i] = threat; |
| 1065 is_threat = true; | 1076 is_threat = true; |
| 1066 } | 1077 } |
| 1067 } | 1078 } |
| 1068 | 1079 |
| 1069 SafeBrowsingCheckDone(check); | 1080 SafeBrowsingCheckDone(check); |
| 1070 return is_threat; | 1081 return is_threat; |
| 1071 } | 1082 } |
| 1072 | 1083 |
| 1073 void SafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread( | 1084 void SafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread( |
|
mattm
2015/02/21 02:03:06
Should also keep an eye on SB2.DownloadUrlCheckDur
gab
2015/02/23 16:33:55
Side-note: we are also contemplating reducing thre
Alexei Svitkine (slow)
2015/02/23 19:03:26
Acknowledged.
| |
| 1074 SafeBrowsingCheck* check) { | 1085 SafeBrowsingCheck* check) { |
| 1075 DCHECK_EQ(base::MessageLoop::current(), | 1086 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 1076 safe_browsing_thread_->message_loop()); | |
| 1077 DCHECK(enable_download_protection_); | 1087 DCHECK(enable_download_protection_); |
| 1078 | 1088 |
| 1079 std::vector<SBPrefix> prefix_hits; | 1089 std::vector<SBPrefix> prefix_hits; |
| 1080 | 1090 |
| 1081 if (!database_->ContainsDownloadUrl(check->urls, &prefix_hits)) { | 1091 if (!database_->ContainsDownloadUrl(check->urls, &prefix_hits)) { |
| 1082 // Good, we don't have hash for this url prefix. | 1092 // Good, we don't have hash for this url prefix. |
| 1083 BrowserThread::PostTask( | 1093 BrowserThread::PostTask( |
| 1084 BrowserThread::IO, FROM_HERE, | 1094 BrowserThread::IO, FROM_HERE, |
| 1085 base::Bind(&SafeBrowsingDatabaseManager::CheckDownloadUrlDone, this, | 1095 base::Bind(&SafeBrowsingDatabaseManager::CheckDownloadUrlDone, this, |
| 1086 check)); | 1096 check)); |
| 1087 return; | 1097 return; |
| 1088 } | 1098 } |
| 1089 | 1099 |
| 1090 check->need_get_hash = true; | 1100 check->need_get_hash = true; |
| 1091 check->prefix_hits.clear(); | 1101 check->prefix_hits.clear(); |
| 1092 check->prefix_hits = prefix_hits; | 1102 check->prefix_hits = prefix_hits; |
| 1093 BrowserThread::PostTask( | 1103 BrowserThread::PostTask( |
| 1094 BrowserThread::IO, FROM_HERE, | 1104 BrowserThread::IO, FROM_HERE, |
| 1095 base::Bind(&SafeBrowsingDatabaseManager::OnCheckDone, this, check)); | 1105 base::Bind(&SafeBrowsingDatabaseManager::OnCheckDone, this, check)); |
| 1096 } | 1106 } |
| 1097 | 1107 |
| 1098 void SafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread( | 1108 void SafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread( |
| 1099 SafeBrowsingCheck* check) { | 1109 SafeBrowsingCheck* check) { |
| 1100 DCHECK_EQ(base::MessageLoop::current(), | 1110 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 1101 safe_browsing_thread_->message_loop()); | |
| 1102 | 1111 |
| 1103 std::vector<SBPrefix> prefixes; | 1112 std::vector<SBPrefix> prefixes; |
| 1104 for (std::vector<SBFullHash>::iterator it = check->full_hashes.begin(); | 1113 for (std::vector<SBFullHash>::iterator it = check->full_hashes.begin(); |
| 1105 it != check->full_hashes.end(); ++it) { | 1114 it != check->full_hashes.end(); ++it) { |
| 1106 prefixes.push_back((*it).prefix); | 1115 prefixes.push_back((*it).prefix); |
| 1107 } | 1116 } |
| 1108 database_->ContainsExtensionPrefixes(prefixes, &check->prefix_hits); | 1117 database_->ContainsExtensionPrefixes(prefixes, &check->prefix_hits); |
| 1109 | 1118 |
| 1110 if (check->prefix_hits.empty()) { | 1119 if (check->prefix_hits.empty()) { |
| 1111 // No matches for any extensions. | 1120 // No matches for any extensions. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1162 } | 1171 } |
| 1163 | 1172 |
| 1164 void SafeBrowsingDatabaseManager::StartSafeBrowsingCheck( | 1173 void SafeBrowsingDatabaseManager::StartSafeBrowsingCheck( |
| 1165 SafeBrowsingCheck* check, | 1174 SafeBrowsingCheck* check, |
| 1166 const base::Closure& task) { | 1175 const base::Closure& task) { |
| 1167 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1176 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1168 check->timeout_factory_.reset( | 1177 check->timeout_factory_.reset( |
| 1169 new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); | 1178 new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); |
| 1170 checks_.insert(check); | 1179 checks_.insert(check); |
| 1171 | 1180 |
| 1172 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); | 1181 safe_browsing_task_runner_->PostTask(FROM_HERE, task); |
| 1173 | 1182 |
| 1174 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1183 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 1175 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, | 1184 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, |
| 1176 check->timeout_factory_->GetWeakPtr(), check), | 1185 check->timeout_factory_->GetWeakPtr(), check), |
| 1177 check_timeout_); | 1186 check_timeout_); |
| 1178 } | 1187 } |
| OLD | NEW |