Chromium Code Reviews| Index: content/browser/download/download_item.cc |
| diff --git a/content/browser/download/download_item.cc b/content/browser/download/download_item.cc |
| index e3eff9943cf34b37c35f0b76a1f26125076bdb2f..ed942e5ec99375ec786bed83722f0b3221ad15d9 100644 |
| --- a/content/browser/download/download_item.cc |
| +++ b/content/browser/download/download_item.cc |
| @@ -130,6 +130,10 @@ DownloadItem::DownloadItem(DownloadManager* download_manager, |
| referrer_url_(info.referrer_url), |
| total_bytes_(info.total_bytes), |
| received_bytes_(info.received_bytes), |
| + hash_(info.hash), |
| + last_modified_time_(info.last_modified_time), |
| + etag_(info.etag), |
| + last_reason_(info.last_reason), |
| start_tick_(base::TimeTicks()), |
| state_(static_cast<DownloadState>(info.state)), |
| start_time_(info.start_time), |
| @@ -175,6 +179,9 @@ DownloadItem::DownloadItem(DownloadManager* download_manager, |
| referrer_charset_(info.referrer_charset), |
| total_bytes_(info.total_bytes), |
| received_bytes_(0), |
| + hash_(DownloadItem::kEmptyFileHash), |
| + last_modified_time_(info.last_modified), |
| + etag_(info.etag), |
| last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
| start_tick_(base::TimeTicks::Now()), |
| state_(IN_PROGRESS), |
| @@ -187,7 +194,8 @@ DownloadItem::DownloadItem(DownloadManager* download_manager, |
| safety_state_(SAFE), |
| auto_opened_(false), |
| is_otr_(is_otr), |
| - is_temporary_(!info.save_info.file_path.empty()), |
| + is_temporary_(!info.save_info.file_path.empty() && |
| + (info.received_bytes == 0)), |
|
Randy Smith (Not in Mondays)
2011/11/16 21:40:25
What's the use case for adding this test? I would
ahendrickson
2011/11/19 20:18:04
Reverted. This is not a path that resuming downlo
|
| all_data_saved_(false), |
| opened_(false), |
| open_enabled_(true), |
| @@ -207,6 +215,7 @@ DownloadItem::DownloadItem(DownloadManager* download_manager, |
| referrer_url_(GURL()), |
| total_bytes_(0), |
| received_bytes_(0), |
| + hash_(DownloadItem::kEmptyFileHash), |
| last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
| start_tick_(base::TimeTicks::Now()), |
| state_(IN_PROGRESS), |
| @@ -320,10 +329,14 @@ void DownloadItem::DangerousDownloadValidated() { |
| download_manager_->MaybeCompleteDownload(this); |
| } |
| -void DownloadItem::UpdateSize(int64 bytes_so_far) { |
| +void DownloadItem::UpdateSizeAndHash(int64 bytes_so_far, |
| + const std::string& partial_hash) { |
| // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + if (!partial_hash.empty() && !BaseFile::IsEmptySha256Hash(partial_hash)) |
| + hash_ = partial_hash; |
|
Randy Smith (Not in Mondays)
2011/11/16 21:40:25
Why not unilaterally assign?
ahendrickson
2011/11/19 20:18:04
Done.
|
| + |
| received_bytes_ = bytes_so_far; |
| // If we've received more data than we were expecting (bad server info?), |
| @@ -335,7 +348,7 @@ void DownloadItem::UpdateSize(int64 bytes_so_far) { |
| // 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 DownloadItem::Update(int64 bytes_so_far) { |
| +void DownloadItem::Update(int64 bytes_so_far, const std::string& partial_hash) { |
| // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -343,7 +356,7 @@ void DownloadItem::Update(int64 bytes_so_far) { |
| NOTREACHED(); |
| return; |
| } |
| - UpdateSize(bytes_so_far); |
| + UpdateSizeAndHash(bytes_so_far, partial_hash); |
| UpdateObservers(); |
| } |
| @@ -390,8 +403,7 @@ void DownloadItem::OnAllDataSaved(int64 size, const std::string& final_hash) { |
| DCHECK(!all_data_saved_); |
| all_data_saved_ = true; |
| - UpdateSize(size); |
| - hash_ = final_hash; |
| + UpdateSizeAndHash(size, final_hash); |
| } |
| void DownloadItem::OnDownloadedFileRemoved() { |
| @@ -453,7 +465,9 @@ void DownloadItem::UpdateTarget() { |
| state_info_.target_name = full_path_.BaseName(); |
| } |
| -void DownloadItem::Interrupted(int64 size, InterruptReason reason) { |
| +void DownloadItem::Interrupted(int64 size, |
| + const std::string partial_hash, |
| + InterruptReason reason) { |
| // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -461,7 +475,7 @@ void DownloadItem::Interrupted(int64 size, InterruptReason reason) { |
| return; |
| last_reason_ = reason; |
| - UpdateSize(size); |
| + UpdateSizeAndHash(size, partial_hash); |
| download_stats::RecordDownloadInterrupted(reason, |
| received_bytes_, |
| total_bytes_); |
| @@ -680,7 +694,11 @@ DownloadPersistentStoreInfo DownloadItem::GetPersistentStoreInfo() const { |
| total_bytes(), |
| state(), |
| db_handle(), |
| - opened()); |
| + opened(), |
| + hash_, |
| + last_modified_time_, |
| + etag_, |
| + last_reason_); |
| } |
| TabContents* DownloadItem::GetTabContents() const { |
| @@ -721,9 +739,8 @@ void DownloadItem::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); |
| } |
| @@ -784,6 +801,8 @@ std::string DownloadItem::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 "\"", |
| @@ -793,6 +812,8 @@ std::string DownloadItem::DebugString(bool verbose) const { |
| is_paused() ? 'T' : 'F', |
| is_otr() ? 'T' : 'F', |
| DebugSafetyStateString(safety_state()), |
| + last_modified_time_.c_str(), |
| + etag_.c_str(), |
| url_list.c_str(), |
| state_info_.target_name.value().c_str(), |
| full_path().value().c_str()); |