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

Side by Side 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: Verify that the checksum check happens async 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file should not be build on Android but is currently getting built. 5 // This file should not be build on Android but is currently getting built.
6 // TODO(vakh): Fix that: http://crbug.com/621647 6 // TODO(vakh): Fix that: http://crbug.com/621647
7 7
8 #include "components/safe_browsing_db/v4_local_database_manager.h" 8 #include "components/safe_browsing_db/v4_local_database_manager.h"
9 9
10 #include <vector> 10 #include <vector>
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 265
266 db_updated_callback_.Reset(); 266 db_updated_callback_.Reset();
267 267
268 SafeBrowsingDatabaseManager::StopOnIOThread(shutdown); 268 SafeBrowsingDatabaseManager::StopOnIOThread(shutdown);
269 } 269 }
270 270
271 // 271 //
272 // End: SafeBrowsingDatabaseManager implementation 272 // End: SafeBrowsingDatabaseManager implementation
273 // 273 //
274 274
275 void V4LocalDatabaseManager::DatabaseReady( 275 void V4LocalDatabaseManager::DatabaseReadyForChecks(
276 std::unique_ptr<V4Database> v4_database) { 276 std::unique_ptr<V4Database> v4_database) {
277 DCHECK_CURRENTLY_ON(BrowserThread::IO); 277 DCHECK_CURRENTLY_ON(BrowserThread::IO);
278 278
279 // The following check is needed because it is possible that by the time the 279 // The following check is needed because it is possible that by the time the
280 // database is ready, StopOnIOThread has been called. 280 // database is ready, StopOnIOThread has been called.
281 if (enabled_) { 281 if (enabled_) {
282 v4_database_ = std::move(v4_database); 282 v4_database_ = std::move(v4_database);
283 283
284 // The database is in place. Start fetching updates now. 284 // The consistency of the stores read from the disk needs to verified. Post
285 v4_update_protocol_manager_->ScheduleNextUpdate( 285 // that task on the task runner. It calls |DatabaseReadyForUpdates|
286 v4_database_->GetStoreStateMap()); 286 // callback with the stores to reset, if any, and then we can schedule the
287 // database updates.
288 v4_database_->VerifyChecksum(
289 base::Bind(&V4LocalDatabaseManager::DatabaseReadyForUpdates,
290 base::Unretained(this)));
287 291
288 ProcessQueuedChecks(); 292 ProcessQueuedChecks();
289 } else { 293 } else {
290 // Schedule the deletion of v4_database off IO thread. 294 // Schedule the deletion of v4_database off IO thread.
291 V4Database::Destroy(std::move(v4_database)); 295 V4Database::Destroy(std::move(v4_database));
292 } 296 }
293 } 297 }
294 298
299 void V4LocalDatabaseManager::DatabaseReadyForUpdates(
300 const std::vector<ListIdentifier>& stores_to_reset) {
301 if (enabled_) {
302 v4_database_->ResetStores(stores_to_reset);
303
304 // The database is ready to process updates. Schedule them now.
305 v4_update_protocol_manager_->ScheduleNextUpdate(
306 v4_database_->GetStoreStateMap());
307 }
308 }
309
295 void V4LocalDatabaseManager::DatabaseUpdated() { 310 void V4LocalDatabaseManager::DatabaseUpdated() {
296 if (enabled_) { 311 if (enabled_) {
297 v4_update_protocol_manager_->ScheduleNextUpdate( 312 v4_update_protocol_manager_->ScheduleNextUpdate(
298 v4_database_->GetStoreStateMap()); 313 v4_database_->GetStoreStateMap());
299 } 314 }
300 } 315 }
301 316
302 bool V4LocalDatabaseManager::GetPrefixMatches( 317 bool V4LocalDatabaseManager::GetPrefixMatches(
303 const std::unique_ptr<PendingCheck>& check, 318 const std::unique_ptr<PendingCheck>& check,
304 FullHashToStoreAndHashPrefixesMap* full_hash_to_store_and_hash_prefixes) { 319 FullHashToStoreAndHashPrefixesMap* full_hash_to_store_and_hash_prefixes) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 if (!task_runner_) { 464 if (!task_runner_) {
450 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); 465 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
451 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( 466 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior(
452 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 467 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
453 } 468 }
454 469
455 // Do not create the database on the IO thread since this may be an expensive 470 // Do not create the database on the IO thread since this may be an expensive
456 // operation. Instead, do that on the task_runner and when the new database 471 // operation. Instead, do that on the task_runner and when the new database
457 // has been created, swap it out on the IO thread. 472 // has been created, swap it out on the IO thread.
458 NewDatabaseReadyCallback db_ready_callback = base::Bind( 473 NewDatabaseReadyCallback db_ready_callback = base::Bind(
459 &V4LocalDatabaseManager::DatabaseReady, base::Unretained(this)); 474 &V4LocalDatabaseManager::DatabaseReadyForChecks, base::Unretained(this));
460 V4Database::Create(task_runner_, base_path_, list_infos_, db_ready_callback); 475 V4Database::Create(task_runner_, base_path_, list_infos_, db_ready_callback);
461 } 476 }
462 477
463 void V4LocalDatabaseManager::SetupUpdateProtocolManager( 478 void V4LocalDatabaseManager::SetupUpdateProtocolManager(
464 net::URLRequestContextGetter* request_context_getter, 479 net::URLRequestContextGetter* request_context_getter,
465 const V4ProtocolConfig& config) { 480 const V4ProtocolConfig& config) {
466 V4UpdateCallback callback = base::Bind( 481 V4UpdateCallback callback = base::Bind(
467 &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this)); 482 &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this));
468 483
469 v4_update_protocol_manager_ = 484 v4_update_protocol_manager_ =
470 V4UpdateProtocolManager::Create(request_context_getter, config, callback); 485 V4UpdateProtocolManager::Create(request_context_getter, config, callback);
471 } 486 }
472 487
473 void V4LocalDatabaseManager::UpdateRequestCompleted( 488 void V4LocalDatabaseManager::UpdateRequestCompleted(
474 std::unique_ptr<ParsedServerResponse> parsed_server_response) { 489 std::unique_ptr<ParsedServerResponse> parsed_server_response) {
475 DCHECK_CURRENTLY_ON(BrowserThread::IO); 490 DCHECK_CURRENTLY_ON(BrowserThread::IO);
476 v4_database_->ApplyUpdate(std::move(parsed_server_response), 491 v4_database_->ApplyUpdate(std::move(parsed_server_response),
477 db_updated_callback_); 492 db_updated_callback_);
478 } 493 }
479 494
480 } // namespace safe_browsing 495 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698