diff options
Diffstat (limited to 'chromium/content/browser/download/download_item_impl.cc')
-rw-r--r-- | chromium/content/browser/download/download_item_impl.cc | 94 |
1 files changed, 67 insertions, 27 deletions
diff --git a/chromium/content/browser/download/download_item_impl.cc b/chromium/content/browser/download/download_item_impl.cc index b8f78ff56ef..433ac78f48b 100644 --- a/chromium/content/browser/download/download_item_impl.cc +++ b/chromium/content/browser/download/download_item_impl.cc @@ -57,12 +57,23 @@ namespace content { namespace { -void DeleteDownloadedFile(const base::FilePath& path) { +bool DeleteDownloadedFile(const base::FilePath& path) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); // Make sure we only delete files. - if (!base::DirectoryExists(path)) - base::DeleteFile(path, false); + if (base::DirectoryExists(path)) + return true; + return base::DeleteFile(path, false); +} + +void DeleteDownloadedFileDone( + base::WeakPtr<DownloadItemImpl> item, + const base::Callback<void(bool)>& callback, + bool success) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (success && item.get()) + item->OnDownloadedFileRemoved(); + callback.Run(success); } // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that @@ -102,6 +113,8 @@ DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, const base::FilePath& target_path, const std::vector<GURL>& url_chain, const GURL& referrer_url, + const std::string& mime_type, + const std::string& original_mime_type, const base::Time& start_time, const base::Time& end_time, const std::string& etag, @@ -122,6 +135,8 @@ DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, referrer_url_(referrer_url), transition_type_(PAGE_TRANSITION_LINK), has_user_gesture_(false), + mime_type_(mime_type), + original_mime_type_(original_mime_type), total_bytes_(total_bytes), received_bytes_(received_bytes), bytes_per_sec_(0), @@ -164,7 +179,9 @@ DownloadItemImpl::DownloadItemImpl( TARGET_DISPOSITION_PROMPT : TARGET_DISPOSITION_OVERWRITE), url_chain_(info.url_chain), referrer_url_(info.referrer_url), - suggested_filename_(UTF16ToUTF8(info.save_info->suggested_name)), + tab_url_(info.tab_url), + tab_referrer_url_(info.tab_referrer_url), + suggested_filename_(base::UTF16ToUTF8(info.save_info->suggested_name)), forced_file_path_(info.save_info->file_path), transition_type_(info.transition_type), has_user_gesture_(info.has_user_gesture), @@ -407,8 +424,9 @@ void DownloadItemImpl::Cancel(bool user_cancel) { // Continuable interruptions leave the intermediate file around. if ((state_ == INTERRUPTED_INTERNAL || state_ == RESUMING_INTERNAL) && !current_path_.empty()) { - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, - base::Bind(&DeleteDownloadedFile, current_path_)); + BrowserThread::PostTask( + BrowserThread::FILE, FROM_HERE, + base::Bind(base::IgnoreResult(&DeleteDownloadedFile), current_path_)); current_path_.clear(); } @@ -538,6 +556,14 @@ const GURL& DownloadItemImpl::GetReferrerUrl() const { return referrer_url_; } +const GURL& DownloadItemImpl::GetTabUrl() const { + return tab_url_; +} + +const GURL& DownloadItemImpl::GetTabReferrerUrl() const { + return tab_referrer_url_; +} + std::string DownloadItemImpl::GetSuggestedFilename() const { return suggested_filename_; } @@ -614,18 +640,29 @@ bool DownloadItemImpl::GetFileExternallyRemoved() const { return file_externally_removed_; } -void DownloadItemImpl::DeleteFile() { +void DownloadItemImpl::DeleteFile(const base::Callback<void(bool)>& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if ((GetState() != DownloadItem::COMPLETE) || - file_externally_removed_) { + if (GetState() != DownloadItem::COMPLETE) { + // Pass a null WeakPtr so it doesn't call OnDownloadedFileRemoved. + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&DeleteDownloadedFileDone, + base::WeakPtr<DownloadItemImpl>(), callback, false)); + return; + } + if (current_path_.empty() || file_externally_removed_) { + // Pass a null WeakPtr so it doesn't call OnDownloadedFileRemoved. + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&DeleteDownloadedFileDone, + base::WeakPtr<DownloadItemImpl>(), callback, true)); return; } - BrowserThread::PostTaskAndReply( + BrowserThread::PostTaskAndReplyWithResult( BrowserThread::FILE, FROM_HERE, base::Bind(&DeleteDownloadedFile, current_path_), - base::Bind(&DownloadItemImpl::OnDownloadedFileRemoved, - weak_ptr_factory_.GetWeakPtr())); - current_path_.clear(); + base::Bind(&DeleteDownloadedFileDone, + weak_ptr_factory_.GetWeakPtr(), callback)); } bool DownloadItemImpl::IsDangerous() const { @@ -805,7 +842,7 @@ std::string DownloadItemImpl::DebugString(bool verbose) const { " target_path = \"%" PRFilePath "\"", GetTotalBytes(), GetReceivedBytes(), - InterruptReasonDebugString(last_reason_).c_str(), + DownloadInterruptReasonToString(last_reason_).c_str(), IsPaused() ? 'T' : 'F', DebugResumeModeString(GetResumeMode()), auto_resume_count_, @@ -866,6 +903,7 @@ DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const { case DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED: case DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED: case DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN: + case DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST: case DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED: case DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN: case DOWNLOAD_INTERRUPT_REASON_CRASH: @@ -1014,7 +1052,7 @@ void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, if (received_bytes_ > total_bytes_) total_bytes_ = 0; - if (bound_net_log_.IsLoggingAllEvents()) { + if (bound_net_log_.IsLogging()) { bound_net_log_.AddEvent( net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); @@ -1378,23 +1416,20 @@ void DownloadItemImpl::Completed() { } } -void DownloadItemImpl::OnResumeRequestStarted(DownloadItem* item, - net::Error error) { +void DownloadItemImpl::OnResumeRequestStarted( + DownloadItem* item, + DownloadInterruptReason interrupt_reason) { // If |item| is not NULL, then Start() has been called already, and nothing // more needs to be done here. if (item) { - DCHECK_EQ(net::OK, error); + DCHECK_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); DCHECK_EQ(static_cast<DownloadItem*>(this), item); return; } // Otherwise, the request failed without passing through // DownloadResourceHandler::OnResponseStarted. - if (error == net::OK) - error = net::ERR_FAILED; - DownloadInterruptReason reason = - ConvertNetErrorToInterruptReason(error, DOWNLOAD_INTERRUPT_FROM_NETWORK); - DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, reason); - Interrupt(reason); + DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); + Interrupt(interrupt_reason); } // **** End of Download progression cascade @@ -1402,6 +1437,7 @@ void DownloadItemImpl::OnResumeRequestStarted(DownloadItem* item, // An error occurred somewhere. void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, reason); // Somewhat counter-intuitively, it is possible for us to receive an // interrupt after we've already been interrupted. The generation of @@ -1421,11 +1457,15 @@ void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) { ResumeMode resume_mode = GetResumeMode(); if (state_ == IN_PROGRESS_INTERNAL) { - // Cancel (delete file) if we're going to restart; no point in leaving - // data around we aren't going to use. Also cancel if resumption isn't - // enabled for the same reason. + // Cancel (delete file) if: + // 1) we're going to restart. + // 2) Resumption isn't possible (download was cancelled or blocked due to + // security restrictions). + // 3) Resumption isn't enabled. + // No point in leaving data around we aren't going to use. ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART || resume_mode == RESUME_MODE_USER_RESTART || + resume_mode == RESUME_MODE_INVALID || !IsDownloadResumptionEnabled()); // Cancel the originating URL request. |