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

Unified Diff: components/safe_browsing_db/v4_local_database_manager.cc

Issue 2427863002: Small: Use a weak pointer for callbacks to V4LocalDatabaseManager (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: components/safe_browsing_db/v4_local_database_manager.cc
diff --git a/components/safe_browsing_db/v4_local_database_manager.cc b/components/safe_browsing_db/v4_local_database_manager.cc
index 1e22f37cd589555340e876debb484ac5603fc47f..746fb0de65f50b80e22c0b8b93cf404d48f02c61 100644
--- a/components/safe_browsing_db/v4_local_database_manager.cc
+++ b/components/safe_browsing_db/v4_local_database_manager.cc
@@ -79,7 +79,10 @@ scoped_refptr<V4LocalDatabaseManager> V4LocalDatabaseManager::Create(
}
V4LocalDatabaseManager::V4LocalDatabaseManager(const base::FilePath& base_path)
- : base_path_(base_path), enabled_(false), list_infos_(GetListInfos()) {
+ : base_path_(base_path),
+ enabled_(false),
+ list_infos_(GetListInfos()),
+ weak_factory_(this) {
DCHECK(!base_path_.empty());
DCHECK(!list_infos_.empty());
@@ -243,7 +246,7 @@ void V4LocalDatabaseManager::StartOnIOThread(
SafeBrowsingDatabaseManager::StartOnIOThread(request_context_getter, config);
db_updated_callback_ = base::Bind(&V4LocalDatabaseManager::DatabaseUpdated,
- base::Unretained(this));
+ weak_factory_.GetWeakPtr());
SetupUpdateProtocolManager(request_context_getter, config);
SetupDatabase();
@@ -293,7 +296,7 @@ void V4LocalDatabaseManager::DatabaseReadyForChecks(
// database updates.
v4_database_->VerifyChecksum(
base::Bind(&V4LocalDatabaseManager::DatabaseReadyForUpdates,
- base::Unretained(this)));
+ weak_factory_.GetWeakPtr()));
ProcessQueuedChecks();
} else {
@@ -428,7 +431,7 @@ void V4LocalDatabaseManager::PerformFullHashCheck(
v4_get_hash_protocol_manager_->GetFullHashes(
full_hash_to_store_and_hash_prefixes,
base::Bind(&V4LocalDatabaseManager::OnFullHashResponse,
- base::Unretained(this), base::Passed(std::move(check))));
+ weak_factory_.GetWeakPtr(), base::Passed(std::move(check))));
}
void V4LocalDatabaseManager::ProcessQueuedChecks() {
@@ -476,16 +479,18 @@ void V4LocalDatabaseManager::SetupDatabase() {
// Do not create the database on the IO thread since this may be an expensive
// operation. Instead, do that on the task_runner and when the new database
// has been created, swap it out on the IO thread.
- NewDatabaseReadyCallback db_ready_callback = base::Bind(
- &V4LocalDatabaseManager::DatabaseReadyForChecks, base::Unretained(this));
+ NewDatabaseReadyCallback db_ready_callback =
+ base::Bind(&V4LocalDatabaseManager::DatabaseReadyForChecks,
+ weak_factory_.GetWeakPtr());
V4Database::Create(task_runner_, base_path_, list_infos_, db_ready_callback);
}
void V4LocalDatabaseManager::SetupUpdateProtocolManager(
net::URLRequestContextGetter* request_context_getter,
const V4ProtocolConfig& config) {
- V4UpdateCallback callback = base::Bind(
- &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this));
+ V4UpdateCallback callback =
+ base::Bind(&V4LocalDatabaseManager::UpdateRequestCompleted,
+ weak_factory_.GetWeakPtr());
v4_update_protocol_manager_ =
V4UpdateProtocolManager::Create(request_context_getter, config, callback);

Powered by Google App Engine
This is Rietveld 408576698