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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 // download file has been released. | 362 // download file has been released. |
363 if (!is_save_package_download_ && download_file_) | 363 if (!is_save_package_download_ && download_file_) |
364 ReleaseDownloadFile(true); | 364 ReleaseDownloadFile(true); |
365 | 365 |
366 if (state_ == IN_PROGRESS_INTERNAL) { | 366 if (state_ == IN_PROGRESS_INTERNAL) { |
367 // Cancel the originating URL request unless it's already been cancelled | 367 // Cancel the originating URL request unless it's already been cancelled |
368 // by interrupt. | 368 // by interrupt. |
369 request_handle_->CancelRequest(); | 369 request_handle_->CancelRequest(); |
370 } | 370 } |
371 | 371 |
372 if ((state_ == INTERRUPTED_INTERNAL || state_ == RESUMING_INTERNAL) && | |
373 !current_path_.empty() && current_path_ != target_path_) { | |
374 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
375 base::Bind(&DeleteDownloadedFile, current_path_)); | |
376 current_path_.clear(); | |
377 } | |
378 | |
372 TransitionTo(CANCELLED_INTERNAL); | 379 TransitionTo(CANCELLED_INTERNAL); |
373 } | 380 } |
374 | 381 |
375 void DownloadItemImpl::Delete(DeleteReason reason) { | 382 void DownloadItemImpl::Delete(DeleteReason reason) { |
376 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 383 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
378 | 385 |
379 switch (reason) { | 386 switch (reason) { |
380 case DELETE_DUE_TO_USER_DISCARD: | 387 case DELETE_DUE_TO_USER_DISCARD: |
381 UMA_HISTOGRAM_ENUMERATION( | 388 UMA_HISTOGRAM_ENUMERATION( |
(...skipping 20 matching lines...) Expand all Loading... | |
402 // We have now been deleted. | 409 // We have now been deleted. |
403 } | 410 } |
404 | 411 |
405 void DownloadItemImpl::Remove() { | 412 void DownloadItemImpl::Remove() { |
406 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 413 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
408 | 415 |
409 // Remove the intermediate file if we are removing an interrupted download. | 416 // Remove the intermediate file if we are removing an interrupted download. |
410 // Continuable interruptions leave the intermediate file around. However, the | 417 // Continuable interruptions leave the intermediate file around. However, the |
411 // intermediate file will be unusable if the download item is removed. | 418 // intermediate file will be unusable if the download item is removed. |
412 if (!current_path_.empty() && IsInterrupted() && !download_file_.get()) { | 419 // |
420 // Be extra cautious here and only delete an intermediate file if we sure it's | |
421 // really an intermediate file. Downloads imported from history may have a | |
422 // non-empty current_path_ that's the same as target_path_. | |
Randy Smith (Not in Mondays)
2013/05/15 15:34:56
I'm slightly confused. If the download was import
asanka
2013/05/21 21:09:02
https://codereview.chromium.org/11363222 introduce
Randy Smith (Not in Mondays)
2013/05/21 21:40:37
I hear you about the entries from before we starte
asanka
2013/05/22 22:55:52
Yeah. I got rid of the check.
| |
423 if (IsInterrupted() && !current_path_.empty() && !target_path_.empty() && | |
424 current_path_ != target_path_) { | |
425 DCHECK(!download_file_.get()); | |
413 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 426 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
414 base::Bind(&DeleteDownloadedFile, current_path_)); | 427 base::Bind(&DeleteDownloadedFile, current_path_)); |
415 current_path_.clear(); | 428 current_path_.clear(); |
416 } | 429 } |
417 | 430 |
418 delegate_->AssertStateConsistent(this); | 431 delegate_->AssertStateConsistent(this); |
419 Cancel(true); | 432 Cancel(true); |
420 delegate_->AssertStateConsistent(this); | 433 delegate_->AssertStateConsistent(this); |
421 | 434 |
422 NotifyRemoved(); | 435 NotifyRemoved(); |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1724 case RESUME_MODE_USER_CONTINUE: | 1737 case RESUME_MODE_USER_CONTINUE: |
1725 return "USER_CONTINUE"; | 1738 return "USER_CONTINUE"; |
1726 case RESUME_MODE_USER_RESTART: | 1739 case RESUME_MODE_USER_RESTART: |
1727 return "USER_RESTART"; | 1740 return "USER_RESTART"; |
1728 } | 1741 } |
1729 NOTREACHED() << "Unknown resume mode " << mode; | 1742 NOTREACHED() << "Unknown resume mode " << mode; |
1730 return "unknown"; | 1743 return "unknown"; |
1731 } | 1744 } |
1732 | 1745 |
1733 } // namespace content | 1746 } // namespace content |
OLD | NEW |