Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: content/browser/download/download_item.cc

Issue 8404049: Added member data to classes to support download resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with trunk Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "content/browser/download/download_item.h" 5 #include "content/browser/download/download_item.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 // Constructor for reading from the history service. 131 // Constructor for reading from the history service.
132 DownloadItem::DownloadItem(DownloadManager* download_manager, 132 DownloadItem::DownloadItem(DownloadManager* download_manager,
133 const DownloadPersistentStoreInfo& info) 133 const DownloadPersistentStoreInfo& info)
134 : download_id_(download_manager->GetNextId()), 134 : download_id_(download_manager->GetNextId()),
135 full_path_(info.path), 135 full_path_(info.path),
136 url_chain_(1, info.url), 136 url_chain_(1, info.url),
137 referrer_url_(info.referrer_url), 137 referrer_url_(info.referrer_url),
138 total_bytes_(info.total_bytes), 138 total_bytes_(info.total_bytes),
139 received_bytes_(info.received_bytes), 139 received_bytes_(info.received_bytes),
140 hash_state_(info.hash_state),
141 last_modified_time_(info.last_modified_time),
142 etag_(info.etag),
143 last_reason_(info.last_reason),
140 start_tick_(base::TimeTicks()), 144 start_tick_(base::TimeTicks()),
141 state_(static_cast<DownloadState>(info.state)), 145 state_(static_cast<DownloadState>(info.state)),
142 start_time_(info.start_time), 146 start_time_(info.start_time),
143 end_time_(info.end_time), 147 end_time_(info.end_time),
144 db_handle_(info.db_handle), 148 db_handle_(info.db_handle),
145 download_manager_(download_manager), 149 download_manager_(download_manager),
146 is_paused_(false), 150 is_paused_(false),
147 open_when_complete_(false), 151 open_when_complete_(false),
148 file_externally_removed_(false), 152 file_externally_removed_(false),
149 safety_state_(SAFE), 153 safety_state_(SAFE),
(...skipping 25 matching lines...) Expand all
175 full_path_(info.path), 179 full_path_(info.path),
176 url_chain_(info.url_chain), 180 url_chain_(info.url_chain),
177 referrer_url_(info.referrer_url), 181 referrer_url_(info.referrer_url),
178 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)), 182 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)),
179 content_disposition_(info.content_disposition), 183 content_disposition_(info.content_disposition),
180 mime_type_(info.mime_type), 184 mime_type_(info.mime_type),
181 original_mime_type_(info.original_mime_type), 185 original_mime_type_(info.original_mime_type),
182 referrer_charset_(info.referrer_charset), 186 referrer_charset_(info.referrer_charset),
183 total_bytes_(info.total_bytes), 187 total_bytes_(info.total_bytes),
184 received_bytes_(0), 188 received_bytes_(0),
189 hash_(DownloadItem::kEmptyFileHash),
190 last_modified_time_(info.last_modified),
191 etag_(info.etag),
185 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 192 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE),
186 start_tick_(base::TimeTicks::Now()), 193 start_tick_(base::TimeTicks::Now()),
187 state_(IN_PROGRESS), 194 state_(IN_PROGRESS),
188 start_time_(info.start_time), 195 start_time_(info.start_time),
189 db_handle_(DownloadItem::kUninitializedHandle), 196 db_handle_(DownloadItem::kUninitializedHandle),
190 download_manager_(download_manager), 197 download_manager_(download_manager),
191 is_paused_(false), 198 is_paused_(false),
192 open_when_complete_(false), 199 open_when_complete_(false),
193 file_externally_removed_(false), 200 file_externally_removed_(false),
194 safety_state_(SAFE), 201 safety_state_(SAFE),
(...skipping 13 matching lines...) Expand all
208 const GURL& url, 215 const GURL& url,
209 bool is_otr, 216 bool is_otr,
210 DownloadId download_id) 217 DownloadId download_id)
211 : request_handle_(new NullDownloadRequestHandle()), 218 : request_handle_(new NullDownloadRequestHandle()),
212 download_id_(download_id), 219 download_id_(download_id),
213 full_path_(path), 220 full_path_(path),
214 url_chain_(1, url), 221 url_chain_(1, url),
215 referrer_url_(GURL()), 222 referrer_url_(GURL()),
216 total_bytes_(0), 223 total_bytes_(0),
217 received_bytes_(0), 224 received_bytes_(0),
225 hash_(DownloadItem::kEmptyFileHash),
218 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 226 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE),
219 start_tick_(base::TimeTicks::Now()), 227 start_tick_(base::TimeTicks::Now()),
220 state_(IN_PROGRESS), 228 state_(IN_PROGRESS),
221 start_time_(base::Time::Now()), 229 start_time_(base::Time::Now()),
222 db_handle_(DownloadItem::kUninitializedHandle), 230 db_handle_(DownloadItem::kUninitializedHandle),
223 download_manager_(download_manager), 231 download_manager_(download_manager),
224 is_paused_(false), 232 is_paused_(false),
225 open_when_complete_(false), 233 open_when_complete_(false),
226 file_externally_removed_(false), 234 file_externally_removed_(false),
227 safety_state_(SAFE), 235 safety_state_(SAFE),
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 341 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
334 342
335 received_bytes_ = bytes_so_far; 343 received_bytes_ = bytes_so_far;
336 344
337 // If we've received more data than we were expecting (bad server info?), 345 // If we've received more data than we were expecting (bad server info?),
338 // revert to 'unknown size mode'. 346 // revert to 'unknown size mode'.
339 if (received_bytes_ > total_bytes_) 347 if (received_bytes_ > total_bytes_)
340 total_bytes_ = 0; 348 total_bytes_ = 0;
341 } 349 }
342 350
351 void DownloadItem::UpdateSizeAndHashState(int64 bytes_so_far,
352 const Pickle& hash_state) {
353 hash_state_ = hash_state;
354
355 UpdateSize(bytes_so_far);
356 }
357
343 // Updates from the download thread may have been posted while this download 358 // Updates from the download thread may have been posted while this download
344 // was being cancelled in the UI thread, so we'll accept them unless we're 359 // was being cancelled in the UI thread, so we'll accept them unless we're
345 // complete. 360 // complete.
346 void DownloadItem::Update(int64 bytes_so_far) { 361 void DownloadItem::Update(int64 bytes_so_far, const Pickle& hash_state) {
347 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 362 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
348 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 363 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
349 364
350 if (!IsInProgress()) { 365 if (!IsInProgress()) {
351 NOTREACHED(); 366 NOTREACHED();
352 return; 367 return;
353 } 368 }
354 UpdateSize(bytes_so_far); 369 UpdateSizeAndHashState(bytes_so_far, hash_state);
355 UpdateObservers(); 370 UpdateObservers();
356 } 371 }
357 372
358 // Triggered by a user action. 373 // Triggered by a user action.
359 void DownloadItem::Cancel(bool user_cancel) { 374 void DownloadItem::Cancel(bool user_cancel) {
360 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 375 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
361 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 376 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
362 377
363 last_reason_ = user_cancel ? 378 last_reason_ = user_cancel ?
364 DOWNLOAD_INTERRUPT_REASON_USER_CANCELED : 379 DOWNLOAD_INTERRUPT_REASON_USER_CANCELED :
(...skipping 26 matching lines...) Expand all
391 auto_opened_ = true; 406 auto_opened_ = true;
392 Completed(); 407 Completed();
393 } 408 }
394 409
395 void DownloadItem::OnAllDataSaved(int64 size, const std::string& final_hash) { 410 void DownloadItem::OnAllDataSaved(int64 size, const std::string& final_hash) {
396 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 411 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
397 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 412 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
398 413
399 DCHECK(!all_data_saved_); 414 DCHECK(!all_data_saved_);
400 all_data_saved_ = true; 415 all_data_saved_ = true;
416 hash_ = final_hash;
401 UpdateSize(size); 417 UpdateSize(size);
402 hash_ = final_hash;
403 } 418 }
404 419
405 void DownloadItem::OnDownloadedFileRemoved() { 420 void DownloadItem::OnDownloadedFileRemoved() {
406 file_externally_removed_ = true; 421 file_externally_removed_ = true;
407 UpdateObservers(); 422 UpdateObservers();
408 } 423 }
409 424
410 void DownloadItem::Completed() { 425 void DownloadItem::Completed() {
411 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 426 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
412 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 427 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 } 468 }
454 469
455 void DownloadItem::UpdateTarget() { 470 void DownloadItem::UpdateTarget() {
456 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 471 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
457 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 472 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
458 473
459 if (state_info_.target_name.value().empty()) 474 if (state_info_.target_name.value().empty())
460 state_info_.target_name = full_path_.BaseName(); 475 state_info_.target_name = full_path_.BaseName();
461 } 476 }
462 477
463 void DownloadItem::Interrupted(int64 size, InterruptReason reason) { 478 void DownloadItem::Interrupted(int64 size,
479 const Pickle& hash_state,
480 InterruptReason reason) {
464 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 481 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
465 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 482 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
466 483
467 if (!IsInProgress()) 484 if (!IsInProgress())
468 return; 485 return;
469 486
470 last_reason_ = reason; 487 last_reason_ = reason;
471 UpdateSize(size); 488 UpdateSizeAndHashState(size, hash_state);
472 download_stats::RecordDownloadInterrupted(reason, 489 download_stats::RecordDownloadInterrupted(reason,
473 received_bytes_, 490 received_bytes_,
474 total_bytes_); 491 total_bytes_);
475 TransitionTo(INTERRUPTED); 492 TransitionTo(INTERRUPTED);
476 } 493 }
477 494
478 void DownloadItem::Delete(DeleteReason reason) { 495 void DownloadItem::Delete(DeleteReason reason) {
479 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 496 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
480 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 497 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
481 498
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 DownloadPersistentStoreInfo DownloadItem::GetPersistentStoreInfo() const { 703 DownloadPersistentStoreInfo DownloadItem::GetPersistentStoreInfo() const {
687 return DownloadPersistentStoreInfo(full_path(), 704 return DownloadPersistentStoreInfo(full_path(),
688 GetURL(), 705 GetURL(),
689 referrer_url(), 706 referrer_url(),
690 start_time(), 707 start_time(),
691 end_time(), 708 end_time(),
692 received_bytes(), 709 received_bytes(),
693 total_bytes(), 710 total_bytes(),
694 state(), 711 state(),
695 db_handle(), 712 db_handle(),
696 opened()); 713 opened(),
714 hash_state_,
715 last_modified_time_,
716 etag_,
717 last_reason_);
697 } 718 }
698 719
699 TabContents* DownloadItem::GetTabContents() const { 720 TabContents* DownloadItem::GetTabContents() const {
700 // TODO(rdsmith): Remove null check after removing GetTabContents() from 721 // TODO(rdsmith): Remove null check after removing GetTabContents() from
701 // paths that might be used by DownloadItems created from history import. 722 // paths that might be used by DownloadItems created from history import.
702 // Currently such items have null request_handle_s, where other items 723 // Currently such items have null request_handle_s, where other items
703 // (regular and SavePackage downloads) have actual objects off the pointer. 724 // (regular and SavePackage downloads) have actual objects off the pointer.
704 if (request_handle_.get()) 725 if (request_handle_.get())
705 return request_handle_->GetTabContents(); 726 return request_handle_->GetTabContents();
706 return NULL; 727 return NULL;
(...skipping 24 matching lines...) Expand all
731 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 752 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
732 base::Bind(&DownloadFileManager::CancelDownload, 753 base::Bind(&DownloadFileManager::CancelDownload,
733 file_manager, global_id())); 754 file_manager, global_id()));
734 } 755 }
735 756
736 void DownloadItem::Init(bool active) { 757 void DownloadItem::Init(bool active) {
737 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 758 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
738 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 759 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
739 760
740 UpdateTarget(); 761 UpdateTarget();
741 if (active) { 762 if (active)
742 download_stats::RecordDownloadCount(download_stats::START_COUNT); 763 download_stats::RecordDownloadCount(download_stats::START_COUNT);
743 }
744 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); 764 VLOG(20) << __FUNCTION__ << "() " << DebugString(true);
745 } 765 }
746 766
747 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to 767 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to
748 // |IsPartialDownload()|, when resuming interrupted downloads is implemented. 768 // |IsPartialDownload()|, when resuming interrupted downloads is implemented.
749 bool DownloadItem::IsPartialDownload() const { 769 bool DownloadItem::IsPartialDownload() const {
750 return (state_ == IN_PROGRESS); 770 return (state_ == IN_PROGRESS);
751 } 771 }
752 772
753 bool DownloadItem::IsInProgress() const { 773 bool DownloadItem::IsInProgress() const {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 } 814 }
795 815
796 if (verbose) { 816 if (verbose) {
797 description += base::StringPrintf( 817 description += base::StringPrintf(
798 " db_handle = %" PRId64 818 " db_handle = %" PRId64
799 " total_bytes = %" PRId64 819 " total_bytes = %" PRId64
800 " received_bytes = %" PRId64 820 " received_bytes = %" PRId64
801 " is_paused = %c" 821 " is_paused = %c"
802 " is_otr = %c" 822 " is_otr = %c"
803 " safety_state = %s" 823 " safety_state = %s"
824 " last_modified = '%s'"
825 " etag = '%s'"
804 " url_chain = \n\t\"%s\"\n\t" 826 " url_chain = \n\t\"%s\"\n\t"
805 " target_name = \"%" PRFilePath "\"" 827 " target_name = \"%" PRFilePath "\""
806 " full_path = \"%" PRFilePath "\"", 828 " full_path = \"%" PRFilePath "\"",
807 db_handle(), 829 db_handle(),
808 total_bytes(), 830 total_bytes(),
809 received_bytes(), 831 received_bytes(),
810 is_paused() ? 'T' : 'F', 832 is_paused() ? 'T' : 'F',
811 is_otr() ? 'T' : 'F', 833 is_otr() ? 'T' : 'F',
812 DebugSafetyStateString(safety_state()), 834 DebugSafetyStateString(safety_state()),
835 last_modified_time_.c_str(),
836 etag_.c_str(),
813 url_list.c_str(), 837 url_list.c_str(),
814 state_info_.target_name.value().c_str(), 838 state_info_.target_name.value().c_str(),
815 full_path().value().c_str()); 839 full_path().value().c_str());
816 } else { 840 } else {
817 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 841 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
818 } 842 }
819 843
820 description += " }"; 844 description += " }";
821 845
822 return description; 846 return description;
823 } 847 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698