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) || |
asanka
2014/01/16 16:05:51
Can you also check whether current_path_ is empty
benjhayden
2014/01/16 17:09:18
Done.
| |
622 file_externally_removed_) { | 622 file_externally_removed_) { |
623 return; | 623 return; |
asanka
2014/01/16 16:05:51
You'll want to invoke the callback before returnin
benjhayden
2014/01/16 17:09:18
Done.
| |
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) { | |
asanka
2014/01/16 16:05:51
Nit: no braces
benjhayden
2014/01/16 17:09:18
Done.
| |
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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
940 | 950 |
941 // Don't update observers. This method is expected to be called just before a | 951 // Don't update observers. This method is expected to be called just before a |
942 // DownloadFile is created and Start() is called. The observers will be | 952 // DownloadFile is created and Start() is called. The observers will be |
943 // notified when the download transitions to the IN_PROGRESS state. | 953 // notified when the download transitions to the IN_PROGRESS state. |
944 } | 954 } |
945 | 955 |
946 void DownloadItemImpl::NotifyRemoved() { | 956 void DownloadItemImpl::NotifyRemoved() { |
947 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); | 957 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); |
948 } | 958 } |
949 | 959 |
950 void DownloadItemImpl::OnDownloadedFileRemoved(bool success) { | 960 void DownloadItemImpl::OnDownloadedFileRemoved() { |
951 if (!success) | |
952 return; | |
953 file_externally_removed_ = true; | 961 file_externally_removed_ = true; |
954 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 962 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
955 UpdateObservers(); | 963 UpdateObservers(); |
956 } | 964 } |
957 | 965 |
958 base::WeakPtr<DownloadDestinationObserver> | 966 base::WeakPtr<DownloadDestinationObserver> |
959 DownloadItemImpl::DestinationObserverAsWeakPtr() { | 967 DownloadItemImpl::DestinationObserverAsWeakPtr() { |
960 return weak_ptr_factory_.GetWeakPtr(); | 968 return weak_ptr_factory_.GetWeakPtr(); |
961 } | 969 } |
962 | 970 |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1762 case RESUME_MODE_USER_CONTINUE: | 1770 case RESUME_MODE_USER_CONTINUE: |
1763 return "USER_CONTINUE"; | 1771 return "USER_CONTINUE"; |
1764 case RESUME_MODE_USER_RESTART: | 1772 case RESUME_MODE_USER_RESTART: |
1765 return "USER_RESTART"; | 1773 return "USER_RESTART"; |
1766 } | 1774 } |
1767 NOTREACHED() << "Unknown resume mode " << mode; | 1775 NOTREACHED() << "Unknown resume mode " << mode; |
1768 return "unknown"; | 1776 return "unknown"; |
1769 } | 1777 } |
1770 | 1778 |
1771 } // namespace content | 1779 } // namespace content |
OLD | NEW |