Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 // A SafeBrowsing whitelist contains a list of whitelisted full-hashes (stored | 261 // A SafeBrowsing whitelist contains a list of whitelisted full-hashes (stored |
| 262 // in a sorted vector) as well as a boolean flag indicating whether all | 262 // in a sorted vector) as well as a boolean flag indicating whether all |
| 263 // lookups in the whitelist should be considered matches for safety. | 263 // lookups in the whitelist should be considered matches for safety. |
| 264 typedef std::pair<std::vector<SBFullHash>, bool> SBWhitelist; | 264 typedef std::pair<std::vector<SBFullHash>, bool> SBWhitelist; |
| 265 | 265 |
| 266 // Returns true if the whitelist is disabled or if any of the given hashes | 266 // Returns true if the whitelist is disabled or if any of the given hashes |
| 267 // matches the whitelist. | 267 // matches the whitelist. |
| 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, |
| 272 // csd_whitelist_store_ based on list_id. | 272 // or csd_whitelist_store_ based on list_id. |
|
Scott Hess - ex-Googler
2013/01/11 23:44:05
Egregious formatting change is egregious.
not at google - send to devlin
2013/01/14 23:00:55
Done.
| |
| 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. |
|
Scott Hess - ex-Googler
2013/01/11 23:44:05
Though this one isn't.
| |
| 276 bool Delete(); | 276 bool Delete(); |
| 277 | 277 |
| 278 // Load the prefix set off disk, if available. | 278 // Load the prefix set off disk, if available. |
| 279 void LoadPrefixSet(); | 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 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 296 // |corruption_detected_|, |HandleCorruptDatabase()| posts | 296 // |corruption_detected_|, |HandleCorruptDatabase()| posts |
| 297 // |OnHandleCorruptDatabase()| to the current thread, to be run | 297 // |OnHandleCorruptDatabase()| to the current thread, to be run |
| 298 // after the current task completes. | 298 // after the current task completes. |
| 299 // TODO(shess): Wire things up to entirely abort the update | 299 // TODO(shess): Wire things up to entirely abort the update |
| 300 // transaction when this happens. | 300 // transaction when this happens. |
| 301 void HandleCorruptDatabase(); | 301 void HandleCorruptDatabase(); |
| 302 void OnHandleCorruptDatabase(); | 302 void OnHandleCorruptDatabase(); |
| 303 | 303 |
| 304 // Helpers for InsertChunks(). | 304 // Helpers for InsertChunks(). |
| 305 void InsertAdd(int chunk, SBPrefix host, const SBEntry* entry, int list_id); | 305 void InsertAdd(int chunk, SBPrefix host, const SBEntry* entry, int list_id); |
| 306 void InsertAddChunks(int list_id, const SBChunkList& chunks); | 306 void InsertAddChunks(safe_browsing_util::ListType list_id, |
| 307 const SBChunkList& chunks); | |
| 307 void InsertSub(int chunk, SBPrefix host, const SBEntry* entry, int list_id); | 308 void InsertSub(int chunk, SBPrefix host, const SBEntry* entry, int list_id); |
| 308 void InsertSubChunks(int list_id, const SBChunkList& chunks); | 309 void InsertSubChunks(safe_browsing_util::ListType list_id, |
| 310 const SBChunkList& chunks); | |
| 309 | 311 |
| 310 void UpdateDownloadStore(); | 312 void UpdateDownloadStore(); |
| 311 void UpdateBrowseStore(); | 313 void UpdateBrowseStore(); |
| 312 void UpdateWhitelistStore(const FilePath& store_filename, | 314 void UpdateWhitelistStore(const FilePath& store_filename, |
| 313 SafeBrowsingStore* store, | 315 SafeBrowsingStore* store, |
| 314 SBWhitelist* whitelist); | 316 SBWhitelist* whitelist); |
| 315 | 317 |
| 316 // Helper function to compare addprefixes in download_store_ with |prefixes|. | |
| 317 // The |list_bit| indicates which list (download url or download hash) | |
| 318 // to compare. | |
| 319 // Returns true if there is a match, |*prefix_hits| will contain the actual | |
| 320 // matching prefixes. | |
| 321 bool MatchDownloadAddPrefixes(int list_bit, | |
| 322 const std::vector<SBPrefix>& prefixes, | |
| 323 std::vector<SBPrefix>* prefix_hits); | |
| 324 | |
| 325 // Used to verify that various calls are made from the thread the | 318 // Used to verify that various calls are made from the thread the |
| 326 // object was created on. | 319 // object was created on. |
| 327 MessageLoop* creation_loop_; | 320 MessageLoop* creation_loop_; |
| 328 | 321 |
| 329 // Lock for protecting access to variables that may be used on the | 322 // Lock for protecting access to variables that may be used on the |
| 330 // IO thread. This includes |prefix_set_|, |full_browse_hashes_|, | 323 // IO thread. This includes |prefix_set_|, |full_browse_hashes_|, |
| 331 // |pending_browse_hashes_|, |prefix_miss_cache_|, |csd_whitelist_|, | 324 // |pending_browse_hashes_|, |prefix_miss_cache_|, |csd_whitelist_|, |
| 332 // and |csd_whitelist_all_urls_|. | 325 // and |csd_whitelist_all_urls_|. |
| 333 base::Lock lookup_lock_; | 326 base::Lock lookup_lock_; |
| 334 | 327 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 std::set<SBPrefix> prefix_miss_cache_; | 361 std::set<SBPrefix> prefix_miss_cache_; |
| 369 | 362 |
| 370 // Used to schedule resetting the database because of corruption. | 363 // Used to schedule resetting the database because of corruption. |
| 371 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; | 364 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; |
| 372 | 365 |
| 373 // Set if corruption is detected during the course of an update. | 366 // Set if corruption is detected during the course of an update. |
| 374 // Causes the update functions to fail with no side effects, until | 367 // Causes the update functions to fail with no side effects, until |
| 375 // the next call to |UpdateStarted()|. | 368 // the next call to |UpdateStarted()|. |
| 376 bool corruption_detected_; | 369 bool corruption_detected_; |
| 377 | 370 |
| 378 // Set to true if any chunks are added or deleted during an update. | 371 // Contains the IDs of stores which changed during an update. |
| 379 // Used to optimize away database update. | 372 std::set<safe_browsing_util::ListType> changes_detected_; |
|
Scott Hess - ex-Googler
2013/01/11 23:44:05
As with the earlier CL we were discussing, I still
not at google - send to devlin
2013/01/14 23:00:55
The "external data structure" for extensions is th
Scott Hess - ex-Googler
2013/01/17 19:24:42
The update frequency is once every 45 minutes, and
| |
| 380 bool change_detected_; | |
| 381 | 373 |
| 382 // Used to check if a prefix was in the database. | 374 // Used to check if a prefix was in the database. |
| 383 FilePath prefix_set_filename_; | 375 FilePath prefix_set_filename_; |
| 384 scoped_ptr<safe_browsing::PrefixSet> prefix_set_; | 376 scoped_ptr<safe_browsing::PrefixSet> prefix_set_; |
| 385 }; | 377 }; |
| 386 | 378 |
| 387 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ | 379 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ |
| OLD | NEW |