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/safe_browsing_database.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 } | 786 } |
787 | 787 |
788 bool SafeBrowsingDatabaseNew::ContainsBrowseUrl( | 788 bool SafeBrowsingDatabaseNew::ContainsBrowseUrl( |
789 const GURL& url, | 789 const GURL& url, |
790 std::vector<SBPrefix>* prefix_hits, | 790 std::vector<SBPrefix>* prefix_hits, |
791 std::vector<SBFullHashResult>* cache_hits) { | 791 std::vector<SBFullHashResult>* cache_hits) { |
792 return PrefixSetContainsUrl(url, PrefixSetId::BROWSE, prefix_hits, | 792 return PrefixSetContainsUrl(url, PrefixSetId::BROWSE, prefix_hits, |
793 cache_hits); | 793 cache_hits); |
794 } | 794 } |
795 | 795 |
796 bool SafeBrowsingDatabaseNew::ContainsBrowseHashes( | |
797 const std::vector<SBFullHash>& full_hashes, | |
798 std::vector<SBPrefix>* prefix_hits, | |
799 std::vector<SBFullHashResult>* cache_hits) { | |
800 return PrefixSetContainsUrlHashes(full_hashes, PrefixSetId::BROWSE, | |
801 prefix_hits, cache_hits); | |
802 } | |
803 | |
796 bool SafeBrowsingDatabaseNew::ContainsUnwantedSoftwareUrl( | 804 bool SafeBrowsingDatabaseNew::ContainsUnwantedSoftwareUrl( |
vakh (use Gerrit instead)
2016/01/14 18:57:47
We could completely remove these Contains.*Url met
Joe Mason
2016/01/14 19:24:08
Ack, browser_tests won't even build since the test
| |
797 const GURL& url, | 805 const GURL& url, |
798 std::vector<SBPrefix>* prefix_hits, | 806 std::vector<SBPrefix>* prefix_hits, |
799 std::vector<SBFullHashResult>* cache_hits) { | 807 std::vector<SBFullHashResult>* cache_hits) { |
800 return PrefixSetContainsUrl(url, PrefixSetId::UNWANTED_SOFTWARE, prefix_hits, | 808 return PrefixSetContainsUrl(url, PrefixSetId::UNWANTED_SOFTWARE, prefix_hits, |
801 cache_hits); | 809 cache_hits); |
802 } | 810 } |
803 | 811 |
812 bool SafeBrowsingDatabaseNew::ContainsUnwantedSoftwareHashes( | |
813 const std::vector<SBFullHash>& full_hashes, | |
814 std::vector<SBPrefix>* prefix_hits, | |
815 std::vector<SBFullHashResult>* cache_hits) { | |
816 return PrefixSetContainsUrlHashes(full_hashes, PrefixSetId::UNWANTED_SOFTWARE, | |
817 prefix_hits, cache_hits); | |
818 } | |
819 | |
804 bool SafeBrowsingDatabaseNew::PrefixSetContainsUrl( | 820 bool SafeBrowsingDatabaseNew::PrefixSetContainsUrl( |
805 const GURL& url, | 821 const GURL& url, |
806 PrefixSetId prefix_set_id, | 822 PrefixSetId prefix_set_id, |
807 std::vector<SBPrefix>* prefix_hits, | 823 std::vector<SBPrefix>* prefix_hits, |
808 std::vector<SBFullHashResult>* cache_hits) { | 824 std::vector<SBFullHashResult>* cache_hits) { |
809 // Clear the results first. | |
810 prefix_hits->clear(); | |
811 cache_hits->clear(); | |
812 | |
813 std::vector<SBFullHash> full_hashes; | 825 std::vector<SBFullHash> full_hashes; |
814 UrlToFullHashes(url, false, &full_hashes); | 826 UrlToFullHashes(url, false, &full_hashes); |
815 if (full_hashes.empty()) | |
816 return false; | |
817 | |
818 return PrefixSetContainsUrlHashes(full_hashes, prefix_set_id, prefix_hits, | 827 return PrefixSetContainsUrlHashes(full_hashes, prefix_set_id, prefix_hits, |
819 cache_hits); | 828 cache_hits); |
820 } | 829 } |
821 | 830 |
822 bool SafeBrowsingDatabaseNew::ContainsBrowseUrlHashesForTesting( | |
823 const std::vector<SBFullHash>& full_hashes, | |
824 std::vector<SBPrefix>* prefix_hits, | |
825 std::vector<SBFullHashResult>* cache_hits) { | |
826 return PrefixSetContainsUrlHashes(full_hashes, PrefixSetId::BROWSE, | |
827 prefix_hits, cache_hits); | |
828 } | |
829 | |
830 bool SafeBrowsingDatabaseNew::PrefixSetContainsUrlHashes( | 831 bool SafeBrowsingDatabaseNew::PrefixSetContainsUrlHashes( |
831 const std::vector<SBFullHash>& full_hashes, | 832 const std::vector<SBFullHash>& full_hashes, |
832 PrefixSetId prefix_set_id, | 833 PrefixSetId prefix_set_id, |
833 std::vector<SBPrefix>* prefix_hits, | 834 std::vector<SBPrefix>* prefix_hits, |
834 std::vector<SBFullHashResult>* cache_hits) { | 835 std::vector<SBFullHashResult>* cache_hits) { |
836 // Clear the results first. | |
837 prefix_hits->clear(); | |
838 cache_hits->clear(); | |
839 | |
840 if (full_hashes.empty()) | |
841 return false; | |
842 | |
835 // Used to determine cache expiration. | 843 // Used to determine cache expiration. |
836 const base::Time now = base::Time::Now(); | 844 const base::Time now = base::Time::Now(); |
837 | 845 |
838 { | 846 { |
839 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); | 847 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); |
840 | 848 |
841 // |prefix_set| is empty until it is either read from disk, or the first | 849 // |prefix_set| is empty until it is either read from disk, or the first |
842 // update populates it. Bail out without a hit if not yet available. | 850 // update populates it. Bail out without a hit if not yet available. |
843 const PrefixSet* prefix_set = txn->GetPrefixSet(prefix_set_id); | 851 const PrefixSet* prefix_set = txn->GetPrefixSet(prefix_set_id); |
844 if (!prefix_set) | 852 if (!prefix_set) |
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1765 | 1773 |
1766 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. | 1774 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. |
1767 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( | 1775 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( |
1768 histogram_name, 1, 1000000, 50, | 1776 histogram_name, 1, 1000000, 50, |
1769 base::HistogramBase::kUmaTargetedHistogramFlag); | 1777 base::HistogramBase::kUmaTargetedHistogramFlag); |
1770 | 1778 |
1771 histogram_pointer->Add(file_size_kilobytes); | 1779 histogram_pointer->Add(file_size_kilobytes); |
1772 } | 1780 } |
1773 | 1781 |
1774 } // namespace safe_browsing | 1782 } // namespace safe_browsing |
OLD | NEW |