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

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

Issue 16007017: [Resumption 10/12] Use DI::IsDone to check for terminal downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months 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) 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 273 }
274 274
275 void DownloadItemImpl::UpdateObservers() { 275 void DownloadItemImpl::UpdateObservers() {
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
277 277
278 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this)); 278 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this));
279 } 279 }
280 280
281 void DownloadItemImpl::ValidateDangerousDownload() { 281 void DownloadItemImpl::ValidateDangerousDownload() {
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
283 DCHECK_EQ(IN_PROGRESS, GetState()); 283 DCHECK(IsPartialDownload());
284 DCHECK(IsDangerous()); 284 DCHECK(IsDangerous());
285 285
286 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); 286 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
287 287
288 if (GetState() != IN_PROGRESS) 288 if (!IsPartialDownload() || !IsDangerous())
289 return; 289 return;
290 290
291 RecordDangerousDownloadAccept(GetDangerType()); 291 RecordDangerousDownloadAccept(GetDangerType());
292 292
293 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED; 293 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED;
294 294
295 bound_net_log_.AddEvent( 295 bound_net_log_.AddEvent(
296 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, 296 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED,
297 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); 297 base::Bind(&ItemCheckedNetLogCallback, GetDangerType()));
298 298
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 delegate_->AssertStateConsistent(this); 416 delegate_->AssertStateConsistent(this);
417 417
418 NotifyRemoved(); 418 NotifyRemoved();
419 delegate_->DownloadRemoved(this); 419 delegate_->DownloadRemoved(this);
420 // We have now been deleted. 420 // We have now been deleted.
421 } 421 }
422 422
423 void DownloadItemImpl::OpenDownload() { 423 void DownloadItemImpl::OpenDownload() {
424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
425 425
426 if (state_ == IN_PROGRESS_INTERNAL) { 426 if (IsPartialDownload()) {
427 // We don't honor the open_when_complete_ flag for temporary 427 // We don't honor the open_when_complete_ flag for temporary
428 // downloads. Don't set it because it shows up in the UI. 428 // downloads. Don't set it because it shows up in the UI.
429 if (!IsTemporary()) 429 if (!IsTemporary())
430 open_when_complete_ = !open_when_complete_; 430 open_when_complete_ = !open_when_complete_;
431 return; 431 return;
432 } 432 }
433 433
434 if (state_ != COMPLETE_INTERNAL || file_externally_removed_) 434 if (state_ != COMPLETE_INTERNAL || file_externally_removed_)
435 return; 435 return;
436 436
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
490 ResumeMode resume_mode = GetResumeMode(); 490 ResumeMode resume_mode = GetResumeMode();
491 return IsDownloadResumptionEnabled() && 491 return IsDownloadResumptionEnabled() &&
492 (resume_mode == RESUME_MODE_USER_RESTART || 492 (resume_mode == RESUME_MODE_USER_RESTART ||
493 resume_mode == RESUME_MODE_USER_CONTINUE); 493 resume_mode == RESUME_MODE_USER_CONTINUE);
494 } 494 }
495 495
496 // TODO(rdsmith): Figure out whether or not we want this probe routine
497 // to consider interrupted (resumably) downloads partial downloads.
498 // Conceptually the answer is probably yes, but everywhere that currently
499 // uses the routine is using it as a synonym for IsInProgress().
500 bool DownloadItemImpl::IsPartialDownload() const { 496 bool DownloadItemImpl::IsPartialDownload() const {
501 DownloadState state = InternalToExternalState(state_); 497 return InternalToExternalState(state_) == IN_PROGRESS || CanResume() ||
502 return (state == IN_PROGRESS); 498 state_ == RESUMING_INTERNAL;
503 } 499 }
504 500
505 bool DownloadItemImpl::IsInProgress() const { 501 bool DownloadItemImpl::IsInProgress() const {
506 return InternalToExternalState(state_) == IN_PROGRESS; 502 return InternalToExternalState(state_) == IN_PROGRESS;
507 } 503 }
508 504
509 bool DownloadItemImpl::IsCancelled() const { 505 bool DownloadItemImpl::IsCancelled() const {
510 return InternalToExternalState(state_) == CANCELLED; 506 return InternalToExternalState(state_) == CANCELLED;
511 } 507 }
512 508
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 bool DownloadItemImpl::CanShowInFolder() { 678 bool DownloadItemImpl::CanShowInFolder() {
683 // A download can be shown in the folder if the downloaded file is in a known 679 // A download can be shown in the folder if the downloaded file is in a known
684 // location. 680 // location.
685 return CanOpenDownload() && !GetFullPath().empty(); 681 return CanOpenDownload() && !GetFullPath().empty();
686 } 682 }
687 683
688 bool DownloadItemImpl::CanOpenDownload() { 684 bool DownloadItemImpl::CanOpenDownload() {
689 // We can open the file or mark it for opening on completion if the download 685 // We can open the file or mark it for opening on completion if the download
690 // is expected to complete successfully. Exclude temporary downloads, since 686 // is expected to complete successfully. Exclude temporary downloads, since
691 // they aren't owned by the download system. 687 // they aren't owned by the download system.
692 return (IsInProgress() || IsComplete()) && !IsTemporary() && 688 return (IsPartialDownload() || IsComplete()) && !IsTemporary() &&
693 !file_externally_removed_; 689 !file_externally_removed_;
694 } 690 }
695 691
696 bool DownloadItemImpl::ShouldOpenFileBasedOnExtension() { 692 bool DownloadItemImpl::ShouldOpenFileBasedOnExtension() {
697 return delegate_->ShouldOpenFileBasedOnExtension(GetTargetFilePath()); 693 return delegate_->ShouldOpenFileBasedOnExtension(GetTargetFilePath());
698 } 694 }
699 695
700 bool DownloadItemImpl::GetOpenWhenComplete() const { 696 bool DownloadItemImpl::GetOpenWhenComplete() const {
701 return open_when_complete_; 697 return open_when_complete_;
702 } 698 }
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 case RESUME_MODE_USER_CONTINUE: 1673 case RESUME_MODE_USER_CONTINUE:
1678 return "USER_CONTINUE"; 1674 return "USER_CONTINUE";
1679 case RESUME_MODE_USER_RESTART: 1675 case RESUME_MODE_USER_RESTART:
1680 return "USER_RESTART"; 1676 return "USER_RESTART";
1681 } 1677 }
1682 NOTREACHED() << "Unknown resume mode " << mode; 1678 NOTREACHED() << "Unknown resume mode " << mode;
1683 return "unknown"; 1679 return "unknown";
1684 } 1680 }
1685 1681
1686 } // namespace content 1682 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698