OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_BLOOM_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_BLOOM_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_BLOOM_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_BLOOM_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <list> | 9 #include <list> |
10 #include <queue> | 10 #include <queue> |
(...skipping 26 matching lines...) Expand all Loading... |
37 // Deletes the current database and creates a new one. | 37 // Deletes the current database and creates a new one. |
38 virtual bool ResetDatabase(); | 38 virtual bool ResetDatabase(); |
39 | 39 |
40 // Returns false if the given url is not in the database. If it returns | 40 // Returns false if the given url is not in the database. If it returns |
41 // true, then either "list" is the name of the matching list, or prefix_hits | 41 // true, then either "list" is the name of the matching list, or prefix_hits |
42 // contains the matching hash prefixes. | 42 // contains the matching hash prefixes. |
43 virtual bool ContainsUrl(const GURL& url, | 43 virtual bool ContainsUrl(const GURL& url, |
44 std::string* matching_list, | 44 std::string* matching_list, |
45 std::vector<SBPrefix>* prefix_hits, | 45 std::vector<SBPrefix>* prefix_hits, |
46 std::vector<SBFullHashResult>* full_hits, | 46 std::vector<SBFullHashResult>* full_hits, |
47 Time last_update); | 47 base::Time last_update); |
48 | 48 |
49 // Processes add/sub commands. Database will free the chunks when it's done. | 49 // Processes add/sub commands. Database will free the chunks when it's done. |
50 virtual void InsertChunks(const std::string& list_name, | 50 virtual void InsertChunks(const std::string& list_name, |
51 std::deque<SBChunk>* chunks); | 51 std::deque<SBChunk>* chunks); |
52 | 52 |
53 // Processs adddel/subdel commands. Database will free chunk_deletes when | 53 // Processs adddel/subdel commands. Database will free chunk_deletes when |
54 // it's done. | 54 // it's done. |
55 virtual void DeleteChunks(std::vector<SBChunkDelete>* chunk_deletes); | 55 virtual void DeleteChunks(std::vector<SBChunkDelete>* chunk_deletes); |
56 | 56 |
57 // Returns the lists and their add/sub chunks. | 57 // Returns the lists and their add/sub chunks. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 void AddDel(int list_id, int add_chunk_id); | 143 void AddDel(int list_id, int add_chunk_id); |
144 | 144 |
145 // Processes a sub-del command, which just removes the sub chunk id from | 145 // Processes a sub-del command, which just removes the sub chunk id from |
146 // our list. | 146 // our list. |
147 void SubDel(const std::string& list_name, int sub_chunk_id); | 147 void SubDel(const std::string& list_name, int sub_chunk_id); |
148 void SubDel(int list_id, int sub_chunk_id); | 148 void SubDel(int list_id, int sub_chunk_id); |
149 | 149 |
150 // Looks up any cached full hashes we may have. | 150 // Looks up any cached full hashes we may have. |
151 void GetCachedFullHashes(const std::vector<SBPrefix>* prefix_hits, | 151 void GetCachedFullHashes(const std::vector<SBPrefix>* prefix_hits, |
152 std::vector<SBFullHashResult>* full_hits, | 152 std::vector<SBFullHashResult>* full_hits, |
153 Time last_update); | 153 base::Time last_update); |
154 | 154 |
155 // Remove cached entries that have prefixes contained in the entry. | 155 // Remove cached entries that have prefixes contained in the entry. |
156 void ClearCachedHashes(const SBEntry* entry); | 156 void ClearCachedHashes(const SBEntry* entry); |
157 | 157 |
158 // Remove all GetHash entries that match the list and chunk id from an AddDel. | 158 // Remove all GetHash entries that match the list and chunk id from an AddDel. |
159 void ClearCachedHashesForChunk(int list_id, int add_chunk_id); | 159 void ClearCachedHashesForChunk(int list_id, int add_chunk_id); |
160 | 160 |
161 void HandleCorruptDatabase(); | 161 void HandleCorruptDatabase(); |
162 void OnHandleCorruptDatabase(); | 162 void OnHandleCorruptDatabase(); |
163 | 163 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 ScopedRunnableMethodFactory<SafeBrowsingDatabaseBloom> reset_factory_; | 223 ScopedRunnableMethodFactory<SafeBrowsingDatabaseBloom> reset_factory_; |
224 | 224 |
225 // Used to schedule resuming from a lower power state. | 225 // Used to schedule resuming from a lower power state. |
226 ScopedRunnableMethodFactory<SafeBrowsingDatabaseBloom> resume_factory_; | 226 ScopedRunnableMethodFactory<SafeBrowsingDatabaseBloom> resume_factory_; |
227 | 227 |
228 // Used for caching GetHash results. | 228 // Used for caching GetHash results. |
229 typedef struct HashCacheEntry { | 229 typedef struct HashCacheEntry { |
230 SBFullHash full_hash; | 230 SBFullHash full_hash; |
231 int list_id; | 231 int list_id; |
232 int add_chunk_id; | 232 int add_chunk_id; |
233 Time received; | 233 base::Time received; |
234 } HashCacheEntry; | 234 } HashCacheEntry; |
235 | 235 |
236 typedef std::list<HashCacheEntry> HashList; | 236 typedef std::list<HashCacheEntry> HashList; |
237 typedef base::hash_map<SBPrefix, HashList> HashCache; | 237 typedef base::hash_map<SBPrefix, HashList> HashCache; |
238 HashCache hash_cache_; | 238 HashCache hash_cache_; |
239 | 239 |
240 // Cache of prefixes that returned empty results (no full hash match). | 240 // Cache of prefixes that returned empty results (no full hash match). |
241 std::set<SBPrefix> prefix_miss_cache_; | 241 std::set<SBPrefix> prefix_miss_cache_; |
242 | 242 |
243 // a cache of all of the existing add and sub chunks | 243 // a cache of all of the existing add and sub chunks |
244 std::set<int> add_chunk_cache_; | 244 std::set<int> add_chunk_cache_; |
245 std::set<int> sub_chunk_cache_; | 245 std::set<int> sub_chunk_cache_; |
246 | 246 |
247 // The number of entries in the add_prefix table. Used to pick the correct | 247 // The number of entries in the add_prefix table. Used to pick the correct |
248 // size for the bloom filter. | 248 // size for the bloom filter. |
249 int add_count_; | 249 int add_count_; |
250 | 250 |
251 // Set to true if the machine just resumed out of a sleep. When this happens, | 251 // Set to true if the machine just resumed out of a sleep. When this happens, |
252 // we pause disk activity for some time to avoid thrashing the system while | 252 // we pause disk activity for some time to avoid thrashing the system while |
253 // it's presumably going to be pretty busy. | 253 // it's presumably going to be pretty busy. |
254 bool did_resume_; | 254 bool did_resume_; |
255 | 255 |
256 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseBloom); | 256 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseBloom); |
257 }; | 257 }; |
258 | 258 |
259 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_BLOOM_H_ | 259 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_BLOOM_H_ |
OLD | NEW |