| 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 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const base::FilePath::CharType kSideEffectFreeWhitelistDBFile[] = | 65 const base::FilePath::CharType kSideEffectFreeWhitelistDBFile[] = |
| 66 FILE_PATH_LITERAL(" Side-Effect Free Whitelist"); | 66 FILE_PATH_LITERAL(" Side-Effect Free Whitelist"); |
| 67 // Filename suffix for the csd malware IP blacklist store. | 67 // Filename suffix for the csd malware IP blacklist store. |
| 68 const base::FilePath::CharType kIPBlacklistDBFile[] = | 68 const base::FilePath::CharType kIPBlacklistDBFile[] = |
| 69 FILE_PATH_LITERAL(" IP Blacklist"); | 69 FILE_PATH_LITERAL(" IP Blacklist"); |
| 70 // Filename suffix for the unwanted software blacklist store. | 70 // Filename suffix for the unwanted software blacklist store. |
| 71 const base::FilePath::CharType kUnwantedSoftwareDBFile[] = | 71 const base::FilePath::CharType kUnwantedSoftwareDBFile[] = |
| 72 FILE_PATH_LITERAL(" UwS List"); | 72 FILE_PATH_LITERAL(" UwS List"); |
| 73 const base::FilePath::CharType kModuleWhitelistDBFile[] = | 73 const base::FilePath::CharType kModuleWhitelistDBFile[] = |
| 74 FILE_PATH_LITERAL(" Module Whitelist"); | 74 FILE_PATH_LITERAL(" Module Whitelist"); |
| 75 // Filename suffix for the resource blacklist store. |
| 76 const base::FilePath::CharType kResourceBlacklistDBFile[] = |
| 77 FILE_PATH_LITERAL(" Resource Blacklist"); |
| 75 | 78 |
| 76 // Filename suffix for browse store. | 79 // Filename suffix for browse store. |
| 77 // TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win. | 80 // TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win. |
| 78 // Unfortunately, to change the name implies lots of transition code | 81 // Unfortunately, to change the name implies lots of transition code |
| 79 // for little benefit. If/when file formats change (say to put all | 82 // for little benefit. If/when file formats change (say to put all |
| 80 // the data in one file), that would be a convenient point to rectify | 83 // the data in one file), that would be a convenient point to rectify |
| 81 // this. | 84 // this. |
| 82 const base::FilePath::CharType kBrowseDBFile[] = FILE_PATH_LITERAL(" Bloom"); | 85 const base::FilePath::CharType kBrowseDBFile[] = FILE_PATH_LITERAL(" Bloom"); |
| 83 | 86 |
| 84 // Maximum number of entries we allow in any of the whitelists, excluding the | 87 // Maximum number of entries we allow in any of the whitelists, excluding the |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 bool enable_module_whitelist) override { | 289 bool enable_module_whitelist) override { |
| 287 return new SafeBrowsingDatabaseNew( | 290 return new SafeBrowsingDatabaseNew( |
| 288 db_task_runner, CreateStore(true, db_task_runner), // browse_store | 291 db_task_runner, CreateStore(true, db_task_runner), // browse_store |
| 289 CreateStore(enable_download_protection, db_task_runner), | 292 CreateStore(enable_download_protection, db_task_runner), |
| 290 CreateStore(enable_client_side_whitelist, db_task_runner), | 293 CreateStore(enable_client_side_whitelist, db_task_runner), |
| 291 CreateStore(enable_download_whitelist, db_task_runner), | 294 CreateStore(enable_download_whitelist, db_task_runner), |
| 292 CreateStore(true, db_task_runner), // inclusion_whitelist_store | 295 CreateStore(true, db_task_runner), // inclusion_whitelist_store |
| 293 CreateStore(enable_extension_blacklist, db_task_runner), | 296 CreateStore(enable_extension_blacklist, db_task_runner), |
| 294 CreateStore(enable_ip_blacklist, db_task_runner), | 297 CreateStore(enable_ip_blacklist, db_task_runner), |
| 295 CreateStore(enable_unwanted_software_list, db_task_runner), | 298 CreateStore(enable_unwanted_software_list, db_task_runner), |
| 296 CreateStore(enable_module_whitelist, db_task_runner)); | 299 CreateStore(enable_module_whitelist, db_task_runner), |
| 300 CreateStore(true, db_task_runner)); // resource_blacklist_store |
| 297 } | 301 } |
| 298 | 302 |
| 299 SafeBrowsingDatabaseFactoryImpl() {} | 303 SafeBrowsingDatabaseFactoryImpl() {} |
| 300 | 304 |
| 301 private: | 305 private: |
| 302 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); | 306 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); |
| 303 }; | 307 }; |
| 304 | 308 |
| 305 // static | 309 // static |
| 306 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; | 310 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile); | 401 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile); |
| 398 } | 402 } |
| 399 | 403 |
| 400 // static | 404 // static |
| 401 base::FilePath SafeBrowsingDatabase::ModuleWhitelistDBFilename( | 405 base::FilePath SafeBrowsingDatabase::ModuleWhitelistDBFilename( |
| 402 const base::FilePath& db_filename) { | 406 const base::FilePath& db_filename) { |
| 403 return base::FilePath(db_filename.value() + kModuleWhitelistDBFile); | 407 return base::FilePath(db_filename.value() + kModuleWhitelistDBFile); |
| 404 } | 408 } |
| 405 | 409 |
| 406 // static | 410 // static |
| 411 base::FilePath SafeBrowsingDatabase::ResourceBlacklistDBFilename( |
| 412 const base::FilePath& db_filename) { |
| 413 return base::FilePath(db_filename.value() + kResourceBlacklistDBFile); |
| 414 } |
| 415 |
| 416 // static |
| 407 void SafeBrowsingDatabase::GetDownloadUrlPrefixes( | 417 void SafeBrowsingDatabase::GetDownloadUrlPrefixes( |
| 408 const std::vector<GURL>& urls, | 418 const std::vector<GURL>& urls, |
| 409 std::vector<SBPrefix>* prefixes) { | 419 std::vector<SBPrefix>* prefixes) { |
| 410 std::vector<SBFullHash> full_hashes; | 420 std::vector<SBFullHash> full_hashes; |
| 411 for (size_t i = 0; i < urls.size(); ++i) | 421 for (size_t i = 0; i < urls.size(); ++i) |
| 412 UrlToFullHashes(urls[i], false, &full_hashes); | 422 UrlToFullHashes(urls[i], false, &full_hashes); |
| 413 | 423 |
| 414 for (size_t i = 0; i < full_hashes.size(); ++i) | 424 for (size_t i = 0; i < full_hashes.size(); ++i) |
| 415 prefixes->push_back(full_hashes[i].prefix); | 425 prefixes->push_back(full_hashes[i].prefix); |
| 416 } | 426 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 430 } else if (list_id == INCLUSIONWHITELIST) { | 440 } else if (list_id == INCLUSIONWHITELIST) { |
| 431 return inclusion_whitelist_store_.get(); | 441 return inclusion_whitelist_store_.get(); |
| 432 } else if (list_id == EXTENSIONBLACKLIST) { | 442 } else if (list_id == EXTENSIONBLACKLIST) { |
| 433 return extension_blacklist_store_.get(); | 443 return extension_blacklist_store_.get(); |
| 434 } else if (list_id == IPBLACKLIST) { | 444 } else if (list_id == IPBLACKLIST) { |
| 435 return ip_blacklist_store_.get(); | 445 return ip_blacklist_store_.get(); |
| 436 } else if (list_id == UNWANTEDURL) { | 446 } else if (list_id == UNWANTEDURL) { |
| 437 return unwanted_software_store_.get(); | 447 return unwanted_software_store_.get(); |
| 438 } else if (list_id == MODULEWHITELIST) { | 448 } else if (list_id == MODULEWHITELIST) { |
| 439 return module_whitelist_store_.get(); | 449 return module_whitelist_store_.get(); |
| 450 } else if (list_id == RESOURCEBLACKLIST) { |
| 451 return resource_blacklist_store_.get(); |
| 440 } | 452 } |
| 441 return NULL; | 453 return NULL; |
| 442 } | 454 } |
| 443 | 455 |
| 444 // static | 456 // static |
| 445 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { | 457 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { |
| 446 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, | 458 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, |
| 447 FAILURE_DATABASE_MAX); | 459 FAILURE_DATABASE_MAX); |
| 448 } | 460 } |
| 449 | 461 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( | 629 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( |
| 618 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 630 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
| 619 SafeBrowsingStore* browse_store, | 631 SafeBrowsingStore* browse_store, |
| 620 SafeBrowsingStore* download_store, | 632 SafeBrowsingStore* download_store, |
| 621 SafeBrowsingStore* csd_whitelist_store, | 633 SafeBrowsingStore* csd_whitelist_store, |
| 622 SafeBrowsingStore* download_whitelist_store, | 634 SafeBrowsingStore* download_whitelist_store, |
| 623 SafeBrowsingStore* inclusion_whitelist_store, | 635 SafeBrowsingStore* inclusion_whitelist_store, |
| 624 SafeBrowsingStore* extension_blacklist_store, | 636 SafeBrowsingStore* extension_blacklist_store, |
| 625 SafeBrowsingStore* ip_blacklist_store, | 637 SafeBrowsingStore* ip_blacklist_store, |
| 626 SafeBrowsingStore* unwanted_software_store, | 638 SafeBrowsingStore* unwanted_software_store, |
| 627 SafeBrowsingStore* module_whitelist_store) | 639 SafeBrowsingStore* module_whitelist_store, |
| 640 SafeBrowsingStore* resource_blacklist_store) |
| 628 : db_task_runner_(db_task_runner), | 641 : db_task_runner_(db_task_runner), |
| 629 state_manager_(db_task_runner_), | 642 state_manager_(db_task_runner_), |
| 630 db_state_manager_(db_task_runner_), | 643 db_state_manager_(db_task_runner_), |
| 631 browse_store_(browse_store), | 644 browse_store_(browse_store), |
| 632 download_store_(download_store), | 645 download_store_(download_store), |
| 633 csd_whitelist_store_(csd_whitelist_store), | 646 csd_whitelist_store_(csd_whitelist_store), |
| 634 download_whitelist_store_(download_whitelist_store), | 647 download_whitelist_store_(download_whitelist_store), |
| 635 inclusion_whitelist_store_(inclusion_whitelist_store), | 648 inclusion_whitelist_store_(inclusion_whitelist_store), |
| 636 extension_blacklist_store_(extension_blacklist_store), | 649 extension_blacklist_store_(extension_blacklist_store), |
| 637 ip_blacklist_store_(ip_blacklist_store), | 650 ip_blacklist_store_(ip_blacklist_store), |
| 638 unwanted_software_store_(unwanted_software_store), | 651 unwanted_software_store_(unwanted_software_store), |
| 639 module_whitelist_store_(module_whitelist_store), | 652 module_whitelist_store_(module_whitelist_store), |
| 653 resource_blacklist_store_(resource_blacklist_store), |
| 640 reset_factory_(this) { | 654 reset_factory_(this) { |
| 641 DCHECK(browse_store_.get()); | 655 DCHECK(browse_store_.get()); |
| 642 } | 656 } |
| 643 | 657 |
| 644 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { | 658 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { |
| 645 // The DCHECK is disabled due to crbug.com/338486 . | 659 // The DCHECK is disabled due to crbug.com/338486 . |
| 646 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 660 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 647 } | 661 } |
| 648 | 662 |
| 649 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { | 663 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 if (module_whitelist_store_->GetAddFullHashes(&full_hashes)) { | 808 if (module_whitelist_store_->GetAddFullHashes(&full_hashes)) { |
| 795 LoadWhitelist(full_hashes, SBWhitelistId::MODULE); | 809 LoadWhitelist(full_hashes, SBWhitelistId::MODULE); |
| 796 } else { | 810 } else { |
| 797 state_manager_.BeginWriteTransaction()->WhitelistEverything( | 811 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 798 SBWhitelistId::MODULE); | 812 SBWhitelistId::MODULE); |
| 799 } | 813 } |
| 800 } else { | 814 } else { |
| 801 state_manager_.BeginWriteTransaction()->WhitelistEverything( | 815 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 802 SBWhitelistId::MODULE); // Just to be safe. | 816 SBWhitelistId::MODULE); // Just to be safe. |
| 803 } | 817 } |
| 818 |
| 819 if (resource_blacklist_store_.get()) { |
| 820 resource_blacklist_store_->Init( |
| 821 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), |
| 822 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
| 823 base::Unretained(this))); |
| 824 } |
| 804 } | 825 } |
| 805 | 826 |
| 806 bool SafeBrowsingDatabaseNew::ResetDatabase() { | 827 bool SafeBrowsingDatabaseNew::ResetDatabase() { |
| 807 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 828 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 808 | 829 |
| 809 // Delete files on disk. | 830 // Delete files on disk. |
| 810 // TODO(shess): Hard to see where one might want to delete without a | 831 // TODO(shess): Hard to see where one might want to delete without a |
| 811 // reset. Perhaps inline |Delete()|? | 832 // reset. Perhaps inline |Delete()|? |
| 812 if (!Delete()) | 833 if (!Delete()) |
| 813 return false; | 834 return false; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 << " mask:" << base::HexEncode(mask.data(), mask.size()) | 997 << " mask:" << base::HexEncode(mask.data(), mask.size()) |
| 977 << " subnet:" << base::HexEncode(subnet.data(), subnet.size()) | 998 << " subnet:" << base::HexEncode(subnet.data(), subnet.size()) |
| 978 << " hash:" << base::HexEncode(hash.data(), hash.size()); | 999 << " hash:" << base::HexEncode(hash.data(), hash.size()); |
| 979 if (it->second.count(hash) > 0) { | 1000 if (it->second.count(hash) > 0) { |
| 980 return true; | 1001 return true; |
| 981 } | 1002 } |
| 982 } | 1003 } |
| 983 return false; | 1004 return false; |
| 984 } | 1005 } |
| 985 | 1006 |
| 1007 bool SafeBrowsingDatabaseNew::ContainsResourceUrlPrefixes( |
| 1008 const std::vector<SBPrefix>& prefixes, |
| 1009 std::vector<SBPrefix>* prefix_hits) { |
| 1010 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 1011 |
| 1012 if (!resource_blacklist_store_) |
| 1013 return false; |
| 1014 |
| 1015 return MatchAddPrefixes(resource_blacklist_store_.get(), |
| 1016 RESOURCEBLACKLIST % 2, prefixes, prefix_hits); |
| 1017 } |
| 1018 |
| 986 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString( | 1019 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString( |
| 987 const std::string& str) { | 1020 const std::string& str) { |
| 988 std::vector<SBFullHash> hashes; | 1021 std::vector<SBFullHash> hashes; |
| 989 hashes.push_back(SBFullHashForString(str)); | 1022 hashes.push_back(SBFullHashForString(str)); |
| 990 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, hashes); | 1023 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, hashes); |
| 991 } | 1024 } |
| 992 | 1025 |
| 993 bool SafeBrowsingDatabaseNew::ContainsModuleWhitelistedString( | 1026 bool SafeBrowsingDatabaseNew::ContainsModuleWhitelistedString( |
| 994 const std::string& str) { | 1027 const std::string& str) { |
| 995 std::vector<SBFullHash> hashes; | 1028 std::vector<SBFullHash> hashes; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 return false; | 1253 return false; |
| 1221 } | 1254 } |
| 1222 | 1255 |
| 1223 if (module_whitelist_store_.get() && | 1256 if (module_whitelist_store_.get() && |
| 1224 !module_whitelist_store_->BeginUpdate()) { | 1257 !module_whitelist_store_->BeginUpdate()) { |
| 1225 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN); | 1258 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN); |
| 1226 HandleCorruptDatabase(); | 1259 HandleCorruptDatabase(); |
| 1227 return false; | 1260 return false; |
| 1228 } | 1261 } |
| 1229 | 1262 |
| 1263 if (resource_blacklist_store_ && !resource_blacklist_store_->BeginUpdate()) { |
| 1264 RecordFailure(FAILURE_RESOURCE_BLACKLIST_UPDATE_BEGIN); |
| 1265 HandleCorruptDatabase(); |
| 1266 return false; |
| 1267 } |
| 1268 |
| 1230 // Cached fullhash results must be cleared on every database update (whether | 1269 // Cached fullhash results must be cleared on every database update (whether |
| 1231 // successful or not). | 1270 // successful or not). |
| 1232 state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); | 1271 state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); |
| 1233 | 1272 |
| 1234 UpdateChunkRangesForLists(browse_store_.get(), kMalwareList, kPhishingList, | 1273 UpdateChunkRangesForLists(browse_store_.get(), kMalwareList, kPhishingList, |
| 1235 lists); | 1274 lists); |
| 1236 | 1275 |
| 1237 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been | 1276 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been |
| 1238 // deprecated. Code to delete the list from the store shows ~15k hits/day as | 1277 // deprecated. Code to delete the list from the store shows ~15k hits/day as |
| 1239 // of Feb 2014, so it has been removed. Everything _should_ be resilient to | 1278 // of Feb 2014, so it has been removed. Everything _should_ be resilient to |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1252 kExtensionBlacklist, lists); | 1291 kExtensionBlacklist, lists); |
| 1253 | 1292 |
| 1254 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); | 1293 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); |
| 1255 | 1294 |
| 1256 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, | 1295 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, |
| 1257 lists); | 1296 lists); |
| 1258 | 1297 |
| 1259 UpdateChunkRangesForList(module_whitelist_store_.get(), kModuleWhitelist, | 1298 UpdateChunkRangesForList(module_whitelist_store_.get(), kModuleWhitelist, |
| 1260 lists); | 1299 lists); |
| 1261 | 1300 |
| 1301 UpdateChunkRangesForList(resource_blacklist_store_.get(), kResourceBlacklist, |
| 1302 lists); |
| 1303 |
| 1262 db_state_manager_.reset_corruption_detected(); | 1304 db_state_manager_.reset_corruption_detected(); |
| 1263 db_state_manager_.reset_change_detected(); | 1305 db_state_manager_.reset_change_detected(); |
| 1264 return true; | 1306 return true; |
| 1265 } | 1307 } |
| 1266 | 1308 |
| 1267 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { | 1309 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { |
| 1268 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1310 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 1269 | 1311 |
| 1270 // The update may have failed due to corrupt storage (for instance, | 1312 // The update may have failed due to corrupt storage (for instance, |
| 1271 // an excessive number of invalid add_chunks and sub_chunks). | 1313 // an excessive number of invalid add_chunks and sub_chunks). |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 } | 1345 } |
| 1304 | 1346 |
| 1305 if (unwanted_software_store_ && | 1347 if (unwanted_software_store_ && |
| 1306 !unwanted_software_store_->CheckValidity()) { | 1348 !unwanted_software_store_->CheckValidity()) { |
| 1307 DLOG(ERROR) << "Unwanted software url list database corrupt."; | 1349 DLOG(ERROR) << "Unwanted software url list database corrupt."; |
| 1308 } | 1350 } |
| 1309 | 1351 |
| 1310 if (module_whitelist_store_ && !module_whitelist_store_->CheckValidity()) { | 1352 if (module_whitelist_store_ && !module_whitelist_store_->CheckValidity()) { |
| 1311 DLOG(ERROR) << "Module digest whitelist database corrupt."; | 1353 DLOG(ERROR) << "Module digest whitelist database corrupt."; |
| 1312 } | 1354 } |
| 1355 |
| 1356 if (resource_blacklist_store_ && |
| 1357 !resource_blacklist_store_->CheckValidity()) { |
| 1358 DLOG(ERROR) << "Resources blacklist url list database corrupt."; |
| 1359 } |
| 1313 } | 1360 } |
| 1314 | 1361 |
| 1315 if (db_state_manager_.corruption_detected()) | 1362 if (db_state_manager_.corruption_detected()) |
| 1316 return; | 1363 return; |
| 1317 | 1364 |
| 1318 // Unroll the transaction if there was a protocol error or if the | 1365 // Unroll the transaction if there was a protocol error or if the |
| 1319 // transaction was empty. This will leave the prefix set, the | 1366 // transaction was empty. This will leave the prefix set, the |
| 1320 // pending hashes, and the prefix miss cache in place. | 1367 // pending hashes, and the prefix miss cache in place. |
| 1321 if (!update_succeeded || !db_state_manager_.change_detected()) { | 1368 if (!update_succeeded || !db_state_manager_.change_detected()) { |
| 1322 // Track empty updates to answer questions at http://crbug.com/72216 . | 1369 // Track empty updates to answer questions at http://crbug.com/72216 . |
| 1323 if (update_succeeded && !db_state_manager_.change_detected()) | 1370 if (update_succeeded && !db_state_manager_.change_detected()) |
| 1324 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); | 1371 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); |
| 1325 browse_store_->CancelUpdate(); | 1372 browse_store_->CancelUpdate(); |
| 1326 if (download_store_.get()) | 1373 if (download_store_.get()) |
| 1327 download_store_->CancelUpdate(); | 1374 download_store_->CancelUpdate(); |
| 1328 if (csd_whitelist_store_.get()) | 1375 if (csd_whitelist_store_.get()) |
| 1329 csd_whitelist_store_->CancelUpdate(); | 1376 csd_whitelist_store_->CancelUpdate(); |
| 1330 if (download_whitelist_store_.get()) | 1377 if (download_whitelist_store_.get()) |
| 1331 download_whitelist_store_->CancelUpdate(); | 1378 download_whitelist_store_->CancelUpdate(); |
| 1332 if (inclusion_whitelist_store_.get()) | 1379 if (inclusion_whitelist_store_.get()) |
| 1333 inclusion_whitelist_store_->CancelUpdate(); | 1380 inclusion_whitelist_store_->CancelUpdate(); |
| 1334 if (extension_blacklist_store_) | 1381 if (extension_blacklist_store_) |
| 1335 extension_blacklist_store_->CancelUpdate(); | 1382 extension_blacklist_store_->CancelUpdate(); |
| 1336 if (ip_blacklist_store_) | 1383 if (ip_blacklist_store_) |
| 1337 ip_blacklist_store_->CancelUpdate(); | 1384 ip_blacklist_store_->CancelUpdate(); |
| 1338 if (unwanted_software_store_) | 1385 if (unwanted_software_store_) |
| 1339 unwanted_software_store_->CancelUpdate(); | 1386 unwanted_software_store_->CancelUpdate(); |
| 1340 if (module_whitelist_store_) | 1387 if (module_whitelist_store_) |
| 1341 module_whitelist_store_->CancelUpdate(); | 1388 module_whitelist_store_->CancelUpdate(); |
| 1389 if (resource_blacklist_store_) |
| 1390 resource_blacklist_store_->CancelUpdate(); |
| 1342 return; | 1391 return; |
| 1343 } | 1392 } |
| 1344 | 1393 |
| 1345 if (download_store_) { | 1394 if (download_store_) { |
| 1346 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()), | 1395 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()), |
| 1347 download_store_.get(), | 1396 download_store_.get(), |
| 1348 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH); | 1397 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH); |
| 1349 } | 1398 } |
| 1350 | 1399 |
| 1351 UpdatePrefixSetUrlStore(BrowseDBFilename(db_state_manager_.filename_base()), | 1400 UpdatePrefixSetUrlStore(BrowseDBFilename(db_state_manager_.filename_base()), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1379 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE, | 1428 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE, |
| 1380 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, | 1429 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, |
| 1381 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); | 1430 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); |
| 1382 } | 1431 } |
| 1383 | 1432 |
| 1384 if (module_whitelist_store_) { | 1433 if (module_whitelist_store_) { |
| 1385 UpdateWhitelistStore( | 1434 UpdateWhitelistStore( |
| 1386 ModuleWhitelistDBFilename(db_state_manager_.filename_base()), | 1435 ModuleWhitelistDBFilename(db_state_manager_.filename_base()), |
| 1387 module_whitelist_store_.get(), SBWhitelistId::MODULE); | 1436 module_whitelist_store_.get(), SBWhitelistId::MODULE); |
| 1388 } | 1437 } |
| 1438 |
| 1439 if (resource_blacklist_store_) { |
| 1440 UpdateHashPrefixStore( |
| 1441 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), |
| 1442 resource_blacklist_store_.get(), |
| 1443 FAILURE_RESOURCE_BLACKLIST_UPDATE_FINISH); |
| 1444 } |
| 1389 } | 1445 } |
| 1390 | 1446 |
| 1391 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( | 1447 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( |
| 1392 const base::FilePath& store_filename, | 1448 const base::FilePath& store_filename, |
| 1393 SafeBrowsingStore* store, | 1449 SafeBrowsingStore* store, |
| 1394 SBWhitelistId whitelist_id) { | 1450 SBWhitelistId whitelist_id) { |
| 1395 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1451 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 1396 | 1452 |
| 1397 if (!store) | 1453 if (!store) |
| 1398 return; | 1454 return; |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 const bool r9 = base::DeleteFile( | 1718 const bool r9 = base::DeleteFile( |
| 1663 IpBlacklistDBFilename(db_state_manager_.filename_base()), false); | 1719 IpBlacklistDBFilename(db_state_manager_.filename_base()), false); |
| 1664 if (!r9) | 1720 if (!r9) |
| 1665 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); | 1721 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); |
| 1666 | 1722 |
| 1667 const bool r10 = base::DeleteFile( | 1723 const bool r10 = base::DeleteFile( |
| 1668 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), false); | 1724 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), false); |
| 1669 if (!r10) | 1725 if (!r10) |
| 1670 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); | 1726 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); |
| 1671 | 1727 |
| 1672 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10; | 1728 const bool r11 = base::DeleteFile( |
| 1729 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), false); |
| 1730 if (!r11) |
| 1731 RecordFailure(FAILURE_RESOURCE_BLACKLIST_DELETE); |
| 1732 |
| 1733 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11; |
| 1673 } | 1734 } |
| 1674 | 1735 |
| 1675 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, | 1736 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, |
| 1676 PrefixSetId prefix_set_id, | 1737 PrefixSetId prefix_set_id, |
| 1677 FailureType write_failure_type) { | 1738 FailureType write_failure_type) { |
| 1678 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1739 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 1679 | 1740 |
| 1680 // Do not grab the lock to avoid contention while writing to disk. This is | 1741 // Do not grab the lock to avoid contention while writing to disk. This is |
| 1681 // safe as only this task runner can ever modify |state_manager_|'s prefix | 1742 // safe as only this task runner can ever modify |state_manager_|'s prefix |
| 1682 // sets anyways. | 1743 // sets anyways. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1838 histogram_name.append(".ExtensionBlacklist"); | 1899 histogram_name.append(".ExtensionBlacklist"); |
| 1839 else if (base::EndsWith(filename, kIPBlacklistDBFile, | 1900 else if (base::EndsWith(filename, kIPBlacklistDBFile, |
| 1840 base::CompareCase::SENSITIVE)) | 1901 base::CompareCase::SENSITIVE)) |
| 1841 histogram_name.append(".IPBlacklist"); | 1902 histogram_name.append(".IPBlacklist"); |
| 1842 else if (base::EndsWith(filename, kUnwantedSoftwareDBFile, | 1903 else if (base::EndsWith(filename, kUnwantedSoftwareDBFile, |
| 1843 base::CompareCase::SENSITIVE)) | 1904 base::CompareCase::SENSITIVE)) |
| 1844 histogram_name.append(".UnwantedSoftware"); | 1905 histogram_name.append(".UnwantedSoftware"); |
| 1845 else if (base::EndsWith(filename, kModuleWhitelistDBFile, | 1906 else if (base::EndsWith(filename, kModuleWhitelistDBFile, |
| 1846 base::CompareCase::SENSITIVE)) | 1907 base::CompareCase::SENSITIVE)) |
| 1847 histogram_name.append(".ModuleWhitelist"); | 1908 histogram_name.append(".ModuleWhitelist"); |
| 1909 else if (base::EndsWith(filename, kResourceBlacklistDBFile, |
| 1910 base::CompareCase::SENSITIVE)) |
| 1911 histogram_name.append(".ResourceBlacklist"); |
| 1848 else | 1912 else |
| 1849 NOTREACHED(); // Add support for new lists above. | 1913 NOTREACHED(); // Add support for new lists above. |
| 1850 | 1914 |
| 1851 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. | 1915 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. |
| 1852 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( | 1916 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( |
| 1853 histogram_name, 1, 1000000, 50, | 1917 histogram_name, 1, 1000000, 50, |
| 1854 base::HistogramBase::kUmaTargetedHistogramFlag); | 1918 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1855 | 1919 |
| 1856 histogram_pointer->Add(file_size_kilobytes); | 1920 histogram_pointer->Add(file_size_kilobytes); |
| 1857 } | 1921 } |
| 1858 | 1922 |
| 1859 } // namespace safe_browsing | 1923 } // namespace safe_browsing |
| OLD | NEW |