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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/download_item_impl.cc
diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc
index b5230a3bc2cddfb815735458a2fa60d77b71f980..27c170796605127ddb40b24c0507a9dbc4d82c06 100644
--- a/content/browser/download/download_item_impl.cc
+++ b/content/browser/download/download_item_impl.cc
@@ -78,6 +78,11 @@ static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) {
download_file->Cancel();
}
+bool IsDownloadResumptionEnabled() {
+ return CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableDownloadResumption);
+}
+
} // namespace
const char DownloadItem::kEmptyFileHash[] = "";
@@ -474,6 +479,24 @@ bool DownloadItemImpl::IsTemporary() const {
return is_temporary_;
}
+bool DownloadItemImpl::CanResume() const {
+ if (IsInProgress() && IsPaused())
+ return true;
+
+ if (state_ != INTERRUPTED_INTERNAL)
+ return false;
+
+ // Downloads that don't have a WebContents should still be resumable, but this
+ // isn't currently the case. See ResumeInterruptedDownload().
+ if (!GetWebContents())
+ return false;
+
+ ResumeMode resume_mode = GetResumeMode();
+ return IsDownloadResumptionEnabled() &&
+ (resume_mode == RESUME_MODE_USER_RESTART ||
+ resume_mode == RESUME_MODE_USER_CONTINUE);
+}
+
// TODO(rdsmith): Figure out whether or not we want this probe routine
// to consider interrupted (resumably) downloads partial downloads.
// Conceptually the answer is probably yes, but everywhere that currently
@@ -1345,11 +1368,9 @@ void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) {
// Cancel (delete file) if we're going to restart; no point in leaving
// data around we aren't going to use. Also cancel if resumption isn't
// enabled for the same reason.
- bool resumption_enabled = CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableDownloadResumption);
ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART ||
resume_mode == RESUME_MODE_USER_RESTART ||
- !resumption_enabled);
+ !IsDownloadResumptionEnabled());
// Reset all data saved, as even if we did save all the data we're going
// to go through another round of downloading when we resume.
« 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