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

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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 full_path_(info.path), 165 full_path_(info.path),
166 url_chain_(info.url_chain), 166 url_chain_(info.url_chain),
167 referrer_url_(info.referrer_url), 167 referrer_url_(info.referrer_url),
168 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)), 168 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)),
169 content_disposition_(info.content_disposition), 169 content_disposition_(info.content_disposition),
170 mime_type_(info.mime_type), 170 mime_type_(info.mime_type),
171 original_mime_type_(info.original_mime_type), 171 original_mime_type_(info.original_mime_type),
172 referrer_charset_(info.referrer_charset), 172 referrer_charset_(info.referrer_charset),
173 total_bytes_(info.total_bytes), 173 total_bytes_(info.total_bytes),
174 received_bytes_(0), 174 received_bytes_(0),
175 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 175 last_modified_time_(info.last_modified),
176 etag_(info.etag),
177 last_reason_(info.server_interrupt_reason),
176 start_tick_(base::TimeTicks::Now()), 178 start_tick_(base::TimeTicks::Now()),
177 state_(IN_PROGRESS), 179 state_(IN_PROGRESS),
178 start_time_(info.start_time), 180 start_time_(info.start_time),
179 db_handle_(DownloadItem::kUninitializedHandle), 181 db_handle_(DownloadItem::kUninitializedHandle),
180 download_manager_(download_manager), 182 download_manager_(download_manager),
181 is_paused_(false), 183 is_paused_(false),
182 open_when_complete_(false), 184 open_when_complete_(false),
183 file_externally_removed_(false), 185 file_externally_removed_(false),
184 safety_state_(SAFE), 186 safety_state_(SAFE),
185 auto_opened_(false), 187 auto_opened_(false),
186 is_otr_(is_otr), 188 is_otr_(is_otr),
187 is_temporary_(!info.save_info.file_path.empty()), 189 is_temporary_(!info.save_info.file_path.empty() &&
190 !info.continued_download),
188 all_data_saved_(false), 191 all_data_saved_(false),
189 opened_(false), 192 opened_(false),
190 open_enabled_(true), 193 open_enabled_(true),
191 delegate_delayed_complete_(false) { 194 delegate_delayed_complete_(false) {
192 Init(true /* actively downloading */); 195 Init(true /* actively downloading */);
193 } 196 }
194 197
195 // Constructing for the "Save Page As..." feature: 198 // Constructing for the "Save Page As..." feature:
196 DownloadItem::DownloadItem(DownloadManager* download_manager, 199 DownloadItem::DownloadItem(DownloadManager* download_manager,
197 const FilePath& path, 200 const FilePath& path,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 330 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
328 331
329 received_bytes_ = bytes_so_far; 332 received_bytes_ = bytes_so_far;
330 333
331 // If we've received more data than we were expecting (bad server info?), 334 // If we've received more data than we were expecting (bad server info?),
332 // revert to 'unknown size mode'. 335 // revert to 'unknown size mode'.
333 if (received_bytes_ > total_bytes_) 336 if (received_bytes_ > total_bytes_)
334 total_bytes_ = 0; 337 total_bytes_ = 0;
335 } 338 }
336 339
340 void DownloadItem::UpdateHash(const std::string& partial_hash) {
341 if (!partial_hash.empty())
342 partial_hash_ = partial_hash;
343 }
344
337 void DownloadItem::StartProgressTimer() { 345 void DownloadItem::StartProgressTimer() {
338 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 346 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
339 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 347 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
340 348
341 update_timer_.Start(FROM_HERE, 349 update_timer_.Start(FROM_HERE,
342 base::TimeDelta::FromMilliseconds(kUpdateTimeMs), this, 350 base::TimeDelta::FromMilliseconds(kUpdateTimeMs), this,
343 &DownloadItem::UpdateObservers); 351 &DownloadItem::UpdateObservers);
344 } 352 }
345 353
346 void DownloadItem::StopProgressTimer() { 354 void DownloadItem::StopProgressTimer() {
347 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 355 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
348 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 356 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
349 357
350 update_timer_.Stop(); 358 update_timer_.Stop();
351 } 359 }
352 360
353 // Updates from the download thread may have been posted while this download 361 // Updates from the download thread may have been posted while this download
354 // was being cancelled in the UI thread, so we'll accept them unless we're 362 // was being cancelled in the UI thread, so we'll accept them unless we're
355 // complete. 363 // complete.
356 void DownloadItem::Update(int64 bytes_so_far) { 364 void DownloadItem::Update(int64 bytes_so_far, const std::string& partial_hash) {
357 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 365 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
358 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 366 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
359 367
360 if (!IsInProgress()) { 368 if (!IsInProgress()) {
361 NOTREACHED(); 369 NOTREACHED();
362 return; 370 return;
363 } 371 }
364 UpdateSize(bytes_so_far); 372 UpdateSize(bytes_so_far);
373 UpdateHash(partial_hash);
365 UpdateObservers(); 374 UpdateObservers();
366 } 375 }
367 376
368 // Triggered by a user action. 377 // Triggered by a user action.
369 void DownloadItem::Cancel(bool user_cancel) { 378 void DownloadItem::Cancel(bool user_cancel) {
370 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 379 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
371 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 380 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
372 381
373 last_reason_ = user_cancel ? 382 last_reason_ = user_cancel ?
374 DOWNLOAD_INTERRUPT_REASON_USER_CANCELED : 383 DOWNLOAD_INTERRUPT_REASON_USER_CANCELED :
(...skipping 21 matching lines...) Expand all
396 DCHECK(all_data_saved_); 405 DCHECK(all_data_saved_);
397 end_time_ = base::Time::Now(); 406 end_time_ = base::Time::Now();
398 TransitionTo(COMPLETE); 407 TransitionTo(COMPLETE);
399 } 408 }
400 409
401 void DownloadItem::CompleteDelayedDownload() { 410 void DownloadItem::CompleteDelayedDownload() {
402 auto_opened_ = true; 411 auto_opened_ = true;
403 Completed(); 412 Completed();
404 } 413 }
405 414
406 void DownloadItem::OnAllDataSaved(int64 size) { 415 void DownloadItem::OnAllDataSaved(int64 size, const std::string final_hash) {
407 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 416 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
408 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 417 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
409 418
410 DCHECK(!all_data_saved_); 419 DCHECK(!all_data_saved_);
411 all_data_saved_ = true; 420 all_data_saved_ = true;
412 UpdateSize(size); 421 UpdateSize(size);
422 UpdateHash(final_hash);
413 StopProgressTimer(); 423 StopProgressTimer();
414 } 424 }
415 425
416 void DownloadItem::OnDownloadedFileRemoved() { 426 void DownloadItem::OnDownloadedFileRemoved() {
417 file_externally_removed_ = true; 427 file_externally_removed_ = true;
418 UpdateObservers(); 428 UpdateObservers();
419 } 429 }
420 430
421 void DownloadItem::Completed() { 431 void DownloadItem::Completed() {
422 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 432 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 475 }
466 476
467 void DownloadItem::UpdateTarget() { 477 void DownloadItem::UpdateTarget() {
468 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 478 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
469 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 479 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
470 480
471 if (state_info_.target_name.value().empty()) 481 if (state_info_.target_name.value().empty())
472 state_info_.target_name = full_path_.BaseName(); 482 state_info_.target_name = full_path_.BaseName();
473 } 483 }
474 484
475 void DownloadItem::Interrupted(int64 size, InterruptReason reason) { 485 void DownloadItem::Interrupted(int64 size,
486 const std::string partial_hash,
487 InterruptReason reason) {
476 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 488 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
477 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 489 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
478 490
479 if (!IsInProgress()) 491 if (!IsInProgress())
480 return; 492 return;
481 493
482 last_reason_ = reason; 494 last_reason_ = reason;
483 UpdateSize(size); 495 UpdateSize(size);
496 UpdateHash(partial_hash);
484 StopProgressTimer(); 497 StopProgressTimer();
485 download_stats::RecordDownloadInterrupted(reason, 498 download_stats::RecordDownloadInterrupted(reason,
486 received_bytes_, 499 received_bytes_,
487 total_bytes_); 500 total_bytes_);
488 TransitionTo(INTERRUPTED); 501 TransitionTo(INTERRUPTED);
489 } 502 }
490 503
491 void DownloadItem::Delete(DeleteReason reason) { 504 void DownloadItem::Delete(DeleteReason reason) {
492 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 505 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
493 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 506 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 } 805 }
793 806
794 if (verbose) { 807 if (verbose) {
795 description += base::StringPrintf( 808 description += base::StringPrintf(
796 " db_handle = %" PRId64 809 " db_handle = %" PRId64
797 " total_bytes = %" PRId64 810 " total_bytes = %" PRId64
798 " received_bytes = %" PRId64 811 " received_bytes = %" PRId64
799 " is_paused = %c" 812 " is_paused = %c"
800 " is_otr = %c" 813 " is_otr = %c"
801 " safety_state = %s" 814 " safety_state = %s"
815 " last_modified = '%s'"
816 " etag = '%s'"
802 " url_chain = \n\t\"%s\"\n\t" 817 " url_chain = \n\t\"%s\"\n\t"
803 " target_name = \"%" PRFilePath "\"" 818 " target_name = \"%" PRFilePath "\""
804 " full_path = \"%" PRFilePath "\"", 819 " full_path = \"%" PRFilePath "\"",
805 db_handle(), 820 db_handle(),
806 total_bytes(), 821 total_bytes(),
807 received_bytes(), 822 received_bytes(),
808 is_paused() ? 'T' : 'F', 823 is_paused() ? 'T' : 'F',
809 is_otr() ? 'T' : 'F', 824 is_otr() ? 'T' : 'F',
810 DebugSafetyStateString(safety_state()), 825 DebugSafetyStateString(safety_state()),
826 last_modified_time_.c_str(),
827 etag_.c_str(),
811 url_list.c_str(), 828 url_list.c_str(),
812 state_info_.target_name.value().c_str(), 829 state_info_.target_name.value().c_str(),
813 full_path().value().c_str()); 830 full_path().value().c_str());
814 } else { 831 } else {
815 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 832 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
816 } 833 }
817 834
818 description += " }"; 835 description += " }";
819 836
820 return description; 837 return description;
821 } 838 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698