Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database.h

Issue 11196036: Finish conversion from bloom filter to prefix set in safe browsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Delete the unnecessary unit test. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_store.h" 16 #include "chrome/browser/safe_browsing/safe_browsing_store.h"
17 17
18 namespace base { 18 namespace base {
19 class Time; 19 class Time;
20 } 20 }
21 21
22 namespace safe_browsing { 22 namespace safe_browsing {
23 class PrefixSet; 23 class PrefixSet;
24 } 24 }
25 25
26 class BloomFilter;
27 class GURL; 26 class GURL;
28 class MessageLoop; 27 class MessageLoop;
29 class SafeBrowsingDatabase; 28 class SafeBrowsingDatabase;
30 29
31 // Factory for creating SafeBrowsingDatabase. Tests implement this factory 30 // Factory for creating SafeBrowsingDatabase. Tests implement this factory
32 // to create fake Databases for testing. 31 // to create fake Databases for testing.
33 class SafeBrowsingDatabaseFactory { 32 class SafeBrowsingDatabaseFactory {
34 public: 33 public:
35 SafeBrowsingDatabaseFactory() { } 34 SafeBrowsingDatabaseFactory() { }
36 virtual ~SafeBrowsingDatabaseFactory() { } 35 virtual ~SafeBrowsingDatabaseFactory() { }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 virtual void UpdateFinished(bool update_succeeded) = 0; 148 virtual void UpdateFinished(bool update_succeeded) = 0;
150 149
151 // Store the results of a GetHash response. In the case of empty results, we 150 // Store the results of a GetHash response. In the case of empty results, we
152 // cache the prefixes until the next update so that we don't have to issue 151 // cache the prefixes until the next update so that we don't have to issue
153 // further GetHash requests we know will be empty. 152 // further GetHash requests we know will be empty.
154 virtual void CacheHashResults( 153 virtual void CacheHashResults(
155 const std::vector<SBPrefix>& prefixes, 154 const std::vector<SBPrefix>& prefixes,
156 const std::vector<SBFullHashResult>& full_hits) = 0; 155 const std::vector<SBFullHashResult>& full_hits) = 0;
157 156
158 // The name of the bloom-filter file for the given database file. 157 // The name of the bloom-filter file for the given database file.
158 // NOTE(shess): OBSOLETE. Present for deleting stale files.
159 static FilePath BloomFilterForFilename(const FilePath& db_filename); 159 static FilePath BloomFilterForFilename(const FilePath& db_filename);
160 160
161 // The name of the prefix set file for the given database file. 161 // The name of the prefix set file for the given database file.
162 static FilePath PrefixSetForFilename(const FilePath& db_filename); 162 static FilePath PrefixSetForFilename(const FilePath& db_filename);
163 163
164 // Filename for malware and phishing URL database. 164 // Filename for malware and phishing URL database.
165 static FilePath BrowseDBFilename(const FilePath& db_base_filename); 165 static FilePath BrowseDBFilename(const FilePath& db_base_filename);
166 166
167 // Filename for download URL and download binary hash database. 167 // Filename for download URL and download binary hash database.
168 static FilePath DownloadDBFilename(const FilePath& db_base_filename); 168 static FilePath DownloadDBFilename(const FilePath& db_base_filename);
169 169
170 // Filename for client-side phishing detection whitelist databsae. 170 // Filename for client-side phishing detection whitelist databsae.
171 static FilePath CsdWhitelistDBFilename( 171 static FilePath CsdWhitelistDBFilename(
172 const FilePath& csd_whitelist_base_filename); 172 const FilePath& csd_whitelist_base_filename);
173 173
174 // Filename for download whitelist databsae. 174 // Filename for download whitelist databsae.
175 static FilePath DownloadWhitelistDBFilename( 175 static FilePath DownloadWhitelistDBFilename(
176 const FilePath& download_whitelist_base_filename); 176 const FilePath& download_whitelist_base_filename);
177 177
178 // Enumerate failures for histogramming purposes. DO NOT CHANGE THE 178 // Enumerate failures for histogramming purposes. DO NOT CHANGE THE
179 // ORDERING OF THESE VALUES. 179 // ORDERING OF THESE VALUES.
180 enum FailureType { 180 enum FailureType {
181 FAILURE_DATABASE_CORRUPT, 181 FAILURE_DATABASE_CORRUPT,
182 FAILURE_DATABASE_CORRUPT_HANDLER, 182 FAILURE_DATABASE_CORRUPT_HANDLER,
183 FAILURE_BROWSE_DATABASE_UPDATE_BEGIN, 183 FAILURE_BROWSE_DATABASE_UPDATE_BEGIN,
184 FAILURE_BROWSE_DATABASE_UPDATE_FINISH, 184 FAILURE_BROWSE_DATABASE_UPDATE_FINISH,
185 FAILURE_DATABASE_FILTER_MISSING, 185 FAILURE_DATABASE_FILTER_MISSING_OBSOLETE,
186 FAILURE_DATABASE_FILTER_READ, 186 FAILURE_DATABASE_FILTER_READ_OBSOLETE,
187 FAILURE_DATABASE_FILTER_WRITE, 187 FAILURE_DATABASE_FILTER_WRITE_OBSOLETE,
188 FAILURE_DATABASE_FILTER_DELETE, 188 FAILURE_DATABASE_FILTER_DELETE,
189 FAILURE_DATABASE_STORE_MISSING, 189 FAILURE_DATABASE_STORE_MISSING,
190 FAILURE_DATABASE_STORE_DELETE, 190 FAILURE_DATABASE_STORE_DELETE,
191 FAILURE_DOWNLOAD_DATABASE_UPDATE_BEGIN, 191 FAILURE_DOWNLOAD_DATABASE_UPDATE_BEGIN,
192 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH, 192 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH,
193 FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN, 193 FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN,
194 FAILURE_WHITELIST_DATABASE_UPDATE_FINISH, 194 FAILURE_WHITELIST_DATABASE_UPDATE_FINISH,
195 FAILURE_DATABASE_PREFIX_SET_MISSING, 195 FAILURE_DATABASE_PREFIX_SET_MISSING,
196 FAILURE_DATABASE_PREFIX_SET_READ, 196 FAILURE_DATABASE_PREFIX_SET_READ,
197 FAILURE_DATABASE_PREFIX_SET_WRITE, 197 FAILURE_DATABASE_PREFIX_SET_WRITE,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 bool ContainsWhitelistedHashes(const SBWhitelist& whitelist, 268 bool ContainsWhitelistedHashes(const SBWhitelist& whitelist,
269 const std::vector<SBFullHash>& hashes); 269 const std::vector<SBFullHash>& hashes);
270 270
271 // Return the browse_store_, download_store_, download_whitelist_store or 271 // Return the browse_store_, download_store_, download_whitelist_store or
272 // csd_whitelist_store_ based on list_id. 272 // csd_whitelist_store_ based on list_id.
273 SafeBrowsingStore* GetStore(int list_id); 273 SafeBrowsingStore* GetStore(int list_id);
274 274
275 // Deletes the files on disk. 275 // Deletes the files on disk.
276 bool Delete(); 276 bool Delete();
277 277
278 // Load the prefix set or bloom filter off disk, if available. 278 // Load the prefix set off disk, if available.
279 void LoadBloomFilterOrPrefixSet(); 279 void LoadPrefixSet();
280 280
281 // Writes the current prefix set to disk. 281 // Writes the current prefix set to disk.
282 void WritePrefixSet(); 282 void WritePrefixSet();
283 283
284 // Loads the given full-length hashes to the given whitelist. If the number 284 // Loads the given full-length hashes to the given whitelist. If the number
285 // of hashes is too large or if the kill switch URL is on the whitelist 285 // of hashes is too large or if the kill switch URL is on the whitelist
286 // we will whitelist everything. 286 // we will whitelist everything.
287 void LoadWhitelist(const std::vector<SBAddFullHash>& full_hashes, 287 void LoadWhitelist(const std::vector<SBAddFullHash>& full_hashes,
288 SBWhitelist* whitelist); 288 SBWhitelist* whitelist);
289 289
(...skipping 30 matching lines...) Expand all
320 // matching prefixes. 320 // matching prefixes.
321 bool MatchDownloadAddPrefixes(int list_bit, 321 bool MatchDownloadAddPrefixes(int list_bit,
322 const std::vector<SBPrefix>& prefixes, 322 const std::vector<SBPrefix>& prefixes,
323 std::vector<SBPrefix>* prefix_hits); 323 std::vector<SBPrefix>* prefix_hits);
324 324
325 // Used to verify that various calls are made from the thread the 325 // Used to verify that various calls are made from the thread the
326 // object was created on. 326 // object was created on.
327 MessageLoop* creation_loop_; 327 MessageLoop* creation_loop_;
328 328
329 // Lock for protecting access to variables that may be used on the 329 // Lock for protecting access to variables that may be used on the
330 // IO thread. This includes |browse_bloom_filter_|, |prefix_set_|, 330 // IO thread. This includes |prefix_set_|, |full_browse_hashes_|,
331 // |full_browse_hashes_|, |pending_browse_hashes_|, 331 // |pending_browse_hashes_|, |prefix_miss_cache_|, |csd_whitelist_|,
332 // |prefix_miss_cache_|, |csd_whitelist_|, and |csd_whitelist_all_urls_|. 332 // and |csd_whitelist_all_urls_|.
333 base::Lock lookup_lock_; 333 base::Lock lookup_lock_;
334 334
335 // Underlying persistent store for chunk data. 335 // Underlying persistent store for chunk data.
336 // For browsing related (phishing and malware URLs) chunks and prefixes. 336 // For browsing related (phishing and malware URLs) chunks and prefixes.
337 FilePath browse_filename_; 337 FilePath browse_filename_;
338 scoped_ptr<SafeBrowsingStore> browse_store_; 338 scoped_ptr<SafeBrowsingStore> browse_store_;
339 339
340 // For download related (download URL and binary hash) chunks and prefixes. 340 // For download related (download URL and binary hash) chunks and prefixes.
341 FilePath download_filename_; 341 FilePath download_filename_;
342 scoped_ptr<SafeBrowsingStore> download_store_; 342 scoped_ptr<SafeBrowsingStore> download_store_;
343 343
344 // For the client-side phishing detection whitelist chunks and full-length 344 // For the client-side phishing detection whitelist chunks and full-length
345 // hashes. This list only contains 256 bit hashes. 345 // hashes. This list only contains 256 bit hashes.
346 FilePath csd_whitelist_filename_; 346 FilePath csd_whitelist_filename_;
347 scoped_ptr<SafeBrowsingStore> csd_whitelist_store_; 347 scoped_ptr<SafeBrowsingStore> csd_whitelist_store_;
348 348
349 // For the download whitelist chunks and full-length hashes. This list only 349 // For the download whitelist chunks and full-length hashes. This list only
350 // contains 256 bit hashes. 350 // contains 256 bit hashes.
351 FilePath download_whitelist_filename_; 351 FilePath download_whitelist_filename_;
352 scoped_ptr<SafeBrowsingStore> download_whitelist_store_; 352 scoped_ptr<SafeBrowsingStore> download_whitelist_store_;
353 353
354 SBWhitelist csd_whitelist_; 354 SBWhitelist csd_whitelist_;
355 SBWhitelist download_whitelist_; 355 SBWhitelist download_whitelist_;
356 356
357 // Bloom filter generated from the add-prefixes in |browse_store_|.
358 // Only browse_store_ requires the BloomFilter for fast query.
359 // TODO(shess): Do not use, being replaced by prefix_set_.
360 FilePath bloom_filter_filename_;
361 scoped_refptr<BloomFilter> browse_bloom_filter_;
362
363 // Cached browse store related full-hash items, ordered by prefix for 357 // Cached browse store related full-hash items, ordered by prefix for
364 // efficient scanning. 358 // efficient scanning.
365 // |full_browse_hashes_| are items from |browse_store_|, 359 // |full_browse_hashes_| are items from |browse_store_|,
366 // |pending_browse_hashes_| are items from |CacheHashResults()|, which 360 // |pending_browse_hashes_| are items from |CacheHashResults()|, which
367 // will be pushed to the store on the next update. 361 // will be pushed to the store on the next update.
368 std::vector<SBAddFullHash> full_browse_hashes_; 362 std::vector<SBAddFullHash> full_browse_hashes_;
369 std::vector<SBAddFullHash> pending_browse_hashes_; 363 std::vector<SBAddFullHash> pending_browse_hashes_;
370 364
371 // Cache of prefixes that returned empty results (no full hash 365 // Cache of prefixes that returned empty results (no full hash
372 // match) to |CacheHashResults()|. Cached to prevent asking for 366 // match) to |CacheHashResults()|. Cached to prevent asking for
(...skipping 11 matching lines...) Expand all
384 // Set to true if any chunks are added or deleted during an update. 378 // Set to true if any chunks are added or deleted during an update.
385 // Used to optimize away database update. 379 // Used to optimize away database update.
386 bool change_detected_; 380 bool change_detected_;
387 381
388 // Used to check if a prefix was in the database. 382 // Used to check if a prefix was in the database.
389 FilePath prefix_set_filename_; 383 FilePath prefix_set_filename_;
390 scoped_ptr<safe_browsing::PrefixSet> prefix_set_; 384 scoped_ptr<safe_browsing::PrefixSet> prefix_set_;
391 }; 385 };
392 386
393 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 387 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/bloom_filter_unittest.cc ('k') | chrome/browser/safe_browsing/safe_browsing_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698