OLD | NEW |
---|---|
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 Loading... | |
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 |db_ready_for_updates_callback| |
286 v4_database_->GetStoreStateMap()); | 286 // callback with the stores to reset, if any, and then we can schedule the |
287 // database updates. | |
288 DatabaseReadyForUpdatesCallback db_ready_for_updates_callback = | |
289 base::Bind(&V4LocalDatabaseManager::DatabaseReadyForUpdates, | |
290 base::Unretained(this)); | |
291 v4_database_->VerifyChecksum(db_ready_for_updates_callback); | |
287 | 292 |
Nathan Parker
2016/10/07 23:24:28
nit: This says "db ready for updates" four times..
vakh (use Gerrit instead)
2016/10/10 17:42:33
Done.
| |
288 ProcessQueuedChecks(); | 293 ProcessQueuedChecks(); |
289 } else { | 294 } else { |
290 // Schedule the deletion of v4_database off IO thread. | 295 // Schedule the deletion of v4_database off IO thread. |
291 V4Database::Destroy(std::move(v4_database)); | 296 V4Database::Destroy(std::move(v4_database)); |
292 } | 297 } |
293 } | 298 } |
294 | 299 |
300 void V4LocalDatabaseManager::DatabaseReadyForUpdates( | |
301 const std::vector<ListIdentifier>& stores_to_reset) { | |
302 if (enabled_) { | |
303 v4_database_->ResetStores(stores_to_reset); | |
304 | |
305 // The database is ready to process updates. Start fetching them now. | |
Nathan Parker
2016/10/07 23:24:28
s/Start fetching/Schedule
vakh (use Gerrit instead)
2016/10/10 17:42:33
Done.
| |
306 v4_update_protocol_manager_->ScheduleNextUpdate( | |
307 v4_database_->GetStoreStateMap()); | |
308 } | |
309 } | |
310 | |
295 void V4LocalDatabaseManager::DatabaseUpdated() { | 311 void V4LocalDatabaseManager::DatabaseUpdated() { |
296 if (enabled_) { | 312 if (enabled_) { |
297 v4_update_protocol_manager_->ScheduleNextUpdate( | 313 v4_update_protocol_manager_->ScheduleNextUpdate( |
298 v4_database_->GetStoreStateMap()); | 314 v4_database_->GetStoreStateMap()); |
299 } | 315 } |
300 } | 316 } |
301 | 317 |
302 bool V4LocalDatabaseManager::GetPrefixMatches( | 318 bool V4LocalDatabaseManager::GetPrefixMatches( |
303 const std::unique_ptr<PendingCheck>& check, | 319 const std::unique_ptr<PendingCheck>& check, |
304 FullHashToStoreAndHashPrefixesMap* full_hash_to_store_and_hash_prefixes) { | 320 FullHashToStoreAndHashPrefixesMap* full_hash_to_store_and_hash_prefixes) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 if (!task_runner_) { | 465 if (!task_runner_) { |
450 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 466 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
451 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( | 467 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( |
452 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 468 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
453 } | 469 } |
454 | 470 |
455 // Do not create the database on the IO thread since this may be an expensive | 471 // 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 | 472 // operation. Instead, do that on the task_runner and when the new database |
457 // has been created, swap it out on the IO thread. | 473 // has been created, swap it out on the IO thread. |
458 NewDatabaseReadyCallback db_ready_callback = base::Bind( | 474 NewDatabaseReadyCallback db_ready_callback = base::Bind( |
459 &V4LocalDatabaseManager::DatabaseReady, base::Unretained(this)); | 475 &V4LocalDatabaseManager::DatabaseReadyForChecks, base::Unretained(this)); |
460 V4Database::Create(task_runner_, base_path_, list_infos_, db_ready_callback); | 476 V4Database::Create(task_runner_, base_path_, list_infos_, db_ready_callback); |
461 } | 477 } |
462 | 478 |
463 void V4LocalDatabaseManager::SetupUpdateProtocolManager( | 479 void V4LocalDatabaseManager::SetupUpdateProtocolManager( |
464 net::URLRequestContextGetter* request_context_getter, | 480 net::URLRequestContextGetter* request_context_getter, |
465 const V4ProtocolConfig& config) { | 481 const V4ProtocolConfig& config) { |
466 V4UpdateCallback callback = base::Bind( | 482 V4UpdateCallback callback = base::Bind( |
467 &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this)); | 483 &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this)); |
468 | 484 |
469 v4_update_protocol_manager_ = | 485 v4_update_protocol_manager_ = |
470 V4UpdateProtocolManager::Create(request_context_getter, config, callback); | 486 V4UpdateProtocolManager::Create(request_context_getter, config, callback); |
471 } | 487 } |
472 | 488 |
473 void V4LocalDatabaseManager::UpdateRequestCompleted( | 489 void V4LocalDatabaseManager::UpdateRequestCompleted( |
474 std::unique_ptr<ParsedServerResponse> parsed_server_response) { | 490 std::unique_ptr<ParsedServerResponse> parsed_server_response) { |
475 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 491 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
476 v4_database_->ApplyUpdate(std::move(parsed_server_response), | 492 v4_database_->ApplyUpdate(std::move(parsed_server_response), |
477 db_updated_callback_); | 493 db_updated_callback_); |
478 } | 494 } |
479 | 495 |
480 } // namespace safe_browsing | 496 } // namespace safe_browsing |
OLD | NEW |