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

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: Merge with r204343 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(!IsDone());
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 (IsDone() || !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 (!IsDone()) {
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 496 bool DownloadItemImpl::IsDone() const {
497 // to consider interrupted (resumably) downloads partial downloads. 497 switch (state_) {
498 // Conceptually the answer is probably yes, but everywhere that currently 498 case IN_PROGRESS_INTERNAL:
499 // uses the routine is using it as a synonym for IsInProgress(). 499 case COMPLETING_INTERNAL:
500 bool DownloadItemImpl::IsPartialDownload() const { 500 return false;
501 DownloadState state = InternalToExternalState(state_); 501
502 return (state == IN_PROGRESS); 502 case COMPLETE_INTERNAL:
503 case CANCELLED_INTERNAL:
504 return true;
505
506 case INTERRUPTED_INTERNAL:
507 return !CanResume();
508
509 case RESUMING_INTERNAL:
510 return false;
511
512 case MAX_DOWNLOAD_INTERNAL_STATE:
513 break;
514 }
515 NOTREACHED();
516 return true;
503 } 517 }
504 518
505 bool DownloadItemImpl::IsInProgress() const { 519 bool DownloadItemImpl::IsInProgress() const {
506 return InternalToExternalState(state_) == IN_PROGRESS; 520 return InternalToExternalState(state_) == IN_PROGRESS;
507 } 521 }
508 522
509 bool DownloadItemImpl::IsCancelled() const { 523 bool DownloadItemImpl::IsCancelled() const {
510 return InternalToExternalState(state_) == CANCELLED; 524 return InternalToExternalState(state_) == CANCELLED;
511 } 525 }
512 526
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 bool DownloadItemImpl::CanShowInFolder() { 696 bool DownloadItemImpl::CanShowInFolder() {
683 // A download can be shown in the folder if the downloaded file is in a known 697 // A download can be shown in the folder if the downloaded file is in a known
684 // location. 698 // location.
685 return CanOpenDownload() && !GetFullPath().empty(); 699 return CanOpenDownload() && !GetFullPath().empty();
686 } 700 }
687 701
688 bool DownloadItemImpl::CanOpenDownload() { 702 bool DownloadItemImpl::CanOpenDownload() {
689 // We can open the file or mark it for opening on completion if the download 703 // 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 704 // is expected to complete successfully. Exclude temporary downloads, since
691 // they aren't owned by the download system. 705 // they aren't owned by the download system.
692 return (IsInProgress() || IsComplete()) && !IsTemporary() && 706 return (!IsDone() || IsComplete()) && !IsTemporary() &&
693 !file_externally_removed_; 707 !file_externally_removed_;
694 } 708 }
695 709
696 bool DownloadItemImpl::ShouldOpenFileBasedOnExtension() { 710 bool DownloadItemImpl::ShouldOpenFileBasedOnExtension() {
697 return delegate_->ShouldOpenFileBasedOnExtension(GetTargetFilePath()); 711 return delegate_->ShouldOpenFileBasedOnExtension(GetTargetFilePath());
698 } 712 }
699 713
700 bool DownloadItemImpl::GetOpenWhenComplete() const { 714 bool DownloadItemImpl::GetOpenWhenComplete() const {
701 return open_when_complete_; 715 return open_when_complete_;
702 } 716 }
703 717
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 case RESUME_MODE_USER_CONTINUE: 1691 case RESUME_MODE_USER_CONTINUE:
1678 return "USER_CONTINUE"; 1692 return "USER_CONTINUE";
1679 case RESUME_MODE_USER_RESTART: 1693 case RESUME_MODE_USER_RESTART:
1680 return "USER_RESTART"; 1694 return "USER_RESTART";
1681 } 1695 }
1682 NOTREACHED() << "Unknown resume mode " << mode; 1696 NOTREACHED() << "Unknown resume mode " << mode;
1683 return "unknown"; 1697 return "unknown";
1684 } 1698 }
1685 1699
1686 } // namespace content 1700 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698