Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database.cc

Issue 1073633002: Remove PrerenderLocalPredictor, part 2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prerender-local-predictor-1
Patch Set: also obsolete the histograms uffix Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/safe_browsing/safe_browsing_database.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 318
319 // The default SafeBrowsingDatabaseFactory. 319 // The default SafeBrowsingDatabaseFactory.
320 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { 320 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory {
321 public: 321 public:
322 SafeBrowsingDatabase* CreateSafeBrowsingDatabase( 322 SafeBrowsingDatabase* CreateSafeBrowsingDatabase(
323 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 323 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
324 bool enable_download_protection, 324 bool enable_download_protection,
325 bool enable_client_side_whitelist, 325 bool enable_client_side_whitelist,
326 bool enable_download_whitelist, 326 bool enable_download_whitelist,
327 bool enable_extension_blacklist, 327 bool enable_extension_blacklist,
328 bool enable_side_effect_free_whitelist,
329 bool enable_ip_blacklist, 328 bool enable_ip_blacklist,
330 bool enable_unwanted_software_list) override { 329 bool enable_unwanted_software_list) override {
331 return new SafeBrowsingDatabaseNew( 330 return new SafeBrowsingDatabaseNew(
332 db_task_runner, CreateStore(true, db_task_runner), // browse_store 331 db_task_runner, CreateStore(true, db_task_runner), // browse_store
333 CreateStore(enable_download_protection, db_task_runner), 332 CreateStore(enable_download_protection, db_task_runner),
334 CreateStore(enable_client_side_whitelist, db_task_runner), 333 CreateStore(enable_client_side_whitelist, db_task_runner),
335 CreateStore(enable_download_whitelist, db_task_runner), 334 CreateStore(enable_download_whitelist, db_task_runner),
336 CreateStore(true, db_task_runner), // inclusion_whitelist_store 335 CreateStore(true, db_task_runner), // inclusion_whitelist_store
337 CreateStore(enable_extension_blacklist, db_task_runner), 336 CreateStore(enable_extension_blacklist, db_task_runner),
338 CreateStore(enable_side_effect_free_whitelist, db_task_runner),
339 CreateStore(enable_ip_blacklist, db_task_runner), 337 CreateStore(enable_ip_blacklist, db_task_runner),
340 CreateStore(enable_unwanted_software_list, db_task_runner)); 338 CreateStore(enable_unwanted_software_list, db_task_runner));
341 } 339 }
342 340
343 SafeBrowsingDatabaseFactoryImpl() { } 341 SafeBrowsingDatabaseFactoryImpl() { }
344 342
345 private: 343 private:
346 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); 344 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl);
347 }; 345 };
348 346
349 // static 347 // static
350 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; 348 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL;
351 349
352 // Factory method, should be called on the Safe Browsing sequenced task runner, 350 // Factory method, should be called on the Safe Browsing sequenced task runner,
353 // which is also passed to the function as |current_task_runner|. 351 // which is also passed to the function as |current_task_runner|.
354 // TODO(shess): There's no need for a factory any longer. Convert 352 // TODO(shess): There's no need for a factory any longer. Convert
355 // SafeBrowsingDatabaseNew to SafeBrowsingDatabase, and have Create() 353 // SafeBrowsingDatabaseNew to SafeBrowsingDatabase, and have Create()
356 // callers just construct things directly. 354 // callers just construct things directly.
357 SafeBrowsingDatabase* SafeBrowsingDatabase::Create( 355 SafeBrowsingDatabase* SafeBrowsingDatabase::Create(
358 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner, 356 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner,
359 bool enable_download_protection, 357 bool enable_download_protection,
360 bool enable_client_side_whitelist, 358 bool enable_client_side_whitelist,
361 bool enable_download_whitelist, 359 bool enable_download_whitelist,
362 bool enable_extension_blacklist, 360 bool enable_extension_blacklist,
363 bool enable_side_effect_free_whitelist,
364 bool enable_ip_blacklist, 361 bool enable_ip_blacklist,
365 bool enable_unwanted_software_list) { 362 bool enable_unwanted_software_list) {
366 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); 363 DCHECK(current_task_runner->RunsTasksOnCurrentThread());
367 if (!factory_) 364 if (!factory_)
368 factory_ = new SafeBrowsingDatabaseFactoryImpl(); 365 factory_ = new SafeBrowsingDatabaseFactoryImpl();
369 return factory_->CreateSafeBrowsingDatabase( 366 return factory_->CreateSafeBrowsingDatabase(
370 current_task_runner, enable_download_protection, 367 current_task_runner, enable_download_protection,
371 enable_client_side_whitelist, enable_download_whitelist, 368 enable_client_side_whitelist, enable_download_whitelist,
372 enable_extension_blacklist, enable_side_effect_free_whitelist, 369 enable_extension_blacklist, enable_ip_blacklist,
373 enable_ip_blacklist, enable_unwanted_software_list); 370 enable_unwanted_software_list);
374 } 371 }
375 372
376 SafeBrowsingDatabase::~SafeBrowsingDatabase() { 373 SafeBrowsingDatabase::~SafeBrowsingDatabase() {
377 } 374 }
378 375
379 // static 376 // static
380 base::FilePath SafeBrowsingDatabase::BrowseDBFilename( 377 base::FilePath SafeBrowsingDatabase::BrowseDBFilename(
381 const base::FilePath& db_base_filename) { 378 const base::FilePath& db_base_filename) {
382 return base::FilePath(db_base_filename.value() + kBrowseDBFile); 379 return base::FilePath(db_base_filename.value() + kBrowseDBFile);
383 } 380 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } else if (list_id == safe_browsing_util::BINURL) { 461 } else if (list_id == safe_browsing_util::BINURL) {
465 return download_store_.get(); 462 return download_store_.get();
466 } else if (list_id == safe_browsing_util::CSDWHITELIST) { 463 } else if (list_id == safe_browsing_util::CSDWHITELIST) {
467 return csd_whitelist_store_.get(); 464 return csd_whitelist_store_.get();
468 } else if (list_id == safe_browsing_util::DOWNLOADWHITELIST) { 465 } else if (list_id == safe_browsing_util::DOWNLOADWHITELIST) {
469 return download_whitelist_store_.get(); 466 return download_whitelist_store_.get();
470 } else if (list_id == safe_browsing_util::INCLUSIONWHITELIST) { 467 } else if (list_id == safe_browsing_util::INCLUSIONWHITELIST) {
471 return inclusion_whitelist_store_.get(); 468 return inclusion_whitelist_store_.get();
472 } else if (list_id == safe_browsing_util::EXTENSIONBLACKLIST) { 469 } else if (list_id == safe_browsing_util::EXTENSIONBLACKLIST) {
473 return extension_blacklist_store_.get(); 470 return extension_blacklist_store_.get();
474 } else if (list_id == safe_browsing_util::SIDEEFFECTFREEWHITELIST) {
475 return side_effect_free_whitelist_store_.get();
476 } else if (list_id == safe_browsing_util::IPBLACKLIST) { 471 } else if (list_id == safe_browsing_util::IPBLACKLIST) {
477 return ip_blacklist_store_.get(); 472 return ip_blacklist_store_.get();
478 } else if (list_id == safe_browsing_util::UNWANTEDURL) { 473 } else if (list_id == safe_browsing_util::UNWANTEDURL) {
479 return unwanted_software_store_.get(); 474 return unwanted_software_store_.get();
480 } 475 }
481 return NULL; 476 return NULL;
482 } 477 }
483 478
484 // static 479 // static
485 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { 480 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) {
(...skipping 15 matching lines...) Expand all
501 NOTREACHED(); 496 NOTREACHED();
502 return nullptr; 497 return nullptr;
503 } 498 }
504 499
505 const IPBlacklist* ip_blacklist() { return &outer_->ip_blacklist_; } 500 const IPBlacklist* ip_blacklist() { return &outer_->ip_blacklist_; }
506 501
507 const PrefixSet* GetPrefixSet(PrefixSetId id) { 502 const PrefixSet* GetPrefixSet(PrefixSetId id) {
508 switch (id) { 503 switch (id) {
509 case PrefixSetId::BROWSE: 504 case PrefixSetId::BROWSE:
510 return outer_->browse_prefix_set_.get(); 505 return outer_->browse_prefix_set_.get();
511 case PrefixSetId::SIDE_EFFECT_FREE_WHITELIST:
512 return outer_->side_effect_free_whitelist_prefix_set_.get();
513 case PrefixSetId::UNWANTED_SOFTWARE: 506 case PrefixSetId::UNWANTED_SOFTWARE:
514 return outer_->unwanted_software_prefix_set_.get(); 507 return outer_->unwanted_software_prefix_set_.get();
515 } 508 }
516 NOTREACHED(); 509 NOTREACHED();
517 return nullptr; 510 return nullptr;
518 } 511 }
519 512
520 PrefixGetHashCache* prefix_gethash_cache() { 513 PrefixGetHashCache* prefix_gethash_cache() {
521 // The cache is special: it is read/write on all threads. Access to it 514 // The cache is special: it is read/write on all threads. Access to it
522 // therefore requires a LOCK'ed transaction (i.e. it can't benefit from 515 // therefore requires a LOCK'ed transaction (i.e. it can't benefit from
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 void swap_ip_blacklist(IPBlacklist* new_blacklist) { 569 void swap_ip_blacklist(IPBlacklist* new_blacklist) {
577 outer_->ip_blacklist_.swap(*new_blacklist); 570 outer_->ip_blacklist_.swap(*new_blacklist);
578 } 571 }
579 572
580 void SwapPrefixSet(PrefixSetId id, 573 void SwapPrefixSet(PrefixSetId id,
581 scoped_ptr<const PrefixSet> new_prefix_set) { 574 scoped_ptr<const PrefixSet> new_prefix_set) {
582 switch (id) { 575 switch (id) {
583 case PrefixSetId::BROWSE: 576 case PrefixSetId::BROWSE:
584 outer_->browse_prefix_set_.swap(new_prefix_set); 577 outer_->browse_prefix_set_.swap(new_prefix_set);
585 break; 578 break;
586 case PrefixSetId::SIDE_EFFECT_FREE_WHITELIST:
587 outer_->side_effect_free_whitelist_prefix_set_.swap(new_prefix_set);
588 break;
589 case PrefixSetId::UNWANTED_SOFTWARE: 579 case PrefixSetId::UNWANTED_SOFTWARE:
590 outer_->unwanted_software_prefix_set_.swap(new_prefix_set); 580 outer_->unwanted_software_prefix_set_.swap(new_prefix_set);
591 break; 581 break;
592 } 582 }
593 } 583 }
594 584
595 void clear_prefix_gethash_cache() { outer_->prefix_gethash_cache_.clear(); } 585 void clear_prefix_gethash_cache() { outer_->prefix_gethash_cache_.clear(); }
596 586
597 private: 587 private:
598 // Only ThreadSafeStateManager is allowed to build a WriteTransaction. 588 // Only ThreadSafeStateManager is allowed to build a WriteTransaction.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 } 650 }
661 651
662 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( 652 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew(
663 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 653 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
664 SafeBrowsingStore* browse_store, 654 SafeBrowsingStore* browse_store,
665 SafeBrowsingStore* download_store, 655 SafeBrowsingStore* download_store,
666 SafeBrowsingStore* csd_whitelist_store, 656 SafeBrowsingStore* csd_whitelist_store,
667 SafeBrowsingStore* download_whitelist_store, 657 SafeBrowsingStore* download_whitelist_store,
668 SafeBrowsingStore* inclusion_whitelist_store, 658 SafeBrowsingStore* inclusion_whitelist_store,
669 SafeBrowsingStore* extension_blacklist_store, 659 SafeBrowsingStore* extension_blacklist_store,
670 SafeBrowsingStore* side_effect_free_whitelist_store,
671 SafeBrowsingStore* ip_blacklist_store, 660 SafeBrowsingStore* ip_blacklist_store,
672 SafeBrowsingStore* unwanted_software_store) 661 SafeBrowsingStore* unwanted_software_store)
673 : db_task_runner_(db_task_runner), 662 : db_task_runner_(db_task_runner),
674 state_manager_(db_task_runner_), 663 state_manager_(db_task_runner_),
675 db_state_manager_(db_task_runner_), 664 db_state_manager_(db_task_runner_),
676 browse_store_(browse_store), 665 browse_store_(browse_store),
677 download_store_(download_store), 666 download_store_(download_store),
678 csd_whitelist_store_(csd_whitelist_store), 667 csd_whitelist_store_(csd_whitelist_store),
679 download_whitelist_store_(download_whitelist_store), 668 download_whitelist_store_(download_whitelist_store),
680 inclusion_whitelist_store_(inclusion_whitelist_store), 669 inclusion_whitelist_store_(inclusion_whitelist_store),
681 extension_blacklist_store_(extension_blacklist_store), 670 extension_blacklist_store_(extension_blacklist_store),
682 side_effect_free_whitelist_store_(side_effect_free_whitelist_store),
683 ip_blacklist_store_(ip_blacklist_store), 671 ip_blacklist_store_(ip_blacklist_store),
684 unwanted_software_store_(unwanted_software_store), 672 unwanted_software_store_(unwanted_software_store),
685 reset_factory_(this) { 673 reset_factory_(this) {
686 DCHECK(browse_store_.get()); 674 DCHECK(browse_store_.get());
687 } 675 }
688 676
689 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { 677 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() {
690 // The DCHECK is disabled due to crbug.com/338486 . 678 // The DCHECK is disabled due to crbug.com/338486 .
691 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 679 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
692 } 680 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 LoadPrefixSet(BrowseDBFilename(db_state_manager_.filename_base()), 715 LoadPrefixSet(BrowseDBFilename(db_state_manager_.filename_base()),
728 txn.get(), PrefixSetId::BROWSE, 716 txn.get(), PrefixSetId::BROWSE,
729 FAILURE_BROWSE_PREFIX_SET_READ); 717 FAILURE_BROWSE_PREFIX_SET_READ);
730 if (unwanted_software_store_.get()) { 718 if (unwanted_software_store_.get()) {
731 LoadPrefixSet( 719 LoadPrefixSet(
732 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), 720 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()),
733 txn.get(), PrefixSetId::UNWANTED_SOFTWARE, 721 txn.get(), PrefixSetId::UNWANTED_SOFTWARE,
734 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_READ); 722 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_READ);
735 } 723 }
736 724
737 if (side_effect_free_whitelist_store_.get()) { 725 // Delete any files of the side-effect free sidelist that may be around
738 const base::FilePath side_effect_free_whitelist_filename = 726 // from when it was previously enabled.
Alexei Svitkine (slow) 2015/04/10 15:03:37 Should this have a TODO() to clean up this code in
Scott Hess - ex-Googler 2015/04/10 15:51:45 I'd say after a specific date, but wouldn't worry
davidben 2015/04/13 19:48:18 Done.
739 SideEffectFreeWhitelistDBFilename(db_state_manager_.filename_base()); 727 SafeBrowsingStoreFile::DeleteStore(
740 side_effect_free_whitelist_store_->Init( 728 SideEffectFreeWhitelistDBFilename(db_state_manager_.filename_base()));
741 side_effect_free_whitelist_filename, 729 base::DeleteFile(PrefixSetForFilename(SideEffectFreeWhitelistDBFilename(
742 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, 730 db_state_manager_.filename_base())),
743 base::Unretained(this))); 731 false);
744
745 LoadPrefixSet(side_effect_free_whitelist_filename, txn.get(),
746 PrefixSetId::SIDE_EFFECT_FREE_WHITELIST,
747 FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_READ);
748 } else {
749 // Delete any files of the side-effect free sidelist that may be around
750 // from when it was previously enabled.
751 SafeBrowsingStoreFile::DeleteStore(
752 SideEffectFreeWhitelistDBFilename(db_state_manager_.filename_base()));
753 base::DeleteFile(PrefixSetForFilename(SideEffectFreeWhitelistDBFilename(
754 db_state_manager_.filename_base())),
755 false);
756 }
757 } 732 }
758 // Note: End the transaction early because LoadWhiteList() and 733 // Note: End the transaction early because LoadWhiteList() and
759 // WhitelistEverything() manage their own transactions. 734 // WhitelistEverything() manage their own transactions.
760 735
761 if (download_store_.get()) { 736 if (download_store_.get()) {
762 download_store_->Init( 737 download_store_->Init(
763 DownloadDBFilename(db_state_manager_.filename_base()), 738 DownloadDBFilename(db_state_manager_.filename_base()),
764 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, 739 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase,
765 base::Unretained(this))); 740 base::Unretained(this)));
766 } 741 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 // Delete files on disk. 822 // Delete files on disk.
848 // TODO(shess): Hard to see where one might want to delete without a 823 // TODO(shess): Hard to see where one might want to delete without a
849 // reset. Perhaps inline |Delete()|? 824 // reset. Perhaps inline |Delete()|?
850 if (!Delete()) 825 if (!Delete())
851 return false; 826 return false;
852 827
853 // Reset objects in memory. 828 // Reset objects in memory.
854 scoped_ptr<WriteTransaction> txn = state_manager_.BeginWriteTransaction(); 829 scoped_ptr<WriteTransaction> txn = state_manager_.BeginWriteTransaction();
855 txn->clear_prefix_gethash_cache(); 830 txn->clear_prefix_gethash_cache();
856 txn->SwapPrefixSet(PrefixSetId::BROWSE, nullptr); 831 txn->SwapPrefixSet(PrefixSetId::BROWSE, nullptr);
857 txn->SwapPrefixSet(PrefixSetId::SIDE_EFFECT_FREE_WHITELIST, nullptr);
858 txn->SwapPrefixSet(PrefixSetId::UNWANTED_SOFTWARE, nullptr); 832 txn->SwapPrefixSet(PrefixSetId::UNWANTED_SOFTWARE, nullptr);
859 txn->clear_ip_blacklist(); 833 txn->clear_ip_blacklist();
860 txn->WhitelistEverything(SBWhitelistId::CSD); 834 txn->WhitelistEverything(SBWhitelistId::CSD);
861 txn->WhitelistEverything(SBWhitelistId::DOWNLOAD); 835 txn->WhitelistEverything(SBWhitelistId::DOWNLOAD);
862 return true; 836 return true;
863 } 837 }
864 838
865 bool SafeBrowsingDatabaseNew::ContainsBrowseUrl( 839 bool SafeBrowsingDatabaseNew::ContainsBrowseUrl(
866 const GURL& url, 840 const GURL& url,
867 std::vector<SBPrefix>* prefix_hits, 841 std::vector<SBPrefix>* prefix_hits,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 953
980 if (!extension_blacklist_store_) 954 if (!extension_blacklist_store_)
981 return false; 955 return false;
982 956
983 return MatchAddPrefixes(extension_blacklist_store_.get(), 957 return MatchAddPrefixes(extension_blacklist_store_.get(),
984 safe_browsing_util::EXTENSIONBLACKLIST % 2, 958 safe_browsing_util::EXTENSIONBLACKLIST % 2,
985 prefixes, 959 prefixes,
986 prefix_hits); 960 prefix_hits);
987 } 961 }
988 962
989 bool SafeBrowsingDatabaseNew::ContainsSideEffectFreeWhitelistUrl(
990 const GURL& url) {
991 std::string host;
992 std::string path;
993 std::string query;
994 safe_browsing_util::CanonicalizeUrl(url, &host, &path, &query);
995 std::string url_to_check = host + path;
996 if (!query.empty())
997 url_to_check += "?" + query;
998 SBFullHash full_hash = SBFullHashForString(url_to_check);
999
1000 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction();
1001
1002 const PrefixSet* side_effect_free_whitelist_prefix_set =
1003 txn->GetPrefixSet(PrefixSetId::SIDE_EFFECT_FREE_WHITELIST);
1004
1005 // |side_effect_free_whitelist_prefix_set_| is empty until it is either read
1006 // from disk, or the first update populates it. Bail out without a hit if
1007 // not yet available.
1008 if (!side_effect_free_whitelist_prefix_set)
1009 return false;
1010
1011 return side_effect_free_whitelist_prefix_set->Exists(full_hash);
1012 }
1013
1014 bool SafeBrowsingDatabaseNew::ContainsMalwareIP(const std::string& ip_address) { 963 bool SafeBrowsingDatabaseNew::ContainsMalwareIP(const std::string& ip_address) {
1015 net::IPAddressNumber ip_number; 964 net::IPAddressNumber ip_number;
1016 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) 965 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number))
1017 return false; 966 return false;
1018 if (ip_number.size() == net::kIPv4AddressSize) 967 if (ip_number.size() == net::kIPv4AddressSize)
1019 ip_number = net::ConvertIPv4NumberToIPv6Number(ip_number); 968 ip_number = net::ConvertIPv4NumberToIPv6Number(ip_number);
1020 if (ip_number.size() != net::kIPv6AddressSize) 969 if (ip_number.size() != net::kIPv6AddressSize)
1021 return false; // better safe than sorry. 970 return false; // better safe than sorry.
1022 971
1023 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); 972 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction();
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 return false; 1205 return false;
1257 } 1206 }
1258 1207
1259 if (extension_blacklist_store_ && 1208 if (extension_blacklist_store_ &&
1260 !extension_blacklist_store_->BeginUpdate()) { 1209 !extension_blacklist_store_->BeginUpdate()) {
1261 RecordFailure(FAILURE_EXTENSION_BLACKLIST_UPDATE_BEGIN); 1210 RecordFailure(FAILURE_EXTENSION_BLACKLIST_UPDATE_BEGIN);
1262 HandleCorruptDatabase(); 1211 HandleCorruptDatabase();
1263 return false; 1212 return false;
1264 } 1213 }
1265 1214
1266 if (side_effect_free_whitelist_store_ &&
1267 !side_effect_free_whitelist_store_->BeginUpdate()) {
1268 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_BEGIN);
1269 HandleCorruptDatabase();
1270 return false;
1271 }
1272
1273 if (ip_blacklist_store_ && !ip_blacklist_store_->BeginUpdate()) { 1215 if (ip_blacklist_store_ && !ip_blacklist_store_->BeginUpdate()) {
1274 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_BEGIN); 1216 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_BEGIN);
1275 HandleCorruptDatabase(); 1217 HandleCorruptDatabase();
1276 return false; 1218 return false;
1277 } 1219 }
1278 1220
1279 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) { 1221 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) {
1280 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN); 1222 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN);
1281 HandleCorruptDatabase(); 1223 HandleCorruptDatabase();
1282 return false; 1224 return false;
(...skipping 20 matching lines...) Expand all
1303 1245
1304 UpdateChunkRangesForList(download_whitelist_store_.get(), 1246 UpdateChunkRangesForList(download_whitelist_store_.get(),
1305 safe_browsing_util::kDownloadWhiteList, lists); 1247 safe_browsing_util::kDownloadWhiteList, lists);
1306 1248
1307 UpdateChunkRangesForList(inclusion_whitelist_store_.get(), 1249 UpdateChunkRangesForList(inclusion_whitelist_store_.get(),
1308 safe_browsing_util::kInclusionWhitelist, lists); 1250 safe_browsing_util::kInclusionWhitelist, lists);
1309 1251
1310 UpdateChunkRangesForList(extension_blacklist_store_.get(), 1252 UpdateChunkRangesForList(extension_blacklist_store_.get(),
1311 safe_browsing_util::kExtensionBlacklist, lists); 1253 safe_browsing_util::kExtensionBlacklist, lists);
1312 1254
1313 UpdateChunkRangesForList(side_effect_free_whitelist_store_.get(),
1314 safe_browsing_util::kSideEffectFreeWhitelist, lists);
1315
1316 UpdateChunkRangesForList(ip_blacklist_store_.get(), 1255 UpdateChunkRangesForList(ip_blacklist_store_.get(),
1317 safe_browsing_util::kIPBlacklist, lists); 1256 safe_browsing_util::kIPBlacklist, lists);
1318 1257
1319 UpdateChunkRangesForList(unwanted_software_store_.get(), 1258 UpdateChunkRangesForList(unwanted_software_store_.get(),
1320 safe_browsing_util::kUnwantedUrlList, 1259 safe_browsing_util::kUnwantedUrlList,
1321 lists); 1260 lists);
1322 1261
1323 db_state_manager_.reset_corruption_detected(); 1262 db_state_manager_.reset_corruption_detected();
1324 db_state_manager_.reset_change_detected(); 1263 db_state_manager_.reset_change_detected();
1325 return true; 1264 return true;
(...skipping 26 matching lines...) Expand all
1352 if (inclusion_whitelist_store_.get() && 1291 if (inclusion_whitelist_store_.get() &&
1353 !inclusion_whitelist_store_->CheckValidity()) { 1292 !inclusion_whitelist_store_->CheckValidity()) {
1354 DLOG(ERROR) << "Safe-browsing inclusion whitelist database corrupt."; 1293 DLOG(ERROR) << "Safe-browsing inclusion whitelist database corrupt.";
1355 } 1294 }
1356 1295
1357 if (extension_blacklist_store_ && 1296 if (extension_blacklist_store_ &&
1358 !extension_blacklist_store_->CheckValidity()) { 1297 !extension_blacklist_store_->CheckValidity()) {
1359 DLOG(ERROR) << "Safe-browsing extension blacklist database corrupt."; 1298 DLOG(ERROR) << "Safe-browsing extension blacklist database corrupt.";
1360 } 1299 }
1361 1300
1362 if (side_effect_free_whitelist_store_ &&
1363 !side_effect_free_whitelist_store_->CheckValidity()) {
1364 DLOG(ERROR) << "Safe-browsing side-effect free whitelist database "
1365 << "corrupt.";
1366 }
1367
1368 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { 1301 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) {
1369 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; 1302 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt.";
1370 } 1303 }
1371 1304
1372 if (unwanted_software_store_ && 1305 if (unwanted_software_store_ &&
1373 !unwanted_software_store_->CheckValidity()) { 1306 !unwanted_software_store_->CheckValidity()) {
1374 DLOG(ERROR) << "Unwanted software url list database corrupt."; 1307 DLOG(ERROR) << "Unwanted software url list database corrupt.";
1375 } 1308 }
1376 } 1309 }
1377 1310
(...skipping 11 matching lines...) Expand all
1389 if (download_store_.get()) 1322 if (download_store_.get())
1390 download_store_->CancelUpdate(); 1323 download_store_->CancelUpdate();
1391 if (csd_whitelist_store_.get()) 1324 if (csd_whitelist_store_.get())
1392 csd_whitelist_store_->CancelUpdate(); 1325 csd_whitelist_store_->CancelUpdate();
1393 if (download_whitelist_store_.get()) 1326 if (download_whitelist_store_.get())
1394 download_whitelist_store_->CancelUpdate(); 1327 download_whitelist_store_->CancelUpdate();
1395 if (inclusion_whitelist_store_.get()) 1328 if (inclusion_whitelist_store_.get())
1396 inclusion_whitelist_store_->CancelUpdate(); 1329 inclusion_whitelist_store_->CancelUpdate();
1397 if (extension_blacklist_store_) 1330 if (extension_blacklist_store_)
1398 extension_blacklist_store_->CancelUpdate(); 1331 extension_blacklist_store_->CancelUpdate();
1399 if (side_effect_free_whitelist_store_)
1400 side_effect_free_whitelist_store_->CancelUpdate();
1401 if (ip_blacklist_store_) 1332 if (ip_blacklist_store_)
1402 ip_blacklist_store_->CancelUpdate(); 1333 ip_blacklist_store_->CancelUpdate();
1403 if (unwanted_software_store_) 1334 if (unwanted_software_store_)
1404 unwanted_software_store_->CancelUpdate(); 1335 unwanted_software_store_->CancelUpdate();
1405 return; 1336 return;
1406 } 1337 }
1407 1338
1408 if (download_store_) { 1339 if (download_store_) {
1409 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()), 1340 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()),
1410 download_store_.get(), 1341 download_store_.get(),
(...skipping 15 matching lines...) Expand all
1426 InclusionWhitelistDBFilename(db_state_manager_.filename_base()), 1357 InclusionWhitelistDBFilename(db_state_manager_.filename_base()),
1427 inclusion_whitelist_store_.get(), SBWhitelistId::INCLUSION); 1358 inclusion_whitelist_store_.get(), SBWhitelistId::INCLUSION);
1428 1359
1429 if (extension_blacklist_store_) { 1360 if (extension_blacklist_store_) {
1430 UpdateHashPrefixStore( 1361 UpdateHashPrefixStore(
1431 ExtensionBlacklistDBFilename(db_state_manager_.filename_base()), 1362 ExtensionBlacklistDBFilename(db_state_manager_.filename_base()),
1432 extension_blacklist_store_.get(), 1363 extension_blacklist_store_.get(),
1433 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH); 1364 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH);
1434 } 1365 }
1435 1366
1436 if (side_effect_free_whitelist_store_) {
1437 UpdatePrefixSetUrlStore(
1438 SideEffectFreeWhitelistDBFilename(db_state_manager_.filename_base()),
1439 side_effect_free_whitelist_store_.get(),
1440 PrefixSetId::SIDE_EFFECT_FREE_WHITELIST,
1441 FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_FINISH,
1442 FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_WRITE, false);
1443 }
1444
1445 if (ip_blacklist_store_) 1367 if (ip_blacklist_store_)
1446 UpdateIpBlacklistStore(); 1368 UpdateIpBlacklistStore();
1447 1369
1448 if (unwanted_software_store_) { 1370 if (unwanted_software_store_) {
1449 UpdatePrefixSetUrlStore( 1371 UpdatePrefixSetUrlStore(
1450 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), 1372 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()),
1451 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE, 1373 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE,
1452 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, 1374 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH,
1453 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); 1375 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true);
1454 } 1376 }
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 const bool r7 = base::DeleteFile(browse_prefix_set_filename, false); 1643 const bool r7 = base::DeleteFile(browse_prefix_set_filename, false);
1722 if (!r7) 1644 if (!r7)
1723 RecordFailure(FAILURE_BROWSE_PREFIX_SET_DELETE); 1645 RecordFailure(FAILURE_BROWSE_PREFIX_SET_DELETE);
1724 1646
1725 const base::FilePath extension_blacklist_filename = 1647 const base::FilePath extension_blacklist_filename =
1726 ExtensionBlacklistDBFilename(db_state_manager_.filename_base()); 1648 ExtensionBlacklistDBFilename(db_state_manager_.filename_base());
1727 const bool r8 = base::DeleteFile(extension_blacklist_filename, false); 1649 const bool r8 = base::DeleteFile(extension_blacklist_filename, false);
1728 if (!r8) 1650 if (!r8)
1729 RecordFailure(FAILURE_EXTENSION_BLACKLIST_DELETE); 1651 RecordFailure(FAILURE_EXTENSION_BLACKLIST_DELETE);
1730 1652
1731 const base::FilePath side_effect_free_whitelist_filename = 1653 const bool r9 = base::DeleteFile(
1732 SideEffectFreeWhitelistDBFilename(db_state_manager_.filename_base()); 1654 IpBlacklistDBFilename(db_state_manager_.filename_base()), false);
1733 const bool r9 = base::DeleteFile(side_effect_free_whitelist_filename,
1734 false);
1735 if (!r9) 1655 if (!r9)
1736 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_DELETE);
1737
1738 const base::FilePath side_effect_free_whitelist_prefix_set_filename =
1739 PrefixSetForFilename(side_effect_free_whitelist_filename);
1740 const bool r10 = base::DeleteFile(
1741 side_effect_free_whitelist_prefix_set_filename,
1742 false);
1743 if (!r10)
1744 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_DELETE);
1745
1746 const bool r11 = base::DeleteFile(
1747 IpBlacklistDBFilename(db_state_manager_.filename_base()), false);
1748 if (!r11)
1749 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); 1656 RecordFailure(FAILURE_IP_BLACKLIST_DELETE);
1750 1657
1751 const bool r12 = base::DeleteFile( 1658 const bool r10 = base::DeleteFile(
1752 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), false); 1659 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), false);
1753 if (!r12) 1660 if (!r10)
1754 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); 1661 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE);
1755 1662
1756 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11 && 1663 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10;
1757 r12;
1758 } 1664 }
1759 1665
1760 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, 1666 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename,
1761 PrefixSetId prefix_set_id, 1667 PrefixSetId prefix_set_id,
1762 FailureType write_failure_type) { 1668 FailureType write_failure_type) {
1763 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1669 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
1764 1670
1765 // Do not grab the lock to avoid contention while writing to disk. This is 1671 // Do not grab the lock to avoid contention while writing to disk. This is
1766 // safe as only this task runner can ever modify |state_manager_|'s prefix 1672 // safe as only this task runner can ever modify |state_manager_|'s prefix
1767 // sets anyways. 1673 // sets anyways.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 else if (EndsWith(filename, kDownloadDBFile, true)) 1808 else if (EndsWith(filename, kDownloadDBFile, true))
1903 histogram_name.append(".Download"); 1809 histogram_name.append(".Download");
1904 else if (EndsWith(filename, kCsdWhitelistDBFile, true)) 1810 else if (EndsWith(filename, kCsdWhitelistDBFile, true))
1905 histogram_name.append(".CsdWhitelist"); 1811 histogram_name.append(".CsdWhitelist");
1906 else if (EndsWith(filename, kDownloadWhitelistDBFile, true)) 1812 else if (EndsWith(filename, kDownloadWhitelistDBFile, true))
1907 histogram_name.append(".DownloadWhitelist"); 1813 histogram_name.append(".DownloadWhitelist");
1908 else if (EndsWith(filename, kInclusionWhitelistDBFile, true)) 1814 else if (EndsWith(filename, kInclusionWhitelistDBFile, true))
1909 histogram_name.append(".InclusionWhitelist"); 1815 histogram_name.append(".InclusionWhitelist");
1910 else if (EndsWith(filename, kExtensionBlacklistDBFile, true)) 1816 else if (EndsWith(filename, kExtensionBlacklistDBFile, true))
1911 histogram_name.append(".ExtensionBlacklist"); 1817 histogram_name.append(".ExtensionBlacklist");
1912 else if (EndsWith(filename, kSideEffectFreeWhitelistDBFile, true))
1913 histogram_name.append(".SideEffectFreeWhitelist");
1914 else if (EndsWith(filename, kIPBlacklistDBFile, true)) 1818 else if (EndsWith(filename, kIPBlacklistDBFile, true))
1915 histogram_name.append(".IPBlacklist"); 1819 histogram_name.append(".IPBlacklist");
1916 else if (EndsWith(filename, kUnwantedSoftwareDBFile, true)) 1820 else if (EndsWith(filename, kUnwantedSoftwareDBFile, true))
1917 histogram_name.append(".UnwantedSoftware"); 1821 histogram_name.append(".UnwantedSoftware");
1918 else 1822 else
1919 NOTREACHED(); // Add support for new lists above. 1823 NOTREACHED(); // Add support for new lists above.
1920 1824
1921 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. 1825 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro.
1922 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( 1826 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet(
1923 histogram_name, 1, 1000000, 50, 1827 histogram_name, 1, 1000000, 50,
1924 base::HistogramBase::kUmaTargetedHistogramFlag); 1828 base::HistogramBase::kUmaTargetedHistogramFlag);
1925 1829
1926 histogram_pointer->Add(file_size_kilobytes); 1830 histogram_pointer->Add(file_size_kilobytes);
1927 } 1831 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698