| 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 <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 // Init()). | 493 // Init()). |
| 494 void LoadPrefixSet(const base::FilePath& db_filename, | 494 void LoadPrefixSet(const base::FilePath& db_filename, |
| 495 ThreadSafeStateManager::WriteTransaction* txn, | 495 ThreadSafeStateManager::WriteTransaction* txn, |
| 496 PrefixSetId prefix_set_id, | 496 PrefixSetId prefix_set_id, |
| 497 FailureType read_failure_type); | 497 FailureType read_failure_type); |
| 498 | 498 |
| 499 // Writes the current prefix set "|db_filename| Prefix Set" on disk. | 499 // Writes the current prefix set "|db_filename| Prefix Set" on disk. |
| 500 // |write_failure_type| provides a caller-specific error code to be used on | 500 // |write_failure_type| provides a caller-specific error code to be used on |
| 501 // failure. | 501 // failure. |
| 502 void WritePrefixSet(const base::FilePath& db_filename, | 502 void WritePrefixSet(const base::FilePath& db_filename, |
| 503 const safe_browsing::PrefixSet* prefix_set, | 503 PrefixSetId prefix_set_id, |
| 504 FailureType write_failure_type); | 504 FailureType write_failure_type); |
| 505 | 505 |
| 506 // Loads the given full-length hashes to the given whitelist. If the number | 506 // Loads the given full-length hashes to the given whitelist. If the number |
| 507 // of hashes is too large or if the kill switch URL is on the whitelist | 507 // of hashes is too large or if the kill switch URL is on the whitelist |
| 508 // we will whitelist everything. | 508 // we will whitelist everything. |
| 509 void LoadWhitelist(const std::vector<SBAddFullHash>& full_hashes, | 509 void LoadWhitelist(const std::vector<SBAddFullHash>& full_hashes, |
| 510 SBWhitelistId whitelist_id); | 510 SBWhitelistId whitelist_id); |
| 511 | 511 |
| 512 // Parses the IP blacklist from the given full-length hashes. | 512 // Parses the IP blacklist from the given full-length hashes. |
| 513 void LoadIpBlacklist(const std::vector<SBAddFullHash>& full_hashes); | 513 void LoadIpBlacklist(const std::vector<SBAddFullHash>& full_hashes); |
| 514 | 514 |
| 515 // Helpers for handling database corruption. | 515 // Helpers for handling database corruption. |
| 516 // |OnHandleCorruptDatabase()| runs |ResetDatabase()| and sets | 516 // |OnHandleCorruptDatabase()| runs |ResetDatabase()| and sets |
| 517 // |corruption_detected_|, |HandleCorruptDatabase()| posts | 517 // |corruption_detected_|, |HandleCorruptDatabase()| posts |
| 518 // |OnHandleCorruptDatabase()| to the current thread, to be run | 518 // |OnHandleCorruptDatabase()| to the current thread, to be run |
| 519 // after the current task completes. | 519 // after the current task completes. |
| 520 // TODO(shess): Wire things up to entirely abort the update | 520 // TODO(shess): Wire things up to entirely abort the update |
| 521 // transaction when this happens. | 521 // transaction when this happens. |
| 522 void HandleCorruptDatabase(); | 522 void HandleCorruptDatabase(); |
| 523 void OnHandleCorruptDatabase(); | 523 void OnHandleCorruptDatabase(); |
| 524 | 524 |
| 525 // Helpers for InsertChunks(). | 525 // Helpers for InsertChunks(). |
| 526 void InsertAddChunk(SafeBrowsingStore* store, | 526 void InsertAddChunk(SafeBrowsingStore* store, |
| 527 safe_browsing_util::ListType list_id, | 527 safe_browsing_util::ListType list_id, |
| 528 const SBChunkData& chunk); | 528 const SBChunkData& chunk); |
| 529 void InsertSubChunk(SafeBrowsingStore* store, | 529 void InsertSubChunk(SafeBrowsingStore* store, |
| 530 safe_browsing_util::ListType list_id, | 530 safe_browsing_util::ListType list_id, |
| 531 const SBChunkData& chunk); | 531 const SBChunkData& chunk); |
| 532 | 532 |
| 533 // Returns the size in bytes of the store after the update. | 533 // Updates the |store| and stores the result on disk under |store_filename|. |
| 534 int64 UpdateHashPrefixStore(const base::FilePath& store_filename, | 534 void UpdateHashPrefixStore(const base::FilePath& store_filename, |
| 535 SafeBrowsingStore* store, | 535 SafeBrowsingStore* store, |
| 536 FailureType failure_type); | 536 FailureType failure_type); |
| 537 | 537 |
| 538 // Updates a PrefixStore store for URLs (|url_store|) which is backed on disk | 538 // Updates a PrefixStore store for URLs (|url_store|) which is backed on disk |
| 539 // by a "|db_filename| Prefix Set" file. Specific failure types are provided | 539 // by a "|db_filename| Prefix Set" file. Specific failure types are provided |
| 540 // to highlight the specific store who made the initial request on failure. | 540 // to highlight the specific store who made the initial request on failure. |
| 541 // |store_full_hashes_in_prefix_set| dictates whether full_hashes from the | 541 // |store_full_hashes_in_prefix_set| dictates whether full_hashes from the |
| 542 // |url_store| should be cached in the |prefix_set| as well. | 542 // |url_store| should be cached in the |prefix_set| as well. |
| 543 void UpdatePrefixSetUrlStore(const base::FilePath& db_filename, | 543 void UpdatePrefixSetUrlStore(const base::FilePath& db_filename, |
| 544 SafeBrowsingStore* url_store, | 544 SafeBrowsingStore* url_store, |
| 545 PrefixSetId prefix_set_id, | 545 PrefixSetId prefix_set_id, |
| 546 FailureType finish_failure_type, | 546 FailureType finish_failure_type, |
| 547 FailureType write_failure_type, | 547 FailureType write_failure_type, |
| 548 bool store_full_hashes_in_prefix_set); | 548 bool store_full_hashes_in_prefix_set); |
| 549 | 549 |
| 550 void UpdateUrlStore(SafeBrowsingStore* url_store, | 550 void UpdateUrlStore(SafeBrowsingStore* url_store, |
| 551 PrefixSetId prefix_set_id, | 551 PrefixSetId prefix_set_id, |
| 552 FailureType failure_type); | 552 FailureType failure_type); |
| 553 | 553 |
| 554 void UpdateWhitelistStore(const base::FilePath& store_filename, | 554 void UpdateWhitelistStore(const base::FilePath& store_filename, |
| 555 SafeBrowsingStore* store, | 555 SafeBrowsingStore* store, |
| 556 SBWhitelistId whitelist_id); | 556 SBWhitelistId whitelist_id); |
| 557 void UpdateIpBlacklistStore(); | 557 void UpdateIpBlacklistStore(); |
| 558 | 558 |
| 559 // Returns a raw pointer to ThreadSafeStateManager's PrefixGetHashCache for | 559 // Returns a raw pointer to ThreadSafeStateManager's PrefixGetHashCache for |
| 560 // testing. This should only be used in unit tests (where multi-threading and | 560 // testing. This should only be used in unit tests (where multi-threading and |
| 561 // synchronization are not problematic). | 561 // synchronization are not problematic). |
| 562 PrefixGetHashCache* GetUnsynchronizedPrefixGetHashCacheForTesting(); | 562 PrefixGetHashCache* GetUnsynchronizedPrefixGetHashCacheForTesting(); |
| 563 | 563 |
| 564 // Records a file size histogram for the database or PrefixSet backed by |
| 565 // |filename|. |
| 566 void RecordFileSizeHistogram(const base::FilePath& file_path); |
| 567 |
| 564 base::ThreadChecker thread_checker_; | 568 base::ThreadChecker thread_checker_; |
| 565 | 569 |
| 566 ThreadSafeStateManager state_manager_; | 570 ThreadSafeStateManager state_manager_; |
| 567 | 571 |
| 568 // The base filename passed to Init(), used to generate the store and prefix | 572 // The base filename passed to Init(), used to generate the store and prefix |
| 569 // set filenames used to store data on disk. | 573 // set filenames used to store data on disk. |
| 570 base::FilePath filename_base_; | 574 base::FilePath filename_base_; |
| 571 | 575 |
| 572 // Underlying persistent store for chunk data. | 576 // Underlying persistent store for chunk data. |
| 573 // For browsing related (phishing and malware URLs) chunks and prefixes. | 577 // For browsing related (phishing and malware URLs) chunks and prefixes. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 603 | 607 |
| 604 // Set to true if any chunks are added or deleted during an update. | 608 // Set to true if any chunks are added or deleted during an update. |
| 605 // Used to optimize away database update. | 609 // Used to optimize away database update. |
| 606 bool change_detected_; | 610 bool change_detected_; |
| 607 | 611 |
| 608 // Used to schedule resetting the database because of corruption. | 612 // Used to schedule resetting the database because of corruption. |
| 609 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; | 613 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; |
| 610 }; | 614 }; |
| 611 | 615 |
| 612 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ | 616 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ |
| OLD | NEW |