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 task_runner_->PostTask(FROM_HERE, |
| 292 base::Bind(&V4Database::VerifyChecksum, |
| 293 base::Unretained(v4_database_.get()), |
| 294 db_ready_for_updates_callback)); |
287 | 295 |
288 ProcessQueuedChecks(); | 296 ProcessQueuedChecks(); |
289 } else { | 297 } else { |
290 // Schedule the deletion of v4_database off IO thread. | 298 // Schedule the deletion of v4_database off IO thread. |
291 V4Database::Destroy(std::move(v4_database)); | 299 V4Database::Destroy(std::move(v4_database)); |
292 } | 300 } |
293 } | 301 } |
294 | 302 |
| 303 void V4LocalDatabaseManager::DatabaseReadyForUpdates( |
| 304 const std::unordered_set<ListIdentifier>& stores_to_reset) { |
| 305 if (enabled_) { |
| 306 v4_database_->ResetStores(stores_to_reset); |
| 307 |
| 308 // The database is ready to process updates. Start fetching them now. |
| 309 v4_update_protocol_manager_->ScheduleNextUpdate( |
| 310 v4_database_->GetStoreStateMap()); |
| 311 } |
| 312 } |
| 313 |
295 void V4LocalDatabaseManager::DatabaseUpdated() { | 314 void V4LocalDatabaseManager::DatabaseUpdated() { |
296 if (enabled_) { | 315 if (enabled_) { |
297 v4_update_protocol_manager_->ScheduleNextUpdate( | 316 v4_update_protocol_manager_->ScheduleNextUpdate( |
298 v4_database_->GetStoreStateMap()); | 317 v4_database_->GetStoreStateMap()); |
299 } | 318 } |
300 } | 319 } |
301 | 320 |
302 bool V4LocalDatabaseManager::GetPrefixMatches( | 321 bool V4LocalDatabaseManager::GetPrefixMatches( |
303 const std::unique_ptr<PendingCheck>& check, | 322 const std::unique_ptr<PendingCheck>& check, |
304 FullHashToStoreAndHashPrefixesMap* full_hash_to_store_and_hash_prefixes) { | 323 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_) { | 468 if (!task_runner_) { |
450 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 469 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
451 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( | 470 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( |
452 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 471 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
453 } | 472 } |
454 | 473 |
455 // Do not create the database on the IO thread since this may be an expensive | 474 // 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 | 475 // operation. Instead, do that on the task_runner and when the new database |
457 // has been created, swap it out on the IO thread. | 476 // has been created, swap it out on the IO thread. |
458 NewDatabaseReadyCallback db_ready_callback = base::Bind( | 477 NewDatabaseReadyCallback db_ready_callback = base::Bind( |
459 &V4LocalDatabaseManager::DatabaseReady, base::Unretained(this)); | 478 &V4LocalDatabaseManager::DatabaseReadyForChecks, base::Unretained(this)); |
460 V4Database::Create(task_runner_, base_path_, list_infos_, db_ready_callback); | 479 V4Database::Create(task_runner_, base_path_, list_infos_, db_ready_callback); |
461 } | 480 } |
462 | 481 |
463 void V4LocalDatabaseManager::SetupUpdateProtocolManager( | 482 void V4LocalDatabaseManager::SetupUpdateProtocolManager( |
464 net::URLRequestContextGetter* request_context_getter, | 483 net::URLRequestContextGetter* request_context_getter, |
465 const V4ProtocolConfig& config) { | 484 const V4ProtocolConfig& config) { |
466 V4UpdateCallback callback = base::Bind( | 485 V4UpdateCallback callback = base::Bind( |
467 &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this)); | 486 &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this)); |
468 | 487 |
469 v4_update_protocol_manager_ = | 488 v4_update_protocol_manager_ = |
470 V4UpdateProtocolManager::Create(request_context_getter, config, callback); | 489 V4UpdateProtocolManager::Create(request_context_getter, config, callback); |
471 } | 490 } |
472 | 491 |
473 void V4LocalDatabaseManager::UpdateRequestCompleted( | 492 void V4LocalDatabaseManager::UpdateRequestCompleted( |
474 std::unique_ptr<ParsedServerResponse> parsed_server_response) { | 493 std::unique_ptr<ParsedServerResponse> parsed_server_response) { |
475 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 494 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
476 v4_database_->ApplyUpdate(std::move(parsed_server_response), | 495 v4_database_->ApplyUpdate(std::move(parsed_server_response), |
477 db_updated_callback_); | 496 db_updated_callback_); |
478 } | 497 } |
479 | 498 |
480 } // namespace safe_browsing | 499 } // namespace safe_browsing |
OLD | NEW |