Chromium Code Reviews| Index: content/browser/download/download_item_impl.cc |
| diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc |
| index 0a76e98db11d58d0c47ac5b96ad8f7b8342da56c..e49c31b1260b85c6d4984db9d94db1d30bd72bf7 100644 |
| --- a/content/browser/download/download_item_impl.cc |
| +++ b/content/browser/download/download_item_impl.cc |
| @@ -126,12 +126,13 @@ class NullDownloadRequestHandle : public DownloadRequestHandleInterface { |
| // Constructor for reading from the history service. |
| DownloadItemImpl::DownloadItemImpl(DownloadManager* download_manager, |
| const DownloadPersistentStoreInfo& info) |
| - : download_id_(download_manager->GetNextId()), |
| + : download_id_(download_manager->GetNextId()), |
| full_path_(info.path), |
| url_chain_(1, info.url), |
| referrer_url_(info.referrer_url), |
| total_bytes_(info.total_bytes), |
| received_bytes_(info.received_bytes), |
| + last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
| start_tick_(base::TimeTicks()), |
| state_(static_cast<DownloadState>(info.state)), |
| start_time_(info.start_time), |
| @@ -324,10 +325,14 @@ void DownloadItemImpl::DangerousDownloadValidated() { |
| download_manager_->MaybeCompleteDownload(this); |
| } |
| -void DownloadItemImpl::UpdateSize(int64 bytes_so_far) { |
| +void DownloadItemImpl::ProgressComplete(int64 bytes_so_far, |
| + const std::string& final_hash) { |
| // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + hash_ = final_hash; |
| + hash_state_ = ""; |
| + |
| received_bytes_ = bytes_so_far; |
| // If we've received more data than we were expecting (bad server info?), |
| @@ -336,10 +341,23 @@ void DownloadItemImpl::UpdateSize(int64 bytes_so_far) { |
| total_bytes_ = 0; |
| } |
| +void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, |
| + const std::string& hash_state) { |
| + hash_state_ = hash_state; |
| + |
| + received_bytes_ = bytes_so_far; |
| + |
| + // If we've received more data than we were expecting (bad server info?), |
| + // revert to 'unknown size mode'. |
| + if (received_bytes_ > total_bytes_) |
| + total_bytes_ = 0; |
| +} |
| + |
| // Updates from the download thread may have been posted while this download |
| // was being cancelled in the UI thread, so we'll accept them unless we're |
| // complete. |
| -void DownloadItemImpl::Update(int64 bytes_so_far) { |
| +void DownloadItemImpl::Update(int64 bytes_so_far, |
| + const std::string& hash_state) { |
| // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -347,7 +365,7 @@ void DownloadItemImpl::Update(int64 bytes_so_far) { |
| NOTREACHED(); |
| return; |
| } |
| - UpdateSize(bytes_so_far); |
| + UpdateProgress(bytes_so_far, hash_state); |
| UpdateObservers(); |
| } |
| @@ -395,8 +413,7 @@ void DownloadItemImpl::OnAllDataSaved( |
| DCHECK(!all_data_saved_); |
| all_data_saved_ = true; |
| - UpdateSize(size); |
| - hash_ = final_hash; |
| + ProgressComplete(size, final_hash); |
| } |
| void DownloadItemImpl::OnDownloadedFileRemoved() { |
| @@ -457,7 +474,9 @@ void DownloadItemImpl::UpdateTarget() { |
| state_info_.target_name = full_path_.BaseName(); |
| } |
| -void DownloadItemImpl::Interrupted(int64 size, InterruptReason reason) { |
| +void DownloadItemImpl::Interrupted(int64 size, |
| + const std::string& hash_state, |
| + InterruptReason reason) { |
| // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -465,7 +484,7 @@ void DownloadItemImpl::Interrupted(int64 size, InterruptReason reason) { |
| return; |
| last_reason_ = reason; |
| - UpdateSize(size); |
| + UpdateProgress(size, hash_state); |
| download_stats::RecordDownloadInterrupted(reason, |
| received_bytes_, |
| total_bytes_); |
| @@ -690,7 +709,7 @@ DownloadPersistentStoreInfo DownloadItemImpl::GetPersistentStoreInfo() const { |
| GetTotalBytes(), |
| GetState(), |
| GetDbHandle(), |
| - GetOpened()); |
| + GetOpened()); |
| } |
| TabContents* DownloadItemImpl::GetTabContents() const { |
| @@ -735,9 +754,8 @@ void DownloadItemImpl::Init(bool active) { |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| UpdateTarget(); |
| - if (active) { |
| + if (active) |
| download_stats::RecordDownloadCount(download_stats::START_COUNT); |
| - } |
| VLOG(20) << __FUNCTION__ << "() " << DebugString(true); |
| } |
| @@ -798,6 +816,8 @@ std::string DownloadItemImpl::DebugString(bool verbose) const { |
| " is_paused = %c" |
| " is_otr = %c" |
| " safety_state = %s" |
| + " last_modified = '%s'" |
| + " etag = '%s'" |
| " url_chain = \n\t\"%s\"\n\t" |
| " target_name = \"%" PRFilePath "\"" |
| " full_path = \"%" PRFilePath "\"", |
| @@ -807,6 +827,8 @@ std::string DownloadItemImpl::DebugString(bool verbose) const { |
| IsPaused() ? 'T' : 'F', |
| IsOtr() ? 'T' : 'F', |
| DebugSafetyStateString(GetSafetyState()), |
| + GetLastModifiedTime().c_str(), |
| + GetETag().c_str(), |
| url_list.c_str(), |
| state_info_.target_name.value().c_str(), |
| GetFullPath().value().c_str()); |
| @@ -853,6 +875,9 @@ void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { |
| } |
| const std::string& DownloadItemImpl::GetHash() const { return hash_; } |
| int64 DownloadItemImpl::GetReceivedBytes() const { return received_bytes_; } |
| +const std::string& DownloadItemImpl::GetHashState() const { |
|
Randy Smith (Not in Mondays)
2011/11/23 19:40:24
Just noticed that we use HashState here and Sha256
ahendrickson
2011/12/20 00:04:14
Changed to using just "Hash" instead of "Sha256Has
|
| + return hash_state_; |
| +} |
| int32 DownloadItemImpl::GetId() const { return download_id_.local(); } |
| DownloadId DownloadItemImpl::GetGlobalId() const { return download_id_; } |
| base::Time DownloadItemImpl::GetStartTime() const { return start_time_; } |
| @@ -889,6 +914,10 @@ const FilePath& DownloadItemImpl::GetSuggestedPath() const { |
| bool DownloadItemImpl::IsTemporary() const { return is_temporary_; } |
| void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; } |
| bool DownloadItemImpl::GetOpened() const { return opened_; } |
| +const std::string& DownloadItemImpl::GetLastModifiedTime() const { |
| + return last_modified_time_; |
| +} |
| +const std::string& DownloadItemImpl::GetETag() const { return etag_; } |
| InterruptReason DownloadItemImpl::GetLastReason() const { |
| return last_reason_; |
| } |