| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 FILE_PATH_LITERAL(" Extension Blacklist"); | 63 FILE_PATH_LITERAL(" Extension Blacklist"); |
| 64 // Filename suffix for the side-effect free whitelist store. | 64 // Filename suffix for the side-effect free whitelist store. |
| 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[] = |
| 74 FILE_PATH_LITERAL(" Module Whitelist"); |
| 73 | 75 |
| 74 // Filename suffix for browse store. | 76 // Filename suffix for browse store. |
| 75 // TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win. | 77 // TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win. |
| 76 // Unfortunately, to change the name implies lots of transition code | 78 // Unfortunately, to change the name implies lots of transition code |
| 77 // for little benefit. If/when file formats change (say to put all | 79 // for little benefit. If/when file formats change (say to put all |
| 78 // the data in one file), that would be a convenient point to rectify | 80 // the data in one file), that would be a convenient point to rectify |
| 79 // this. | 81 // this. |
| 80 const base::FilePath::CharType kBrowseDBFile[] = FILE_PATH_LITERAL(" Bloom"); | 82 const base::FilePath::CharType kBrowseDBFile[] = FILE_PATH_LITERAL(" Bloom"); |
| 81 | 83 |
| 82 // Maximum number of entries we allow in any of the whitelists. | 84 // Maximum number of entries we allow in any of the whitelists. |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // The default SafeBrowsingDatabaseFactory. | 274 // The default SafeBrowsingDatabaseFactory. |
| 273 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { | 275 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { |
| 274 public: | 276 public: |
| 275 SafeBrowsingDatabase* CreateSafeBrowsingDatabase( | 277 SafeBrowsingDatabase* CreateSafeBrowsingDatabase( |
| 276 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 278 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
| 277 bool enable_download_protection, | 279 bool enable_download_protection, |
| 278 bool enable_client_side_whitelist, | 280 bool enable_client_side_whitelist, |
| 279 bool enable_download_whitelist, | 281 bool enable_download_whitelist, |
| 280 bool enable_extension_blacklist, | 282 bool enable_extension_blacklist, |
| 281 bool enable_ip_blacklist, | 283 bool enable_ip_blacklist, |
| 282 bool enable_unwanted_software_list) override { | 284 bool enable_unwanted_software_list, |
| 285 bool enable_module_whitelist) override { |
| 283 return new SafeBrowsingDatabaseNew( | 286 return new SafeBrowsingDatabaseNew( |
| 284 db_task_runner, CreateStore(true, db_task_runner), // browse_store | 287 db_task_runner, CreateStore(true, db_task_runner), // browse_store |
| 285 CreateStore(enable_download_protection, db_task_runner), | 288 CreateStore(enable_download_protection, db_task_runner), |
| 286 CreateStore(enable_client_side_whitelist, db_task_runner), | 289 CreateStore(enable_client_side_whitelist, db_task_runner), |
| 287 CreateStore(enable_download_whitelist, db_task_runner), | 290 CreateStore(enable_download_whitelist, db_task_runner), |
| 288 CreateStore(true, db_task_runner), // inclusion_whitelist_store | 291 CreateStore(true, db_task_runner), // inclusion_whitelist_store |
| 289 CreateStore(enable_extension_blacklist, db_task_runner), | 292 CreateStore(enable_extension_blacklist, db_task_runner), |
| 290 CreateStore(enable_ip_blacklist, db_task_runner), | 293 CreateStore(enable_ip_blacklist, db_task_runner), |
| 291 CreateStore(enable_unwanted_software_list, db_task_runner)); | 294 CreateStore(enable_unwanted_software_list, db_task_runner), |
| 295 CreateStore(enable_module_whitelist, db_task_runner)); |
| 292 } | 296 } |
| 293 | 297 |
| 294 SafeBrowsingDatabaseFactoryImpl() {} | 298 SafeBrowsingDatabaseFactoryImpl() {} |
| 295 | 299 |
| 296 private: | 300 private: |
| 297 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); | 301 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); |
| 298 }; | 302 }; |
| 299 | 303 |
| 300 // static | 304 // static |
| 301 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; | 305 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; |
| 302 | 306 |
| 303 // Factory method, should be called on the Safe Browsing sequenced task runner, | 307 // Factory method, should be called on the Safe Browsing sequenced task runner, |
| 304 // which is also passed to the function as |current_task_runner|. | 308 // which is also passed to the function as |current_task_runner|. |
| 305 // TODO(shess): There's no need for a factory any longer. Convert | 309 // TODO(shess): There's no need for a factory any longer. Convert |
| 306 // SafeBrowsingDatabaseNew to SafeBrowsingDatabase, and have Create() | 310 // SafeBrowsingDatabaseNew to SafeBrowsingDatabase, and have Create() |
| 307 // callers just construct things directly. | 311 // callers just construct things directly. |
| 308 SafeBrowsingDatabase* SafeBrowsingDatabase::Create( | 312 SafeBrowsingDatabase* SafeBrowsingDatabase::Create( |
| 309 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner, | 313 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner, |
| 310 bool enable_download_protection, | 314 bool enable_download_protection, |
| 311 bool enable_client_side_whitelist, | 315 bool enable_client_side_whitelist, |
| 312 bool enable_download_whitelist, | 316 bool enable_download_whitelist, |
| 313 bool enable_extension_blacklist, | 317 bool enable_extension_blacklist, |
| 314 bool enable_ip_blacklist, | 318 bool enable_ip_blacklist, |
| 315 bool enable_unwanted_software_list) { | 319 bool enable_unwanted_software_list, |
| 320 bool enable_module_whitelist) { |
| 316 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); | 321 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); |
| 317 if (!factory_) | 322 if (!factory_) |
| 318 factory_ = new SafeBrowsingDatabaseFactoryImpl(); | 323 factory_ = new SafeBrowsingDatabaseFactoryImpl(); |
| 319 return factory_->CreateSafeBrowsingDatabase( | 324 return factory_->CreateSafeBrowsingDatabase( |
| 320 current_task_runner, enable_download_protection, | 325 current_task_runner, enable_download_protection, |
| 321 enable_client_side_whitelist, enable_download_whitelist, | 326 enable_client_side_whitelist, enable_download_whitelist, |
| 322 enable_extension_blacklist, enable_ip_blacklist, | 327 enable_extension_blacklist, enable_ip_blacklist, |
| 323 enable_unwanted_software_list); | 328 enable_unwanted_software_list, enable_module_whitelist); |
| 324 } | 329 } |
| 325 | 330 |
| 326 SafeBrowsingDatabase::~SafeBrowsingDatabase() {} | 331 SafeBrowsingDatabase::~SafeBrowsingDatabase() {} |
| 327 | 332 |
| 328 // static | 333 // static |
| 329 base::FilePath SafeBrowsingDatabase::BrowseDBFilename( | 334 base::FilePath SafeBrowsingDatabase::BrowseDBFilename( |
| 330 const base::FilePath& db_base_filename) { | 335 const base::FilePath& db_base_filename) { |
| 331 return base::FilePath(db_base_filename.value() + kBrowseDBFile); | 336 return base::FilePath(db_base_filename.value() + kBrowseDBFile); |
| 332 } | 337 } |
| 333 | 338 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 return base::FilePath(db_filename.value() + kIPBlacklistDBFile); | 390 return base::FilePath(db_filename.value() + kIPBlacklistDBFile); |
| 386 } | 391 } |
| 387 | 392 |
| 388 // static | 393 // static |
| 389 base::FilePath SafeBrowsingDatabase::UnwantedSoftwareDBFilename( | 394 base::FilePath SafeBrowsingDatabase::UnwantedSoftwareDBFilename( |
| 390 const base::FilePath& db_filename) { | 395 const base::FilePath& db_filename) { |
| 391 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile); | 396 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile); |
| 392 } | 397 } |
| 393 | 398 |
| 394 // static | 399 // static |
| 400 base::FilePath SafeBrowsingDatabase::ModuleWhitelistDBFilename( |
| 401 const base::FilePath& db_filename) { |
| 402 return base::FilePath(db_filename.value() + kModuleWhitelistDBFile); |
| 403 } |
| 404 |
| 405 // static |
| 395 void SafeBrowsingDatabase::GetDownloadUrlPrefixes( | 406 void SafeBrowsingDatabase::GetDownloadUrlPrefixes( |
| 396 const std::vector<GURL>& urls, | 407 const std::vector<GURL>& urls, |
| 397 std::vector<SBPrefix>* prefixes) { | 408 std::vector<SBPrefix>* prefixes) { |
| 398 std::vector<SBFullHash> full_hashes; | 409 std::vector<SBFullHash> full_hashes; |
| 399 for (size_t i = 0; i < urls.size(); ++i) | 410 for (size_t i = 0; i < urls.size(); ++i) |
| 400 UrlToFullHashes(urls[i], false, &full_hashes); | 411 UrlToFullHashes(urls[i], false, &full_hashes); |
| 401 | 412 |
| 402 for (size_t i = 0; i < full_hashes.size(); ++i) | 413 for (size_t i = 0; i < full_hashes.size(); ++i) |
| 403 prefixes->push_back(full_hashes[i].prefix); | 414 prefixes->push_back(full_hashes[i].prefix); |
| 404 } | 415 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 416 } else if (list_id == DOWNLOADWHITELIST) { | 427 } else if (list_id == DOWNLOADWHITELIST) { |
| 417 return download_whitelist_store_.get(); | 428 return download_whitelist_store_.get(); |
| 418 } else if (list_id == INCLUSIONWHITELIST) { | 429 } else if (list_id == INCLUSIONWHITELIST) { |
| 419 return inclusion_whitelist_store_.get(); | 430 return inclusion_whitelist_store_.get(); |
| 420 } else if (list_id == EXTENSIONBLACKLIST) { | 431 } else if (list_id == EXTENSIONBLACKLIST) { |
| 421 return extension_blacklist_store_.get(); | 432 return extension_blacklist_store_.get(); |
| 422 } else if (list_id == IPBLACKLIST) { | 433 } else if (list_id == IPBLACKLIST) { |
| 423 return ip_blacklist_store_.get(); | 434 return ip_blacklist_store_.get(); |
| 424 } else if (list_id == UNWANTEDURL) { | 435 } else if (list_id == UNWANTEDURL) { |
| 425 return unwanted_software_store_.get(); | 436 return unwanted_software_store_.get(); |
| 437 } else if (list_id == MODULEWHITELIST) { |
| 438 return module_whitelist_store_.get(); |
| 426 } | 439 } |
| 427 return NULL; | 440 return NULL; |
| 428 } | 441 } |
| 429 | 442 |
| 430 // static | 443 // static |
| 431 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { | 444 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { |
| 432 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, | 445 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, |
| 433 FAILURE_DATABASE_MAX); | 446 FAILURE_DATABASE_MAX); |
| 434 } | 447 } |
| 435 | 448 |
| 436 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::ReadTransaction { | 449 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::ReadTransaction { |
| 437 public: | 450 public: |
| 438 const SBWhitelist* GetSBWhitelist(SBWhitelistId id) { | 451 const SBWhitelist* GetSBWhitelist(SBWhitelistId id) { |
| 439 switch (id) { | 452 switch (id) { |
| 440 case SBWhitelistId::CSD: | 453 case SBWhitelistId::CSD: |
| 441 return &outer_->csd_whitelist_; | 454 return &outer_->csd_whitelist_; |
| 442 case SBWhitelistId::DOWNLOAD: | 455 case SBWhitelistId::DOWNLOAD: |
| 443 return &outer_->download_whitelist_; | 456 return &outer_->download_whitelist_; |
| 444 case SBWhitelistId::INCLUSION: | 457 case SBWhitelistId::INCLUSION: |
| 445 return &outer_->inclusion_whitelist_; | 458 return &outer_->inclusion_whitelist_; |
| 459 case SBWhitelistId::MODULE: |
| 460 return &outer_->module_whitelist_; |
| 446 } | 461 } |
| 447 NOTREACHED(); | 462 NOTREACHED(); |
| 448 return nullptr; | 463 return nullptr; |
| 449 } | 464 } |
| 450 | 465 |
| 451 const IPBlacklist* ip_blacklist() { return &outer_->ip_blacklist_; } | 466 const IPBlacklist* ip_blacklist() { return &outer_->ip_blacklist_; } |
| 452 | 467 |
| 453 const PrefixSet* GetPrefixSet(PrefixSetId id) { | 468 const PrefixSet* GetPrefixSet(PrefixSetId id) { |
| 454 switch (id) { | 469 switch (id) { |
| 455 case PrefixSetId::BROWSE: | 470 case PrefixSetId::BROWSE: |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 } | 561 } |
| 547 | 562 |
| 548 SBWhitelist* SBWhitelistForId(SBWhitelistId id) { | 563 SBWhitelist* SBWhitelistForId(SBWhitelistId id) { |
| 549 switch (id) { | 564 switch (id) { |
| 550 case SBWhitelistId::CSD: | 565 case SBWhitelistId::CSD: |
| 551 return &outer_->csd_whitelist_; | 566 return &outer_->csd_whitelist_; |
| 552 case SBWhitelistId::DOWNLOAD: | 567 case SBWhitelistId::DOWNLOAD: |
| 553 return &outer_->download_whitelist_; | 568 return &outer_->download_whitelist_; |
| 554 case SBWhitelistId::INCLUSION: | 569 case SBWhitelistId::INCLUSION: |
| 555 return &outer_->inclusion_whitelist_; | 570 return &outer_->inclusion_whitelist_; |
| 571 case SBWhitelistId::MODULE: |
| 572 return &outer_->module_whitelist_; |
| 556 } | 573 } |
| 557 NOTREACHED(); | 574 NOTREACHED(); |
| 558 return nullptr; | 575 return nullptr; |
| 559 } | 576 } |
| 560 | 577 |
| 561 ThreadSafeStateManager* outer_; | 578 ThreadSafeStateManager* outer_; |
| 562 base::AutoLock transaction_lock_; | 579 base::AutoLock transaction_lock_; |
| 563 | 580 |
| 564 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); | 581 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); |
| 565 }; | 582 }; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 615 |
| 599 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( | 616 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( |
| 600 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 617 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
| 601 SafeBrowsingStore* browse_store, | 618 SafeBrowsingStore* browse_store, |
| 602 SafeBrowsingStore* download_store, | 619 SafeBrowsingStore* download_store, |
| 603 SafeBrowsingStore* csd_whitelist_store, | 620 SafeBrowsingStore* csd_whitelist_store, |
| 604 SafeBrowsingStore* download_whitelist_store, | 621 SafeBrowsingStore* download_whitelist_store, |
| 605 SafeBrowsingStore* inclusion_whitelist_store, | 622 SafeBrowsingStore* inclusion_whitelist_store, |
| 606 SafeBrowsingStore* extension_blacklist_store, | 623 SafeBrowsingStore* extension_blacklist_store, |
| 607 SafeBrowsingStore* ip_blacklist_store, | 624 SafeBrowsingStore* ip_blacklist_store, |
| 608 SafeBrowsingStore* unwanted_software_store) | 625 SafeBrowsingStore* unwanted_software_store, |
| 626 SafeBrowsingStore* module_whitelist_store) |
| 609 : db_task_runner_(db_task_runner), | 627 : db_task_runner_(db_task_runner), |
| 610 state_manager_(db_task_runner_), | 628 state_manager_(db_task_runner_), |
| 611 db_state_manager_(db_task_runner_), | 629 db_state_manager_(db_task_runner_), |
| 612 browse_store_(browse_store), | 630 browse_store_(browse_store), |
| 613 download_store_(download_store), | 631 download_store_(download_store), |
| 614 csd_whitelist_store_(csd_whitelist_store), | 632 csd_whitelist_store_(csd_whitelist_store), |
| 615 download_whitelist_store_(download_whitelist_store), | 633 download_whitelist_store_(download_whitelist_store), |
| 616 inclusion_whitelist_store_(inclusion_whitelist_store), | 634 inclusion_whitelist_store_(inclusion_whitelist_store), |
| 617 extension_blacklist_store_(extension_blacklist_store), | 635 extension_blacklist_store_(extension_blacklist_store), |
| 618 ip_blacklist_store_(ip_blacklist_store), | 636 ip_blacklist_store_(ip_blacklist_store), |
| 619 unwanted_software_store_(unwanted_software_store), | 637 unwanted_software_store_(unwanted_software_store), |
| 638 module_whitelist_store_(module_whitelist_store), |
| 620 reset_factory_(this) { | 639 reset_factory_(this) { |
| 621 DCHECK(browse_store_.get()); | 640 DCHECK(browse_store_.get()); |
| 622 } | 641 } |
| 623 | 642 |
| 624 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { | 643 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { |
| 625 // The DCHECK is disabled due to crbug.com/338486 . | 644 // The DCHECK is disabled due to crbug.com/338486 . |
| 626 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 645 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 627 } | 646 } |
| 628 | 647 |
| 629 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { | 648 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, | 775 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
| 757 base::Unretained(this))); | 776 base::Unretained(this))); |
| 758 | 777 |
| 759 std::vector<SBAddFullHash> full_hashes; | 778 std::vector<SBAddFullHash> full_hashes; |
| 760 if (ip_blacklist_store_->GetAddFullHashes(&full_hashes)) { | 779 if (ip_blacklist_store_->GetAddFullHashes(&full_hashes)) { |
| 761 LoadIpBlacklist(full_hashes); | 780 LoadIpBlacklist(full_hashes); |
| 762 } else { | 781 } else { |
| 763 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. | 782 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. |
| 764 } | 783 } |
| 765 } | 784 } |
| 785 |
| 786 if (module_whitelist_store_.get()) { |
| 787 module_whitelist_store_->Init( |
| 788 ModuleWhitelistDBFilename(db_state_manager_.filename_base()), |
| 789 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
| 790 base::Unretained(this))); |
| 791 |
| 792 std::vector<SBAddFullHash> full_hashes; |
| 793 if (module_whitelist_store_->GetAddFullHashes(&full_hashes)) { |
| 794 LoadWhitelist(full_hashes, SBWhitelistId::MODULE); |
| 795 } else { |
| 796 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 797 SBWhitelistId::MODULE); |
| 798 } |
| 799 } else { |
| 800 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 801 SBWhitelistId::MODULE); // Just to be safe. |
| 802 } |
| 766 } | 803 } |
| 767 | 804 |
| 768 bool SafeBrowsingDatabaseNew::ResetDatabase() { | 805 bool SafeBrowsingDatabaseNew::ResetDatabase() { |
| 769 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 806 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 770 | 807 |
| 771 // Delete files on disk. | 808 // Delete files on disk. |
| 772 // TODO(shess): Hard to see where one might want to delete without a | 809 // TODO(shess): Hard to see where one might want to delete without a |
| 773 // reset. Perhaps inline |Delete()|? | 810 // reset. Perhaps inline |Delete()|? |
| 774 if (!Delete()) | 811 if (!Delete()) |
| 775 return false; | 812 return false; |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 HandleCorruptDatabase(); | 1205 HandleCorruptDatabase(); |
| 1169 return false; | 1206 return false; |
| 1170 } | 1207 } |
| 1171 | 1208 |
| 1172 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) { | 1209 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) { |
| 1173 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN); | 1210 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN); |
| 1174 HandleCorruptDatabase(); | 1211 HandleCorruptDatabase(); |
| 1175 return false; | 1212 return false; |
| 1176 } | 1213 } |
| 1177 | 1214 |
| 1215 if (module_whitelist_store_.get() && |
| 1216 !module_whitelist_store_->BeginUpdate()) { |
| 1217 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN); |
| 1218 HandleCorruptDatabase(); |
| 1219 return false; |
| 1220 } |
| 1221 |
| 1178 // Cached fullhash results must be cleared on every database update (whether | 1222 // Cached fullhash results must be cleared on every database update (whether |
| 1179 // successful or not). | 1223 // successful or not). |
| 1180 state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); | 1224 state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); |
| 1181 | 1225 |
| 1182 UpdateChunkRangesForLists(browse_store_.get(), kMalwareList, kPhishingList, | 1226 UpdateChunkRangesForLists(browse_store_.get(), kMalwareList, kPhishingList, |
| 1183 lists); | 1227 lists); |
| 1184 | 1228 |
| 1185 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been | 1229 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been |
| 1186 // deprecated. Code to delete the list from the store shows ~15k hits/day as | 1230 // deprecated. Code to delete the list from the store shows ~15k hits/day as |
| 1187 // of Feb 2014, so it has been removed. Everything _should_ be resilient to | 1231 // of Feb 2014, so it has been removed. Everything _should_ be resilient to |
| 1188 // extra data of that sort. | 1232 // extra data of that sort. |
| 1189 UpdateChunkRangesForList(download_store_.get(), kBinUrlList, lists); | 1233 UpdateChunkRangesForList(download_store_.get(), kBinUrlList, lists); |
| 1190 | 1234 |
| 1191 UpdateChunkRangesForList(csd_whitelist_store_.get(), kCsdWhiteList, lists); | 1235 UpdateChunkRangesForList(csd_whitelist_store_.get(), kCsdWhiteList, lists); |
| 1192 | 1236 |
| 1193 UpdateChunkRangesForList(download_whitelist_store_.get(), kDownloadWhiteList, | 1237 UpdateChunkRangesForList(download_whitelist_store_.get(), kDownloadWhiteList, |
| 1194 lists); | 1238 lists); |
| 1195 | 1239 |
| 1196 UpdateChunkRangesForList(inclusion_whitelist_store_.get(), | 1240 UpdateChunkRangesForList(inclusion_whitelist_store_.get(), |
| 1197 kInclusionWhitelist, lists); | 1241 kInclusionWhitelist, lists); |
| 1198 | 1242 |
| 1199 UpdateChunkRangesForList(extension_blacklist_store_.get(), | 1243 UpdateChunkRangesForList(extension_blacklist_store_.get(), |
| 1200 kExtensionBlacklist, lists); | 1244 kExtensionBlacklist, lists); |
| 1201 | 1245 |
| 1202 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); | 1246 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); |
| 1203 | 1247 |
| 1204 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, | 1248 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, |
| 1205 lists); | 1249 lists); |
| 1206 | 1250 |
| 1251 UpdateChunkRangesForList(module_whitelist_store_.get(), kModuleWhitelist, |
| 1252 lists); |
| 1253 |
| 1207 db_state_manager_.reset_corruption_detected(); | 1254 db_state_manager_.reset_corruption_detected(); |
| 1208 db_state_manager_.reset_change_detected(); | 1255 db_state_manager_.reset_change_detected(); |
| 1209 return true; | 1256 return true; |
| 1210 } | 1257 } |
| 1211 | 1258 |
| 1212 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { | 1259 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { |
| 1213 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1260 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 1214 | 1261 |
| 1215 // The update may have failed due to corrupt storage (for instance, | 1262 // The update may have failed due to corrupt storage (for instance, |
| 1216 // an excessive number of invalid add_chunks and sub_chunks). | 1263 // an excessive number of invalid add_chunks and sub_chunks). |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1244 } | 1291 } |
| 1245 | 1292 |
| 1246 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { | 1293 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { |
| 1247 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; | 1294 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; |
| 1248 } | 1295 } |
| 1249 | 1296 |
| 1250 if (unwanted_software_store_ && | 1297 if (unwanted_software_store_ && |
| 1251 !unwanted_software_store_->CheckValidity()) { | 1298 !unwanted_software_store_->CheckValidity()) { |
| 1252 DLOG(ERROR) << "Unwanted software url list database corrupt."; | 1299 DLOG(ERROR) << "Unwanted software url list database corrupt."; |
| 1253 } | 1300 } |
| 1301 |
| 1302 if (module_whitelist_store_ && !module_whitelist_store_->CheckValidity()) { |
| 1303 DLOG(ERROR) << "Module digest whitelist database corrupt."; |
| 1304 } |
| 1254 } | 1305 } |
| 1255 | 1306 |
| 1256 if (db_state_manager_.corruption_detected()) | 1307 if (db_state_manager_.corruption_detected()) |
| 1257 return; | 1308 return; |
| 1258 | 1309 |
| 1259 // Unroll the transaction if there was a protocol error or if the | 1310 // Unroll the transaction if there was a protocol error or if the |
| 1260 // transaction was empty. This will leave the prefix set, the | 1311 // transaction was empty. This will leave the prefix set, the |
| 1261 // pending hashes, and the prefix miss cache in place. | 1312 // pending hashes, and the prefix miss cache in place. |
| 1262 if (!update_succeeded || !db_state_manager_.change_detected()) { | 1313 if (!update_succeeded || !db_state_manager_.change_detected()) { |
| 1263 // Track empty updates to answer questions at http://crbug.com/72216 . | 1314 // Track empty updates to answer questions at http://crbug.com/72216 . |
| 1264 if (update_succeeded && !db_state_manager_.change_detected()) | 1315 if (update_succeeded && !db_state_manager_.change_detected()) |
| 1265 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); | 1316 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); |
| 1266 browse_store_->CancelUpdate(); | 1317 browse_store_->CancelUpdate(); |
| 1267 if (download_store_.get()) | 1318 if (download_store_.get()) |
| 1268 download_store_->CancelUpdate(); | 1319 download_store_->CancelUpdate(); |
| 1269 if (csd_whitelist_store_.get()) | 1320 if (csd_whitelist_store_.get()) |
| 1270 csd_whitelist_store_->CancelUpdate(); | 1321 csd_whitelist_store_->CancelUpdate(); |
| 1271 if (download_whitelist_store_.get()) | 1322 if (download_whitelist_store_.get()) |
| 1272 download_whitelist_store_->CancelUpdate(); | 1323 download_whitelist_store_->CancelUpdate(); |
| 1273 if (inclusion_whitelist_store_.get()) | 1324 if (inclusion_whitelist_store_.get()) |
| 1274 inclusion_whitelist_store_->CancelUpdate(); | 1325 inclusion_whitelist_store_->CancelUpdate(); |
| 1275 if (extension_blacklist_store_) | 1326 if (extension_blacklist_store_) |
| 1276 extension_blacklist_store_->CancelUpdate(); | 1327 extension_blacklist_store_->CancelUpdate(); |
| 1277 if (ip_blacklist_store_) | 1328 if (ip_blacklist_store_) |
| 1278 ip_blacklist_store_->CancelUpdate(); | 1329 ip_blacklist_store_->CancelUpdate(); |
| 1279 if (unwanted_software_store_) | 1330 if (unwanted_software_store_) |
| 1280 unwanted_software_store_->CancelUpdate(); | 1331 unwanted_software_store_->CancelUpdate(); |
| 1332 if (module_whitelist_store_) |
| 1333 module_whitelist_store_->CancelUpdate(); |
| 1281 return; | 1334 return; |
| 1282 } | 1335 } |
| 1283 | 1336 |
| 1284 if (download_store_) { | 1337 if (download_store_) { |
| 1285 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()), | 1338 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()), |
| 1286 download_store_.get(), | 1339 download_store_.get(), |
| 1287 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH); | 1340 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH); |
| 1288 } | 1341 } |
| 1289 | 1342 |
| 1290 UpdatePrefixSetUrlStore(BrowseDBFilename(db_state_manager_.filename_base()), | 1343 UpdatePrefixSetUrlStore(BrowseDBFilename(db_state_manager_.filename_base()), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1312 if (ip_blacklist_store_) | 1365 if (ip_blacklist_store_) |
| 1313 UpdateIpBlacklistStore(); | 1366 UpdateIpBlacklistStore(); |
| 1314 | 1367 |
| 1315 if (unwanted_software_store_) { | 1368 if (unwanted_software_store_) { |
| 1316 UpdatePrefixSetUrlStore( | 1369 UpdatePrefixSetUrlStore( |
| 1317 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), | 1370 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), |
| 1318 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE, | 1371 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE, |
| 1319 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, | 1372 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, |
| 1320 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); | 1373 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); |
| 1321 } | 1374 } |
| 1375 |
| 1376 if (module_whitelist_store_) { |
| 1377 UpdateWhitelistStore( |
| 1378 ModuleWhitelistDBFilename(db_state_manager_.filename_base()), |
| 1379 module_whitelist_store_.get(), SBWhitelistId::MODULE); |
| 1380 } |
| 1322 } | 1381 } |
| 1323 | 1382 |
| 1324 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( | 1383 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( |
| 1325 const base::FilePath& store_filename, | 1384 const base::FilePath& store_filename, |
| 1326 SafeBrowsingStore* store, | 1385 SafeBrowsingStore* store, |
| 1327 SBWhitelistId whitelist_id) { | 1386 SBWhitelistId whitelist_id) { |
| 1328 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1387 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 1329 | 1388 |
| 1330 if (!store) | 1389 if (!store) |
| 1331 return; | 1390 return; |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 histogram_name.append(".InclusionWhitelist"); | 1820 histogram_name.append(".InclusionWhitelist"); |
| 1762 else if (base::EndsWith(filename, kExtensionBlacklistDBFile, | 1821 else if (base::EndsWith(filename, kExtensionBlacklistDBFile, |
| 1763 base::CompareCase::SENSITIVE)) | 1822 base::CompareCase::SENSITIVE)) |
| 1764 histogram_name.append(".ExtensionBlacklist"); | 1823 histogram_name.append(".ExtensionBlacklist"); |
| 1765 else if (base::EndsWith(filename, kIPBlacklistDBFile, | 1824 else if (base::EndsWith(filename, kIPBlacklistDBFile, |
| 1766 base::CompareCase::SENSITIVE)) | 1825 base::CompareCase::SENSITIVE)) |
| 1767 histogram_name.append(".IPBlacklist"); | 1826 histogram_name.append(".IPBlacklist"); |
| 1768 else if (base::EndsWith(filename, kUnwantedSoftwareDBFile, | 1827 else if (base::EndsWith(filename, kUnwantedSoftwareDBFile, |
| 1769 base::CompareCase::SENSITIVE)) | 1828 base::CompareCase::SENSITIVE)) |
| 1770 histogram_name.append(".UnwantedSoftware"); | 1829 histogram_name.append(".UnwantedSoftware"); |
| 1830 else if (base::EndsWith(filename, kModuleWhitelistDBFile, |
| 1831 base::CompareCase::SENSITIVE)) |
| 1832 histogram_name.append(".ModuleWhitelist"); |
| 1771 else | 1833 else |
| 1772 NOTREACHED(); // Add support for new lists above. | 1834 NOTREACHED(); // Add support for new lists above. |
| 1773 | 1835 |
| 1774 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. | 1836 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. |
| 1775 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( | 1837 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( |
| 1776 histogram_name, 1, 1000000, 50, | 1838 histogram_name, 1, 1000000, 50, |
| 1777 base::HistogramBase::kUmaTargetedHistogramFlag); | 1839 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1778 | 1840 |
| 1779 histogram_pointer->Add(file_size_kilobytes); | 1841 histogram_pointer->Add(file_size_kilobytes); |
| 1780 } | 1842 } |
| 1781 | 1843 |
| 1782 } // namespace safe_browsing | 1844 } // namespace safe_browsing |
| OLD | NEW |