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 <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 STATS_COUNTER("SB.PrefixAdd", 1); | 848 STATS_COUNTER("SB.PrefixAdd", 1); |
849 store->WriteAddPrefix(encoded_chunk_id, host); | 849 store->WriteAddPrefix(encoded_chunk_id, host); |
850 } else if (entry->IsPrefix()) { | 850 } else if (entry->IsPrefix()) { |
851 // Prefixes only. | 851 // Prefixes only. |
852 for (int i = 0; i < count; i++) { | 852 for (int i = 0; i < count; i++) { |
853 const SBPrefix prefix = entry->PrefixAt(i); | 853 const SBPrefix prefix = entry->PrefixAt(i); |
854 STATS_COUNTER("SB.PrefixAdd", 1); | 854 STATS_COUNTER("SB.PrefixAdd", 1); |
855 store->WriteAddPrefix(encoded_chunk_id, prefix); | 855 store->WriteAddPrefix(encoded_chunk_id, prefix); |
856 } | 856 } |
857 } else { | 857 } else { |
858 // Prefixes and hashes. | 858 // Full hashes only. |
859 const base::Time receive_time = base::Time::Now(); | 859 const base::Time receive_time = base::Time::Now(); |
860 for (int i = 0; i < count; ++i) { | 860 for (int i = 0; i < count; ++i) { |
861 const SBFullHash full_hash = entry->FullHashAt(i); | 861 const SBFullHash full_hash = entry->FullHashAt(i); |
862 const SBPrefix prefix = full_hash.prefix; | |
863 | |
864 STATS_COUNTER("SB.PrefixAdd", 1); | |
865 store->WriteAddPrefix(encoded_chunk_id, prefix); | |
866 | 862 |
867 STATS_COUNTER("SB.PrefixAddFull", 1); | 863 STATS_COUNTER("SB.PrefixAddFull", 1); |
868 store->WriteAddHash(encoded_chunk_id, receive_time, full_hash); | 864 store->WriteAddHash(encoded_chunk_id, receive_time, full_hash); |
869 } | 865 } |
870 } | 866 } |
871 } | 867 } |
872 | 868 |
873 // Helper to iterate over all the entries in the hosts in |chunks| and | 869 // Helper to iterate over all the entries in the hosts in |chunks| and |
874 // add them to the store. | 870 // add them to the store. |
875 void SafeBrowsingDatabaseNew::InsertAddChunks( | 871 void SafeBrowsingDatabaseNew::InsertAddChunks( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 // Prefixes only. | 919 // Prefixes only. |
924 for (int i = 0; i < count; i++) { | 920 for (int i = 0; i < count; i++) { |
925 const SBPrefix prefix = entry->PrefixAt(i); | 921 const SBPrefix prefix = entry->PrefixAt(i); |
926 const int add_chunk_id = | 922 const int add_chunk_id = |
927 EncodeChunkId(entry->ChunkIdAtPrefix(i), list_id); | 923 EncodeChunkId(entry->ChunkIdAtPrefix(i), list_id); |
928 | 924 |
929 STATS_COUNTER("SB.PrefixSub", 1); | 925 STATS_COUNTER("SB.PrefixSub", 1); |
930 store->WriteSubPrefix(encoded_chunk_id, add_chunk_id, prefix); | 926 store->WriteSubPrefix(encoded_chunk_id, add_chunk_id, prefix); |
931 } | 927 } |
932 } else { | 928 } else { |
933 // Prefixes and hashes. | 929 // Full hashes only. |
934 for (int i = 0; i < count; ++i) { | 930 for (int i = 0; i < count; ++i) { |
935 const SBFullHash full_hash = entry->FullHashAt(i); | 931 const SBFullHash full_hash = entry->FullHashAt(i); |
936 const int add_chunk_id = | 932 const int add_chunk_id = |
937 EncodeChunkId(entry->ChunkIdAtPrefix(i), list_id); | 933 EncodeChunkId(entry->ChunkIdAtPrefix(i), list_id); |
938 | 934 |
939 STATS_COUNTER("SB.PrefixSub", 1); | |
940 store->WriteSubPrefix(encoded_chunk_id, add_chunk_id, full_hash.prefix); | |
941 | |
942 STATS_COUNTER("SB.PrefixSubFull", 1); | 935 STATS_COUNTER("SB.PrefixSubFull", 1); |
943 store->WriteSubHash(encoded_chunk_id, add_chunk_id, full_hash); | 936 store->WriteSubHash(encoded_chunk_id, add_chunk_id, full_hash); |
944 } | 937 } |
945 } | 938 } |
946 } | 939 } |
947 | 940 |
948 // Helper to iterate over all the entries in the hosts in |chunks| and | 941 // Helper to iterate over all the entries in the hosts in |chunks| and |
949 // add them to the store. | 942 // add them to the store. |
950 void SafeBrowsingDatabaseNew::InsertSubChunks( | 943 void SafeBrowsingDatabaseNew::InsertSubChunks( |
951 safe_browsing_util::ListType list_id, | 944 safe_browsing_util::ListType list_id, |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1639 base::AutoLock locked(lookup_lock_); | 1632 base::AutoLock locked(lookup_lock_); |
1640 ip_blacklist_.swap(new_blacklist); | 1633 ip_blacklist_.swap(new_blacklist); |
1641 } | 1634 } |
1642 | 1635 |
1643 bool SafeBrowsingDatabaseNew::IsMalwareIPMatchKillSwitchOn() { | 1636 bool SafeBrowsingDatabaseNew::IsMalwareIPMatchKillSwitchOn() { |
1644 SBFullHash malware_kill_switch = SBFullHashForString(kMalwareIPKillSwitchUrl); | 1637 SBFullHash malware_kill_switch = SBFullHashForString(kMalwareIPKillSwitchUrl); |
1645 std::vector<SBFullHash> full_hashes; | 1638 std::vector<SBFullHash> full_hashes; |
1646 full_hashes.push_back(malware_kill_switch); | 1639 full_hashes.push_back(malware_kill_switch); |
1647 return ContainsWhitelistedHashes(csd_whitelist_, full_hashes); | 1640 return ContainsWhitelistedHashes(csd_whitelist_, full_hashes); |
1648 } | 1641 } |
OLD | NEW |