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

Unified Diff: components/safe_browsing_db/v4_local_database_manager.cc

Issue 2384893002: PVer4: Test checksum on startup outside the hotpath of DB load (Closed)
Patch Set: go: design-doc-v4store-verifychecksum -- VerifyChecksum in a way that avoids race conditions betwee… 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 28320252fec77167878326768d915c7ef53f9ae8..9e5a92dc22b1cbe6c6f415b8e7080b00a40f1290 100644
--- a/components/safe_browsing_db/v4_local_database_manager.cc
+++ b/components/safe_browsing_db/v4_local_database_manager.cc
@@ -272,7 +272,7 @@ void V4LocalDatabaseManager::StopOnIOThread(bool shutdown) {
// End: SafeBrowsingDatabaseManager implementation
//
-void V4LocalDatabaseManager::DatabaseReady(
+void V4LocalDatabaseManager::DatabaseReadyForChecks(
std::unique_ptr<V4Database> v4_database) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -281,9 +281,17 @@ void V4LocalDatabaseManager::DatabaseReady(
if (enabled_) {
v4_database_ = std::move(v4_database);
- // The database is in place. Start fetching updates now.
- v4_update_protocol_manager_->ScheduleNextUpdate(
- v4_database_->GetStoreStateMap());
+ // The consistency of the stores read from the disk needs to verified. Post
+ // that task on the task runner. It calls |db_ready_for_updates_callback|
+ // callback with the stores to reset, if any, and then we can schedule the
+ // database updates.
+ DatabaseReadyForUpdatesCallback db_ready_for_updates_callback =
+ base::Bind(&V4LocalDatabaseManager::DatabaseReadyForUpdates,
+ base::Unretained(this));
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&V4Database::VerifyChecksum,
+ base::Unretained(v4_database_.get()),
+ db_ready_for_updates_callback));
ProcessQueuedChecks();
} else {
@@ -292,6 +300,17 @@ void V4LocalDatabaseManager::DatabaseReady(
}
}
+void V4LocalDatabaseManager::DatabaseReadyForUpdates(
+ const std::unordered_set<ListIdentifier>& stores_to_reset) {
+ if (enabled_) {
+ v4_database_->ResetStores(stores_to_reset);
+
+ // The database is ready to process updates. Start fetching them now.
+ v4_update_protocol_manager_->ScheduleNextUpdate(
+ v4_database_->GetStoreStateMap());
+ }
+}
+
void V4LocalDatabaseManager::DatabaseUpdated() {
if (enabled_) {
v4_update_protocol_manager_->ScheduleNextUpdate(
@@ -456,7 +475,7 @@ void V4LocalDatabaseManager::SetupDatabase() {
// 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::DatabaseReady, base::Unretained(this));
+ &V4LocalDatabaseManager::DatabaseReadyForChecks, base::Unretained(this));
V4Database::Create(task_runner_, base_path_, list_infos_, db_ready_callback);
}

Powered by Google App Engine
This is Rietveld 408576698