OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana
ger.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana
ger.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 for (const auto& manager_context_pair : contexts_) { | 396 for (const auto& manager_context_pair : contexts_) { |
397 if (manager_context_pair.first->GetBrowserContext() == browser_context) { | 397 if (manager_context_pair.first->GetBrowserContext() == browser_context) { |
398 manager_context_pair.second->GetDownloadDetails(callback); | 398 manager_context_pair.second->GetDownloadDetails(callback); |
399 return; | 399 return; |
400 } | 400 } |
401 } | 401 } |
402 | 402 |
403 // Fire off a task to load the details and return them to the caller. | 403 // Fire off a task to load the details and return them to the caller. |
404 DownloadMetadata* metadata = new DownloadMetadata(); | 404 DownloadMetadata* metadata = new DownloadMetadata(); |
405 read_runner_->PostTaskAndReply( | 405 read_runner_->PostTaskAndReply( |
406 FROM_HERE, base::Bind(&ReadMetadataOnWorkerPool, | 406 FROM_HERE, |
407 GetMetadataPath(browser_context), metadata), | 407 base::BindOnce(&ReadMetadataOnWorkerPool, |
408 base::Bind(&ReturnResults, callback, | 408 GetMetadataPath(browser_context), metadata), |
409 base::Passed(base::WrapUnique(metadata)))); | 409 base::BindOnce(&ReturnResults, callback, |
| 410 base::Passed(base::WrapUnique(metadata)))); |
410 } | 411 } |
411 | 412 |
412 content::DownloadManager* | 413 content::DownloadManager* |
413 DownloadMetadataManager::GetDownloadManagerForBrowserContext( | 414 DownloadMetadataManager::GetDownloadManagerForBrowserContext( |
414 content::BrowserContext* context) { | 415 content::BrowserContext* context) { |
415 return content::BrowserContext::GetDownloadManager(context); | 416 return content::BrowserContext::GetDownloadManager(context); |
416 } | 417 } |
417 | 418 |
418 void DownloadMetadataManager::OnDownloadCreated( | 419 void DownloadMetadataManager::OnDownloadCreated( |
419 content::DownloadManager* download_manager, | 420 content::DownloadManager* download_manager, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 RunCallbacks(); | 560 RunCallbacks(); |
560 } | 561 } |
561 | 562 |
562 void DownloadMetadataManager::ManagerContext::ReadMetadata() { | 563 void DownloadMetadataManager::ManagerContext::ReadMetadata() { |
563 DCHECK_NE(state_, LOAD_COMPLETE); | 564 DCHECK_NE(state_, LOAD_COMPLETE); |
564 | 565 |
565 DownloadMetadata* metadata = new DownloadMetadata(); | 566 DownloadMetadata* metadata = new DownloadMetadata(); |
566 // Do not block shutdown on this read since nothing will come of it. | 567 // Do not block shutdown on this read since nothing will come of it. |
567 read_runner_->PostTaskAndReply( | 568 read_runner_->PostTaskAndReply( |
568 FROM_HERE, | 569 FROM_HERE, |
569 base::Bind(&ReadMetadataOnWorkerPool, metadata_path_, metadata), | 570 base::BindOnce(&ReadMetadataOnWorkerPool, metadata_path_, metadata), |
570 base::Bind(&DownloadMetadataManager::ManagerContext::OnMetadataReady, | 571 base::BindOnce(&DownloadMetadataManager::ManagerContext::OnMetadataReady, |
571 weak_factory_.GetWeakPtr(), | 572 weak_factory_.GetWeakPtr(), |
572 base::Passed(base::WrapUnique(metadata)))); | 573 base::Passed(base::WrapUnique(metadata)))); |
573 } | 574 } |
574 | 575 |
575 void DownloadMetadataManager::ManagerContext::WriteMetadata() { | 576 void DownloadMetadataManager::ManagerContext::WriteMetadata() { |
576 write_runner_->PostTask( | 577 write_runner_->PostTask( |
577 FROM_HERE, | 578 FROM_HERE, |
578 base::Bind(&WriteMetadataOnWorkerPool, | 579 base::BindOnce(&WriteMetadataOnWorkerPool, metadata_path_, |
579 metadata_path_, | 580 base::Owned(new DownloadMetadata(*download_metadata_)))); |
580 base::Owned(new DownloadMetadata(*download_metadata_)))); | |
581 } | 581 } |
582 | 582 |
583 void DownloadMetadataManager::ManagerContext::RemoveMetadata() { | 583 void DownloadMetadataManager::ManagerContext::RemoveMetadata() { |
584 if (state_ != LOAD_COMPLETE) { | 584 if (state_ != LOAD_COMPLETE) { |
585 // Abandon the read task since the file is to be removed. | 585 // Abandon the read task since the file is to be removed. |
586 weak_factory_.InvalidateWeakPtrs(); | 586 weak_factory_.InvalidateWeakPtrs(); |
587 state_ = LOAD_COMPLETE; | 587 state_ = LOAD_COMPLETE; |
588 // Drop any recorded operations. | 588 // Drop any recorded operations. |
589 ClearPendingItems(); | 589 ClearPendingItems(); |
590 } | 590 } |
591 // Remove any metadata. | 591 // Remove any metadata. |
592 download_metadata_.reset(); | 592 download_metadata_.reset(); |
593 write_runner_->PostTask( | 593 write_runner_->PostTask( |
594 FROM_HERE, base::Bind(&DeleteMetadataOnWorkerPool, metadata_path_)); | 594 FROM_HERE, base::BindOnce(&DeleteMetadataOnWorkerPool, metadata_path_)); |
595 // Run callbacks (only present in case of a transition to LOAD_COMPLETE). | 595 // Run callbacks (only present in case of a transition to LOAD_COMPLETE). |
596 RunCallbacks(); | 596 RunCallbacks(); |
597 } | 597 } |
598 | 598 |
599 void DownloadMetadataManager::ManagerContext::ClearPendingItems() { | 599 void DownloadMetadataManager::ManagerContext::ClearPendingItems() { |
600 pending_items_.clear(); | 600 pending_items_.clear(); |
601 } | 601 } |
602 | 602 |
603 void DownloadMetadataManager::ManagerContext::RunCallbacks() { | 603 void DownloadMetadataManager::ManagerContext::RunCallbacks() { |
604 while (!get_details_callbacks_.empty()) { | 604 while (!get_details_callbacks_.empty()) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 } | 656 } |
657 | 657 |
658 void DownloadMetadataManager::ManagerContext::UpdateLastOpenedTime( | 658 void DownloadMetadataManager::ManagerContext::UpdateLastOpenedTime( |
659 const base::Time& last_opened_time) { | 659 const base::Time& last_opened_time) { |
660 download_metadata_->mutable_download()->set_open_time_msec( | 660 download_metadata_->mutable_download()->set_open_time_msec( |
661 last_opened_time.ToJavaTime()); | 661 last_opened_time.ToJavaTime()); |
662 WriteMetadata(); | 662 WriteMetadata(); |
663 } | 663 } |
664 | 664 |
665 } // namespace safe_browsing | 665 } // namespace safe_browsing |
OLD | NEW |