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

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

Issue 14957002: [Resumption 7/11] Add a CanResume() method to DownloadItem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with r200532 Created 7 years, 7 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
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/public/browser/download_item.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 static void DownloadFileDetach(scoped_ptr<DownloadFile> download_file) { 71 static void DownloadFileDetach(scoped_ptr<DownloadFile> download_file) {
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
73 download_file->Detach(); 73 download_file->Detach();
74 } 74 }
75 75
76 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { 76 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
78 download_file->Cancel(); 78 download_file->Cancel();
79 } 79 }
80 80
81 bool IsDownloadResumptionEnabled() {
82 return CommandLine::ForCurrentProcess()->HasSwitch(
83 switches::kEnableDownloadResumption);
84 }
85
81 } // namespace 86 } // namespace
82 87
83 const char DownloadItem::kEmptyFileHash[] = ""; 88 const char DownloadItem::kEmptyFileHash[] = "";
84 89
85 // The maximum number of attempts we will make to resume automatically. 90 // The maximum number of attempts we will make to resume automatically.
86 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5; 91 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5;
87 92
88 // Constructor for reading from the history service. 93 // Constructor for reading from the history service.
89 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, 94 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
90 DownloadId download_id, 95 DownloadId download_id,
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 472 }
468 473
469 bool DownloadItemImpl::IsPaused() const { 474 bool DownloadItemImpl::IsPaused() const {
470 return is_paused_; 475 return is_paused_;
471 } 476 }
472 477
473 bool DownloadItemImpl::IsTemporary() const { 478 bool DownloadItemImpl::IsTemporary() const {
474 return is_temporary_; 479 return is_temporary_;
475 } 480 }
476 481
482 bool DownloadItemImpl::CanResume() const {
483 if (IsInProgress() && IsPaused())
484 return true;
485
486 if (state_ != INTERRUPTED_INTERNAL)
487 return false;
488
489 // Downloads that don't have a WebContents should still be resumable, but this
490 // isn't currently the case. See ResumeInterruptedDownload().
491 if (!GetWebContents())
492 return false;
493
494 ResumeMode resume_mode = GetResumeMode();
495 return IsDownloadResumptionEnabled() &&
496 (resume_mode == RESUME_MODE_USER_RESTART ||
497 resume_mode == RESUME_MODE_USER_CONTINUE);
498 }
499
477 // TODO(rdsmith): Figure out whether or not we want this probe routine 500 // TODO(rdsmith): Figure out whether or not we want this probe routine
478 // to consider interrupted (resumably) downloads partial downloads. 501 // to consider interrupted (resumably) downloads partial downloads.
479 // Conceptually the answer is probably yes, but everywhere that currently 502 // Conceptually the answer is probably yes, but everywhere that currently
480 // uses the routine is using it as a synonym for IsInProgress(). 503 // uses the routine is using it as a synonym for IsInProgress().
481 bool DownloadItemImpl::IsPartialDownload() const { 504 bool DownloadItemImpl::IsPartialDownload() const {
482 DownloadState state = InternalToExternalState(state_); 505 DownloadState state = InternalToExternalState(state_);
483 return (state == IN_PROGRESS); 506 return (state == IN_PROGRESS);
484 } 507 }
485 508
486 bool DownloadItemImpl::IsInProgress() const { 509 bool DownloadItemImpl::IsInProgress() const {
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 // Whatever happens, the first one to hit the UI thread wins. 1361 // Whatever happens, the first one to hit the UI thread wins.
1339 if (state_ != IN_PROGRESS_INTERNAL && state_ != RESUMING_INTERNAL) 1362 if (state_ != IN_PROGRESS_INTERNAL && state_ != RESUMING_INTERNAL)
1340 return; 1363 return;
1341 1364
1342 last_reason_ = reason; 1365 last_reason_ = reason;
1343 1366
1344 ResumeMode resume_mode = GetResumeMode(); 1367 ResumeMode resume_mode = GetResumeMode();
1345 // Cancel (delete file) if we're going to restart; no point in leaving 1368 // Cancel (delete file) if we're going to restart; no point in leaving
1346 // data around we aren't going to use. Also cancel if resumption isn't 1369 // data around we aren't going to use. Also cancel if resumption isn't
1347 // enabled for the same reason. 1370 // enabled for the same reason.
1348 bool resumption_enabled = CommandLine::ForCurrentProcess()->HasSwitch(
1349 switches::kEnableDownloadResumption);
1350 ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART || 1371 ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART ||
1351 resume_mode == RESUME_MODE_USER_RESTART || 1372 resume_mode == RESUME_MODE_USER_RESTART ||
1352 !resumption_enabled); 1373 !IsDownloadResumptionEnabled());
1353 1374
1354 // Reset all data saved, as even if we did save all the data we're going 1375 // Reset all data saved, as even if we did save all the data we're going
1355 // to go through another round of downloading when we resume. 1376 // to go through another round of downloading when we resume.
1356 // There's a potential problem here in the abstract, as if we did download 1377 // There's a potential problem here in the abstract, as if we did download
1357 // all the data and then run into a continuable error, on resumption we 1378 // all the data and then run into a continuable error, on resumption we
1358 // won't download any more data. However, a) there are currently no 1379 // won't download any more data. However, a) there are currently no
1359 // continuable errors that can occur after we download all the data, and 1380 // continuable errors that can occur after we download all the data, and
1360 // b) if there were, that would probably simply result in a null range 1381 // b) if there were, that would probably simply result in a null range
1361 // request, which would generate a DestinationCompleted() notification 1382 // request, which would generate a DestinationCompleted() notification
1362 // from the DownloadFile, which would behave properly with setting 1383 // from the DownloadFile, which would behave properly with setting
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 case RESUME_MODE_USER_CONTINUE: 1685 case RESUME_MODE_USER_CONTINUE:
1665 return "USER_CONTINUE"; 1686 return "USER_CONTINUE";
1666 case RESUME_MODE_USER_RESTART: 1687 case RESUME_MODE_USER_RESTART:
1667 return "USER_RESTART"; 1688 return "USER_RESTART";
1668 } 1689 }
1669 NOTREACHED() << "Unknown resume mode " << mode; 1690 NOTREACHED() << "Unknown resume mode " << mode;
1670 return "unknown"; 1691 return "unknown";
1671 } 1692 }
1672 1693
1673 } // namespace content 1694 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/public/browser/download_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698