| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 bool enable_download_whitelist, | 287 bool enable_download_whitelist, |
| 288 bool enable_extension_blacklist, | 288 bool enable_extension_blacklist, |
| 289 bool enable_ip_blacklist, | 289 bool enable_ip_blacklist, |
| 290 bool enable_unwanted_software_list, | 290 bool enable_unwanted_software_list, |
| 291 bool enable_module_whitelist) override { | 291 bool enable_module_whitelist) override { |
| 292 return new SafeBrowsingDatabaseNew( | 292 return new SafeBrowsingDatabaseNew( |
| 293 db_task_runner, CreateStore(true, db_task_runner), // browse_store | 293 db_task_runner, CreateStore(true, db_task_runner), // browse_store |
| 294 CreateStore(enable_download_protection, db_task_runner), | 294 CreateStore(enable_download_protection, db_task_runner), |
| 295 CreateStore(enable_client_side_whitelist, db_task_runner), | 295 CreateStore(enable_client_side_whitelist, db_task_runner), |
| 296 CreateStore(enable_download_whitelist, db_task_runner), | 296 CreateStore(enable_download_whitelist, db_task_runner), |
| 297 CreateStore(true, db_task_runner), // inclusion_whitelist_store | |
| 298 CreateStore(enable_extension_blacklist, db_task_runner), | 297 CreateStore(enable_extension_blacklist, db_task_runner), |
| 299 CreateStore(enable_ip_blacklist, db_task_runner), | 298 CreateStore(enable_ip_blacklist, db_task_runner), |
| 300 CreateStore(enable_unwanted_software_list, db_task_runner), | 299 CreateStore(enable_unwanted_software_list, db_task_runner), |
| 301 CreateStore(enable_module_whitelist, db_task_runner), | 300 CreateStore(enable_module_whitelist, db_task_runner), |
| 302 CreateStore(true, db_task_runner)); // resource_blacklist_store | 301 CreateStore(true, db_task_runner)); // resource_blacklist_store |
| 303 } | 302 } |
| 304 | 303 |
| 305 SafeBrowsingDatabaseFactoryImpl() {} | 304 SafeBrowsingDatabaseFactoryImpl() {} |
| 306 | 305 |
| 307 private: | 306 private: |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 431 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 433 | 432 |
| 434 if (list_id == PHISH || list_id == MALWARE) { | 433 if (list_id == PHISH || list_id == MALWARE) { |
| 435 return browse_store_.get(); | 434 return browse_store_.get(); |
| 436 } else if (list_id == BINURL) { | 435 } else if (list_id == BINURL) { |
| 437 return download_store_.get(); | 436 return download_store_.get(); |
| 438 } else if (list_id == CSDWHITELIST) { | 437 } else if (list_id == CSDWHITELIST) { |
| 439 return csd_whitelist_store_.get(); | 438 return csd_whitelist_store_.get(); |
| 440 } else if (list_id == DOWNLOADWHITELIST) { | 439 } else if (list_id == DOWNLOADWHITELIST) { |
| 441 return download_whitelist_store_.get(); | 440 return download_whitelist_store_.get(); |
| 442 } else if (list_id == INCLUSIONWHITELIST) { | |
| 443 return inclusion_whitelist_store_.get(); | |
| 444 } else if (list_id == EXTENSIONBLACKLIST) { | 441 } else if (list_id == EXTENSIONBLACKLIST) { |
| 445 return extension_blacklist_store_.get(); | 442 return extension_blacklist_store_.get(); |
| 446 } else if (list_id == IPBLACKLIST) { | 443 } else if (list_id == IPBLACKLIST) { |
| 447 return ip_blacklist_store_.get(); | 444 return ip_blacklist_store_.get(); |
| 448 } else if (list_id == UNWANTEDURL) { | 445 } else if (list_id == UNWANTEDURL) { |
| 449 return unwanted_software_store_.get(); | 446 return unwanted_software_store_.get(); |
| 450 } else if (list_id == MODULEWHITELIST) { | 447 } else if (list_id == MODULEWHITELIST) { |
| 451 return module_whitelist_store_.get(); | 448 return module_whitelist_store_.get(); |
| 452 } else if (list_id == RESOURCEBLACKLIST) { | 449 } else if (list_id == RESOURCEBLACKLIST) { |
| 453 return resource_blacklist_store_.get(); | 450 return resource_blacklist_store_.get(); |
| 454 } | 451 } |
| 455 return NULL; | 452 return NULL; |
| 456 } | 453 } |
| 457 | 454 |
| 458 // static | 455 // static |
| 459 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { | 456 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { |
| 460 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, | 457 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, |
| 461 FAILURE_DATABASE_MAX); | 458 FAILURE_DATABASE_MAX); |
| 462 } | 459 } |
| 463 | 460 |
| 464 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::ReadTransaction { | 461 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::ReadTransaction { |
| 465 public: | 462 public: |
| 466 const SBWhitelist* GetSBWhitelist(SBWhitelistId id) { | 463 const SBWhitelist* GetSBWhitelist(SBWhitelistId id) { |
| 467 switch (id) { | 464 switch (id) { |
| 468 case SBWhitelistId::CSD: | 465 case SBWhitelistId::CSD: |
| 469 return &outer_->csd_whitelist_; | 466 return &outer_->csd_whitelist_; |
| 470 case SBWhitelistId::DOWNLOAD: | 467 case SBWhitelistId::DOWNLOAD: |
| 471 return &outer_->download_whitelist_; | 468 return &outer_->download_whitelist_; |
| 472 case SBWhitelistId::INCLUSION: | |
| 473 return &outer_->inclusion_whitelist_; | |
| 474 case SBWhitelistId::MODULE: | 469 case SBWhitelistId::MODULE: |
| 475 return &outer_->module_whitelist_; | 470 return &outer_->module_whitelist_; |
| 476 } | 471 } |
| 477 NOTREACHED(); | 472 NOTREACHED(); |
| 478 return nullptr; | 473 return nullptr; |
| 479 } | 474 } |
| 480 | 475 |
| 481 const IPBlacklist* ip_blacklist() { return &outer_->ip_blacklist_; } | 476 const IPBlacklist* ip_blacklist() { return &outer_->ip_blacklist_; } |
| 482 | 477 |
| 483 const PrefixSet* GetPrefixSet(PrefixSetId id) { | 478 const PrefixSet* GetPrefixSet(PrefixSetId id) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 DCHECK(outer_); | 569 DCHECK(outer_); |
| 575 DCHECK(outer_->db_task_runner_->RunsTasksOnCurrentThread()); | 570 DCHECK(outer_->db_task_runner_->RunsTasksOnCurrentThread()); |
| 576 } | 571 } |
| 577 | 572 |
| 578 SBWhitelist* SBWhitelistForId(SBWhitelistId id) { | 573 SBWhitelist* SBWhitelistForId(SBWhitelistId id) { |
| 579 switch (id) { | 574 switch (id) { |
| 580 case SBWhitelistId::CSD: | 575 case SBWhitelistId::CSD: |
| 581 return &outer_->csd_whitelist_; | 576 return &outer_->csd_whitelist_; |
| 582 case SBWhitelistId::DOWNLOAD: | 577 case SBWhitelistId::DOWNLOAD: |
| 583 return &outer_->download_whitelist_; | 578 return &outer_->download_whitelist_; |
| 584 case SBWhitelistId::INCLUSION: | |
| 585 return &outer_->inclusion_whitelist_; | |
| 586 case SBWhitelistId::MODULE: | 579 case SBWhitelistId::MODULE: |
| 587 return &outer_->module_whitelist_; | 580 return &outer_->module_whitelist_; |
| 588 } | 581 } |
| 589 NOTREACHED(); | 582 NOTREACHED(); |
| 590 return nullptr; | 583 return nullptr; |
| 591 } | 584 } |
| 592 | 585 |
| 593 ThreadSafeStateManager* outer_; | 586 ThreadSafeStateManager* outer_; |
| 594 base::AutoLock transaction_lock_; | 587 base::AutoLock transaction_lock_; |
| 595 | 588 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 SafeBrowsingDatabaseNew::ThreadSafeStateManager::BeginWriteTransaction() { | 621 SafeBrowsingDatabaseNew::ThreadSafeStateManager::BeginWriteTransaction() { |
| 629 return base::WrapUnique(new WriteTransaction(this)); | 622 return base::WrapUnique(new WriteTransaction(this)); |
| 630 } | 623 } |
| 631 | 624 |
| 632 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( | 625 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( |
| 633 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 626 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
| 634 SafeBrowsingStore* browse_store, | 627 SafeBrowsingStore* browse_store, |
| 635 SafeBrowsingStore* download_store, | 628 SafeBrowsingStore* download_store, |
| 636 SafeBrowsingStore* csd_whitelist_store, | 629 SafeBrowsingStore* csd_whitelist_store, |
| 637 SafeBrowsingStore* download_whitelist_store, | 630 SafeBrowsingStore* download_whitelist_store, |
| 638 SafeBrowsingStore* inclusion_whitelist_store, | |
| 639 SafeBrowsingStore* extension_blacklist_store, | 631 SafeBrowsingStore* extension_blacklist_store, |
| 640 SafeBrowsingStore* ip_blacklist_store, | 632 SafeBrowsingStore* ip_blacklist_store, |
| 641 SafeBrowsingStore* unwanted_software_store, | 633 SafeBrowsingStore* unwanted_software_store, |
| 642 SafeBrowsingStore* module_whitelist_store, | 634 SafeBrowsingStore* module_whitelist_store, |
| 643 SafeBrowsingStore* resource_blacklist_store) | 635 SafeBrowsingStore* resource_blacklist_store) |
| 644 : db_task_runner_(db_task_runner), | 636 : db_task_runner_(db_task_runner), |
| 645 state_manager_(db_task_runner_), | 637 state_manager_(db_task_runner_), |
| 646 db_state_manager_(db_task_runner_), | 638 db_state_manager_(db_task_runner_), |
| 647 browse_store_(browse_store), | 639 browse_store_(browse_store), |
| 648 download_store_(download_store), | 640 download_store_(download_store), |
| 649 csd_whitelist_store_(csd_whitelist_store), | 641 csd_whitelist_store_(csd_whitelist_store), |
| 650 download_whitelist_store_(download_whitelist_store), | 642 download_whitelist_store_(download_whitelist_store), |
| 651 inclusion_whitelist_store_(inclusion_whitelist_store), | |
| 652 extension_blacklist_store_(extension_blacklist_store), | 643 extension_blacklist_store_(extension_blacklist_store), |
| 653 ip_blacklist_store_(ip_blacklist_store), | 644 ip_blacklist_store_(ip_blacklist_store), |
| 654 unwanted_software_store_(unwanted_software_store), | 645 unwanted_software_store_(unwanted_software_store), |
| 655 module_whitelist_store_(module_whitelist_store), | 646 module_whitelist_store_(module_whitelist_store), |
| 656 resource_blacklist_store_(resource_blacklist_store), | 647 resource_blacklist_store_(resource_blacklist_store), |
| 657 reset_factory_(this) { | 648 reset_factory_(this) { |
| 658 DCHECK(browse_store_.get()); | 649 DCHECK(browse_store_.get()); |
| 659 } | 650 } |
| 660 | 651 |
| 661 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { | 652 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 | 700 |
| 710 // Delete any files of the side-effect free sidelist that may be around | 701 // Delete any files of the side-effect free sidelist that may be around |
| 711 // from when it was previously enabled. | 702 // from when it was previously enabled. |
| 712 // | 703 // |
| 713 // TODO(davidben): Remove this after April 15, 2016. | 704 // TODO(davidben): Remove this after April 15, 2016. |
| 714 SafeBrowsingStoreFile::DeleteStore( | 705 SafeBrowsingStoreFile::DeleteStore( |
| 715 SideEffectFreeWhitelistDBFilename(db_state_manager_.filename_base())); | 706 SideEffectFreeWhitelistDBFilename(db_state_manager_.filename_base())); |
| 716 base::DeleteFile(PrefixSetForFilename(SideEffectFreeWhitelistDBFilename( | 707 base::DeleteFile(PrefixSetForFilename(SideEffectFreeWhitelistDBFilename( |
| 717 db_state_manager_.filename_base())), | 708 db_state_manager_.filename_base())), |
| 718 false); | 709 false); |
| 710 |
| 711 // Delete any files of the off-domain inclusion whitelist that may be around |
| 712 // from when it was previously enabled. |
| 713 // |
| 714 // TODO(joenotcharles): Remove this after May 11, 2017. |
| 715 SafeBrowsingStoreFile::DeleteStore( |
| 716 InclusionWhitelistDBFilename(db_state_manager_.filename_base())); |
| 717 base::DeleteFile(PrefixSetForFilename(InclusionWhitelistDBFilename( |
| 718 db_state_manager_.filename_base())), |
| 719 false); |
| 719 } | 720 } |
| 720 // Note: End the transaction early because LoadWhiteList() and | 721 // Note: End the transaction early because LoadWhiteList() and |
| 721 // WhitelistEverything() manage their own transactions. | 722 // WhitelistEverything() manage their own transactions. |
| 722 | 723 |
| 723 if (download_store_.get()) { | 724 if (download_store_.get()) { |
| 724 download_store_->Init( | 725 download_store_->Init( |
| 725 DownloadDBFilename(db_state_manager_.filename_base()), | 726 DownloadDBFilename(db_state_manager_.filename_base()), |
| 726 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, | 727 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
| 727 base::Unretained(this))); | 728 base::Unretained(this))); |
| 728 } | 729 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 756 LoadWhitelist(full_hashes, SBWhitelistId::DOWNLOAD); | 757 LoadWhitelist(full_hashes, SBWhitelistId::DOWNLOAD); |
| 757 } else { | 758 } else { |
| 758 state_manager_.BeginWriteTransaction()->WhitelistEverything( | 759 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 759 SBWhitelistId::DOWNLOAD); | 760 SBWhitelistId::DOWNLOAD); |
| 760 } | 761 } |
| 761 } else { | 762 } else { |
| 762 state_manager_.BeginWriteTransaction()->WhitelistEverything( | 763 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 763 SBWhitelistId::DOWNLOAD); // Just to be safe. | 764 SBWhitelistId::DOWNLOAD); // Just to be safe. |
| 764 } | 765 } |
| 765 | 766 |
| 766 if (inclusion_whitelist_store_.get()) { | |
| 767 inclusion_whitelist_store_->Init( | |
| 768 InclusionWhitelistDBFilename(db_state_manager_.filename_base()), | |
| 769 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, | |
| 770 base::Unretained(this))); | |
| 771 | |
| 772 std::vector<SBAddFullHash> full_hashes; | |
| 773 if (inclusion_whitelist_store_->GetAddFullHashes(&full_hashes)) { | |
| 774 LoadWhitelist(full_hashes, SBWhitelistId::INCLUSION); | |
| 775 } else { | |
| 776 state_manager_.BeginWriteTransaction()->WhitelistEverything( | |
| 777 SBWhitelistId::INCLUSION); | |
| 778 } | |
| 779 } else { | |
| 780 state_manager_.BeginWriteTransaction()->WhitelistEverything( | |
| 781 SBWhitelistId::INCLUSION); // Just to be safe. | |
| 782 } | |
| 783 | |
| 784 if (extension_blacklist_store_.get()) { | 767 if (extension_blacklist_store_.get()) { |
| 785 extension_blacklist_store_->Init( | 768 extension_blacklist_store_->Init( |
| 786 ExtensionBlacklistDBFilename(db_state_manager_.filename_base()), | 769 ExtensionBlacklistDBFilename(db_state_manager_.filename_base()), |
| 787 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, | 770 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
| 788 base::Unretained(this))); | 771 base::Unretained(this))); |
| 789 } | 772 } |
| 790 | 773 |
| 791 if (ip_blacklist_store_.get()) { | 774 if (ip_blacklist_store_.get()) { |
| 792 ip_blacklist_store_->Init( | 775 ip_blacklist_store_->Init( |
| 793 IpBlacklistDBFilename(db_state_manager_.filename_base()), | 776 IpBlacklistDBFilename(db_state_manager_.filename_base()), |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 UrlToFullHashes(url, true, &full_hashes); | 937 UrlToFullHashes(url, true, &full_hashes); |
| 955 return ContainsWhitelistedHashes(SBWhitelistId::CSD, full_hashes); | 938 return ContainsWhitelistedHashes(SBWhitelistId::CSD, full_hashes); |
| 956 } | 939 } |
| 957 | 940 |
| 958 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedUrl(const GURL& url) { | 941 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedUrl(const GURL& url) { |
| 959 std::vector<SBFullHash> full_hashes; | 942 std::vector<SBFullHash> full_hashes; |
| 960 UrlToFullHashes(url, true, &full_hashes); | 943 UrlToFullHashes(url, true, &full_hashes); |
| 961 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, full_hashes); | 944 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, full_hashes); |
| 962 } | 945 } |
| 963 | 946 |
| 964 bool SafeBrowsingDatabaseNew::ContainsInclusionWhitelistedUrl(const GURL& url) { | |
| 965 std::vector<SBFullHash> full_hashes; | |
| 966 UrlToFullHashes(url, true, &full_hashes); | |
| 967 return ContainsWhitelistedHashes(SBWhitelistId::INCLUSION, full_hashes); | |
| 968 } | |
| 969 | |
| 970 bool SafeBrowsingDatabaseNew::ContainsExtensionPrefixes( | 947 bool SafeBrowsingDatabaseNew::ContainsExtensionPrefixes( |
| 971 const std::vector<SBPrefix>& prefixes, | 948 const std::vector<SBPrefix>& prefixes, |
| 972 std::vector<SBPrefix>* prefix_hits) { | 949 std::vector<SBPrefix>* prefix_hits) { |
| 973 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 950 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 974 | 951 |
| 975 if (!extension_blacklist_store_) | 952 if (!extension_blacklist_store_) |
| 976 return false; | 953 return false; |
| 977 | 954 |
| 978 return MatchAddPrefixes(extension_blacklist_store_.get(), | 955 return MatchAddPrefixes(extension_blacklist_store_.get(), |
| 979 EXTENSIONBLACKLIST % 2, prefixes, prefix_hits); | 956 EXTENSIONBLACKLIST % 2, prefixes, prefix_hits); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 return false; | 1204 return false; |
| 1228 } | 1205 } |
| 1229 | 1206 |
| 1230 if (download_whitelist_store_.get() && | 1207 if (download_whitelist_store_.get() && |
| 1231 !download_whitelist_store_->BeginUpdate()) { | 1208 !download_whitelist_store_->BeginUpdate()) { |
| 1232 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN); | 1209 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN); |
| 1233 HandleCorruptDatabase(); | 1210 HandleCorruptDatabase(); |
| 1234 return false; | 1211 return false; |
| 1235 } | 1212 } |
| 1236 | 1213 |
| 1237 if (inclusion_whitelist_store_.get() && | |
| 1238 !inclusion_whitelist_store_->BeginUpdate()) { | |
| 1239 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN); | |
| 1240 HandleCorruptDatabase(); | |
| 1241 return false; | |
| 1242 } | |
| 1243 | |
| 1244 if (extension_blacklist_store_ && | 1214 if (extension_blacklist_store_ && |
| 1245 !extension_blacklist_store_->BeginUpdate()) { | 1215 !extension_blacklist_store_->BeginUpdate()) { |
| 1246 RecordFailure(FAILURE_EXTENSION_BLACKLIST_UPDATE_BEGIN); | 1216 RecordFailure(FAILURE_EXTENSION_BLACKLIST_UPDATE_BEGIN); |
| 1247 HandleCorruptDatabase(); | 1217 HandleCorruptDatabase(); |
| 1248 return false; | 1218 return false; |
| 1249 } | 1219 } |
| 1250 | 1220 |
| 1251 if (ip_blacklist_store_ && !ip_blacklist_store_->BeginUpdate()) { | 1221 if (ip_blacklist_store_ && !ip_blacklist_store_->BeginUpdate()) { |
| 1252 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_BEGIN); | 1222 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_BEGIN); |
| 1253 HandleCorruptDatabase(); | 1223 HandleCorruptDatabase(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1284 // deprecated. Code to delete the list from the store shows ~15k hits/day as | 1254 // deprecated. Code to delete the list from the store shows ~15k hits/day as |
| 1285 // of Feb 2014, so it has been removed. Everything _should_ be resilient to | 1255 // of Feb 2014, so it has been removed. Everything _should_ be resilient to |
| 1286 // extra data of that sort. | 1256 // extra data of that sort. |
| 1287 UpdateChunkRangesForList(download_store_.get(), kBinUrlList, lists); | 1257 UpdateChunkRangesForList(download_store_.get(), kBinUrlList, lists); |
| 1288 | 1258 |
| 1289 UpdateChunkRangesForList(csd_whitelist_store_.get(), kCsdWhiteList, lists); | 1259 UpdateChunkRangesForList(csd_whitelist_store_.get(), kCsdWhiteList, lists); |
| 1290 | 1260 |
| 1291 UpdateChunkRangesForList(download_whitelist_store_.get(), kDownloadWhiteList, | 1261 UpdateChunkRangesForList(download_whitelist_store_.get(), kDownloadWhiteList, |
| 1292 lists); | 1262 lists); |
| 1293 | 1263 |
| 1294 UpdateChunkRangesForList(inclusion_whitelist_store_.get(), | |
| 1295 kInclusionWhitelist, lists); | |
| 1296 | |
| 1297 UpdateChunkRangesForList(extension_blacklist_store_.get(), | 1264 UpdateChunkRangesForList(extension_blacklist_store_.get(), |
| 1298 kExtensionBlacklist, lists); | 1265 kExtensionBlacklist, lists); |
| 1299 | 1266 |
| 1300 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); | 1267 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); |
| 1301 | 1268 |
| 1302 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, | 1269 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, |
| 1303 lists); | 1270 lists); |
| 1304 | 1271 |
| 1305 UpdateChunkRangesForList(module_whitelist_store_.get(), kModuleWhitelist, | 1272 UpdateChunkRangesForList(module_whitelist_store_.get(), kModuleWhitelist, |
| 1306 lists); | 1273 lists); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1330 DLOG(ERROR) << "Safe-browsing download database corrupt."; | 1297 DLOG(ERROR) << "Safe-browsing download database corrupt."; |
| 1331 | 1298 |
| 1332 if (csd_whitelist_store_.get() && !csd_whitelist_store_->CheckValidity()) | 1299 if (csd_whitelist_store_.get() && !csd_whitelist_store_->CheckValidity()) |
| 1333 DLOG(ERROR) << "Safe-browsing csd whitelist database corrupt."; | 1300 DLOG(ERROR) << "Safe-browsing csd whitelist database corrupt."; |
| 1334 | 1301 |
| 1335 if (download_whitelist_store_.get() && | 1302 if (download_whitelist_store_.get() && |
| 1336 !download_whitelist_store_->CheckValidity()) { | 1303 !download_whitelist_store_->CheckValidity()) { |
| 1337 DLOG(ERROR) << "Safe-browsing download whitelist database corrupt."; | 1304 DLOG(ERROR) << "Safe-browsing download whitelist database corrupt."; |
| 1338 } | 1305 } |
| 1339 | 1306 |
| 1340 if (inclusion_whitelist_store_.get() && | |
| 1341 !inclusion_whitelist_store_->CheckValidity()) { | |
| 1342 DLOG(ERROR) << "Safe-browsing inclusion whitelist database corrupt."; | |
| 1343 } | |
| 1344 | |
| 1345 if (extension_blacklist_store_ && | 1307 if (extension_blacklist_store_ && |
| 1346 !extension_blacklist_store_->CheckValidity()) { | 1308 !extension_blacklist_store_->CheckValidity()) { |
| 1347 DLOG(ERROR) << "Safe-browsing extension blacklist database corrupt."; | 1309 DLOG(ERROR) << "Safe-browsing extension blacklist database corrupt."; |
| 1348 } | 1310 } |
| 1349 | 1311 |
| 1350 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { | 1312 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { |
| 1351 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; | 1313 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; |
| 1352 } | 1314 } |
| 1353 | 1315 |
| 1354 if (unwanted_software_store_ && | 1316 if (unwanted_software_store_ && |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1376 // Track empty updates to answer questions at http://crbug.com/72216 . | 1338 // Track empty updates to answer questions at http://crbug.com/72216 . |
| 1377 if (update_succeeded && !db_state_manager_.change_detected()) | 1339 if (update_succeeded && !db_state_manager_.change_detected()) |
| 1378 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); | 1340 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); |
| 1379 browse_store_->CancelUpdate(); | 1341 browse_store_->CancelUpdate(); |
| 1380 if (download_store_.get()) | 1342 if (download_store_.get()) |
| 1381 download_store_->CancelUpdate(); | 1343 download_store_->CancelUpdate(); |
| 1382 if (csd_whitelist_store_.get()) | 1344 if (csd_whitelist_store_.get()) |
| 1383 csd_whitelist_store_->CancelUpdate(); | 1345 csd_whitelist_store_->CancelUpdate(); |
| 1384 if (download_whitelist_store_.get()) | 1346 if (download_whitelist_store_.get()) |
| 1385 download_whitelist_store_->CancelUpdate(); | 1347 download_whitelist_store_->CancelUpdate(); |
| 1386 if (inclusion_whitelist_store_.get()) | |
| 1387 inclusion_whitelist_store_->CancelUpdate(); | |
| 1388 if (extension_blacklist_store_) | 1348 if (extension_blacklist_store_) |
| 1389 extension_blacklist_store_->CancelUpdate(); | 1349 extension_blacklist_store_->CancelUpdate(); |
| 1390 if (ip_blacklist_store_) | 1350 if (ip_blacklist_store_) |
| 1391 ip_blacklist_store_->CancelUpdate(); | 1351 ip_blacklist_store_->CancelUpdate(); |
| 1392 if (unwanted_software_store_) | 1352 if (unwanted_software_store_) |
| 1393 unwanted_software_store_->CancelUpdate(); | 1353 unwanted_software_store_->CancelUpdate(); |
| 1394 if (module_whitelist_store_) | 1354 if (module_whitelist_store_) |
| 1395 module_whitelist_store_->CancelUpdate(); | 1355 module_whitelist_store_->CancelUpdate(); |
| 1396 if (resource_blacklist_store_) | 1356 if (resource_blacklist_store_) |
| 1397 resource_blacklist_store_->CancelUpdate(); | 1357 resource_blacklist_store_->CancelUpdate(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1408 browse_store_.get(), PrefixSetId::BROWSE, | 1368 browse_store_.get(), PrefixSetId::BROWSE, |
| 1409 FAILURE_BROWSE_DATABASE_UPDATE_FINISH, | 1369 FAILURE_BROWSE_DATABASE_UPDATE_FINISH, |
| 1410 FAILURE_BROWSE_PREFIX_SET_WRITE, true); | 1370 FAILURE_BROWSE_PREFIX_SET_WRITE, true); |
| 1411 | 1371 |
| 1412 UpdateWhitelistStore( | 1372 UpdateWhitelistStore( |
| 1413 CsdWhitelistDBFilename(db_state_manager_.filename_base()), | 1373 CsdWhitelistDBFilename(db_state_manager_.filename_base()), |
| 1414 csd_whitelist_store_.get(), SBWhitelistId::CSD); | 1374 csd_whitelist_store_.get(), SBWhitelistId::CSD); |
| 1415 UpdateWhitelistStore( | 1375 UpdateWhitelistStore( |
| 1416 DownloadWhitelistDBFilename(db_state_manager_.filename_base()), | 1376 DownloadWhitelistDBFilename(db_state_manager_.filename_base()), |
| 1417 download_whitelist_store_.get(), SBWhitelistId::DOWNLOAD); | 1377 download_whitelist_store_.get(), SBWhitelistId::DOWNLOAD); |
| 1418 UpdateWhitelistStore( | |
| 1419 InclusionWhitelistDBFilename(db_state_manager_.filename_base()), | |
| 1420 inclusion_whitelist_store_.get(), SBWhitelistId::INCLUSION); | |
| 1421 | 1378 |
| 1422 if (extension_blacklist_store_) { | 1379 if (extension_blacklist_store_) { |
| 1423 UpdateHashPrefixStore( | 1380 UpdateHashPrefixStore( |
| 1424 ExtensionBlacklistDBFilename(db_state_manager_.filename_base()), | 1381 ExtensionBlacklistDBFilename(db_state_manager_.filename_base()), |
| 1425 extension_blacklist_store_.get(), | 1382 extension_blacklist_store_.get(), |
| 1426 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH); | 1383 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH); |
| 1427 } | 1384 } |
| 1428 | 1385 |
| 1429 if (ip_blacklist_store_) | 1386 if (ip_blacklist_store_) |
| 1430 UpdateIpBlacklistStore(); | 1387 UpdateIpBlacklistStore(); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1689 csd_whitelist_store_.get() ? csd_whitelist_store_->Delete() : true; | 1646 csd_whitelist_store_.get() ? csd_whitelist_store_->Delete() : true; |
| 1690 if (!r3) | 1647 if (!r3) |
| 1691 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | 1648 RecordFailure(FAILURE_DATABASE_STORE_DELETE); |
| 1692 | 1649 |
| 1693 const bool r4 = download_whitelist_store_.get() | 1650 const bool r4 = download_whitelist_store_.get() |
| 1694 ? download_whitelist_store_->Delete() | 1651 ? download_whitelist_store_->Delete() |
| 1695 : true; | 1652 : true; |
| 1696 if (!r4) | 1653 if (!r4) |
| 1697 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | 1654 RecordFailure(FAILURE_DATABASE_STORE_DELETE); |
| 1698 | 1655 |
| 1699 const bool r5 = inclusion_whitelist_store_.get() | |
| 1700 ? inclusion_whitelist_store_->Delete() | |
| 1701 : true; | |
| 1702 if (!r5) | |
| 1703 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | |
| 1704 | |
| 1705 const base::FilePath browse_filename = | 1656 const base::FilePath browse_filename = |
| 1706 BrowseDBFilename(db_state_manager_.filename_base()); | 1657 BrowseDBFilename(db_state_manager_.filename_base()); |
| 1707 const base::FilePath bloom_filter_filename = | 1658 const base::FilePath bloom_filter_filename = |
| 1708 BloomFilterForFilename(browse_filename); | 1659 BloomFilterForFilename(browse_filename); |
| 1709 const bool r6 = base::DeleteFile(bloom_filter_filename, false); | 1660 const bool r5 = base::DeleteFile(bloom_filter_filename, false); |
| 1710 if (!r6) | 1661 if (!r5) |
| 1711 RecordFailure(FAILURE_DATABASE_FILTER_DELETE); | 1662 RecordFailure(FAILURE_DATABASE_FILTER_DELETE); |
| 1712 | 1663 |
| 1713 const base::FilePath browse_prefix_set_filename = | 1664 const base::FilePath browse_prefix_set_filename = |
| 1714 PrefixSetForFilename(browse_filename); | 1665 PrefixSetForFilename(browse_filename); |
| 1715 const bool r7 = base::DeleteFile(browse_prefix_set_filename, false); | 1666 const bool r6 = base::DeleteFile(browse_prefix_set_filename, false); |
| 1716 if (!r7) | 1667 if (!r6) |
| 1717 RecordFailure(FAILURE_BROWSE_PREFIX_SET_DELETE); | 1668 RecordFailure(FAILURE_BROWSE_PREFIX_SET_DELETE); |
| 1718 | 1669 |
| 1719 const base::FilePath extension_blacklist_filename = | 1670 const base::FilePath extension_blacklist_filename = |
| 1720 ExtensionBlacklistDBFilename(db_state_manager_.filename_base()); | 1671 ExtensionBlacklistDBFilename(db_state_manager_.filename_base()); |
| 1721 const bool r8 = base::DeleteFile(extension_blacklist_filename, false); | 1672 const bool r7 = base::DeleteFile(extension_blacklist_filename, false); |
| 1722 if (!r8) | 1673 if (!r7) |
| 1723 RecordFailure(FAILURE_EXTENSION_BLACKLIST_DELETE); | 1674 RecordFailure(FAILURE_EXTENSION_BLACKLIST_DELETE); |
| 1724 | 1675 |
| 1725 const bool r9 = base::DeleteFile( | 1676 const bool r8 = base::DeleteFile( |
| 1726 IpBlacklistDBFilename(db_state_manager_.filename_base()), false); | 1677 IpBlacklistDBFilename(db_state_manager_.filename_base()), false); |
| 1727 if (!r9) | 1678 if (!r8) |
| 1728 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); | 1679 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); |
| 1729 | 1680 |
| 1730 const bool r10 = base::DeleteFile( | 1681 const bool r9 = base::DeleteFile( |
| 1731 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), false); | 1682 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), false); |
| 1732 if (!r10) | 1683 if (!r9) |
| 1733 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); | 1684 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); |
| 1734 | 1685 |
| 1735 const bool r11 = base::DeleteFile( | 1686 const bool r10 = base::DeleteFile( |
| 1736 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), false); | 1687 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), false); |
| 1737 if (!r11) | 1688 if (!r10) |
| 1738 RecordFailure(FAILURE_RESOURCE_BLACKLIST_DELETE); | 1689 RecordFailure(FAILURE_RESOURCE_BLACKLIST_DELETE); |
| 1739 | 1690 |
| 1740 const bool r12 = | 1691 const bool r11 = |
| 1741 module_whitelist_store_.get() ? module_whitelist_store_->Delete() : true; | 1692 module_whitelist_store_.get() ? module_whitelist_store_->Delete() : true; |
| 1742 if (!r12) | 1693 if (!r11) |
| 1743 RecordFailure(FAILURE_MODULE_WHITELIST_DELETE); | 1694 RecordFailure(FAILURE_MODULE_WHITELIST_DELETE); |
| 1744 | 1695 |
| 1745 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11 && | 1696 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11; |
| 1746 r12; | |
| 1747 } | 1697 } |
| 1748 | 1698 |
| 1749 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, | 1699 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, |
| 1750 PrefixSetId prefix_set_id, | 1700 PrefixSetId prefix_set_id, |
| 1751 FailureType write_failure_type) { | 1701 FailureType write_failure_type) { |
| 1752 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1702 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 1753 | 1703 |
| 1754 // Do not grab the lock to avoid contention while writing to disk. This is | 1704 // Do not grab the lock to avoid contention while writing to disk. This is |
| 1755 // safe as only this task runner can ever modify |state_manager_|'s prefix | 1705 // safe as only this task runner can ever modify |state_manager_|'s prefix |
| 1756 // sets anyways. | 1706 // sets anyways. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1927 | 1877 |
| 1928 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. | 1878 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. |
| 1929 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( | 1879 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( |
| 1930 histogram_name, 1, 1000000, 50, | 1880 histogram_name, 1, 1000000, 50, |
| 1931 base::HistogramBase::kUmaTargetedHistogramFlag); | 1881 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1932 | 1882 |
| 1933 histogram_pointer->Add(file_size_kilobytes); | 1883 histogram_pointer->Add(file_size_kilobytes); |
| 1934 } | 1884 } |
| 1935 | 1885 |
| 1936 } // namespace safe_browsing | 1886 } // namespace safe_browsing |
| OLD | NEW |