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

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

Issue 1870003002: Convert //chrome/browser/safe_browsing from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address comments Created 4 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9
9 #include <algorithm> 10 #include <algorithm>
10 #include <iterator> 11 #include <iterator>
11 #include <utility> 12 #include <utility>
12 13
13 #include "base/bind.h" 14 #include "base/bind.h"
14 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h"
16 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
17 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
18 #include "base/process/process_handle.h" 20 #include "base/process/process_handle.h"
19 #include "base/process/process_metrics.h" 21 #include "base/process/process_metrics.h"
20 #include "base/sha1.h" 22 #include "base/sha1.h"
21 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
24 #include "base/time/time.h" 26 #include "base/time/time.h"
25 #include "build/build_config.h" 27 #include "build/build_config.h"
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 AutoLockRequirement auto_lock_requirement) 516 AutoLockRequirement auto_lock_requirement)
515 : outer_(outer) { 517 : outer_(outer) {
516 DCHECK(outer_); 518 DCHECK(outer_);
517 if (auto_lock_requirement == AutoLockRequirement::LOCK) 519 if (auto_lock_requirement == AutoLockRequirement::LOCK)
518 transaction_lock_.reset(new base::AutoLock(outer_->lock_)); 520 transaction_lock_.reset(new base::AutoLock(outer_->lock_));
519 else 521 else
520 DCHECK(outer_->db_task_runner_->RunsTasksOnCurrentThread()); 522 DCHECK(outer_->db_task_runner_->RunsTasksOnCurrentThread());
521 } 523 }
522 524
523 const ThreadSafeStateManager* outer_; 525 const ThreadSafeStateManager* outer_;
524 scoped_ptr<base::AutoLock> transaction_lock_; 526 std::unique_ptr<base::AutoLock> transaction_lock_;
525 527
526 DISALLOW_COPY_AND_ASSIGN(ReadTransaction); 528 DISALLOW_COPY_AND_ASSIGN(ReadTransaction);
527 }; 529 };
528 530
529 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::WriteTransaction { 531 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::WriteTransaction {
530 public: 532 public:
531 // Call this method if an error occured with the given whitelist. This will 533 // Call this method if an error occured with the given whitelist. This will
532 // result in all lookups to the whitelist to return true. 534 // result in all lookups to the whitelist to return true.
533 void WhitelistEverything(SBWhitelistId id) { 535 void WhitelistEverything(SBWhitelistId id) {
534 SBWhitelist* whitelist = SBWhitelistForId(id); 536 SBWhitelist* whitelist = SBWhitelistForId(id);
535 whitelist->second = true; 537 whitelist->second = true;
536 whitelist->first.clear(); 538 whitelist->first.clear();
537 } 539 }
538 540
539 void SwapSBWhitelist(SBWhitelistId id, 541 void SwapSBWhitelist(SBWhitelistId id,
540 std::vector<SBFullHash>* new_whitelist) { 542 std::vector<SBFullHash>* new_whitelist) {
541 SBWhitelist* whitelist = SBWhitelistForId(id); 543 SBWhitelist* whitelist = SBWhitelistForId(id);
542 whitelist->second = false; 544 whitelist->second = false;
543 whitelist->first.swap(*new_whitelist); 545 whitelist->first.swap(*new_whitelist);
544 } 546 }
545 547
546 void clear_ip_blacklist() { outer_->ip_blacklist_.clear(); } 548 void clear_ip_blacklist() { outer_->ip_blacklist_.clear(); }
547 549
548 void swap_ip_blacklist(IPBlacklist* new_blacklist) { 550 void swap_ip_blacklist(IPBlacklist* new_blacklist) {
549 outer_->ip_blacklist_.swap(*new_blacklist); 551 outer_->ip_blacklist_.swap(*new_blacklist);
550 } 552 }
551 553
552 void SwapPrefixSet(PrefixSetId id, 554 void SwapPrefixSet(PrefixSetId id,
553 scoped_ptr<const PrefixSet> new_prefix_set) { 555 std::unique_ptr<const PrefixSet> new_prefix_set) {
554 switch (id) { 556 switch (id) {
555 case PrefixSetId::BROWSE: 557 case PrefixSetId::BROWSE:
556 outer_->browse_prefix_set_.swap(new_prefix_set); 558 outer_->browse_prefix_set_.swap(new_prefix_set);
557 break; 559 break;
558 case PrefixSetId::UNWANTED_SOFTWARE: 560 case PrefixSetId::UNWANTED_SOFTWARE:
559 outer_->unwanted_software_prefix_set_.swap(new_prefix_set); 561 outer_->unwanted_software_prefix_set_.swap(new_prefix_set);
560 break; 562 break;
561 } 563 }
562 } 564 }
563 565
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 SafeBrowsingDatabaseNew::ThreadSafeStateManager::~ThreadSafeStateManager() {} 603 SafeBrowsingDatabaseNew::ThreadSafeStateManager::~ThreadSafeStateManager() {}
602 604
603 SafeBrowsingDatabaseNew::DatabaseStateManager::DatabaseStateManager( 605 SafeBrowsingDatabaseNew::DatabaseStateManager::DatabaseStateManager(
604 const scoped_refptr<const base::SequencedTaskRunner>& db_task_runner) 606 const scoped_refptr<const base::SequencedTaskRunner>& db_task_runner)
605 : db_task_runner_(db_task_runner), 607 : db_task_runner_(db_task_runner),
606 corruption_detected_(false), 608 corruption_detected_(false),
607 change_detected_(false) {} 609 change_detected_(false) {}
608 610
609 SafeBrowsingDatabaseNew::DatabaseStateManager::~DatabaseStateManager() {} 611 SafeBrowsingDatabaseNew::DatabaseStateManager::~DatabaseStateManager() {}
610 612
611 scoped_ptr<SafeBrowsingDatabaseNew::ReadTransaction> 613 std::unique_ptr<SafeBrowsingDatabaseNew::ReadTransaction>
612 SafeBrowsingDatabaseNew::ThreadSafeStateManager::BeginReadTransaction() { 614 SafeBrowsingDatabaseNew::ThreadSafeStateManager::BeginReadTransaction() {
613 return make_scoped_ptr( 615 return base::WrapUnique(
614 new ReadTransaction(this, ReadTransaction::AutoLockRequirement::LOCK)); 616 new ReadTransaction(this, ReadTransaction::AutoLockRequirement::LOCK));
615 } 617 }
616 618
617 scoped_ptr<SafeBrowsingDatabaseNew::ReadTransaction> SafeBrowsingDatabaseNew:: 619 std::unique_ptr<SafeBrowsingDatabaseNew::ReadTransaction>
618 ThreadSafeStateManager::BeginReadTransactionNoLockOnMainTaskRunner() { 620 SafeBrowsingDatabaseNew::ThreadSafeStateManager::
619 return make_scoped_ptr(new ReadTransaction( 621 BeginReadTransactionNoLockOnMainTaskRunner() {
622 return base::WrapUnique(new ReadTransaction(
620 this, 623 this,
621 ReadTransaction::AutoLockRequirement::DONT_LOCK_ON_MAIN_TASK_RUNNER)); 624 ReadTransaction::AutoLockRequirement::DONT_LOCK_ON_MAIN_TASK_RUNNER));
622 } 625 }
623 626
624 scoped_ptr<SafeBrowsingDatabaseNew::WriteTransaction> 627 std::unique_ptr<SafeBrowsingDatabaseNew::WriteTransaction>
625 SafeBrowsingDatabaseNew::ThreadSafeStateManager::BeginWriteTransaction() { 628 SafeBrowsingDatabaseNew::ThreadSafeStateManager::BeginWriteTransaction() {
626 return make_scoped_ptr(new WriteTransaction(this)); 629 return base::WrapUnique(new WriteTransaction(this));
627 } 630 }
628 631
629 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( 632 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew(
630 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 633 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
631 SafeBrowsingStore* browse_store, 634 SafeBrowsingStore* browse_store,
632 SafeBrowsingStore* download_store, 635 SafeBrowsingStore* download_store,
633 SafeBrowsingStore* csd_whitelist_store, 636 SafeBrowsingStore* csd_whitelist_store,
634 SafeBrowsingStore* download_whitelist_store, 637 SafeBrowsingStore* download_whitelist_store,
635 SafeBrowsingStore* inclusion_whitelist_store, 638 SafeBrowsingStore* inclusion_whitelist_store,
636 SafeBrowsingStore* extension_blacklist_store, 639 SafeBrowsingStore* extension_blacklist_store,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 // The store variables are also tested to see if a list is enabled. Perhaps 674 // The store variables are also tested to see if a list is enabled. Perhaps
672 // the stores could be refactored into an update object so that they are only 675 // the stores could be refactored into an update object so that they are only
673 // live in memory while being actively used. The sense of enabled probably 676 // live in memory while being actively used. The sense of enabled probably
674 // belongs in protocol_manager or database_manager. 677 // belongs in protocol_manager or database_manager.
675 678
676 { 679 {
677 // NOTE: A transaction here is overkill as there are no pointers to this 680 // NOTE: A transaction here is overkill as there are no pointers to this
678 // class on other threads until this function returns, but it's also 681 // class on other threads until this function returns, but it's also
679 // harmless as that also means there is no possibility of contention on the 682 // harmless as that also means there is no possibility of contention on the
680 // lock. 683 // lock.
681 scoped_ptr<WriteTransaction> txn = state_manager_.BeginWriteTransaction(); 684 std::unique_ptr<WriteTransaction> txn =
685 state_manager_.BeginWriteTransaction();
682 686
683 txn->clear_prefix_gethash_cache(); 687 txn->clear_prefix_gethash_cache();
684 688
685 browse_store_->Init( 689 browse_store_->Init(
686 BrowseDBFilename(db_state_manager_.filename_base()), 690 BrowseDBFilename(db_state_manager_.filename_base()),
687 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, 691 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase,
688 base::Unretained(this))); 692 base::Unretained(this)));
689 693
690 if (unwanted_software_store_.get()) { 694 if (unwanted_software_store_.get()) {
691 unwanted_software_store_->Init( 695 unwanted_software_store_->Init(
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 bool SafeBrowsingDatabaseNew::ResetDatabase() { 831 bool SafeBrowsingDatabaseNew::ResetDatabase() {
828 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 832 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
829 833
830 // Delete files on disk. 834 // Delete files on disk.
831 // TODO(shess): Hard to see where one might want to delete without a 835 // TODO(shess): Hard to see where one might want to delete without a
832 // reset. Perhaps inline |Delete()|? 836 // reset. Perhaps inline |Delete()|?
833 if (!Delete()) 837 if (!Delete())
834 return false; 838 return false;
835 839
836 // Reset objects in memory. 840 // Reset objects in memory.
837 scoped_ptr<WriteTransaction> txn = state_manager_.BeginWriteTransaction(); 841 std::unique_ptr<WriteTransaction> txn =
842 state_manager_.BeginWriteTransaction();
838 txn->clear_prefix_gethash_cache(); 843 txn->clear_prefix_gethash_cache();
839 txn->SwapPrefixSet(PrefixSetId::BROWSE, nullptr); 844 txn->SwapPrefixSet(PrefixSetId::BROWSE, nullptr);
840 txn->SwapPrefixSet(PrefixSetId::UNWANTED_SOFTWARE, nullptr); 845 txn->SwapPrefixSet(PrefixSetId::UNWANTED_SOFTWARE, nullptr);
841 txn->clear_ip_blacklist(); 846 txn->clear_ip_blacklist();
842 txn->WhitelistEverything(SBWhitelistId::CSD); 847 txn->WhitelistEverything(SBWhitelistId::CSD);
843 txn->WhitelistEverything(SBWhitelistId::DOWNLOAD); 848 txn->WhitelistEverything(SBWhitelistId::DOWNLOAD);
844 txn->WhitelistEverything(SBWhitelistId::MODULE); 849 txn->WhitelistEverything(SBWhitelistId::MODULE);
845 return true; 850 return true;
846 } 851 }
847 852
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 prefix_hits->clear(); 902 prefix_hits->clear();
898 cache_hits->clear(); 903 cache_hits->clear();
899 904
900 if (full_hashes.empty()) 905 if (full_hashes.empty())
901 return false; 906 return false;
902 907
903 // Used to determine cache expiration. 908 // Used to determine cache expiration.
904 const base::Time now = base::Time::Now(); 909 const base::Time now = base::Time::Now();
905 910
906 { 911 {
907 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); 912 std::unique_ptr<ReadTransaction> txn =
913 state_manager_.BeginReadTransaction();
908 914
909 // |prefix_set| is empty until it is either read from disk, or the first 915 // |prefix_set| is empty until it is either read from disk, or the first
910 // update populates it. Bail out without a hit if not yet available. 916 // update populates it. Bail out without a hit if not yet available.
911 const PrefixSet* prefix_set = txn->GetPrefixSet(prefix_set_id); 917 const PrefixSet* prefix_set = txn->GetPrefixSet(prefix_set_id);
912 if (!prefix_set) 918 if (!prefix_set)
913 return false; 919 return false;
914 920
915 for (size_t i = 0; i < full_hashes.size(); ++i) { 921 for (size_t i = 0; i < full_hashes.size(); ++i) {
916 if (!GetCachedFullHash(txn->prefix_gethash_cache(), full_hashes[i], now, 922 if (!GetCachedFullHash(txn->prefix_gethash_cache(), full_hashes[i], now,
917 cache_hits)) { 923 cache_hits)) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 981
976 bool SafeBrowsingDatabaseNew::ContainsMalwareIP(const std::string& ip_address) { 982 bool SafeBrowsingDatabaseNew::ContainsMalwareIP(const std::string& ip_address) {
977 net::IPAddress address; 983 net::IPAddress address;
978 if (!address.AssignFromIPLiteral(ip_address)) 984 if (!address.AssignFromIPLiteral(ip_address))
979 return false; 985 return false;
980 if (address.IsIPv4()) 986 if (address.IsIPv4())
981 address = net::ConvertIPv4ToIPv4MappedIPv6(address); 987 address = net::ConvertIPv4ToIPv4MappedIPv6(address);
982 if (!address.IsIPv6()) 988 if (!address.IsIPv6())
983 return false; // better safe than sorry. 989 return false; // better safe than sorry.
984 990
985 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); 991 std::unique_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction();
986 const IPBlacklist* ip_blacklist = txn->ip_blacklist(); 992 const IPBlacklist* ip_blacklist = txn->ip_blacklist();
987 for (IPBlacklist::const_iterator it = ip_blacklist->begin(); 993 for (IPBlacklist::const_iterator it = ip_blacklist->begin();
988 it != ip_blacklist->end(); ++it) { 994 it != ip_blacklist->end(); ++it) {
989 const std::string& mask = it->first; 995 const std::string& mask = it->first;
990 DCHECK_EQ(mask.size(), address.size()); 996 DCHECK_EQ(mask.size(), address.size());
991 std::string subnet(net::IPAddress::kIPv6AddressSize, '\0'); 997 std::string subnet(net::IPAddress::kIPv6AddressSize, '\0');
992 for (size_t i = 0; i < net::IPAddress::kIPv6AddressSize; ++i) { 998 for (size_t i = 0; i < net::IPAddress::kIPv6AddressSize; ++i) {
993 subnet[i] = address.bytes()[i] & mask[i]; 999 subnet[i] = address.bytes()[i] & mask[i];
994 } 1000 }
995 const std::string hash = base::SHA1HashString(subnet); 1001 const std::string hash = base::SHA1HashString(subnet);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 bool SafeBrowsingDatabaseNew::ContainsModuleWhitelistedString( 1033 bool SafeBrowsingDatabaseNew::ContainsModuleWhitelistedString(
1028 const std::string& str) { 1034 const std::string& str) {
1029 std::vector<SBFullHash> hashes; 1035 std::vector<SBFullHash> hashes;
1030 hashes.push_back(SBFullHashForString(str)); 1036 hashes.push_back(SBFullHashForString(str));
1031 return ContainsWhitelistedHashes(SBWhitelistId::MODULE, hashes); 1037 return ContainsWhitelistedHashes(SBWhitelistId::MODULE, hashes);
1032 } 1038 }
1033 1039
1034 bool SafeBrowsingDatabaseNew::ContainsWhitelistedHashes( 1040 bool SafeBrowsingDatabaseNew::ContainsWhitelistedHashes(
1035 SBWhitelistId whitelist_id, 1041 SBWhitelistId whitelist_id,
1036 const std::vector<SBFullHash>& hashes) { 1042 const std::vector<SBFullHash>& hashes) {
1037 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); 1043 std::unique_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction();
1038 const SBWhitelist* whitelist = txn->GetSBWhitelist(whitelist_id); 1044 const SBWhitelist* whitelist = txn->GetSBWhitelist(whitelist_id);
1039 if (whitelist->second) 1045 if (whitelist->second)
1040 return true; 1046 return true;
1041 for (std::vector<SBFullHash>::const_iterator it = hashes.begin(); 1047 for (std::vector<SBFullHash>::const_iterator it = hashes.begin();
1042 it != hashes.end(); ++it) { 1048 it != hashes.end(); ++it) {
1043 if (std::binary_search(whitelist->first.begin(), whitelist->first.end(), 1049 if (std::binary_search(whitelist->first.begin(), whitelist->first.end(),
1044 *it, SBFullHashLess)) { 1050 *it, SBFullHashLess)) {
1045 return true; 1051 return true;
1046 } 1052 }
1047 } 1053 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 const int add_chunk_id = chunk_data.AddChunkNumberAt(i); 1111 const int add_chunk_id = chunk_data.AddChunkNumberAt(i);
1106 const int encoded_add_chunk_id = EncodeChunkId(add_chunk_id, list_id); 1112 const int encoded_add_chunk_id = EncodeChunkId(add_chunk_id, list_id);
1107 store->WriteSubHash(encoded_chunk_id, encoded_add_chunk_id, 1113 store->WriteSubHash(encoded_chunk_id, encoded_add_chunk_id,
1108 chunk_data.FullHashAt(i)); 1114 chunk_data.FullHashAt(i));
1109 } 1115 }
1110 } 1116 }
1111 } 1117 }
1112 1118
1113 void SafeBrowsingDatabaseNew::InsertChunks( 1119 void SafeBrowsingDatabaseNew::InsertChunks(
1114 const std::string& list_name, 1120 const std::string& list_name,
1115 const std::vector<scoped_ptr<SBChunkData>>& chunks) { 1121 const std::vector<std::unique_ptr<SBChunkData>>& chunks) {
1116 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1122 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
1117 1123
1118 if (db_state_manager_.corruption_detected() || chunks.empty()) 1124 if (db_state_manager_.corruption_detected() || chunks.empty())
1119 return; 1125 return;
1120 1126
1121 const base::TimeTicks before = base::TimeTicks::Now(); 1127 const base::TimeTicks before = base::TimeTicks::Now();
1122 1128
1123 // TODO(shess): The caller should just pass list_id. 1129 // TODO(shess): The caller should just pass list_id.
1124 const ListType list_id = GetListId(list_name); 1130 const ListType list_id = GetListId(list_name);
1125 1131
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 } 1180 }
1175 } 1181 }
1176 } 1182 }
1177 1183
1178 void SafeBrowsingDatabaseNew::CacheHashResults( 1184 void SafeBrowsingDatabaseNew::CacheHashResults(
1179 const std::vector<SBPrefix>& prefixes, 1185 const std::vector<SBPrefix>& prefixes,
1180 const std::vector<SBFullHashResult>& full_hits, 1186 const std::vector<SBFullHashResult>& full_hits,
1181 const base::TimeDelta& cache_lifetime) { 1187 const base::TimeDelta& cache_lifetime) {
1182 const base::Time expire_after = base::Time::Now() + cache_lifetime; 1188 const base::Time expire_after = base::Time::Now() + cache_lifetime;
1183 1189
1184 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); 1190 std::unique_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction();
1185 PrefixGetHashCache* prefix_gethash_cache = txn->prefix_gethash_cache(); 1191 PrefixGetHashCache* prefix_gethash_cache = txn->prefix_gethash_cache();
1186 1192
1187 // Create or reset all cached results for these prefixes. 1193 // Create or reset all cached results for these prefixes.
1188 for (size_t i = 0; i < prefixes.size(); ++i) { 1194 for (size_t i = 0; i < prefixes.size(); ++i) {
1189 (*prefix_gethash_cache)[prefixes[i]] = SBCachedFullHashResult(expire_after); 1195 (*prefix_gethash_cache)[prefixes[i]] = SBCachedFullHashResult(expire_after);
1190 } 1196 }
1191 1197
1192 // Insert any fullhash hits. Note that there may be one, multiple, or no 1198 // Insert any fullhash hits. Note that there may be one, multiple, or no
1193 // fullhashes for any given entry in |prefixes|. 1199 // fullhashes for any given entry in |prefixes|.
1194 for (size_t i = 0; i < full_hits.size(); ++i) { 1200 for (size_t i = 0; i < full_hits.size(); ++i) {
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 SafeBrowsingStore* url_store, 1505 SafeBrowsingStore* url_store,
1500 PrefixSetId prefix_set_id, 1506 PrefixSetId prefix_set_id,
1501 FailureType finish_failure_type, 1507 FailureType finish_failure_type,
1502 FailureType write_failure_type, 1508 FailureType write_failure_type,
1503 bool store_full_hashes_in_prefix_set) { 1509 bool store_full_hashes_in_prefix_set) {
1504 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1510 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
1505 DCHECK(url_store); 1511 DCHECK(url_store);
1506 1512
1507 // Measure the amount of IO during the filter build. 1513 // Measure the amount of IO during the filter build.
1508 base::IoCounters io_before, io_after; 1514 base::IoCounters io_before, io_after;
1509 scoped_ptr<base::ProcessMetrics> metric( 1515 std::unique_ptr<base::ProcessMetrics> metric(
1510 base::ProcessMetrics::CreateCurrentProcessMetrics()); 1516 base::ProcessMetrics::CreateCurrentProcessMetrics());
1511 1517
1512 // IoCounters are currently not supported on Mac, and may not be 1518 // IoCounters are currently not supported on Mac, and may not be
1513 // available for Linux, so we check the result and only show IO 1519 // available for Linux, so we check the result and only show IO
1514 // stats if they are available. 1520 // stats if they are available.
1515 const bool got_counters = metric->GetIOCounters(&io_before); 1521 const bool got_counters = metric->GetIOCounters(&io_before);
1516 1522
1517 const base::TimeTicks before = base::TimeTicks::Now(); 1523 const base::TimeTicks before = base::TimeTicks::Now();
1518 1524
1519 // TODO(shess): Perhaps refactor to let builder accumulate full hashes on the 1525 // TODO(shess): Perhaps refactor to let builder accumulate full hashes on the
1520 // fly? Other clients use the SBAddFullHash vector, but AFAICT they only use 1526 // fly? Other clients use the SBAddFullHash vector, but AFAICT they only use
1521 // the SBFullHash portion. It would need an accessor on PrefixSet. 1527 // the SBFullHash portion. It would need an accessor on PrefixSet.
1522 PrefixSetBuilder builder; 1528 PrefixSetBuilder builder;
1523 std::vector<SBAddFullHash> add_full_hashes; 1529 std::vector<SBAddFullHash> add_full_hashes;
1524 if (!url_store->FinishUpdate(&builder, &add_full_hashes)) { 1530 if (!url_store->FinishUpdate(&builder, &add_full_hashes)) {
1525 RecordFailure(finish_failure_type); 1531 RecordFailure(finish_failure_type);
1526 return; 1532 return;
1527 } 1533 }
1528 1534
1529 scoped_ptr<const PrefixSet> new_prefix_set; 1535 std::unique_ptr<const PrefixSet> new_prefix_set;
1530 if (store_full_hashes_in_prefix_set) { 1536 if (store_full_hashes_in_prefix_set) {
1531 std::vector<SBFullHash> full_hash_results; 1537 std::vector<SBFullHash> full_hash_results;
1532 for (size_t i = 0; i < add_full_hashes.size(); ++i) { 1538 for (size_t i = 0; i < add_full_hashes.size(); ++i) {
1533 full_hash_results.push_back(add_full_hashes[i].full_hash); 1539 full_hash_results.push_back(add_full_hashes[i].full_hash);
1534 } 1540 }
1535 1541
1536 new_prefix_set = builder.GetPrefixSet(full_hash_results); 1542 new_prefix_set = builder.GetPrefixSet(full_hash_results);
1537 } else { 1543 } else {
1538 // TODO(gab): Ensure that stores which do not want full hashes just don't 1544 // TODO(gab): Ensure that stores which do not want full hashes just don't
1539 // have full hashes in the first place and remove 1545 // have full hashes in the first place and remove
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 if (!GetFileSizeOrZero(db_filename)) 1647 if (!GetFileSizeOrZero(db_filename))
1642 return; 1648 return;
1643 1649
1644 // Cleanup any stale bloom filter (no longer used). 1650 // Cleanup any stale bloom filter (no longer used).
1645 // TODO(shess): Track existence to drive removal of this code? 1651 // TODO(shess): Track existence to drive removal of this code?
1646 const base::FilePath bloom_filter_filename = 1652 const base::FilePath bloom_filter_filename =
1647 BloomFilterForFilename(db_filename); 1653 BloomFilterForFilename(db_filename);
1648 base::DeleteFile(bloom_filter_filename, false); 1654 base::DeleteFile(bloom_filter_filename, false);
1649 1655
1650 const base::TimeTicks before = base::TimeTicks::Now(); 1656 const base::TimeTicks before = base::TimeTicks::Now();
1651 scoped_ptr<const PrefixSet> new_prefix_set = 1657 std::unique_ptr<const PrefixSet> new_prefix_set =
1652 PrefixSet::LoadFile(PrefixSetForFilename(db_filename)); 1658 PrefixSet::LoadFile(PrefixSetForFilename(db_filename));
1653 if (!new_prefix_set.get()) 1659 if (!new_prefix_set.get())
1654 RecordFailure(read_failure_type); 1660 RecordFailure(read_failure_type);
1655 txn->SwapPrefixSet(prefix_set_id, std::move(new_prefix_set)); 1661 txn->SwapPrefixSet(prefix_set_id, std::move(new_prefix_set));
1656 UMA_HISTOGRAM_TIMES("SB2.PrefixSetLoad", base::TimeTicks::Now() - before); 1662 UMA_HISTOGRAM_TIMES("SB2.PrefixSetLoad", base::TimeTicks::Now() - before);
1657 } 1663 }
1658 1664
1659 bool SafeBrowsingDatabaseNew::Delete() { 1665 bool SafeBrowsingDatabaseNew::Delete() {
1660 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1666 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
1661 DCHECK(!db_state_manager_.filename_base().empty()); 1667 DCHECK(!db_state_manager_.filename_base().empty());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 } 1747 }
1742 1748
1743 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, 1749 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename,
1744 PrefixSetId prefix_set_id, 1750 PrefixSetId prefix_set_id,
1745 FailureType write_failure_type) { 1751 FailureType write_failure_type) {
1746 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1752 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
1747 1753
1748 // Do not grab the lock to avoid contention while writing to disk. This is 1754 // Do not grab the lock to avoid contention while writing to disk. This is
1749 // safe as only this task runner can ever modify |state_manager_|'s prefix 1755 // safe as only this task runner can ever modify |state_manager_|'s prefix
1750 // sets anyways. 1756 // sets anyways.
1751 scoped_ptr<ReadTransaction> txn = 1757 std::unique_ptr<ReadTransaction> txn =
1752 state_manager_.BeginReadTransactionNoLockOnMainTaskRunner(); 1758 state_manager_.BeginReadTransactionNoLockOnMainTaskRunner();
1753 const PrefixSet* prefix_set = txn->GetPrefixSet(prefix_set_id); 1759 const PrefixSet* prefix_set = txn->GetPrefixSet(prefix_set_id);
1754 1760
1755 if (!prefix_set) 1761 if (!prefix_set)
1756 return; 1762 return;
1757 1763
1758 const base::FilePath prefix_set_filename = PrefixSetForFilename(db_filename); 1764 const base::FilePath prefix_set_filename = PrefixSetForFilename(db_filename);
1759 1765
1760 const base::TimeTicks before = base::TimeTicks::Now(); 1766 const base::TimeTicks before = base::TimeTicks::Now();
1761 const bool write_ok = prefix_set->WriteFile(prefix_set_filename); 1767 const bool write_ok = prefix_set->WriteFile(prefix_set_filename);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 1927
1922 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. 1928 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro.
1923 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( 1929 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet(
1924 histogram_name, 1, 1000000, 50, 1930 histogram_name, 1, 1000000, 50,
1925 base::HistogramBase::kUmaTargetedHistogramFlag); 1931 base::HistogramBase::kUmaTargetedHistogramFlag);
1926 1932
1927 histogram_pointer->Add(file_size_kilobytes); 1933 histogram_pointer->Add(file_size_kilobytes);
1928 } 1934 }
1929 1935
1930 } // namespace safe_browsing 1936 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_database.h ('k') | chrome/browser/safe_browsing/safe_browsing_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698