Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 FILE_PATH_LITERAL(" Prefix Set"); | 43 FILE_PATH_LITERAL(" Prefix Set"); |
| 44 // Filename suffix for download store. | 44 // Filename suffix for download store. |
| 45 const base::FilePath::CharType kDownloadDBFile[] = | 45 const base::FilePath::CharType kDownloadDBFile[] = |
| 46 FILE_PATH_LITERAL(" Download"); | 46 FILE_PATH_LITERAL(" Download"); |
| 47 // Filename suffix for client-side phishing detection whitelist store. | 47 // Filename suffix for client-side phishing detection whitelist store. |
| 48 const base::FilePath::CharType kCsdWhitelistDBFile[] = | 48 const base::FilePath::CharType kCsdWhitelistDBFile[] = |
| 49 FILE_PATH_LITERAL(" Csd Whitelist"); | 49 FILE_PATH_LITERAL(" Csd Whitelist"); |
| 50 // Filename suffix for the download whitelist store. | 50 // Filename suffix for the download whitelist store. |
| 51 const base::FilePath::CharType kDownloadWhitelistDBFile[] = | 51 const base::FilePath::CharType kDownloadWhitelistDBFile[] = |
| 52 FILE_PATH_LITERAL(" Download Whitelist"); | 52 FILE_PATH_LITERAL(" Download Whitelist"); |
| 53 // Filename suffix for the off-domain inclusion whitelist store. | |
| 54 const base::FilePath::CharType kInclusionWhitelistDBFile[] = | |
| 55 FILE_PATH_LITERAL(" Inclusion Whitelist"); | |
| 53 // Filename suffix for the extension blacklist store. | 56 // Filename suffix for the extension blacklist store. |
| 54 const base::FilePath::CharType kExtensionBlacklistDBFile[] = | 57 const base::FilePath::CharType kExtensionBlacklistDBFile[] = |
| 55 FILE_PATH_LITERAL(" Extension Blacklist"); | 58 FILE_PATH_LITERAL(" Extension Blacklist"); |
| 56 // Filename suffix for the side-effect free whitelist store. | 59 // Filename suffix for the side-effect free whitelist store. |
| 57 const base::FilePath::CharType kSideEffectFreeWhitelistDBFile[] = | 60 const base::FilePath::CharType kSideEffectFreeWhitelistDBFile[] = |
| 58 FILE_PATH_LITERAL(" Side-Effect Free Whitelist"); | 61 FILE_PATH_LITERAL(" Side-Effect Free Whitelist"); |
| 59 // Filename suffix for the csd malware IP blacklist store. | 62 // Filename suffix for the csd malware IP blacklist store. |
| 60 const base::FilePath::CharType kIPBlacklistDBFile[] = | 63 const base::FilePath::CharType kIPBlacklistDBFile[] = |
| 61 FILE_PATH_LITERAL(" IP Blacklist"); | 64 FILE_PATH_LITERAL(" IP Blacklist"); |
| 62 // Filename suffix for the unwanted software blacklist store. | 65 // Filename suffix for the unwanted software blacklist store. |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 public: | 323 public: |
| 321 SafeBrowsingDatabase* CreateSafeBrowsingDatabase( | 324 SafeBrowsingDatabase* CreateSafeBrowsingDatabase( |
| 322 bool enable_download_protection, | 325 bool enable_download_protection, |
| 323 bool enable_client_side_whitelist, | 326 bool enable_client_side_whitelist, |
| 324 bool enable_download_whitelist, | 327 bool enable_download_whitelist, |
| 325 bool enable_extension_blacklist, | 328 bool enable_extension_blacklist, |
| 326 bool enable_side_effect_free_whitelist, | 329 bool enable_side_effect_free_whitelist, |
| 327 bool enable_ip_blacklist, | 330 bool enable_ip_blacklist, |
| 328 bool enable_unwanted_software_list) override { | 331 bool enable_unwanted_software_list) override { |
| 329 return new SafeBrowsingDatabaseNew( | 332 return new SafeBrowsingDatabaseNew( |
| 330 new SafeBrowsingStoreFile, | 333 new SafeBrowsingStoreFile, // browse_store |
| 331 enable_download_protection ? new SafeBrowsingStoreFile : NULL, | 334 enable_download_protection ? new SafeBrowsingStoreFile : NULL, |
| 332 enable_client_side_whitelist ? new SafeBrowsingStoreFile : NULL, | 335 enable_client_side_whitelist ? new SafeBrowsingStoreFile : NULL, |
| 333 enable_download_whitelist ? new SafeBrowsingStoreFile : NULL, | 336 enable_download_whitelist ? new SafeBrowsingStoreFile : NULL, |
| 337 new SafeBrowsingStoreFile, // inclusion_whitelist_store | |
| 334 enable_extension_blacklist ? new SafeBrowsingStoreFile : NULL, | 338 enable_extension_blacklist ? new SafeBrowsingStoreFile : NULL, |
| 335 enable_side_effect_free_whitelist ? new SafeBrowsingStoreFile : NULL, | 339 enable_side_effect_free_whitelist ? new SafeBrowsingStoreFile : NULL, |
| 336 enable_ip_blacklist ? new SafeBrowsingStoreFile : NULL, | 340 enable_ip_blacklist ? new SafeBrowsingStoreFile : NULL, |
| 337 enable_unwanted_software_list ? new SafeBrowsingStoreFile : NULL); | 341 enable_unwanted_software_list ? new SafeBrowsingStoreFile : NULL); |
| 338 } | 342 } |
| 339 | 343 |
| 340 SafeBrowsingDatabaseFactoryImpl() { } | 344 SafeBrowsingDatabaseFactoryImpl() { } |
| 341 | 345 |
| 342 private: | 346 private: |
| 343 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); | 347 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 return base::FilePath(db_filename.value() + kCsdWhitelistDBFile); | 407 return base::FilePath(db_filename.value() + kCsdWhitelistDBFile); |
| 404 } | 408 } |
| 405 | 409 |
| 406 // static | 410 // static |
| 407 base::FilePath SafeBrowsingDatabase::DownloadWhitelistDBFilename( | 411 base::FilePath SafeBrowsingDatabase::DownloadWhitelistDBFilename( |
| 408 const base::FilePath& db_filename) { | 412 const base::FilePath& db_filename) { |
| 409 return base::FilePath(db_filename.value() + kDownloadWhitelistDBFile); | 413 return base::FilePath(db_filename.value() + kDownloadWhitelistDBFile); |
| 410 } | 414 } |
| 411 | 415 |
| 412 // static | 416 // static |
| 417 base::FilePath SafeBrowsingDatabase::InclusionWhitelistDBFilename( | |
| 418 const base::FilePath& db_filename) { | |
| 419 return base::FilePath(db_filename.value() + kInclusionWhitelistDBFile); | |
| 420 } | |
| 421 | |
| 422 // static | |
| 413 base::FilePath SafeBrowsingDatabase::ExtensionBlacklistDBFilename( | 423 base::FilePath SafeBrowsingDatabase::ExtensionBlacklistDBFilename( |
| 414 const base::FilePath& db_filename) { | 424 const base::FilePath& db_filename) { |
| 415 return base::FilePath(db_filename.value() + kExtensionBlacklistDBFile); | 425 return base::FilePath(db_filename.value() + kExtensionBlacklistDBFile); |
| 416 } | 426 } |
| 417 | 427 |
| 418 // static | 428 // static |
| 419 base::FilePath SafeBrowsingDatabase::SideEffectFreeWhitelistDBFilename( | 429 base::FilePath SafeBrowsingDatabase::SideEffectFreeWhitelistDBFilename( |
| 420 const base::FilePath& db_filename) { | 430 const base::FilePath& db_filename) { |
| 421 return base::FilePath(db_filename.value() + kSideEffectFreeWhitelistDBFile); | 431 return base::FilePath(db_filename.value() + kSideEffectFreeWhitelistDBFile); |
| 422 } | 432 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 439 | 449 |
| 440 if (list_id == safe_browsing_util::PHISH || | 450 if (list_id == safe_browsing_util::PHISH || |
| 441 list_id == safe_browsing_util::MALWARE) { | 451 list_id == safe_browsing_util::MALWARE) { |
| 442 return browse_store_.get(); | 452 return browse_store_.get(); |
| 443 } else if (list_id == safe_browsing_util::BINURL) { | 453 } else if (list_id == safe_browsing_util::BINURL) { |
| 444 return download_store_.get(); | 454 return download_store_.get(); |
| 445 } else if (list_id == safe_browsing_util::CSDWHITELIST) { | 455 } else if (list_id == safe_browsing_util::CSDWHITELIST) { |
| 446 return csd_whitelist_store_.get(); | 456 return csd_whitelist_store_.get(); |
| 447 } else if (list_id == safe_browsing_util::DOWNLOADWHITELIST) { | 457 } else if (list_id == safe_browsing_util::DOWNLOADWHITELIST) { |
| 448 return download_whitelist_store_.get(); | 458 return download_whitelist_store_.get(); |
| 459 } else if (list_id == safe_browsing_util::INCLUSIONWHITELIST) { | |
| 460 return inclusion_whitelist_store_.get(); | |
| 449 } else if (list_id == safe_browsing_util::EXTENSIONBLACKLIST) { | 461 } else if (list_id == safe_browsing_util::EXTENSIONBLACKLIST) { |
| 450 return extension_blacklist_store_.get(); | 462 return extension_blacklist_store_.get(); |
| 451 } else if (list_id == safe_browsing_util::SIDEEFFECTFREEWHITELIST) { | 463 } else if (list_id == safe_browsing_util::SIDEEFFECTFREEWHITELIST) { |
| 452 return side_effect_free_whitelist_store_.get(); | 464 return side_effect_free_whitelist_store_.get(); |
| 453 } else if (list_id == safe_browsing_util::IPBLACKLIST) { | 465 } else if (list_id == safe_browsing_util::IPBLACKLIST) { |
| 454 return ip_blacklist_store_.get(); | 466 return ip_blacklist_store_.get(); |
| 455 } else if (list_id == safe_browsing_util::UNWANTEDURL) { | 467 } else if (list_id == safe_browsing_util::UNWANTEDURL) { |
| 456 return unwanted_software_store_.get(); | 468 return unwanted_software_store_.get(); |
| 457 } | 469 } |
| 458 return NULL; | 470 return NULL; |
| 459 } | 471 } |
| 460 | 472 |
| 461 // static | 473 // static |
| 462 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { | 474 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { |
| 463 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, | 475 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, |
| 464 FAILURE_DATABASE_MAX); | 476 FAILURE_DATABASE_MAX); |
| 465 } | 477 } |
| 466 | 478 |
| 467 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::ReadTransaction { | 479 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::ReadTransaction { |
| 468 public: | 480 public: |
| 469 const SBWhitelist* GetSBWhitelist(SBWhitelistId id) { | 481 const SBWhitelist* GetSBWhitelist(SBWhitelistId id) { |
| 470 switch (id) { | 482 switch (id) { |
| 471 case SBWhitelistId::CSD: | 483 case SBWhitelistId::CSD: |
| 472 return &outer_->csd_whitelist_; | 484 return &outer_->csd_whitelist_; |
| 473 case SBWhitelistId::DOWNLOAD: | 485 case SBWhitelistId::DOWNLOAD: |
| 474 return &outer_->download_whitelist_; | 486 return &outer_->download_whitelist_; |
| 487 case SBWhitelistId::INCLUSION: | |
| 488 return &outer_->inclusion_whitelist_; | |
| 475 } | 489 } |
| 476 NOTREACHED(); | 490 NOTREACHED(); |
| 477 return nullptr; | 491 return nullptr; |
| 478 } | 492 } |
| 479 | 493 |
| 480 const IPBlacklist* ip_blacklist() { return &outer_->ip_blacklist_; } | 494 const IPBlacklist* ip_blacklist() { return &outer_->ip_blacklist_; } |
| 481 | 495 |
| 482 const PrefixSet* GetPrefixSet(PrefixSetId id) { | 496 const PrefixSet* GetPrefixSet(PrefixSetId id) { |
| 483 switch (id) { | 497 switch (id) { |
| 484 case PrefixSetId::BROWSE: | 498 case PrefixSetId::BROWSE: |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 DCHECK(outer_); | 592 DCHECK(outer_); |
| 579 DCHECK(outer_->thread_checker_.CalledOnValidThread()); | 593 DCHECK(outer_->thread_checker_.CalledOnValidThread()); |
| 580 } | 594 } |
| 581 | 595 |
| 582 SBWhitelist* SBWhitelistForId(SBWhitelistId id) { | 596 SBWhitelist* SBWhitelistForId(SBWhitelistId id) { |
| 583 switch (id) { | 597 switch (id) { |
| 584 case SBWhitelistId::CSD: | 598 case SBWhitelistId::CSD: |
| 585 return &outer_->csd_whitelist_; | 599 return &outer_->csd_whitelist_; |
| 586 case SBWhitelistId::DOWNLOAD: | 600 case SBWhitelistId::DOWNLOAD: |
| 587 return &outer_->download_whitelist_; | 601 return &outer_->download_whitelist_; |
| 602 case SBWhitelistId::INCLUSION: | |
| 603 return &outer_->inclusion_whitelist_; | |
| 588 } | 604 } |
| 589 NOTREACHED(); | 605 NOTREACHED(); |
| 590 return nullptr; | 606 return nullptr; |
| 591 } | 607 } |
| 592 | 608 |
| 593 ThreadSafeStateManager* outer_; | 609 ThreadSafeStateManager* outer_; |
| 594 base::AutoLock transaction_lock_; | 610 base::AutoLock transaction_lock_; |
| 595 | 611 |
| 596 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); | 612 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); |
| 597 }; | 613 }; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 615 return make_scoped_ptr(new ReadTransaction( | 631 return make_scoped_ptr(new ReadTransaction( |
| 616 this, ReadTransaction::AutoLockRequirement::DONT_LOCK_ON_MAIN_THREAD)); | 632 this, ReadTransaction::AutoLockRequirement::DONT_LOCK_ON_MAIN_THREAD)); |
| 617 } | 633 } |
| 618 | 634 |
| 619 scoped_ptr<SafeBrowsingDatabaseNew::WriteTransaction> | 635 scoped_ptr<SafeBrowsingDatabaseNew::WriteTransaction> |
| 620 SafeBrowsingDatabaseNew::ThreadSafeStateManager::BeginWriteTransaction() { | 636 SafeBrowsingDatabaseNew::ThreadSafeStateManager::BeginWriteTransaction() { |
| 621 return make_scoped_ptr(new WriteTransaction(this)); | 637 return make_scoped_ptr(new WriteTransaction(this)); |
| 622 } | 638 } |
| 623 | 639 |
| 624 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew() | 640 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew() |
| 625 : SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile, | 641 : SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile, // browse_store |
| 626 NULL, | 642 NULL, // download_store |
| 627 NULL, | 643 NULL, // csd_whitelist_store |
| 628 NULL, | 644 NULL, // download_whitelist_store |
| 629 NULL, | 645 NULL, // inclusion_whitelist_store |
| 630 NULL, | 646 NULL, // extension_blacklist_store |
| 631 NULL, | 647 NULL, // side_effect_free_whitelist_store |
| 632 NULL) { | 648 NULL, // ip_blacklist_store |
| 649 NULL) { // unwanted_software_store | |
| 633 DCHECK(browse_store_.get()); | 650 DCHECK(browse_store_.get()); |
| 634 DCHECK(!download_store_.get()); | 651 DCHECK(!download_store_.get()); |
| 635 DCHECK(!csd_whitelist_store_.get()); | 652 DCHECK(!csd_whitelist_store_.get()); |
| 636 DCHECK(!download_whitelist_store_.get()); | 653 DCHECK(!download_whitelist_store_.get()); |
| 654 DCHECK(!inclusion_whitelist_store_.get()); | |
| 637 DCHECK(!extension_blacklist_store_.get()); | 655 DCHECK(!extension_blacklist_store_.get()); |
| 638 DCHECK(!side_effect_free_whitelist_store_.get()); | 656 DCHECK(!side_effect_free_whitelist_store_.get()); |
| 639 DCHECK(!ip_blacklist_store_.get()); | 657 DCHECK(!ip_blacklist_store_.get()); |
| 640 DCHECK(!unwanted_software_store_.get()); | 658 DCHECK(!unwanted_software_store_.get()); |
| 641 } | 659 } |
| 642 | 660 |
| 643 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( | 661 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( |
| 644 SafeBrowsingStore* browse_store, | 662 SafeBrowsingStore* browse_store, |
| 645 SafeBrowsingStore* download_store, | 663 SafeBrowsingStore* download_store, |
| 646 SafeBrowsingStore* csd_whitelist_store, | 664 SafeBrowsingStore* csd_whitelist_store, |
| 647 SafeBrowsingStore* download_whitelist_store, | 665 SafeBrowsingStore* download_whitelist_store, |
| 666 SafeBrowsingStore* inclusion_whitelist_store, | |
| 648 SafeBrowsingStore* extension_blacklist_store, | 667 SafeBrowsingStore* extension_blacklist_store, |
| 649 SafeBrowsingStore* side_effect_free_whitelist_store, | 668 SafeBrowsingStore* side_effect_free_whitelist_store, |
| 650 SafeBrowsingStore* ip_blacklist_store, | 669 SafeBrowsingStore* ip_blacklist_store, |
| 651 SafeBrowsingStore* unwanted_software_store) | 670 SafeBrowsingStore* unwanted_software_store) |
| 652 : state_manager_(thread_checker_), | 671 : state_manager_(thread_checker_), |
| 653 browse_store_(browse_store), | 672 browse_store_(browse_store), |
| 654 download_store_(download_store), | 673 download_store_(download_store), |
| 655 csd_whitelist_store_(csd_whitelist_store), | 674 csd_whitelist_store_(csd_whitelist_store), |
| 656 download_whitelist_store_(download_whitelist_store), | 675 download_whitelist_store_(download_whitelist_store), |
| 676 inclusion_whitelist_store_(inclusion_whitelist_store), | |
| 657 extension_blacklist_store_(extension_blacklist_store), | 677 extension_blacklist_store_(extension_blacklist_store), |
| 658 side_effect_free_whitelist_store_(side_effect_free_whitelist_store), | 678 side_effect_free_whitelist_store_(side_effect_free_whitelist_store), |
| 659 ip_blacklist_store_(ip_blacklist_store), | 679 ip_blacklist_store_(ip_blacklist_store), |
| 660 unwanted_software_store_(unwanted_software_store), | 680 unwanted_software_store_(unwanted_software_store), |
| 661 corruption_detected_(false), | 681 corruption_detected_(false), |
| 662 change_detected_(false), | 682 change_detected_(false), |
| 663 reset_factory_(this) { | 683 reset_factory_(this) { |
| 664 DCHECK(browse_store_.get()); | 684 DCHECK(browse_store_.get()); |
| 665 } | 685 } |
| 666 | 686 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 773 LoadWhitelist(full_hashes, SBWhitelistId::DOWNLOAD); | 793 LoadWhitelist(full_hashes, SBWhitelistId::DOWNLOAD); |
| 774 } else { | 794 } else { |
| 775 state_manager_.BeginWriteTransaction()->WhitelistEverything( | 795 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 776 SBWhitelistId::DOWNLOAD); | 796 SBWhitelistId::DOWNLOAD); |
| 777 } | 797 } |
| 778 } else { | 798 } else { |
| 779 state_manager_.BeginWriteTransaction()->WhitelistEverything( | 799 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 780 SBWhitelistId::DOWNLOAD); // Just to be safe. | 800 SBWhitelistId::DOWNLOAD); // Just to be safe. |
| 781 } | 801 } |
| 782 | 802 |
| 803 if (inclusion_whitelist_store_.get()) { | |
| 804 inclusion_whitelist_store_->Init( | |
| 805 InclusionWhitelistDBFilename(filename_base_), | |
| 806 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, | |
| 807 base::Unretained(this))); | |
| 808 | |
| 809 std::vector<SBAddFullHash> full_hashes; | |
| 810 if (inclusion_whitelist_store_->GetAddFullHashes(&full_hashes)) { | |
| 811 LoadWhitelist(full_hashes, SBWhitelistId::INCLUSION); | |
| 812 } else { | |
| 813 state_manager_.BeginWriteTransaction()->WhitelistEverything( | |
| 814 SBWhitelistId::INCLUSION); | |
| 815 } | |
| 816 } else { | |
| 817 state_manager_.BeginWriteTransaction()->WhitelistEverything( | |
| 818 SBWhitelistId::INCLUSION); // Just to be safe. | |
| 819 } | |
| 820 | |
| 783 if (extension_blacklist_store_.get()) { | 821 if (extension_blacklist_store_.get()) { |
| 784 extension_blacklist_store_->Init( | 822 extension_blacklist_store_->Init( |
| 785 ExtensionBlacklistDBFilename(filename_base_), | 823 ExtensionBlacklistDBFilename(filename_base_), |
| 786 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, | 824 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
| 787 base::Unretained(this))); | 825 base::Unretained(this))); |
| 788 } | 826 } |
| 789 | 827 |
| 790 if (ip_blacklist_store_.get()) { | 828 if (ip_blacklist_store_.get()) { |
| 791 ip_blacklist_store_->Init( | 829 ip_blacklist_store_->Init( |
| 792 IpBlacklistDBFilename(filename_base_), | 830 IpBlacklistDBFilename(filename_base_), |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 922 UrlToFullHashes(url, true, &full_hashes); | 960 UrlToFullHashes(url, true, &full_hashes); |
| 923 return ContainsWhitelistedHashes(SBWhitelistId::CSD, full_hashes); | 961 return ContainsWhitelistedHashes(SBWhitelistId::CSD, full_hashes); |
| 924 } | 962 } |
| 925 | 963 |
| 926 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedUrl(const GURL& url) { | 964 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedUrl(const GURL& url) { |
| 927 std::vector<SBFullHash> full_hashes; | 965 std::vector<SBFullHash> full_hashes; |
| 928 UrlToFullHashes(url, true, &full_hashes); | 966 UrlToFullHashes(url, true, &full_hashes); |
| 929 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, full_hashes); | 967 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, full_hashes); |
| 930 } | 968 } |
| 931 | 969 |
| 970 bool SafeBrowsingDatabaseNew::ContainsInclusionWhitelistedUrl(const GURL& url) { | |
| 971 std::vector<SBFullHash> full_hashes; | |
| 972 UrlToFullHashes(url, true, &full_hashes); | |
| 973 return ContainsWhitelistedHashes(SBWhitelistId::INCLUSION, full_hashes); | |
| 974 } | |
| 975 | |
| 932 bool SafeBrowsingDatabaseNew::ContainsExtensionPrefixes( | 976 bool SafeBrowsingDatabaseNew::ContainsExtensionPrefixes( |
| 933 const std::vector<SBPrefix>& prefixes, | 977 const std::vector<SBPrefix>& prefixes, |
| 934 std::vector<SBPrefix>* prefix_hits) { | 978 std::vector<SBPrefix>* prefix_hits) { |
| 935 DCHECK(thread_checker_.CalledOnValidThread()); | 979 DCHECK(thread_checker_.CalledOnValidThread()); |
| 936 | 980 |
| 937 if (!extension_blacklist_store_) | 981 if (!extension_blacklist_store_) |
| 938 return false; | 982 return false; |
| 939 | 983 |
| 940 return MatchAddPrefixes(extension_blacklist_store_.get(), | 984 return MatchAddPrefixes(extension_blacklist_store_.get(), |
| 941 safe_browsing_util::EXTENSIONBLACKLIST % 2, | 985 safe_browsing_util::EXTENSIONBLACKLIST % 2, |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 return false; | 1247 return false; |
| 1204 } | 1248 } |
| 1205 | 1249 |
| 1206 if (download_whitelist_store_.get() && | 1250 if (download_whitelist_store_.get() && |
| 1207 !download_whitelist_store_->BeginUpdate()) { | 1251 !download_whitelist_store_->BeginUpdate()) { |
| 1208 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN); | 1252 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN); |
| 1209 HandleCorruptDatabase(); | 1253 HandleCorruptDatabase(); |
| 1210 return false; | 1254 return false; |
| 1211 } | 1255 } |
| 1212 | 1256 |
| 1257 if (inclusion_whitelist_store_.get() && | |
| 1258 !inclusion_whitelist_store_->BeginUpdate()) { | |
| 1259 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN); | |
| 1260 HandleCorruptDatabase(); | |
| 1261 return false; | |
| 1262 } | |
| 1263 | |
| 1213 if (extension_blacklist_store_ && | 1264 if (extension_blacklist_store_ && |
| 1214 !extension_blacklist_store_->BeginUpdate()) { | 1265 !extension_blacklist_store_->BeginUpdate()) { |
| 1215 RecordFailure(FAILURE_EXTENSION_BLACKLIST_UPDATE_BEGIN); | 1266 RecordFailure(FAILURE_EXTENSION_BLACKLIST_UPDATE_BEGIN); |
| 1216 HandleCorruptDatabase(); | 1267 HandleCorruptDatabase(); |
| 1217 return false; | 1268 return false; |
| 1218 } | 1269 } |
| 1219 | 1270 |
| 1220 if (side_effect_free_whitelist_store_ && | 1271 if (side_effect_free_whitelist_store_ && |
| 1221 !side_effect_free_whitelist_store_->BeginUpdate()) { | 1272 !side_effect_free_whitelist_store_->BeginUpdate()) { |
| 1222 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_BEGIN); | 1273 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_BEGIN); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1251 // extra data of that sort. | 1302 // extra data of that sort. |
| 1252 UpdateChunkRangesForList(download_store_.get(), | 1303 UpdateChunkRangesForList(download_store_.get(), |
| 1253 safe_browsing_util::kBinUrlList, lists); | 1304 safe_browsing_util::kBinUrlList, lists); |
| 1254 | 1305 |
| 1255 UpdateChunkRangesForList(csd_whitelist_store_.get(), | 1306 UpdateChunkRangesForList(csd_whitelist_store_.get(), |
| 1256 safe_browsing_util::kCsdWhiteList, lists); | 1307 safe_browsing_util::kCsdWhiteList, lists); |
| 1257 | 1308 |
| 1258 UpdateChunkRangesForList(download_whitelist_store_.get(), | 1309 UpdateChunkRangesForList(download_whitelist_store_.get(), |
| 1259 safe_browsing_util::kDownloadWhiteList, lists); | 1310 safe_browsing_util::kDownloadWhiteList, lists); |
| 1260 | 1311 |
| 1312 UpdateChunkRangesForList(inclusion_whitelist_store_.get(), | |
| 1313 safe_browsing_util::kInclusionWhitelist, lists); | |
| 1314 | |
| 1261 UpdateChunkRangesForList(extension_blacklist_store_.get(), | 1315 UpdateChunkRangesForList(extension_blacklist_store_.get(), |
| 1262 safe_browsing_util::kExtensionBlacklist, lists); | 1316 safe_browsing_util::kExtensionBlacklist, lists); |
| 1263 | 1317 |
| 1264 UpdateChunkRangesForList(side_effect_free_whitelist_store_.get(), | 1318 UpdateChunkRangesForList(side_effect_free_whitelist_store_.get(), |
| 1265 safe_browsing_util::kSideEffectFreeWhitelist, lists); | 1319 safe_browsing_util::kSideEffectFreeWhitelist, lists); |
| 1266 | 1320 |
| 1267 UpdateChunkRangesForList(ip_blacklist_store_.get(), | 1321 UpdateChunkRangesForList(ip_blacklist_store_.get(), |
| 1268 safe_browsing_util::kIPBlacklist, lists); | 1322 safe_browsing_util::kIPBlacklist, lists); |
| 1269 | 1323 |
| 1270 UpdateChunkRangesForList(unwanted_software_store_.get(), | 1324 UpdateChunkRangesForList(unwanted_software_store_.get(), |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1293 DLOG(ERROR) << "Safe-browsing download database corrupt."; | 1347 DLOG(ERROR) << "Safe-browsing download database corrupt."; |
| 1294 | 1348 |
| 1295 if (csd_whitelist_store_.get() && !csd_whitelist_store_->CheckValidity()) | 1349 if (csd_whitelist_store_.get() && !csd_whitelist_store_->CheckValidity()) |
| 1296 DLOG(ERROR) << "Safe-browsing csd whitelist database corrupt."; | 1350 DLOG(ERROR) << "Safe-browsing csd whitelist database corrupt."; |
| 1297 | 1351 |
| 1298 if (download_whitelist_store_.get() && | 1352 if (download_whitelist_store_.get() && |
| 1299 !download_whitelist_store_->CheckValidity()) { | 1353 !download_whitelist_store_->CheckValidity()) { |
| 1300 DLOG(ERROR) << "Safe-browsing download whitelist database corrupt."; | 1354 DLOG(ERROR) << "Safe-browsing download whitelist database corrupt."; |
| 1301 } | 1355 } |
| 1302 | 1356 |
| 1357 if (inclusion_whitelist_store_.get() && | |
| 1358 !inclusion_whitelist_store_->CheckValidity()) { | |
| 1359 DLOG(ERROR) << "Safe-browsing inclusion whitelist database corrupt."; | |
| 1360 } | |
| 1361 | |
| 1303 if (extension_blacklist_store_ && | 1362 if (extension_blacklist_store_ && |
| 1304 !extension_blacklist_store_->CheckValidity()) { | 1363 !extension_blacklist_store_->CheckValidity()) { |
| 1305 DLOG(ERROR) << "Safe-browsing extension blacklist database corrupt."; | 1364 DLOG(ERROR) << "Safe-browsing extension blacklist database corrupt."; |
| 1306 } | 1365 } |
| 1307 | 1366 |
| 1308 if (side_effect_free_whitelist_store_ && | 1367 if (side_effect_free_whitelist_store_ && |
| 1309 !side_effect_free_whitelist_store_->CheckValidity()) { | 1368 !side_effect_free_whitelist_store_->CheckValidity()) { |
| 1310 DLOG(ERROR) << "Safe-browsing side-effect free whitelist database " | 1369 DLOG(ERROR) << "Safe-browsing side-effect free whitelist database " |
| 1311 << "corrupt."; | 1370 << "corrupt."; |
| 1312 } | 1371 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1331 // Track empty updates to answer questions at http://crbug.com/72216 . | 1390 // Track empty updates to answer questions at http://crbug.com/72216 . |
| 1332 if (update_succeeded && !change_detected_) | 1391 if (update_succeeded && !change_detected_) |
| 1333 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); | 1392 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); |
| 1334 browse_store_->CancelUpdate(); | 1393 browse_store_->CancelUpdate(); |
| 1335 if (download_store_.get()) | 1394 if (download_store_.get()) |
| 1336 download_store_->CancelUpdate(); | 1395 download_store_->CancelUpdate(); |
| 1337 if (csd_whitelist_store_.get()) | 1396 if (csd_whitelist_store_.get()) |
| 1338 csd_whitelist_store_->CancelUpdate(); | 1397 csd_whitelist_store_->CancelUpdate(); |
| 1339 if (download_whitelist_store_.get()) | 1398 if (download_whitelist_store_.get()) |
| 1340 download_whitelist_store_->CancelUpdate(); | 1399 download_whitelist_store_->CancelUpdate(); |
| 1400 if (inclusion_whitelist_store_.get()) | |
| 1401 inclusion_whitelist_store_->CancelUpdate(); | |
| 1341 if (extension_blacklist_store_) | 1402 if (extension_blacklist_store_) |
| 1342 extension_blacklist_store_->CancelUpdate(); | 1403 extension_blacklist_store_->CancelUpdate(); |
| 1343 if (side_effect_free_whitelist_store_) | 1404 if (side_effect_free_whitelist_store_) |
| 1344 side_effect_free_whitelist_store_->CancelUpdate(); | 1405 side_effect_free_whitelist_store_->CancelUpdate(); |
| 1345 if (ip_blacklist_store_) | 1406 if (ip_blacklist_store_) |
| 1346 ip_blacklist_store_->CancelUpdate(); | 1407 ip_blacklist_store_->CancelUpdate(); |
| 1347 if (unwanted_software_store_) | 1408 if (unwanted_software_store_) |
| 1348 unwanted_software_store_->CancelUpdate(); | 1409 unwanted_software_store_->CancelUpdate(); |
| 1349 return; | 1410 return; |
| 1350 } | 1411 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1364 FAILURE_BROWSE_DATABASE_UPDATE_FINISH, | 1425 FAILURE_BROWSE_DATABASE_UPDATE_FINISH, |
| 1365 FAILURE_BROWSE_PREFIX_SET_WRITE, | 1426 FAILURE_BROWSE_PREFIX_SET_WRITE, |
| 1366 true); | 1427 true); |
| 1367 | 1428 |
| 1368 UpdateWhitelistStore(CsdWhitelistDBFilename(filename_base_), | 1429 UpdateWhitelistStore(CsdWhitelistDBFilename(filename_base_), |
| 1369 csd_whitelist_store_.get(), | 1430 csd_whitelist_store_.get(), |
| 1370 SBWhitelistId::CSD); | 1431 SBWhitelistId::CSD); |
| 1371 UpdateWhitelistStore(DownloadWhitelistDBFilename(filename_base_), | 1432 UpdateWhitelistStore(DownloadWhitelistDBFilename(filename_base_), |
| 1372 download_whitelist_store_.get(), | 1433 download_whitelist_store_.get(), |
| 1373 SBWhitelistId::DOWNLOAD); | 1434 SBWhitelistId::DOWNLOAD); |
| 1435 UpdateWhitelistStore(InclusionWhitelistDBFilename(filename_base_), | |
| 1436 inclusion_whitelist_store_.get(), | |
| 1437 SBWhitelistId::INCLUSION); | |
| 1374 | 1438 |
| 1375 if (extension_blacklist_store_) { | 1439 if (extension_blacklist_store_) { |
| 1376 int64 size_bytes = UpdateHashPrefixStore( | 1440 int64 size_bytes = UpdateHashPrefixStore( |
| 1377 ExtensionBlacklistDBFilename(filename_base_), | 1441 ExtensionBlacklistDBFilename(filename_base_), |
| 1378 extension_blacklist_store_.get(), | 1442 extension_blacklist_store_.get(), |
| 1379 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH); | 1443 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH); |
| 1380 UMA_HISTOGRAM_COUNTS("SB2.ExtensionBlacklistKilobytes", | 1444 UMA_HISTOGRAM_COUNTS("SB2.ExtensionBlacklistKilobytes", |
| 1381 static_cast<int>(size_bytes / 1024)); | 1445 static_cast<int>(size_bytes / 1024)); |
| 1382 } | 1446 } |
| 1383 | 1447 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1648 const bool r3 = csd_whitelist_store_.get() ? | 1712 const bool r3 = csd_whitelist_store_.get() ? |
| 1649 csd_whitelist_store_->Delete() : true; | 1713 csd_whitelist_store_->Delete() : true; |
| 1650 if (!r3) | 1714 if (!r3) |
| 1651 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | 1715 RecordFailure(FAILURE_DATABASE_STORE_DELETE); |
| 1652 | 1716 |
| 1653 const bool r4 = download_whitelist_store_.get() ? | 1717 const bool r4 = download_whitelist_store_.get() ? |
| 1654 download_whitelist_store_->Delete() : true; | 1718 download_whitelist_store_->Delete() : true; |
| 1655 if (!r4) | 1719 if (!r4) |
| 1656 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | 1720 RecordFailure(FAILURE_DATABASE_STORE_DELETE); |
| 1657 | 1721 |
| 1722 const bool r5 = inclusion_whitelist_store_.get() ? | |
| 1723 inclusion_whitelist_store_->Delete() : true; | |
| 1724 if (!r5) | |
| 1725 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | |
|
mattm
2015/01/08 22:07:27
These don't seem to be sorted anyway, so why not j
gab
2015/01/09 13:51:29
I inserted the |inclusion_whitelist_store_| code r
mattm
2015/01/10 01:10:54
Since new lists keep getting added, would be nice.
gab
2015/01/10 06:34:12
Agreed, I think the most likely refactoring would
gab
2015/01/10 06:41:35
Err... Swipe typo on phone.. s/complementizing/com
| |
| 1726 | |
| 1658 const base::FilePath browse_filename = BrowseDBFilename(filename_base_); | 1727 const base::FilePath browse_filename = BrowseDBFilename(filename_base_); |
| 1659 const base::FilePath bloom_filter_filename = | 1728 const base::FilePath bloom_filter_filename = |
| 1660 BloomFilterForFilename(browse_filename); | 1729 BloomFilterForFilename(browse_filename); |
| 1661 const bool r5 = base::DeleteFile(bloom_filter_filename, false); | 1730 const bool r6 = base::DeleteFile(bloom_filter_filename, false); |
| 1662 if (!r5) | 1731 if (!r6) |
| 1663 RecordFailure(FAILURE_DATABASE_FILTER_DELETE); | 1732 RecordFailure(FAILURE_DATABASE_FILTER_DELETE); |
| 1664 | 1733 |
| 1665 const base::FilePath browse_prefix_set_filename = | 1734 const base::FilePath browse_prefix_set_filename = |
| 1666 PrefixSetForFilename(browse_filename); | 1735 PrefixSetForFilename(browse_filename); |
| 1667 const bool r6 = base::DeleteFile(browse_prefix_set_filename, false); | 1736 const bool r7 = base::DeleteFile(browse_prefix_set_filename, false); |
| 1668 if (!r6) | 1737 if (!r7) |
| 1669 RecordFailure(FAILURE_BROWSE_PREFIX_SET_DELETE); | 1738 RecordFailure(FAILURE_BROWSE_PREFIX_SET_DELETE); |
| 1670 | 1739 |
| 1671 const base::FilePath extension_blacklist_filename = | 1740 const base::FilePath extension_blacklist_filename = |
| 1672 ExtensionBlacklistDBFilename(filename_base_); | 1741 ExtensionBlacklistDBFilename(filename_base_); |
| 1673 const bool r7 = base::DeleteFile(extension_blacklist_filename, false); | 1742 const bool r8 = base::DeleteFile(extension_blacklist_filename, false); |
| 1674 if (!r7) | 1743 if (!r8) |
| 1675 RecordFailure(FAILURE_EXTENSION_BLACKLIST_DELETE); | 1744 RecordFailure(FAILURE_EXTENSION_BLACKLIST_DELETE); |
| 1676 | 1745 |
| 1677 const base::FilePath side_effect_free_whitelist_filename = | 1746 const base::FilePath side_effect_free_whitelist_filename = |
| 1678 SideEffectFreeWhitelistDBFilename(filename_base_); | 1747 SideEffectFreeWhitelistDBFilename(filename_base_); |
| 1679 const bool r8 = base::DeleteFile(side_effect_free_whitelist_filename, | 1748 const bool r9 = base::DeleteFile(side_effect_free_whitelist_filename, |
| 1680 false); | 1749 false); |
| 1681 if (!r8) | 1750 if (!r9) |
| 1682 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_DELETE); | 1751 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_DELETE); |
| 1683 | 1752 |
| 1684 const base::FilePath side_effect_free_whitelist_prefix_set_filename = | 1753 const base::FilePath side_effect_free_whitelist_prefix_set_filename = |
| 1685 PrefixSetForFilename(side_effect_free_whitelist_filename); | 1754 PrefixSetForFilename(side_effect_free_whitelist_filename); |
| 1686 const bool r9 = base::DeleteFile( | 1755 const bool r10 = base::DeleteFile( |
| 1687 side_effect_free_whitelist_prefix_set_filename, | 1756 side_effect_free_whitelist_prefix_set_filename, |
| 1688 false); | 1757 false); |
| 1689 if (!r9) | 1758 if (!r10) |
| 1690 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_DELETE); | 1759 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_DELETE); |
| 1691 | 1760 |
| 1692 const bool r10 = base::DeleteFile(IpBlacklistDBFilename(filename_base_), | 1761 const bool r11 = base::DeleteFile(IpBlacklistDBFilename(filename_base_), |
| 1693 false); | 1762 false); |
| 1694 if (!r10) | 1763 if (!r11) |
| 1695 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); | 1764 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); |
| 1696 | 1765 |
| 1697 const bool r11 = | 1766 const bool r12 = |
| 1698 base::DeleteFile(UnwantedSoftwareDBFilename(filename_base_), false); | 1767 base::DeleteFile(UnwantedSoftwareDBFilename(filename_base_), false); |
| 1699 if (!r11) | 1768 if (!r12) |
| 1700 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); | 1769 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); |
| 1701 | 1770 |
| 1702 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11; | 1771 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11 && |
| 1772 r12; | |
| 1703 } | 1773 } |
| 1704 | 1774 |
| 1705 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, | 1775 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, |
| 1706 const PrefixSet* prefix_set, | 1776 const PrefixSet* prefix_set, |
| 1707 FailureType write_failure_type) { | 1777 FailureType write_failure_type) { |
| 1708 DCHECK(thread_checker_.CalledOnValidThread()); | 1778 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1709 | 1779 |
| 1710 if (!prefix_set) | 1780 if (!prefix_set) |
| 1711 return; | 1781 return; |
| 1712 | 1782 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1807 bool SafeBrowsingDatabaseNew::IsCsdWhitelistKillSwitchOn() { | 1877 bool SafeBrowsingDatabaseNew::IsCsdWhitelistKillSwitchOn() { |
| 1808 return state_manager_.BeginReadTransaction() | 1878 return state_manager_.BeginReadTransaction() |
| 1809 ->GetSBWhitelist(SBWhitelistId::CSD) | 1879 ->GetSBWhitelist(SBWhitelistId::CSD) |
| 1810 ->second; | 1880 ->second; |
| 1811 } | 1881 } |
| 1812 | 1882 |
| 1813 SafeBrowsingDatabaseNew::PrefixGetHashCache* | 1883 SafeBrowsingDatabaseNew::PrefixGetHashCache* |
| 1814 SafeBrowsingDatabaseNew::GetUnsynchronizedPrefixGetHashCacheForTesting() { | 1884 SafeBrowsingDatabaseNew::GetUnsynchronizedPrefixGetHashCacheForTesting() { |
| 1815 return state_manager_.BeginReadTransaction()->prefix_gethash_cache(); | 1885 return state_manager_.BeginReadTransaction()->prefix_gethash_cache(); |
| 1816 } | 1886 } |
| OLD | NEW |