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

Unified Diff: components/safe_browsing_db/v4_database.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_database.cc
diff --git a/components/safe_browsing_db/v4_database.cc b/components/safe_browsing_db/v4_database.cc
index efcbe7b1aaa5eea6e23df6f255b8055e8add198c..7c131004ec99326b748814a5b13ff20114e177bb 100644
--- a/components/safe_browsing_db/v4_database.cc
+++ b/components/safe_browsing_db/v4_database.cc
@@ -69,7 +69,7 @@ void V4Database::CreateOnTaskRunner(
new V4Database(db_task_runner, std::move(store_map)));
// Database is done loading, pass it to the new_db_callback on the caller's
- // thread.
+ // thread. This would unblock URL navigation.
callback_task_runner->PostTask(
FROM_HERE, base::Bind(new_db_callback, base::Passed(&v4_database)));
}
@@ -81,7 +81,6 @@ V4Database::V4Database(
store_map_(std::move(store_map)),
pending_store_updates_(0) {
DCHECK(db_task_runner->RunsTasksOnCurrentThread());
- // TODO(vakh): Implement skeleton
}
// static
@@ -152,17 +151,6 @@ void V4Database::UpdatedStoreReady(ListIdentifier identifier,
}
}
-bool V4Database::ResetDatabase() {
- DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
- bool reset_success = true;
- for (const auto& store_map_iter : *store_map_) {
- if (!store_map_iter.second->Reset()) {
- reset_success = false;
- }
- }
- return reset_success;
-}
-
std::unique_ptr<StoreStateMap> V4Database::GetStoreStateMap() {
std::unique_ptr<StoreStateMap> store_state_map =
base::MakeUnique<StoreStateMap>();
@@ -189,6 +177,40 @@ void V4Database::GetStoresMatchingFullHash(
}
}
+void V4Database::ResetStores(
+ const std::unordered_set<ListIdentifier>& stores_to_reset) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ for (const ListIdentifier& identifier : stores_to_reset) {
+ const auto& store_pair = store_map_->find(identifier);
+ DCHECK(store_pair != store_map_->end());
+ store_pair->second->Reset();
+ }
+}
+
+void V4Database::VerifyChecksum(
+ DatabaseReadyForUpdatesCallback db_ready_for_updates_callback) {
+ const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner =
+ base::MessageLoop::current()->task_runner();
+ db_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&V4Database::VerifyChecksumOnTaskRunner,
+ base::Unretained(this), callback_task_runner,
+ db_ready_for_updates_callback));
+}
+
+void V4Database::VerifyChecksumOnTaskRunner(
+ const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner,
+ DatabaseReadyForUpdatesCallback db_ready_for_updates_callback) {
+ std::unordered_set<ListIdentifier> stores_to_reset;
+ for (const auto& store_map_iter : *store_map_) {
+ if (!store_map_iter.second->VerifyChecksum()) {
+ stores_to_reset.insert(store_map_iter.first);
+ }
+ }
+
+ callback_task_runner->PostTask(
+ FROM_HERE, base::Bind(db_ready_for_updates_callback, stores_to_reset));
+}
+
ListInfo::ListInfo(const bool fetch_updates,
const std::string& filename,
const ListIdentifier& list_id,

Powered by Google App Engine
This is Rietveld 408576698