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 // Remove the intermediate file if we are cancelling an interrupted download. |
| 373 // Continuable interruptions leave the intermediate file around. |
| 374 if ((state_ == INTERRUPTED_INTERNAL || state_ == RESUMING_INTERNAL) && |
| 375 !current_path_.empty()) { |
| 376 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 377 base::Bind(&DeleteDownloadedFile, current_path_)); |
| 378 current_path_.clear(); |
| 379 } |
| 380 |
372 TransitionTo(CANCELLED_INTERNAL); | 381 TransitionTo(CANCELLED_INTERNAL); |
373 } | 382 } |
374 | 383 |
375 void DownloadItemImpl::Delete(DeleteReason reason) { | 384 void DownloadItemImpl::Delete(DeleteReason reason) { |
376 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 385 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
378 | 387 |
379 switch (reason) { | 388 switch (reason) { |
380 case DELETE_DUE_TO_USER_DISCARD: | 389 case DELETE_DUE_TO_USER_DISCARD: |
381 UMA_HISTOGRAM_ENUMERATION( | 390 UMA_HISTOGRAM_ENUMERATION( |
(...skipping 17 matching lines...) Expand all Loading... |
399 current_path_.clear(); | 408 current_path_.clear(); |
400 } | 409 } |
401 Remove(); | 410 Remove(); |
402 // We have now been deleted. | 411 // We have now been deleted. |
403 } | 412 } |
404 | 413 |
405 void DownloadItemImpl::Remove() { | 414 void DownloadItemImpl::Remove() { |
406 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 415 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
408 | 417 |
409 // Remove the intermediate file if we are removing an interrupted download. | |
410 // Continuable interruptions leave the intermediate file around. However, the | |
411 // intermediate file will be unusable if the download item is removed. | |
412 if (!current_path_.empty() && IsInterrupted() && !download_file_.get()) { | |
413 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
414 base::Bind(&DeleteDownloadedFile, current_path_)); | |
415 current_path_.clear(); | |
416 } | |
417 | |
418 delegate_->AssertStateConsistent(this); | 418 delegate_->AssertStateConsistent(this); |
419 Cancel(true); | 419 Cancel(true); |
420 delegate_->AssertStateConsistent(this); | 420 delegate_->AssertStateConsistent(this); |
421 | 421 |
422 NotifyRemoved(); | 422 NotifyRemoved(); |
423 delegate_->DownloadRemoved(this); | 423 delegate_->DownloadRemoved(this); |
424 // We have now been deleted. | 424 // We have now been deleted. |
425 } | 425 } |
426 | 426 |
427 void DownloadItemImpl::OpenDownload() { | 427 void DownloadItemImpl::OpenDownload() { |
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 case RESUME_MODE_USER_CONTINUE: | 1678 case RESUME_MODE_USER_CONTINUE: |
1679 return "USER_CONTINUE"; | 1679 return "USER_CONTINUE"; |
1680 case RESUME_MODE_USER_RESTART: | 1680 case RESUME_MODE_USER_RESTART: |
1681 return "USER_RESTART"; | 1681 return "USER_RESTART"; |
1682 } | 1682 } |
1683 NOTREACHED() << "Unknown resume mode " << mode; | 1683 NOTREACHED() << "Unknown resume mode " << mode; |
1684 return "unknown"; | 1684 return "unknown"; |
1685 } | 1685 } |
1686 | 1686 |
1687 } // namespace content | 1687 } // namespace content |
OLD | NEW |