| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 scoped_refptr<V4LocalDatabaseManager> V4LocalDatabaseManager::Create( | 72 scoped_refptr<V4LocalDatabaseManager> V4LocalDatabaseManager::Create( |
| 73 const base::FilePath& base_path) { | 73 const base::FilePath& base_path) { |
| 74 if (!V4FeatureList::IsLocalDatabaseManagerEnabled()) { | 74 if (!V4FeatureList::IsLocalDatabaseManagerEnabled()) { |
| 75 return nullptr; | 75 return nullptr; |
| 76 } | 76 } |
| 77 | 77 |
| 78 return make_scoped_refptr(new V4LocalDatabaseManager(base_path)); | 78 return make_scoped_refptr(new V4LocalDatabaseManager(base_path)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 V4LocalDatabaseManager::V4LocalDatabaseManager(const base::FilePath& base_path) | 81 V4LocalDatabaseManager::V4LocalDatabaseManager(const base::FilePath& base_path) |
| 82 : base_path_(base_path), enabled_(false), list_infos_(GetListInfos()) { | 82 : base_path_(base_path), |
| 83 enabled_(false), |
| 84 list_infos_(GetListInfos()), |
| 85 weak_factory_(this) { |
| 83 DCHECK(!base_path_.empty()); | 86 DCHECK(!base_path_.empty()); |
| 84 DCHECK(!list_infos_.empty()); | 87 DCHECK(!list_infos_.empty()); |
| 85 | 88 |
| 86 DVLOG(1) << "V4LocalDatabaseManager::V4LocalDatabaseManager: " | 89 DVLOG(1) << "V4LocalDatabaseManager::V4LocalDatabaseManager: " |
| 87 << "base_path_: " << base_path_.AsUTF8Unsafe(); | 90 << "base_path_: " << base_path_.AsUTF8Unsafe(); |
| 88 } | 91 } |
| 89 | 92 |
| 90 V4LocalDatabaseManager::~V4LocalDatabaseManager() { | 93 V4LocalDatabaseManager::~V4LocalDatabaseManager() { |
| 91 DCHECK(!enabled_); | 94 DCHECK(!enabled_); |
| 92 } | 95 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 bool V4LocalDatabaseManager::IsSupported() const { | 241 bool V4LocalDatabaseManager::IsSupported() const { |
| 239 return true; | 242 return true; |
| 240 } | 243 } |
| 241 | 244 |
| 242 void V4LocalDatabaseManager::StartOnIOThread( | 245 void V4LocalDatabaseManager::StartOnIOThread( |
| 243 net::URLRequestContextGetter* request_context_getter, | 246 net::URLRequestContextGetter* request_context_getter, |
| 244 const V4ProtocolConfig& config) { | 247 const V4ProtocolConfig& config) { |
| 245 SafeBrowsingDatabaseManager::StartOnIOThread(request_context_getter, config); | 248 SafeBrowsingDatabaseManager::StartOnIOThread(request_context_getter, config); |
| 246 | 249 |
| 247 db_updated_callback_ = base::Bind(&V4LocalDatabaseManager::DatabaseUpdated, | 250 db_updated_callback_ = base::Bind(&V4LocalDatabaseManager::DatabaseUpdated, |
| 248 base::Unretained(this)); | 251 weak_factory_.GetWeakPtr()); |
| 249 | 252 |
| 250 SetupUpdateProtocolManager(request_context_getter, config); | 253 SetupUpdateProtocolManager(request_context_getter, config); |
| 251 SetupDatabase(); | 254 SetupDatabase(); |
| 252 | 255 |
| 253 enabled_ = true; | 256 enabled_ = true; |
| 254 } | 257 } |
| 255 | 258 |
| 256 void V4LocalDatabaseManager::StopOnIOThread(bool shutdown) { | 259 void V4LocalDatabaseManager::StopOnIOThread(bool shutdown) { |
| 257 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 260 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 258 | 261 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 288 // database is ready, StopOnIOThread has been called. | 291 // database is ready, StopOnIOThread has been called. |
| 289 if (enabled_) { | 292 if (enabled_) { |
| 290 v4_database_ = std::move(v4_database); | 293 v4_database_ = std::move(v4_database); |
| 291 | 294 |
| 292 // The consistency of the stores read from the disk needs to verified. Post | 295 // The consistency of the stores read from the disk needs to verified. Post |
| 293 // that task on the task runner. It calls |DatabaseReadyForUpdates| | 296 // that task on the task runner. It calls |DatabaseReadyForUpdates| |
| 294 // callback with the stores to reset, if any, and then we can schedule the | 297 // callback with the stores to reset, if any, and then we can schedule the |
| 295 // database updates. | 298 // database updates. |
| 296 v4_database_->VerifyChecksum( | 299 v4_database_->VerifyChecksum( |
| 297 base::Bind(&V4LocalDatabaseManager::DatabaseReadyForUpdates, | 300 base::Bind(&V4LocalDatabaseManager::DatabaseReadyForUpdates, |
| 298 base::Unretained(this))); | 301 weak_factory_.GetWeakPtr())); |
| 299 | 302 |
| 300 ProcessQueuedChecks(); | 303 ProcessQueuedChecks(); |
| 301 } else { | 304 } else { |
| 302 // Schedule the deletion of v4_database off IO thread. | 305 // Schedule the deletion of v4_database off IO thread. |
| 303 V4Database::Destroy(std::move(v4_database)); | 306 V4Database::Destroy(std::move(v4_database)); |
| 304 } | 307 } |
| 305 } | 308 } |
| 306 | 309 |
| 307 void V4LocalDatabaseManager::DatabaseReadyForUpdates( | 310 void V4LocalDatabaseManager::DatabaseReadyForUpdates( |
| 308 const std::vector<ListIdentifier>& stores_to_reset) { | 311 const std::vector<ListIdentifier>& stores_to_reset) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 426 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 424 | 427 |
| 425 DCHECK(enabled_); | 428 DCHECK(enabled_); |
| 426 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); | 429 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); |
| 427 | 430 |
| 428 pending_clients_.insert(check->client); | 431 pending_clients_.insert(check->client); |
| 429 | 432 |
| 430 v4_get_hash_protocol_manager_->GetFullHashes( | 433 v4_get_hash_protocol_manager_->GetFullHashes( |
| 431 full_hash_to_store_and_hash_prefixes, | 434 full_hash_to_store_and_hash_prefixes, |
| 432 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, | 435 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, |
| 433 base::Unretained(this), base::Passed(std::move(check)))); | 436 weak_factory_.GetWeakPtr(), base::Passed(std::move(check)))); |
| 434 } | 437 } |
| 435 | 438 |
| 436 void V4LocalDatabaseManager::ProcessQueuedChecks() { | 439 void V4LocalDatabaseManager::ProcessQueuedChecks() { |
| 437 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 440 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 438 for (auto& it : queued_checks_) { | 441 for (auto& it : queued_checks_) { |
| 439 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; | 442 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; |
| 440 if (!GetPrefixMatches(it, &full_hash_to_store_and_hash_prefixes)) { | 443 if (!GetPrefixMatches(it, &full_hash_to_store_and_hash_prefixes)) { |
| 441 RespondToClient(std::move(it)); | 444 RespondToClient(std::move(it)); |
| 442 } else { | 445 } else { |
| 443 PerformFullHashCheck(std::move(it), full_hash_to_store_and_hash_prefixes); | 446 PerformFullHashCheck(std::move(it), full_hash_to_store_and_hash_prefixes); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 471 // previously been started and stopped, a task runner could already exist. | 474 // previously been started and stopped, a task runner could already exist. |
| 472 if (!task_runner_) { | 475 if (!task_runner_) { |
| 473 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 476 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
| 474 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( | 477 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 475 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 478 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 476 } | 479 } |
| 477 | 480 |
| 478 // Do not create the database on the IO thread since this may be an expensive | 481 // Do not create the database on the IO thread since this may be an expensive |
| 479 // operation. Instead, do that on the task_runner and when the new database | 482 // operation. Instead, do that on the task_runner and when the new database |
| 480 // has been created, swap it out on the IO thread. | 483 // has been created, swap it out on the IO thread. |
| 481 NewDatabaseReadyCallback db_ready_callback = base::Bind( | 484 NewDatabaseReadyCallback db_ready_callback = |
| 482 &V4LocalDatabaseManager::DatabaseReadyForChecks, base::Unretained(this)); | 485 base::Bind(&V4LocalDatabaseManager::DatabaseReadyForChecks, |
| 486 weak_factory_.GetWeakPtr()); |
| 483 V4Database::Create(task_runner_, base_path_, list_infos_, db_ready_callback); | 487 V4Database::Create(task_runner_, base_path_, list_infos_, db_ready_callback); |
| 484 } | 488 } |
| 485 | 489 |
| 486 void V4LocalDatabaseManager::SetupUpdateProtocolManager( | 490 void V4LocalDatabaseManager::SetupUpdateProtocolManager( |
| 487 net::URLRequestContextGetter* request_context_getter, | 491 net::URLRequestContextGetter* request_context_getter, |
| 488 const V4ProtocolConfig& config) { | 492 const V4ProtocolConfig& config) { |
| 489 V4UpdateCallback callback = base::Bind( | 493 V4UpdateCallback callback = |
| 490 &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this)); | 494 base::Bind(&V4LocalDatabaseManager::UpdateRequestCompleted, |
| 495 weak_factory_.GetWeakPtr()); |
| 491 | 496 |
| 492 v4_update_protocol_manager_ = | 497 v4_update_protocol_manager_ = |
| 493 V4UpdateProtocolManager::Create(request_context_getter, config, callback); | 498 V4UpdateProtocolManager::Create(request_context_getter, config, callback); |
| 494 } | 499 } |
| 495 | 500 |
| 496 void V4LocalDatabaseManager::UpdateRequestCompleted( | 501 void V4LocalDatabaseManager::UpdateRequestCompleted( |
| 497 std::unique_ptr<ParsedServerResponse> parsed_server_response) { | 502 std::unique_ptr<ParsedServerResponse> parsed_server_response) { |
| 498 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 503 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 499 v4_database_->ApplyUpdate(std::move(parsed_server_response), | 504 v4_database_->ApplyUpdate(std::move(parsed_server_response), |
| 500 db_updated_callback_); | 505 db_updated_callback_); |
| 501 } | 506 } |
| 502 | 507 |
| 503 } // namespace safe_browsing | 508 } // namespace safe_browsing |
| OLD | NEW |