Chromium Code Reviews| 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 | 469 |
| 470 bool DownloadItemImpl::IsPaused() const { | 470 bool DownloadItemImpl::IsPaused() const { |
| 471 return is_paused_; | 471 return is_paused_; |
| 472 } | 472 } |
| 473 | 473 |
| 474 bool DownloadItemImpl::IsTemporary() const { | 474 bool DownloadItemImpl::IsTemporary() const { |
| 475 return is_temporary_; | 475 return is_temporary_; |
| 476 } | 476 } |
| 477 | 477 |
| 478 bool DownloadItemImpl::CanResume() const { | 478 bool DownloadItemImpl::CanResume() const { |
| 479 if (IsInProgress() && IsPaused()) | 479 if ((GetState() == IN_PROGRESS) && IsPaused()) |
| 480 return true; | 480 return true; |
| 481 | 481 |
| 482 if (state_ != INTERRUPTED_INTERNAL) | 482 if (state_ != INTERRUPTED_INTERNAL) |
| 483 return false; | 483 return false; |
| 484 | 484 |
| 485 // Downloads that don't have a WebContents should still be resumable, but this | 485 // Downloads that don't have a WebContents should still be resumable, but this |
| 486 // isn't currently the case. See ResumeInterruptedDownload(). | 486 // isn't currently the case. See ResumeInterruptedDownload(). |
| 487 if (!GetWebContents()) | 487 if (!GetWebContents()) |
| 488 return false; | 488 return false; |
| 489 | 489 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 509 case RESUMING_INTERNAL: | 509 case RESUMING_INTERNAL: |
| 510 return false; | 510 return false; |
| 511 | 511 |
| 512 case MAX_DOWNLOAD_INTERNAL_STATE: | 512 case MAX_DOWNLOAD_INTERNAL_STATE: |
| 513 break; | 513 break; |
| 514 } | 514 } |
| 515 NOTREACHED(); | 515 NOTREACHED(); |
| 516 return true; | 516 return true; |
| 517 } | 517 } |
| 518 | 518 |
| 519 bool DownloadItemImpl::IsInProgress() const { | |
| 520 return InternalToExternalState(state_) == IN_PROGRESS; | |
| 521 } | |
| 522 | |
| 523 bool DownloadItemImpl::IsCancelled() const { | |
| 524 return InternalToExternalState(state_) == CANCELLED; | |
| 525 } | |
| 526 | |
| 527 bool DownloadItemImpl::IsInterrupted() const { | |
| 528 return InternalToExternalState(state_) == INTERRUPTED; | |
| 529 } | |
| 530 | |
| 531 bool DownloadItemImpl::IsComplete() const { | |
| 532 return InternalToExternalState(state_) == COMPLETE; | |
| 533 } | |
| 534 | |
| 535 const GURL& DownloadItemImpl::GetURL() const { | 519 const GURL& DownloadItemImpl::GetURL() const { |
| 536 return url_chain_.empty() ? GURL::EmptyGURL() : url_chain_.back(); | 520 return url_chain_.empty() ? GURL::EmptyGURL() : url_chain_.back(); |
| 537 } | 521 } |
| 538 | 522 |
| 539 const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const { | 523 const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const { |
| 540 return url_chain_; | 524 return url_chain_; |
| 541 } | 525 } |
| 542 | 526 |
| 543 const GURL& DownloadItemImpl::GetOriginalUrl() const { | 527 const GURL& DownloadItemImpl::GetOriginalUrl() const { |
| 544 // Be careful about taking the front() of possibly-empty vectors! | 528 // Be careful about taking the front() of possibly-empty vectors! |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 bool DownloadItemImpl::CanShowInFolder() { | 680 bool DownloadItemImpl::CanShowInFolder() { |
| 697 // A download can be shown in the folder if the downloaded file is in a known | 681 // A download can be shown in the folder if the downloaded file is in a known |
| 698 // location. | 682 // location. |
| 699 return CanOpenDownload() && !GetFullPath().empty(); | 683 return CanOpenDownload() && !GetFullPath().empty(); |
| 700 } | 684 } |
| 701 | 685 |
| 702 bool DownloadItemImpl::CanOpenDownload() { | 686 bool DownloadItemImpl::CanOpenDownload() { |
| 703 // We can open the file or mark it for opening on completion if the download | 687 // We can open the file or mark it for opening on completion if the download |
| 704 // is expected to complete successfully. Exclude temporary downloads, since | 688 // is expected to complete successfully. Exclude temporary downloads, since |
| 705 // they aren't owned by the download system. | 689 // they aren't owned by the download system. |
| 706 return (!IsDone() || IsComplete()) && !IsTemporary() && | 690 const bool isComplete = GetState() == DownloadItem::COMPLETE; |
|
benjhayden
2013/06/13 19:01:45
use hacker_style for variable names: is_complete
| |
| 691 return (!IsDone() || isComplete) && !IsTemporary() && | |
| 707 !file_externally_removed_; | 692 !file_externally_removed_; |
| 708 } | 693 } |
| 709 | 694 |
| 710 bool DownloadItemImpl::ShouldOpenFileBasedOnExtension() { | 695 bool DownloadItemImpl::ShouldOpenFileBasedOnExtension() { |
| 711 return delegate_->ShouldOpenFileBasedOnExtension(GetTargetFilePath()); | 696 return delegate_->ShouldOpenFileBasedOnExtension(GetTargetFilePath()); |
| 712 } | 697 } |
| 713 | 698 |
| 714 bool DownloadItemImpl::GetOpenWhenComplete() const { | 699 bool DownloadItemImpl::GetOpenWhenComplete() const { |
| 715 return open_when_complete_; | 700 return open_when_complete_; |
| 716 } | 701 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 937 end_time_ = base::Time::Now(); | 922 end_time_ = base::Time::Now(); |
| 938 TransitionTo(COMPLETE_INTERNAL); | 923 TransitionTo(COMPLETE_INTERNAL); |
| 939 } | 924 } |
| 940 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, | 925 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, |
| 941 int64 bytes_per_sec, | 926 int64 bytes_per_sec, |
| 942 const std::string& hash_state) { | 927 const std::string& hash_state) { |
| 943 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 928 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 944 VLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far | 929 VLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far |
| 945 << " per_sec=" << bytes_per_sec << " download=" << DebugString(true); | 930 << " per_sec=" << bytes_per_sec << " download=" << DebugString(true); |
| 946 | 931 |
| 947 if (!IsInProgress()) { | 932 if (GetState() != IN_PROGRESS) { |
| 948 // Ignore if we're no longer in-progress. This can happen if we race a | 933 // Ignore if we're no longer in-progress. This can happen if we race a |
| 949 // Cancel on the UI thread with an update on the FILE thread. | 934 // Cancel on the UI thread with an update on the FILE thread. |
| 950 // | 935 // |
| 951 // TODO(rdsmith): Arguably we should let this go through, as this means | 936 // TODO(rdsmith): Arguably we should let this go through, as this means |
| 952 // the download really did get further than we know before it was | 937 // the download really did get further than we know before it was |
| 953 // cancelled. But the gain isn't very large, and the code is more | 938 // cancelled. But the gain isn't very large, and the code is more |
| 954 // fragile if it has to support in progress updates in a non-in-progress | 939 // fragile if it has to support in progress updates in a non-in-progress |
| 955 // state. This issue should be readdressed when we revamp performance | 940 // state. This issue should be readdressed when we revamp performance |
| 956 // reporting. | 941 // reporting. |
| 957 return; | 942 return; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 979 // has completed and the intermediate file has been renamed to simplify | 964 // has completed and the intermediate file has been renamed to simplify |
| 980 // resumption conditions. | 965 // resumption conditions. |
| 981 if (current_path_.empty() || target_path_.empty()) | 966 if (current_path_.empty() || target_path_.empty()) |
| 982 destination_error_ = reason; | 967 destination_error_ = reason; |
| 983 else | 968 else |
| 984 Interrupt(reason); | 969 Interrupt(reason); |
| 985 } | 970 } |
| 986 | 971 |
| 987 void DownloadItemImpl::DestinationCompleted(const std::string& final_hash) { | 972 void DownloadItemImpl::DestinationCompleted(const std::string& final_hash) { |
| 988 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 973 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
| 989 if (!IsInProgress()) | 974 if (GetState() != IN_PROGRESS) |
| 990 return; | 975 return; |
| 991 OnAllDataSaved(final_hash); | 976 OnAllDataSaved(final_hash); |
| 992 MaybeCompleteDownload(); | 977 MaybeCompleteDownload(); |
| 993 } | 978 } |
| 994 | 979 |
| 995 // **** Download progression cascade | 980 // **** Download progression cascade |
| 996 | 981 |
| 997 void DownloadItemImpl::Init(bool active, | 982 void DownloadItemImpl::Init(bool active, |
| 998 DownloadType download_type) { | 983 DownloadType download_type) { |
| 999 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 984 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1034 scoped_ptr<DownloadFile> file, | 1019 scoped_ptr<DownloadFile> file, |
| 1035 scoped_ptr<DownloadRequestHandleInterface> req_handle) { | 1020 scoped_ptr<DownloadRequestHandleInterface> req_handle) { |
| 1036 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1021 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1037 DCHECK(!download_file_.get()); | 1022 DCHECK(!download_file_.get()); |
| 1038 DCHECK(file.get()); | 1023 DCHECK(file.get()); |
| 1039 DCHECK(req_handle.get()); | 1024 DCHECK(req_handle.get()); |
| 1040 | 1025 |
| 1041 download_file_ = file.Pass(); | 1026 download_file_ = file.Pass(); |
| 1042 request_handle_ = req_handle.Pass(); | 1027 request_handle_ = req_handle.Pass(); |
| 1043 | 1028 |
| 1044 if (IsCancelled()) { | 1029 if (GetState() == CANCELLED) { |
| 1045 // The download was in the process of resuming when it was cancelled. Don't | 1030 // The download was in the process of resuming when it was cancelled. Don't |
| 1046 // proceed. | 1031 // proceed. |
| 1047 ReleaseDownloadFile(true); | 1032 ReleaseDownloadFile(true); |
| 1048 request_handle_->CancelRequest(); | 1033 request_handle_->CancelRequest(); |
| 1049 return; | 1034 return; |
| 1050 } | 1035 } |
| 1051 | 1036 |
| 1052 TransitionTo(IN_PROGRESS_INTERNAL); | 1037 TransitionTo(IN_PROGRESS_INTERNAL); |
| 1053 | 1038 |
| 1054 last_reason_ = DOWNLOAD_INTERRUPT_REASON_NONE; | 1039 last_reason_ = DOWNLOAD_INTERRUPT_REASON_NONE; |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1691 case RESUME_MODE_USER_CONTINUE: | 1676 case RESUME_MODE_USER_CONTINUE: |
| 1692 return "USER_CONTINUE"; | 1677 return "USER_CONTINUE"; |
| 1693 case RESUME_MODE_USER_RESTART: | 1678 case RESUME_MODE_USER_RESTART: |
| 1694 return "USER_RESTART"; | 1679 return "USER_RESTART"; |
| 1695 } | 1680 } |
| 1696 NOTREACHED() << "Unknown resume mode " << mode; | 1681 NOTREACHED() << "Unknown resume mode " << mode; |
| 1697 return "unknown"; | 1682 return "unknown"; |
| 1698 } | 1683 } |
| 1699 | 1684 |
| 1700 } // namespace content | 1685 } // namespace content |
| OLD | NEW |