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

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

Issue 2871303004: Rename TaskRunner::RunsTasksOnCurrentThread() in //chrome (Closed)
Patch Set: fixed build error Created 3 years, 7 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // callers just construct things directly. 317 // callers just construct things directly.
318 std::unique_ptr<SafeBrowsingDatabase> SafeBrowsingDatabase::Create( 318 std::unique_ptr<SafeBrowsingDatabase> SafeBrowsingDatabase::Create(
319 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner, 319 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner,
320 bool enable_download_protection, 320 bool enable_download_protection,
321 bool enable_client_side_whitelist, 321 bool enable_client_side_whitelist,
322 bool enable_download_whitelist, 322 bool enable_download_whitelist,
323 bool enable_extension_blacklist, 323 bool enable_extension_blacklist,
324 bool enable_ip_blacklist, 324 bool enable_ip_blacklist,
325 bool enable_unwanted_software_list, 325 bool enable_unwanted_software_list,
326 bool enable_module_whitelist) { 326 bool enable_module_whitelist) {
327 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); 327 DCHECK(current_task_runner->RunsTasksInCurrentSequence());
328 if (!factory_) 328 if (!factory_)
329 factory_ = new SafeBrowsingDatabaseFactoryImpl(); 329 factory_ = new SafeBrowsingDatabaseFactoryImpl();
330 return factory_->CreateSafeBrowsingDatabase( 330 return factory_->CreateSafeBrowsingDatabase(
331 current_task_runner, enable_download_protection, 331 current_task_runner, enable_download_protection,
332 enable_client_side_whitelist, enable_download_whitelist, 332 enable_client_side_whitelist, enable_download_whitelist,
333 enable_extension_blacklist, enable_ip_blacklist, 333 enable_extension_blacklist, enable_ip_blacklist,
334 enable_unwanted_software_list, enable_module_whitelist); 334 enable_unwanted_software_list, enable_module_whitelist);
335 } 335 }
336 336
337 SafeBrowsingDatabase::~SafeBrowsingDatabase() {} 337 SafeBrowsingDatabase::~SafeBrowsingDatabase() {}
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 std::vector<SBFullHash> full_hashes; 421 std::vector<SBFullHash> full_hashes;
422 for (size_t i = 0; i < urls.size(); ++i) 422 for (size_t i = 0; i < urls.size(); ++i)
423 UrlToFullHashes(urls[i], false, &full_hashes); 423 UrlToFullHashes(urls[i], false, &full_hashes);
424 424
425 for (size_t i = 0; i < full_hashes.size(); ++i) 425 for (size_t i = 0; i < full_hashes.size(); ++i)
426 prefixes->push_back(full_hashes[i].prefix); 426 prefixes->push_back(full_hashes[i].prefix);
427 } 427 }
428 428
429 SafeBrowsingStore* SafeBrowsingDatabaseNew::GetStore(const int list_id) { 429 SafeBrowsingStore* SafeBrowsingDatabaseNew::GetStore(const int list_id) {
430 // Stores are not thread safe. 430 // Stores are not thread safe.
431 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 431 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
432 432
433 if (list_id == PHISH || list_id == MALWARE) { 433 if (list_id == PHISH || list_id == MALWARE) {
434 return browse_store_.get(); 434 return browse_store_.get();
435 } else if (list_id == BINURL) { 435 } else if (list_id == BINURL) {
436 return download_store_.get(); 436 return download_store_.get();
437 } else if (list_id == CSDWHITELIST) { 437 } else if (list_id == CSDWHITELIST) {
438 return csd_whitelist_store_.get(); 438 return csd_whitelist_store_.get();
439 } else if (list_id == DOWNLOADWHITELIST) { 439 } else if (list_id == DOWNLOADWHITELIST) {
440 return download_whitelist_store_.get(); 440 return download_whitelist_store_.get();
441 } else if (list_id == EXTENSIONBLACKLIST) { 441 } else if (list_id == EXTENSIONBLACKLIST) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 DONT_LOCK_ON_MAIN_TASK_RUNNER 507 DONT_LOCK_ON_MAIN_TASK_RUNNER
508 }; 508 };
509 509
510 ReadTransaction(const ThreadSafeStateManager* outer, 510 ReadTransaction(const ThreadSafeStateManager* outer,
511 AutoLockRequirement auto_lock_requirement) 511 AutoLockRequirement auto_lock_requirement)
512 : outer_(outer) { 512 : outer_(outer) {
513 DCHECK(outer_); 513 DCHECK(outer_);
514 if (auto_lock_requirement == AutoLockRequirement::LOCK) 514 if (auto_lock_requirement == AutoLockRequirement::LOCK)
515 transaction_lock_.reset(new base::AutoLock(outer_->lock_)); 515 transaction_lock_.reset(new base::AutoLock(outer_->lock_));
516 else 516 else
517 DCHECK(outer_->db_task_runner_->RunsTasksOnCurrentThread()); 517 DCHECK(outer_->db_task_runner_->RunsTasksInCurrentSequence());
518 } 518 }
519 519
520 const ThreadSafeStateManager* outer_; 520 const ThreadSafeStateManager* outer_;
521 std::unique_ptr<base::AutoLock> transaction_lock_; 521 std::unique_ptr<base::AutoLock> transaction_lock_;
522 522
523 DISALLOW_COPY_AND_ASSIGN(ReadTransaction); 523 DISALLOW_COPY_AND_ASSIGN(ReadTransaction);
524 }; 524 };
525 525
526 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::WriteTransaction { 526 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::WriteTransaction {
527 public: 527 public:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 560
561 void clear_prefix_gethash_cache() { outer_->prefix_gethash_cache_.clear(); } 561 void clear_prefix_gethash_cache() { outer_->prefix_gethash_cache_.clear(); }
562 562
563 private: 563 private:
564 // Only ThreadSafeStateManager is allowed to build a WriteTransaction. 564 // Only ThreadSafeStateManager is allowed to build a WriteTransaction.
565 friend class ThreadSafeStateManager; 565 friend class ThreadSafeStateManager;
566 566
567 explicit WriteTransaction(ThreadSafeStateManager* outer) 567 explicit WriteTransaction(ThreadSafeStateManager* outer)
568 : outer_(outer), transaction_lock_(outer_->lock_) { 568 : outer_(outer), transaction_lock_(outer_->lock_) {
569 DCHECK(outer_); 569 DCHECK(outer_);
570 DCHECK(outer_->db_task_runner_->RunsTasksOnCurrentThread()); 570 DCHECK(outer_->db_task_runner_->RunsTasksInCurrentSequence());
571 } 571 }
572 572
573 SBWhitelist* SBWhitelistForId(SBWhitelistId id) { 573 SBWhitelist* SBWhitelistForId(SBWhitelistId id) {
574 switch (id) { 574 switch (id) {
575 case SBWhitelistId::CSD: 575 case SBWhitelistId::CSD:
576 return &outer_->csd_whitelist_; 576 return &outer_->csd_whitelist_;
577 case SBWhitelistId::DOWNLOAD: 577 case SBWhitelistId::DOWNLOAD:
578 return &outer_->download_whitelist_; 578 return &outer_->download_whitelist_;
579 case SBWhitelistId::MODULE: 579 case SBWhitelistId::MODULE:
580 return &outer_->module_whitelist_; 580 return &outer_->module_whitelist_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 ip_blacklist_store_(ip_blacklist_store), 644 ip_blacklist_store_(ip_blacklist_store),
645 unwanted_software_store_(unwanted_software_store), 645 unwanted_software_store_(unwanted_software_store),
646 module_whitelist_store_(module_whitelist_store), 646 module_whitelist_store_(module_whitelist_store),
647 resource_blacklist_store_(resource_blacklist_store), 647 resource_blacklist_store_(resource_blacklist_store),
648 reset_factory_(this) { 648 reset_factory_(this) {
649 DCHECK(browse_store_.get()); 649 DCHECK(browse_store_.get());
650 } 650 }
651 651
652 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { 652 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() {
653 // The DCHECK is disabled due to crbug.com/338486 . 653 // The DCHECK is disabled due to crbug.com/338486 .
654 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 654 // DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
655 } 655 }
656 656
657 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { 657 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) {
658 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 658 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
659 659
660 db_state_manager_.init_filename_base(filename_base); 660 db_state_manager_.init_filename_base(filename_base);
661 661
662 // TODO(shess): The various stores are really only necessary while doing 662 // TODO(shess): The various stores are really only necessary while doing
663 // updates (see |UpdateFinished()|) or when querying a store directly (see 663 // updates (see |UpdateFinished()|) or when querying a store directly (see
664 // |ContainsDownloadUrl()|). 664 // |ContainsDownloadUrl()|).
665 // The store variables are also tested to see if a list is enabled. Perhaps 665 // The store variables are also tested to see if a list is enabled. Perhaps
666 // the stores could be refactored into an update object so that they are only 666 // the stores could be refactored into an update object so that they are only
667 // live in memory while being actively used. The sense of enabled probably 667 // live in memory while being actively used. The sense of enabled probably
668 // belongs in protocol_manager or database_manager. 668 // belongs in protocol_manager or database_manager.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 805
806 if (resource_blacklist_store_.get()) { 806 if (resource_blacklist_store_.get()) {
807 resource_blacklist_store_->Init( 807 resource_blacklist_store_->Init(
808 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), 808 ResourceBlacklistDBFilename(db_state_manager_.filename_base()),
809 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, 809 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase,
810 base::Unretained(this))); 810 base::Unretained(this)));
811 } 811 }
812 } 812 }
813 813
814 bool SafeBrowsingDatabaseNew::ResetDatabase() { 814 bool SafeBrowsingDatabaseNew::ResetDatabase() {
815 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 815 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
816 816
817 // Delete files on disk. 817 // Delete files on disk.
818 // TODO(shess): Hard to see where one might want to delete without a 818 // TODO(shess): Hard to see where one might want to delete without a
819 // reset. Perhaps inline |Delete()|? 819 // reset. Perhaps inline |Delete()|?
820 if (!Delete()) 820 if (!Delete())
821 return false; 821 return false;
822 822
823 // Reset objects in memory. 823 // Reset objects in memory.
824 std::unique_ptr<WriteTransaction> txn = 824 std::unique_ptr<WriteTransaction> txn =
825 state_manager_.BeginWriteTransaction(); 825 state_manager_.BeginWriteTransaction();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 std::sort(prefix_hits->begin(), prefix_hits->end()); 915 std::sort(prefix_hits->begin(), prefix_hits->end());
916 prefix_hits->erase(std::unique(prefix_hits->begin(), prefix_hits->end()), 916 prefix_hits->erase(std::unique(prefix_hits->begin(), prefix_hits->end()),
917 prefix_hits->end()); 917 prefix_hits->end());
918 918
919 return !prefix_hits->empty() || !cache_hits->empty(); 919 return !prefix_hits->empty() || !cache_hits->empty();
920 } 920 }
921 921
922 bool SafeBrowsingDatabaseNew::ContainsDownloadUrlPrefixes( 922 bool SafeBrowsingDatabaseNew::ContainsDownloadUrlPrefixes(
923 const std::vector<SBPrefix>& prefixes, 923 const std::vector<SBPrefix>& prefixes,
924 std::vector<SBPrefix>* prefix_hits) { 924 std::vector<SBPrefix>* prefix_hits) {
925 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 925 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
926 926
927 // Ignore this check when download checking is not enabled. 927 // Ignore this check when download checking is not enabled.
928 if (!download_store_.get()) 928 if (!download_store_.get())
929 return false; 929 return false;
930 930
931 return MatchAddPrefixes(download_store_.get(), BINURL % 2, prefixes, 931 return MatchAddPrefixes(download_store_.get(), BINURL % 2, prefixes,
932 prefix_hits); 932 prefix_hits);
933 } 933 }
934 934
935 bool SafeBrowsingDatabaseNew::ContainsCsdWhitelistedUrl(const GURL& url) { 935 bool SafeBrowsingDatabaseNew::ContainsCsdWhitelistedUrl(const GURL& url) {
936 std::vector<SBFullHash> full_hashes; 936 std::vector<SBFullHash> full_hashes;
937 UrlToFullHashes(url, true, &full_hashes); 937 UrlToFullHashes(url, true, &full_hashes);
938 return ContainsWhitelistedHashes(SBWhitelistId::CSD, full_hashes); 938 return ContainsWhitelistedHashes(SBWhitelistId::CSD, full_hashes);
939 } 939 }
940 940
941 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedUrl(const GURL& url) { 941 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedUrl(const GURL& url) {
942 std::vector<SBFullHash> full_hashes; 942 std::vector<SBFullHash> full_hashes;
943 UrlToFullHashes(url, true, &full_hashes); 943 UrlToFullHashes(url, true, &full_hashes);
944 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, full_hashes); 944 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, full_hashes);
945 } 945 }
946 946
947 bool SafeBrowsingDatabaseNew::ContainsExtensionPrefixes( 947 bool SafeBrowsingDatabaseNew::ContainsExtensionPrefixes(
948 const std::vector<SBPrefix>& prefixes, 948 const std::vector<SBPrefix>& prefixes,
949 std::vector<SBPrefix>* prefix_hits) { 949 std::vector<SBPrefix>* prefix_hits) {
950 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 950 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
951 951
952 if (!extension_blacklist_store_) 952 if (!extension_blacklist_store_)
953 return false; 953 return false;
954 954
955 return MatchAddPrefixes(extension_blacklist_store_.get(), 955 return MatchAddPrefixes(extension_blacklist_store_.get(),
956 EXTENSIONBLACKLIST % 2, prefixes, prefix_hits); 956 EXTENSIONBLACKLIST % 2, prefixes, prefix_hits);
957 } 957 }
958 958
959 bool SafeBrowsingDatabaseNew::ContainsMalwareIP(const std::string& ip_address) { 959 bool SafeBrowsingDatabaseNew::ContainsMalwareIP(const std::string& ip_address) {
960 net::IPAddress address; 960 net::IPAddress address;
(...skipping 20 matching lines...) Expand all
981 if (it->second.count(hash) > 0) { 981 if (it->second.count(hash) > 0) {
982 return true; 982 return true;
983 } 983 }
984 } 984 }
985 return false; 985 return false;
986 } 986 }
987 987
988 bool SafeBrowsingDatabaseNew::ContainsResourceUrlPrefixes( 988 bool SafeBrowsingDatabaseNew::ContainsResourceUrlPrefixes(
989 const std::vector<SBPrefix>& prefixes, 989 const std::vector<SBPrefix>& prefixes,
990 std::vector<SBPrefix>* prefix_hits) { 990 std::vector<SBPrefix>* prefix_hits) {
991 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 991 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
992 992
993 if (!resource_blacklist_store_) 993 if (!resource_blacklist_store_)
994 return false; 994 return false;
995 995
996 return MatchAddPrefixes(resource_blacklist_store_.get(), 996 return MatchAddPrefixes(resource_blacklist_store_.get(),
997 RESOURCEBLACKLIST % 2, prefixes, prefix_hits); 997 RESOURCEBLACKLIST % 2, prefixes, prefix_hits);
998 } 998 }
999 999
1000 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString( 1000 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString(
1001 const std::string& str) { 1001 const std::string& str) {
(...skipping 23 matching lines...) Expand all
1025 return true; 1025 return true;
1026 } 1026 }
1027 } 1027 }
1028 return false; 1028 return false;
1029 } 1029 }
1030 1030
1031 // Helper to insert add-chunk entries. 1031 // Helper to insert add-chunk entries.
1032 void SafeBrowsingDatabaseNew::InsertAddChunk(SafeBrowsingStore* store, 1032 void SafeBrowsingDatabaseNew::InsertAddChunk(SafeBrowsingStore* store,
1033 const ListType list_id, 1033 const ListType list_id,
1034 const SBChunkData& chunk_data) { 1034 const SBChunkData& chunk_data) {
1035 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1035 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1036 DCHECK(store); 1036 DCHECK(store);
1037 1037
1038 // The server can give us a chunk that we already have because 1038 // The server can give us a chunk that we already have because
1039 // it's part of a range. Don't add it again. 1039 // it's part of a range. Don't add it again.
1040 const int chunk_id = chunk_data.ChunkNumber(); 1040 const int chunk_id = chunk_data.ChunkNumber();
1041 const int encoded_chunk_id = EncodeChunkId(chunk_id, list_id); 1041 const int encoded_chunk_id = EncodeChunkId(chunk_id, list_id);
1042 if (store->CheckAddChunk(encoded_chunk_id)) 1042 if (store->CheckAddChunk(encoded_chunk_id))
1043 return; 1043 return;
1044 1044
1045 store->SetAddChunk(encoded_chunk_id); 1045 store->SetAddChunk(encoded_chunk_id);
1046 if (chunk_data.IsPrefix()) { 1046 if (chunk_data.IsPrefix()) {
1047 const size_t c = chunk_data.PrefixCount(); 1047 const size_t c = chunk_data.PrefixCount();
1048 for (size_t i = 0; i < c; ++i) { 1048 for (size_t i = 0; i < c; ++i) {
1049 store->WriteAddPrefix(encoded_chunk_id, chunk_data.PrefixAt(i)); 1049 store->WriteAddPrefix(encoded_chunk_id, chunk_data.PrefixAt(i));
1050 } 1050 }
1051 } else { 1051 } else {
1052 const size_t c = chunk_data.FullHashCount(); 1052 const size_t c = chunk_data.FullHashCount();
1053 for (size_t i = 0; i < c; ++i) { 1053 for (size_t i = 0; i < c; ++i) {
1054 store->WriteAddHash(encoded_chunk_id, chunk_data.FullHashAt(i)); 1054 store->WriteAddHash(encoded_chunk_id, chunk_data.FullHashAt(i));
1055 } 1055 }
1056 } 1056 }
1057 } 1057 }
1058 1058
1059 // Helper to insert sub-chunk entries. 1059 // Helper to insert sub-chunk entries.
1060 void SafeBrowsingDatabaseNew::InsertSubChunk(SafeBrowsingStore* store, 1060 void SafeBrowsingDatabaseNew::InsertSubChunk(SafeBrowsingStore* store,
1061 const ListType list_id, 1061 const ListType list_id,
1062 const SBChunkData& chunk_data) { 1062 const SBChunkData& chunk_data) {
1063 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1063 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1064 DCHECK(store); 1064 DCHECK(store);
1065 1065
1066 // The server can give us a chunk that we already have because 1066 // The server can give us a chunk that we already have because
1067 // it's part of a range. Don't add it again. 1067 // it's part of a range. Don't add it again.
1068 const int chunk_id = chunk_data.ChunkNumber(); 1068 const int chunk_id = chunk_data.ChunkNumber();
1069 const int encoded_chunk_id = EncodeChunkId(chunk_id, list_id); 1069 const int encoded_chunk_id = EncodeChunkId(chunk_id, list_id);
1070 if (store->CheckSubChunk(encoded_chunk_id)) 1070 if (store->CheckSubChunk(encoded_chunk_id))
1071 return; 1071 return;
1072 1072
1073 store->SetSubChunk(encoded_chunk_id); 1073 store->SetSubChunk(encoded_chunk_id);
(...skipping 12 matching lines...) Expand all
1086 const int encoded_add_chunk_id = EncodeChunkId(add_chunk_id, list_id); 1086 const int encoded_add_chunk_id = EncodeChunkId(add_chunk_id, list_id);
1087 store->WriteSubHash(encoded_chunk_id, encoded_add_chunk_id, 1087 store->WriteSubHash(encoded_chunk_id, encoded_add_chunk_id,
1088 chunk_data.FullHashAt(i)); 1088 chunk_data.FullHashAt(i));
1089 } 1089 }
1090 } 1090 }
1091 } 1091 }
1092 1092
1093 void SafeBrowsingDatabaseNew::InsertChunks( 1093 void SafeBrowsingDatabaseNew::InsertChunks(
1094 const std::string& list_name, 1094 const std::string& list_name,
1095 const std::vector<std::unique_ptr<SBChunkData>>& chunks) { 1095 const std::vector<std::unique_ptr<SBChunkData>>& chunks) {
1096 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1096 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1097 1097
1098 if (db_state_manager_.corruption_detected() || chunks.empty()) 1098 if (db_state_manager_.corruption_detected() || chunks.empty())
1099 return; 1099 return;
1100 1100
1101 const base::TimeTicks before = base::TimeTicks::Now(); 1101 const base::TimeTicks before = base::TimeTicks::Now();
1102 1102
1103 // TODO(shess): The caller should just pass list_id. 1103 // TODO(shess): The caller should just pass list_id.
1104 const ListType list_id = GetListId(list_name); 1104 const ListType list_id = GetListId(list_name);
1105 1105
1106 SafeBrowsingStore* store = GetStore(list_id); 1106 SafeBrowsingStore* store = GetStore(list_id);
(...skipping 14 matching lines...) Expand all
1121 NOTREACHED(); 1121 NOTREACHED();
1122 } 1122 }
1123 } 1123 }
1124 store->FinishChunk(); 1124 store->FinishChunk();
1125 1125
1126 UMA_HISTOGRAM_TIMES("SB2.ChunkInsert", base::TimeTicks::Now() - before); 1126 UMA_HISTOGRAM_TIMES("SB2.ChunkInsert", base::TimeTicks::Now() - before);
1127 } 1127 }
1128 1128
1129 void SafeBrowsingDatabaseNew::DeleteChunks( 1129 void SafeBrowsingDatabaseNew::DeleteChunks(
1130 const std::vector<SBChunkDelete>& chunk_deletes) { 1130 const std::vector<SBChunkDelete>& chunk_deletes) {
1131 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1131 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1132 1132
1133 if (db_state_manager_.corruption_detected() || chunk_deletes.empty()) 1133 if (db_state_manager_.corruption_detected() || chunk_deletes.empty())
1134 return; 1134 return;
1135 1135
1136 const std::string& list_name = chunk_deletes.front().list_name; 1136 const std::string& list_name = chunk_deletes.front().list_name;
1137 const ListType list_id = GetListId(list_name); 1137 const ListType list_id = GetListId(list_name);
1138 1138
1139 SafeBrowsingStore* store = GetStore(list_id); 1139 SafeBrowsingStore* store = GetStore(list_id);
1140 if (!store) 1140 if (!store)
1141 return; 1141 return;
(...skipping 30 matching lines...) Expand all
1172 // Insert any fullhash hits. Note that there may be one, multiple, or no 1172 // Insert any fullhash hits. Note that there may be one, multiple, or no
1173 // fullhashes for any given entry in |prefixes|. 1173 // fullhashes for any given entry in |prefixes|.
1174 for (size_t i = 0; i < full_hits.size(); ++i) { 1174 for (size_t i = 0; i < full_hits.size(); ++i) {
1175 const SBPrefix prefix = full_hits[i].hash.prefix; 1175 const SBPrefix prefix = full_hits[i].hash.prefix;
1176 (*prefix_gethash_cache)[prefix].full_hashes.push_back(full_hits[i]); 1176 (*prefix_gethash_cache)[prefix].full_hashes.push_back(full_hits[i]);
1177 } 1177 }
1178 } 1178 }
1179 1179
1180 bool SafeBrowsingDatabaseNew::UpdateStarted( 1180 bool SafeBrowsingDatabaseNew::UpdateStarted(
1181 std::vector<SBListChunkRanges>* lists) { 1181 std::vector<SBListChunkRanges>* lists) {
1182 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1182 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1183 DCHECK(lists); 1183 DCHECK(lists);
1184 1184
1185 // If |BeginUpdate()| fails, reset the database. 1185 // If |BeginUpdate()| fails, reset the database.
1186 if (!browse_store_->BeginUpdate()) { 1186 if (!browse_store_->BeginUpdate()) {
1187 RecordFailure(FAILURE_BROWSE_DATABASE_UPDATE_BEGIN); 1187 RecordFailure(FAILURE_BROWSE_DATABASE_UPDATE_BEGIN);
1188 HandleCorruptDatabase(); 1188 HandleCorruptDatabase();
1189 return false; 1189 return false;
1190 } 1190 }
1191 1191
1192 if (download_store_.get() && !download_store_->BeginUpdate()) { 1192 if (download_store_.get() && !download_store_->BeginUpdate()) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 1271
1272 UpdateChunkRangesForList(resource_blacklist_store_.get(), kResourceBlacklist, 1272 UpdateChunkRangesForList(resource_blacklist_store_.get(), kResourceBlacklist,
1273 lists); 1273 lists);
1274 1274
1275 db_state_manager_.reset_corruption_detected(); 1275 db_state_manager_.reset_corruption_detected();
1276 db_state_manager_.reset_change_detected(); 1276 db_state_manager_.reset_change_detected();
1277 return true; 1277 return true;
1278 } 1278 }
1279 1279
1280 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { 1280 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) {
1281 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1281 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1282 1282
1283 // The update may have failed due to corrupt storage (for instance, 1283 // The update may have failed due to corrupt storage (for instance,
1284 // an excessive number of invalid add_chunks and sub_chunks). 1284 // an excessive number of invalid add_chunks and sub_chunks).
1285 // Double-check that the databases are valid. 1285 // Double-check that the databases are valid.
1286 // TODO(shess): Providing a checksum for the add_chunk and sub_chunk 1286 // TODO(shess): Providing a checksum for the add_chunk and sub_chunk
1287 // sections would allow throwing a corruption error in 1287 // sections would allow throwing a corruption error in
1288 // UpdateStarted(). 1288 // UpdateStarted().
1289 if (!update_succeeded) { 1289 if (!update_succeeded) {
1290 if (!browse_store_->CheckValidity()) 1290 if (!browse_store_->CheckValidity())
1291 DLOG(ERROR) << "Safe-browsing browse database corrupt."; 1291 DLOG(ERROR) << "Safe-browsing browse database corrupt.";
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), 1402 ResourceBlacklistDBFilename(db_state_manager_.filename_base()),
1403 resource_blacklist_store_.get(), 1403 resource_blacklist_store_.get(),
1404 FAILURE_RESOURCE_BLACKLIST_UPDATE_FINISH); 1404 FAILURE_RESOURCE_BLACKLIST_UPDATE_FINISH);
1405 } 1405 }
1406 } 1406 }
1407 1407
1408 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( 1408 void SafeBrowsingDatabaseNew::UpdateWhitelistStore(
1409 const base::FilePath& store_filename, 1409 const base::FilePath& store_filename,
1410 SafeBrowsingStore* store, 1410 SafeBrowsingStore* store,
1411 SBWhitelistId whitelist_id) { 1411 SBWhitelistId whitelist_id) {
1412 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1412 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1413 1413
1414 if (!store) 1414 if (!store)
1415 return; 1415 return;
1416 1416
1417 // Note: |builder| will not be empty. The current data store implementation 1417 // Note: |builder| will not be empty. The current data store implementation
1418 // stores all full-length hashes as both full and prefix hashes. 1418 // stores all full-length hashes as both full and prefix hashes.
1419 PrefixSetBuilder builder; 1419 PrefixSetBuilder builder;
1420 std::vector<SBAddFullHash> full_hashes; 1420 std::vector<SBAddFullHash> full_hashes;
1421 if (!store->FinishUpdate(&builder, &full_hashes)) { 1421 if (!store->FinishUpdate(&builder, &full_hashes)) {
1422 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_FINISH); 1422 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_FINISH);
1423 state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id); 1423 state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id);
1424 return; 1424 return;
1425 } 1425 }
1426 1426
1427 RecordFileSizeHistogram(store_filename); 1427 RecordFileSizeHistogram(store_filename);
1428 1428
1429 #if defined(OS_MACOSX) 1429 #if defined(OS_MACOSX)
1430 base::mac::SetFileBackupExclusion(store_filename); 1430 base::mac::SetFileBackupExclusion(store_filename);
1431 #endif 1431 #endif
1432 1432
1433 LoadWhitelist(full_hashes, whitelist_id); 1433 LoadWhitelist(full_hashes, whitelist_id);
1434 } 1434 }
1435 1435
1436 void SafeBrowsingDatabaseNew::UpdateHashPrefixStore( 1436 void SafeBrowsingDatabaseNew::UpdateHashPrefixStore(
1437 const base::FilePath& store_filename, 1437 const base::FilePath& store_filename,
1438 SafeBrowsingStore* store, 1438 SafeBrowsingStore* store,
1439 FailureType failure_type) { 1439 FailureType failure_type) {
1440 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1440 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1441 1441
1442 // These results are not used after this call. Simply ignore the 1442 // These results are not used after this call. Simply ignore the
1443 // returned value after FinishUpdate(...). 1443 // returned value after FinishUpdate(...).
1444 PrefixSetBuilder builder; 1444 PrefixSetBuilder builder;
1445 std::vector<SBAddFullHash> add_full_hashes_result; 1445 std::vector<SBAddFullHash> add_full_hashes_result;
1446 1446
1447 if (!store->FinishUpdate(&builder, &add_full_hashes_result)) 1447 if (!store->FinishUpdate(&builder, &add_full_hashes_result))
1448 RecordFailure(failure_type); 1448 RecordFailure(failure_type);
1449 1449
1450 RecordFileSizeHistogram(store_filename); 1450 RecordFileSizeHistogram(store_filename);
1451 1451
1452 #if defined(OS_MACOSX) 1452 #if defined(OS_MACOSX)
1453 base::mac::SetFileBackupExclusion(store_filename); 1453 base::mac::SetFileBackupExclusion(store_filename);
1454 #endif 1454 #endif
1455 } 1455 }
1456 1456
1457 void SafeBrowsingDatabaseNew::UpdatePrefixSetUrlStore( 1457 void SafeBrowsingDatabaseNew::UpdatePrefixSetUrlStore(
1458 const base::FilePath& db_filename, 1458 const base::FilePath& db_filename,
1459 SafeBrowsingStore* url_store, 1459 SafeBrowsingStore* url_store,
1460 PrefixSetId prefix_set_id, 1460 PrefixSetId prefix_set_id,
1461 FailureType finish_failure_type, 1461 FailureType finish_failure_type,
1462 FailureType write_failure_type, 1462 FailureType write_failure_type,
1463 bool store_full_hashes_in_prefix_set) { 1463 bool store_full_hashes_in_prefix_set) {
1464 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1464 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1465 DCHECK(url_store); 1465 DCHECK(url_store);
1466 1466
1467 // Measure the amount of IO during the filter build. 1467 // Measure the amount of IO during the filter build.
1468 base::IoCounters io_before, io_after; 1468 base::IoCounters io_before, io_after;
1469 std::unique_ptr<base::ProcessMetrics> metric( 1469 std::unique_ptr<base::ProcessMetrics> metric(
1470 base::ProcessMetrics::CreateCurrentProcessMetrics()); 1470 base::ProcessMetrics::CreateCurrentProcessMetrics());
1471 1471
1472 // IoCounters are currently not supported on Mac, and may not be 1472 // IoCounters are currently not supported on Mac, and may not be
1473 // available for Linux, so we check the result and only show IO 1473 // available for Linux, so we check the result and only show IO
1474 // stats if they are available. 1474 // stats if they are available.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 } 1529 }
1530 1530
1531 RecordFileSizeHistogram(db_filename); 1531 RecordFileSizeHistogram(db_filename);
1532 1532
1533 #if defined(OS_MACOSX) 1533 #if defined(OS_MACOSX)
1534 base::mac::SetFileBackupExclusion(db_filename); 1534 base::mac::SetFileBackupExclusion(db_filename);
1535 #endif 1535 #endif
1536 } 1536 }
1537 1537
1538 void SafeBrowsingDatabaseNew::UpdateIpBlacklistStore() { 1538 void SafeBrowsingDatabaseNew::UpdateIpBlacklistStore() {
1539 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1539 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1540 1540
1541 // Note: prefixes will not be empty. The current data store implementation 1541 // Note: prefixes will not be empty. The current data store implementation
1542 // stores all full-length hashes as both full and prefix hashes. 1542 // stores all full-length hashes as both full and prefix hashes.
1543 PrefixSetBuilder builder; 1543 PrefixSetBuilder builder;
1544 std::vector<SBAddFullHash> full_hashes; 1544 std::vector<SBAddFullHash> full_hashes;
1545 if (!ip_blacklist_store_->FinishUpdate(&builder, &full_hashes)) { 1545 if (!ip_blacklist_store_->FinishUpdate(&builder, &full_hashes)) {
1546 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_FINISH); 1546 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_FINISH);
1547 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. 1547 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list.
1548 return; 1548 return;
1549 } 1549 }
1550 1550
1551 const base::FilePath ip_blacklist_filename = 1551 const base::FilePath ip_blacklist_filename =
1552 IpBlacklistDBFilename(db_state_manager_.filename_base()); 1552 IpBlacklistDBFilename(db_state_manager_.filename_base());
1553 1553
1554 RecordFileSizeHistogram(ip_blacklist_filename); 1554 RecordFileSizeHistogram(ip_blacklist_filename);
1555 1555
1556 #if defined(OS_MACOSX) 1556 #if defined(OS_MACOSX)
1557 base::mac::SetFileBackupExclusion(ip_blacklist_filename); 1557 base::mac::SetFileBackupExclusion(ip_blacklist_filename);
1558 #endif 1558 #endif
1559 1559
1560 LoadIpBlacklist(full_hashes); 1560 LoadIpBlacklist(full_hashes);
1561 } 1561 }
1562 1562
1563 void SafeBrowsingDatabaseNew::HandleCorruptDatabase() { 1563 void SafeBrowsingDatabaseNew::HandleCorruptDatabase() {
1564 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1564 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1565 1565
1566 // Reset the database after the current task has unwound (but only 1566 // Reset the database after the current task has unwound (but only
1567 // reset once within the scope of a given task). 1567 // reset once within the scope of a given task).
1568 if (!reset_factory_.HasWeakPtrs()) { 1568 if (!reset_factory_.HasWeakPtrs()) {
1569 RecordFailure(FAILURE_DATABASE_CORRUPT); 1569 RecordFailure(FAILURE_DATABASE_CORRUPT);
1570 db_task_runner_->PostTask( 1570 db_task_runner_->PostTask(
1571 FROM_HERE, 1571 FROM_HERE,
1572 base::BindOnce(&SafeBrowsingDatabaseNew::OnHandleCorruptDatabase, 1572 base::BindOnce(&SafeBrowsingDatabaseNew::OnHandleCorruptDatabase,
1573 reset_factory_.GetWeakPtr())); 1573 reset_factory_.GetWeakPtr()));
1574 } 1574 }
1575 } 1575 }
1576 1576
1577 void SafeBrowsingDatabaseNew::OnHandleCorruptDatabase() { 1577 void SafeBrowsingDatabaseNew::OnHandleCorruptDatabase() {
1578 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1578 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1579 1579
1580 RecordFailure(FAILURE_DATABASE_CORRUPT_HANDLER); 1580 RecordFailure(FAILURE_DATABASE_CORRUPT_HANDLER);
1581 db_state_manager_.set_corruption_detected(); // Stop updating the database. 1581 db_state_manager_.set_corruption_detected(); // Stop updating the database.
1582 ResetDatabase(); 1582 ResetDatabase();
1583 1583
1584 // NOTE(shess): ResetDatabase() should remove the corruption, so this should 1584 // NOTE(shess): ResetDatabase() should remove the corruption, so this should
1585 // only happen once. If you are here because you are hitting this after a 1585 // only happen once. If you are here because you are hitting this after a
1586 // restart, then I would be very interested in working with you to figure out 1586 // restart, then I would be very interested in working with you to figure out
1587 // what is happening, since it may affect real users. 1587 // what is happening, since it may affect real users.
1588 DLOG(FATAL) << "SafeBrowsing database was corrupt and reset"; 1588 DLOG(FATAL) << "SafeBrowsing database was corrupt and reset";
1589 } 1589 }
1590 1590
1591 // TODO(shess): I'm not clear why this code doesn't have any 1591 // TODO(shess): I'm not clear why this code doesn't have any
1592 // real error-handling. 1592 // real error-handling.
1593 void SafeBrowsingDatabaseNew::LoadPrefixSet(const base::FilePath& db_filename, 1593 void SafeBrowsingDatabaseNew::LoadPrefixSet(const base::FilePath& db_filename,
1594 WriteTransaction* txn, 1594 WriteTransaction* txn,
1595 PrefixSetId prefix_set_id, 1595 PrefixSetId prefix_set_id,
1596 FailureType read_failure_type) { 1596 FailureType read_failure_type) {
1597 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1597 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1598 DCHECK(txn); 1598 DCHECK(txn);
1599 DCHECK(!db_state_manager_.filename_base().empty()); 1599 DCHECK(!db_state_manager_.filename_base().empty());
1600 1600
1601 // Only use the prefix set if database is present and non-empty. 1601 // Only use the prefix set if database is present and non-empty.
1602 if (!GetFileSizeOrZero(db_filename)) 1602 if (!GetFileSizeOrZero(db_filename))
1603 return; 1603 return;
1604 1604
1605 // Cleanup any stale bloom filter (no longer used). 1605 // Cleanup any stale bloom filter (no longer used).
1606 // TODO(shess): Track existence to drive removal of this code? 1606 // TODO(shess): Track existence to drive removal of this code?
1607 const base::FilePath bloom_filter_filename = 1607 const base::FilePath bloom_filter_filename =
1608 BloomFilterForFilename(db_filename); 1608 BloomFilterForFilename(db_filename);
1609 base::DeleteFile(bloom_filter_filename, false); 1609 base::DeleteFile(bloom_filter_filename, false);
1610 1610
1611 const base::TimeTicks before = base::TimeTicks::Now(); 1611 const base::TimeTicks before = base::TimeTicks::Now();
1612 std::unique_ptr<const PrefixSet> new_prefix_set = 1612 std::unique_ptr<const PrefixSet> new_prefix_set =
1613 PrefixSet::LoadFile(PrefixSetForFilename(db_filename)); 1613 PrefixSet::LoadFile(PrefixSetForFilename(db_filename));
1614 if (!new_prefix_set.get()) 1614 if (!new_prefix_set.get())
1615 RecordFailure(read_failure_type); 1615 RecordFailure(read_failure_type);
1616 txn->SwapPrefixSet(prefix_set_id, std::move(new_prefix_set)); 1616 txn->SwapPrefixSet(prefix_set_id, std::move(new_prefix_set));
1617 UMA_HISTOGRAM_TIMES("SB2.PrefixSetLoad", base::TimeTicks::Now() - before); 1617 UMA_HISTOGRAM_TIMES("SB2.PrefixSetLoad", base::TimeTicks::Now() - before);
1618 } 1618 }
1619 1619
1620 bool SafeBrowsingDatabaseNew::Delete() { 1620 bool SafeBrowsingDatabaseNew::Delete() {
1621 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1621 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1622 DCHECK(!db_state_manager_.filename_base().empty()); 1622 DCHECK(!db_state_manager_.filename_base().empty());
1623 1623
1624 // TODO(shess): This is a mess. SafeBrowsingFileStore::Delete() closes the 1624 // TODO(shess): This is a mess. SafeBrowsingFileStore::Delete() closes the
1625 // store before calling DeleteStore(). DeleteStore() deletes transient files 1625 // store before calling DeleteStore(). DeleteStore() deletes transient files
1626 // in addition to the main file. Probably all of these should be converted to 1626 // in addition to the main file. Probably all of these should be converted to
1627 // a helper which calls Delete() if the store exists, else DeleteStore() on 1627 // a helper which calls Delete() if the store exists, else DeleteStore() on
1628 // the generated filename. 1628 // the generated filename.
1629 1629
1630 // TODO(shess): Determine if the histograms are useful in any way. I cannot 1630 // TODO(shess): Determine if the histograms are useful in any way. I cannot
1631 // recall any action taken as a result of their values, in which case it might 1631 // recall any action taken as a result of their values, in which case it might
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 module_whitelist_store_.get() ? module_whitelist_store_->Delete() : true; 1690 module_whitelist_store_.get() ? module_whitelist_store_->Delete() : true;
1691 if (!r11) 1691 if (!r11)
1692 RecordFailure(FAILURE_MODULE_WHITELIST_DELETE); 1692 RecordFailure(FAILURE_MODULE_WHITELIST_DELETE);
1693 1693
1694 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11; 1694 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11;
1695 } 1695 }
1696 1696
1697 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, 1697 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename,
1698 PrefixSetId prefix_set_id, 1698 PrefixSetId prefix_set_id,
1699 FailureType write_failure_type) { 1699 FailureType write_failure_type) {
1700 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1700 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1701 1701
1702 // Do not grab the lock to avoid contention while writing to disk. This is 1702 // Do not grab the lock to avoid contention while writing to disk. This is
1703 // safe as only this task runner can ever modify |state_manager_|'s prefix 1703 // safe as only this task runner can ever modify |state_manager_|'s prefix
1704 // sets anyways. 1704 // sets anyways.
1705 std::unique_ptr<ReadTransaction> txn = 1705 std::unique_ptr<ReadTransaction> txn =
1706 state_manager_.BeginReadTransactionNoLockOnMainTaskRunner(); 1706 state_manager_.BeginReadTransactionNoLockOnMainTaskRunner();
1707 const PrefixSet* prefix_set = txn->GetPrefixSet(prefix_set_id); 1707 const PrefixSet* prefix_set = txn->GetPrefixSet(prefix_set_id);
1708 1708
1709 if (!prefix_set) 1709 if (!prefix_set)
1710 return; 1710 return;
(...skipping 10 matching lines...) Expand all
1721 RecordFailure(write_failure_type); 1721 RecordFailure(write_failure_type);
1722 1722
1723 #if defined(OS_MACOSX) 1723 #if defined(OS_MACOSX)
1724 base::mac::SetFileBackupExclusion(prefix_set_filename); 1724 base::mac::SetFileBackupExclusion(prefix_set_filename);
1725 #endif 1725 #endif
1726 } 1726 }
1727 1727
1728 void SafeBrowsingDatabaseNew::LoadWhitelist( 1728 void SafeBrowsingDatabaseNew::LoadWhitelist(
1729 const std::vector<SBAddFullHash>& full_hashes, 1729 const std::vector<SBAddFullHash>& full_hashes,
1730 SBWhitelistId whitelist_id) { 1730 SBWhitelistId whitelist_id) {
1731 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1731 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1732 1732
1733 if (full_hashes.size() > kMaxWhitelistSize && 1733 if (full_hashes.size() > kMaxWhitelistSize &&
1734 whitelist_id != SBWhitelistId::MODULE) { 1734 whitelist_id != SBWhitelistId::MODULE) {
1735 state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id); 1735 state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id);
1736 return; 1736 return;
1737 } 1737 }
1738 1738
1739 if (full_hashes.empty() && whitelist_id == SBWhitelistId::MODULE) { 1739 if (full_hashes.empty() && whitelist_id == SBWhitelistId::MODULE) {
1740 state_manager_.BeginWriteTransaction()->WhitelistEverything( 1740 state_manager_.BeginWriteTransaction()->WhitelistEverything(
1741 SBWhitelistId::MODULE); 1741 SBWhitelistId::MODULE);
(...skipping 14 matching lines...) Expand all
1756 // The kill switch is whitelisted hence we whitelist all URLs. 1756 // The kill switch is whitelisted hence we whitelist all URLs.
1757 state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id); 1757 state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id);
1758 } else { 1758 } else {
1759 state_manager_.BeginWriteTransaction()->SwapSBWhitelist(whitelist_id, 1759 state_manager_.BeginWriteTransaction()->SwapSBWhitelist(whitelist_id,
1760 &new_whitelist); 1760 &new_whitelist);
1761 } 1761 }
1762 } 1762 }
1763 1763
1764 void SafeBrowsingDatabaseNew::LoadIpBlacklist( 1764 void SafeBrowsingDatabaseNew::LoadIpBlacklist(
1765 const std::vector<SBAddFullHash>& full_hashes) { 1765 const std::vector<SBAddFullHash>& full_hashes) {
1766 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1766 DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
1767 1767
1768 IPBlacklist new_blacklist; 1768 IPBlacklist new_blacklist;
1769 for (std::vector<SBAddFullHash>::const_iterator it = full_hashes.begin(); 1769 for (std::vector<SBAddFullHash>::const_iterator it = full_hashes.begin();
1770 it != full_hashes.end(); ++it) { 1770 it != full_hashes.end(); ++it) {
1771 const char* full_hash = it->full_hash.full_hash; 1771 const char* full_hash = it->full_hash.full_hash;
1772 DCHECK_EQ(crypto::kSHA256Length, arraysize(it->full_hash.full_hash)); 1772 DCHECK_EQ(crypto::kSHA256Length, arraysize(it->full_hash.full_hash));
1773 // The format of the IP blacklist is: 1773 // The format of the IP blacklist is:
1774 // SHA-1(IPv6 prefix) + uint8_t(prefix size) + 11 unused bytes. 1774 // SHA-1(IPv6 prefix) + uint8_t(prefix size) + 11 unused bytes.
1775 std::string hashed_ip_prefix(full_hash, base::kSHA1Length); 1775 std::string hashed_ip_prefix(full_hash, base::kSHA1Length);
1776 size_t prefix_size = static_cast<uint8_t>(full_hash[base::kSHA1Length]); 1776 size_t prefix_size = static_cast<uint8_t>(full_hash[base::kSHA1Length]);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 1875
1876 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. 1876 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro.
1877 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( 1877 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet(
1878 histogram_name, 1, 1000000, 50, 1878 histogram_name, 1, 1000000, 50,
1879 base::HistogramBase::kUmaTargetedHistogramFlag); 1879 base::HistogramBase::kUmaTargetedHistogramFlag);
1880 1880
1881 histogram_pointer->Add(file_size_kilobytes); 1881 histogram_pointer->Add(file_size_kilobytes);
1882 } 1882 }
1883 1883
1884 } // namespace safe_browsing 1884 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_database.h ('k') | chrome/browser/safe_browsing/safe_browsing_store_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698