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

Unified Diff: components/safe_browsing_db/v4_database.cc

Issue 2675063002: Browser tests for using the new SafeBrowsing protocol (v4) (Closed)
Patch Set: Nit: Add comments in tests Created 3 years, 10 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_database.cc
diff --git a/components/safe_browsing_db/v4_database.cc b/components/safe_browsing_db/v4_database.cc
index 8b20a88b3444cf5526903604da78e1f487b3f7b6..5a9742067829bb810584b6c896108cfdb1a26113 100644
--- a/components/safe_browsing_db/v4_database.cc
+++ b/components/safe_browsing_db/v4_database.cc
@@ -25,7 +25,18 @@ const char kV4DatabaseSizeMetric[] = "SafeBrowsing.V4Database.Size";
} // namespace
// static
-V4StoreFactory* V4Database::factory_ = NULL;
+std::unique_ptr<V4DatabaseFactory> V4Database::db_factory_;
+
+// static
+std::unique_ptr<V4StoreFactory> V4Database::store_factory_;
+
+std::unique_ptr<V4Database> V4DatabaseFactory::Create(
+ const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
+ std::unique_ptr<StoreMap> store_map) {
+ // Not using MakeUnique since the constructor of V4Database is protected.
+ return std::unique_ptr<V4Database>(
+ new V4Database(db_task_runner, std::move(store_map)));
+}
// static
void V4Database::Create(
@@ -54,9 +65,8 @@ void V4Database::CreateOnTaskRunner(
const TimeTicks create_start_time) {
DCHECK(db_task_runner->RunsTasksOnCurrentThread());
- if (!factory_) {
- factory_ = new V4StoreFactory();
- ANNOTATE_LEAKING_OBJECT_PTR(factory_);
+ if (!store_factory_) {
+ store_factory_.reset(new V4StoreFactory());
}
if (!base::CreateDirectory(base_path)) {
@@ -72,10 +82,14 @@ void V4Database::CreateOnTaskRunner(
const base::FilePath store_path = base_path.AppendASCII(it.filename());
(*store_map)[it.list_id()].reset(
- factory_->CreateV4Store(db_task_runner, store_path));
+ store_factory_->CreateV4Store(db_task_runner, store_path));
+ }
+
+ if (!db_factory_) {
+ db_factory_.reset(new V4DatabaseFactory());
}
std::unique_ptr<V4Database> v4_database(
- new V4Database(db_task_runner, std::move(store_map)));
+ db_factory_->Create(db_task_runner, std::move(store_map)));
// Database is done loading, pass it to the new_db_callback on the caller's
// thread. This would unblock resource loads.
@@ -89,8 +103,8 @@ void V4Database::CreateOnTaskRunner(
V4Database::V4Database(
const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
std::unique_ptr<StoreMap> store_map)
- : db_task_runner_(db_task_runner),
- store_map_(std::move(store_map)),
+ : store_map_(std::move(store_map)),
+ db_task_runner_(db_task_runner),
pending_store_updates_(0),
weak_factory_on_io_(this) {
DCHECK(db_task_runner->RunsTasksOnCurrentThread());

Powered by Google App Engine
This is Rietveld 408576698