OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // File method ordering: Methods in this file are in the same order as | 5 // File method ordering: Methods in this file are in the same order as |
6 // in download_item_impl.h, with the following exception: The public | 6 // in download_item_impl.h, with the following exception: The public |
7 // interface Start is placed in chronological order with the other | 7 // interface Start is placed in chronological order with the other |
8 // (private) routines that together define a DownloadItem's state | 8 // (private) routines that together define a DownloadItem's state |
9 // transitions as the download progresses. See "Download progression | 9 // transitions as the download progresses. See "Download progression |
10 // cascade" later in this file. | 10 // cascade" later in this file. |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 } | 609 } |
610 | 610 |
611 const std::string& DownloadItemImpl::GetHashState() const { | 611 const std::string& DownloadItemImpl::GetHashState() const { |
612 return hash_state_; | 612 return hash_state_; |
613 } | 613 } |
614 | 614 |
615 bool DownloadItemImpl::GetFileExternallyRemoved() const { | 615 bool DownloadItemImpl::GetFileExternallyRemoved() const { |
616 return file_externally_removed_; | 616 return file_externally_removed_; |
617 } | 617 } |
618 | 618 |
619 void DownloadItemImpl::DeleteFile() { | 619 void DownloadItemImpl::DeleteFile(const base::Callback<void(bool)>& callback) { |
620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
621 if ((GetState() != DownloadItem::COMPLETE) || | 621 if ((GetState() != DownloadItem::COMPLETE) || |
622 file_externally_removed_) { | 622 file_externally_removed_) { |
623 return; | 623 return; |
624 } | 624 } |
625 BrowserThread::PostTaskAndReplyWithResult( | 625 BrowserThread::PostTaskAndReplyWithResult( |
626 BrowserThread::FILE, FROM_HERE, | 626 BrowserThread::FILE, FROM_HERE, |
627 base::Bind(&DeleteDownloadedFile, current_path_), | 627 base::Bind(&DeleteDownloadedFile, current_path_), |
628 base::Bind(&DownloadItemImpl::OnDownloadedFileRemoved, | 628 base::Bind(&DownloadItemImpl::DeleteFileDone, |
629 weak_ptr_factory_.GetWeakPtr())); | 629 weak_ptr_factory_.GetWeakPtr(), |
| 630 callback)); |
630 current_path_.clear(); | 631 current_path_.clear(); |
631 } | 632 } |
632 | 633 |
| 634 void DownloadItemImpl::DeleteFileDone( |
| 635 const base::Callback<void(bool)>& callback, |
| 636 bool success) { |
| 637 if (success) { |
| 638 OnDownloadedFileRemoved(); |
| 639 } |
| 640 callback.Run(success); |
| 641 } |
| 642 |
633 bool DownloadItemImpl::IsDangerous() const { | 643 bool DownloadItemImpl::IsDangerous() const { |
634 #if defined(OS_WIN) | 644 #if defined(OS_WIN) |
635 // TODO(noelutz): At this point only the windows views UI supports | 645 // TODO(noelutz): At this point only the windows views UI supports |
636 // warnings based on dangerous content. | 646 // warnings based on dangerous content. |
637 return (danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || | 647 return (danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || |
638 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || | 648 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || |
639 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || | 649 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || |
640 danger_type_ == DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT || | 650 danger_type_ == DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT || |
641 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST || | 651 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST || |
642 danger_type_ == DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED); | 652 danger_type_ == DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 | 949 |
940 // Don't update observers. This method is expected to be called just before a | 950 // Don't update observers. This method is expected to be called just before a |
941 // DownloadFile is created and Start() is called. The observers will be | 951 // DownloadFile is created and Start() is called. The observers will be |
942 // notified when the download transitions to the IN_PROGRESS state. | 952 // notified when the download transitions to the IN_PROGRESS state. |
943 } | 953 } |
944 | 954 |
945 void DownloadItemImpl::NotifyRemoved() { | 955 void DownloadItemImpl::NotifyRemoved() { |
946 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); | 956 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); |
947 } | 957 } |
948 | 958 |
949 void DownloadItemImpl::OnDownloadedFileRemoved(bool success) { | 959 void DownloadItemImpl::OnDownloadedFileRemoved() { |
950 if (!success) | |
951 return; | |
952 file_externally_removed_ = true; | 960 file_externally_removed_ = true; |
953 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 961 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
954 UpdateObservers(); | 962 UpdateObservers(); |
955 } | 963 } |
956 | 964 |
957 base::WeakPtr<DownloadDestinationObserver> | 965 base::WeakPtr<DownloadDestinationObserver> |
958 DownloadItemImpl::DestinationObserverAsWeakPtr() { | 966 DownloadItemImpl::DestinationObserverAsWeakPtr() { |
959 return weak_ptr_factory_.GetWeakPtr(); | 967 return weak_ptr_factory_.GetWeakPtr(); |
960 } | 968 } |
961 | 969 |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1752 case RESUME_MODE_USER_CONTINUE: | 1760 case RESUME_MODE_USER_CONTINUE: |
1753 return "USER_CONTINUE"; | 1761 return "USER_CONTINUE"; |
1754 case RESUME_MODE_USER_RESTART: | 1762 case RESUME_MODE_USER_RESTART: |
1755 return "USER_RESTART"; | 1763 return "USER_RESTART"; |
1756 } | 1764 } |
1757 NOTREACHED() << "Unknown resume mode " << mode; | 1765 NOTREACHED() << "Unknown resume mode " << mode; |
1758 return "unknown"; | 1766 return "unknown"; |
1759 } | 1767 } |
1760 | 1768 |
1761 } // namespace content | 1769 } // namespace content |
OLD | NEW |