Index: chrome/browser/safe_browsing/local_database_manager.cc |
diff --git a/chrome/browser/safe_browsing/local_database_manager.cc b/chrome/browser/safe_browsing/local_database_manager.cc |
index 3bff7600bef97ea0e1bbd6f086ae24534359ef20..8d3d1a9b2ac46ae575e7f45e26287c8d8692af48 100644 |
--- a/chrome/browser/safe_browsing/local_database_manager.cc |
+++ b/chrome/browser/safe_browsing/local_database_manager.cc |
@@ -13,9 +13,9 @@ |
#include "base/command_line.h" |
#include "base/debug/leak_tracker.h" |
#include "base/location.h" |
+#include "base/memory/ptr_util.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/single_thread_task_runner.h" |
-#include "base/stl_util.h" |
#include "base/strings/string_util.h" |
#include "base/threading/thread_task_runner_handle.h" |
#include "chrome/browser/browser_process.h" |
@@ -349,13 +349,14 @@ bool LocalSafeBrowsingDatabaseManager::CheckDownloadUrl( |
// We need to check the database for url prefix, and later may fetch the url |
// from the safebrowsing backends. These need to be asynchronous. |
- SafeBrowsingCheck* check = new SafeBrowsingCheck( |
- url_chain, std::vector<SBFullHash>(), client, BINURL, |
- std::vector<SBThreatType>(1, SB_THREAT_TYPE_BINARY_MALWARE_URL)); |
+ std::unique_ptr<SafeBrowsingCheck> check = |
+ base::MakeUnique<SafeBrowsingCheck>( |
+ url_chain, std::vector<SBFullHash>(), client, BINURL, |
+ std::vector<SBThreatType>(1, SB_THREAT_TYPE_BINARY_MALWARE_URL)); |
std::vector<SBPrefix> prefixes; |
SafeBrowsingDatabase::GetDownloadUrlPrefixes(url_chain, &prefixes); |
StartSafeBrowsingCheck( |
- check, |
+ std::move(check), |
base::Bind(&LocalSafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread, |
this, prefixes)); |
return false; |
@@ -376,11 +377,12 @@ bool LocalSafeBrowsingDatabaseManager::CheckExtensionIDs( |
for (const SBFullHash& hash : extension_id_hashes) |
prefixes.push_back(hash.prefix); |
- SafeBrowsingCheck* check = new SafeBrowsingCheck( |
- std::vector<GURL>(), extension_id_hashes, client, EXTENSIONBLACKLIST, |
- std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION)); |
+ std::unique_ptr<SafeBrowsingCheck> check = |
+ base::MakeUnique<SafeBrowsingCheck>( |
+ std::vector<GURL>(), extension_id_hashes, client, EXTENSIONBLACKLIST, |
+ std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION)); |
StartSafeBrowsingCheck( |
- check, |
+ std::move(check), |
base::Bind(&LocalSafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread, |
this, prefixes)); |
return false; |
@@ -403,14 +405,14 @@ bool LocalSafeBrowsingDatabaseManager::CheckResourceUrl(const GURL& url, |
return false; |
} |
- SafeBrowsingCheck* check = |
+ std::unique_ptr<SafeBrowsingCheck> check = base::WrapUnique( |
new SafeBrowsingCheck({url}, std::vector<SBFullHash>(), client, |
- RESOURCEBLACKLIST, expected_threats); |
+ RESOURCEBLACKLIST, expected_threats)); |
std::vector<SBPrefix> prefixes; |
SafeBrowsingDatabase::GetDownloadUrlPrefixes(check->urls, &prefixes); |
StartSafeBrowsingCheck( |
- check, |
+ std::move(check), |
base::Bind(&LocalSafeBrowsingDatabaseManager::CheckResourceUrlOnSBThread, |
this, prefixes)); |
return false; |
@@ -547,7 +549,7 @@ bool LocalSafeBrowsingDatabaseManager::CheckBrowseUrl(const GURL& url, |
check->need_get_hash = cache_hits.empty(); |
check->prefix_hits.swap(prefix_hits); |
check->cache_hits.swap(cache_hits); |
- checks_.insert(check); |
+ checks_[check] = base::WrapUnique(check); |
BrowserThread::PostTask( |
BrowserThread::IO, FROM_HERE, |
@@ -558,18 +560,17 @@ bool LocalSafeBrowsingDatabaseManager::CheckBrowseUrl(const GURL& url, |
void LocalSafeBrowsingDatabaseManager::CancelCheck(Client* client) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- for (CurrentChecks::iterator i = checks_.begin(); i != checks_.end(); ++i) { |
+ for (const auto& check : checks_) { |
// We can't delete matching checks here because the db thread has a copy of |
// the pointer. Instead, we simply NULL out the client, and when the db |
// thread calls us back, we'll clean up the check. |
- if ((*i)->client == client) |
- (*i)->client = NULL; |
+ if (check.first->client == client) |
+ check.first->client = NULL; |
} |
// Scan the queued clients store. Clients may be here if they requested a URL |
// check before the database has finished loading. |
- for (std::deque<QueuedCheck>::iterator it(queued_checks_.begin()); |
- it != queued_checks_.end();) { |
+ for (auto it = queued_checks_.begin(); it != queued_checks_.end();) { |
// In this case it's safe to delete matches entirely since nothing has a |
// pointer to them. |
if (it->client == client) |
@@ -768,14 +769,12 @@ void LocalSafeBrowsingDatabaseManager::DoStopOnIOThread() { |
// We have to do this after the db thread returns because methods on it can |
// have copies of these pointers, so deleting them might lead to accessing |
// garbage. |
- for (CurrentChecks::iterator it = checks_.begin(); it != checks_.end(); |
- ++it) { |
- SafeBrowsingCheck* check = *it; |
- if (check->client) |
- check->OnSafeBrowsingResult(); |
+ for (const auto& check : checks_) { |
+ if (check.first->client) |
+ check.first->OnSafeBrowsingResult(); |
} |
- base::STLDeleteElements(&checks_); |
+ checks_.clear(); |
gethash_requests_.clear(); |
} |
@@ -1220,24 +1219,25 @@ void LocalSafeBrowsingDatabaseManager::SafeBrowsingCheckDone( |
if (check->client) |
check->OnSafeBrowsingResult(); |
checks_.erase(check); |
- delete check; |
} |
void LocalSafeBrowsingDatabaseManager::StartSafeBrowsingCheck( |
- SafeBrowsingCheck* check, |
+ std::unique_ptr<SafeBrowsingCheck> check, |
const base::Callback<std::vector<SBPrefix>(void)>& task) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
check->weak_ptr_factory_.reset( |
new base::WeakPtrFactory<LocalSafeBrowsingDatabaseManager>(this)); |
- checks_.insert(check); |
+ SafeBrowsingCheck* check_ptr = check.get(); |
+ checks_[check_ptr] = std::move(check); |
base::PostTaskAndReplyWithResult( |
safe_browsing_task_runner_.get(), FROM_HERE, task, |
base::Bind(&LocalSafeBrowsingDatabaseManager::OnAsyncCheckDone, |
- check->weak_ptr_factory_->GetWeakPtr(), check)); |
+ check_ptr->weak_ptr_factory_->GetWeakPtr(), check_ptr)); |
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
- FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, |
- check->weak_ptr_factory_->GetWeakPtr(), check), |
+ FROM_HERE, |
+ base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, |
+ check_ptr->weak_ptr_factory_->GetWeakPtr(), check_ptr), |
check_timeout_); |
} |