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

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

Issue 1418663010: Adding WebContent-free Download (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing nits. Created 5 years 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
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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 return is_temporary_; 497 return is_temporary_;
498 } 498 }
499 499
500 bool DownloadItemImpl::CanResume() const { 500 bool DownloadItemImpl::CanResume() const {
501 if ((GetState() == IN_PROGRESS) && IsPaused()) 501 if ((GetState() == IN_PROGRESS) && IsPaused())
502 return true; 502 return true;
503 503
504 if (state_ != INTERRUPTED_INTERNAL) 504 if (state_ != INTERRUPTED_INTERNAL)
505 return false; 505 return false;
506 506
507 // Downloads that don't have a WebContents should still be resumable, but this 507 // We currently only support HTTP(S) requests for download resumption.
508 // isn't currently the case. See ResumeInterruptedDownload(). 508 if (!GetURL().SchemeIsHTTPOrHTTPS())
509 if (!GetWebContents())
510 return false; 509 return false;
511 510
512 ResumeMode resume_mode = GetResumeMode(); 511 ResumeMode resume_mode = GetResumeMode();
513 return IsDownloadResumptionEnabled() && 512 return IsDownloadResumptionEnabled() &&
514 (resume_mode == RESUME_MODE_USER_RESTART || 513 (resume_mode == RESUME_MODE_USER_RESTART ||
515 resume_mode == RESUME_MODE_USER_CONTINUE); 514 resume_mode == RESUME_MODE_USER_CONTINUE);
516 } 515 }
517 516
518 bool DownloadItemImpl::IsDone() const { 517 bool DownloadItemImpl::IsDone() const {
519 switch (state_) { 518 switch (state_) {
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 // this request. 1685 // this request.
1687 const base::CommandLine& command_line = 1686 const base::CommandLine& command_line =
1688 *base::CommandLine::ForCurrentProcess(); 1687 *base::CommandLine::ForCurrentProcess();
1689 if (!command_line.HasSwitch(switches::kEnableDownloadResumption)) 1688 if (!command_line.HasSwitch(switches::kEnableDownloadResumption))
1690 return; 1689 return;
1691 1690
1692 // If we're not interrupted, ignore the request; our caller is drunk. 1691 // If we're not interrupted, ignore the request; our caller is drunk.
1693 if (state_ != INTERRUPTED_INTERNAL) 1692 if (state_ != INTERRUPTED_INTERNAL)
1694 return; 1693 return;
1695 1694
1696 // If we can't get a web contents, we can't resume the download.
1697 // TODO(rdsmith): Find some alternative web contents to use--this
1698 // means we can't restart a download if it's a download imported
1699 // from the history.
1700 if (!GetWebContents())
1701 return;
1702
1703 // Reset the appropriate state if restarting. 1695 // Reset the appropriate state if restarting.
1704 ResumeMode mode = GetResumeMode(); 1696 ResumeMode mode = GetResumeMode();
1705 if (mode == RESUME_MODE_IMMEDIATE_RESTART || 1697 if (mode == RESUME_MODE_IMMEDIATE_RESTART ||
1706 mode == RESUME_MODE_USER_RESTART) { 1698 mode == RESUME_MODE_USER_RESTART) {
1707 received_bytes_ = 0; 1699 received_bytes_ = 0;
1708 hash_state_ = ""; 1700 hash_state_ = "";
1709 last_modified_time_ = ""; 1701 last_modified_time_ = "";
1710 etag_ = ""; 1702 etag_ = "";
1711 } 1703 }
1712 1704
1713 scoped_ptr<DownloadUrlParameters> download_params( 1705 scoped_ptr<DownloadUrlParameters> download_params;
1714 DownloadUrlParameters::FromWebContents(GetWebContents(), 1706 if (GetWebContents()) {
1715 GetOriginalUrl())); 1707 download_params = DownloadUrlParameters::FromWebContents(GetWebContents(),
1708 GetOriginalUrl());
1709 } else if (GetBrowserContext()) {
1710 download_params = make_scoped_ptr(
1711 new DownloadUrlParameters(GetOriginalUrl(), -1, -1, -1,
1712 GetBrowserContext()->GetResourceContext()));
1713 } else {
1714 return;
1715 }
1716 1716
1717 download_params->set_file_path(GetFullPath()); 1717 download_params->set_file_path(GetFullPath());
1718 download_params->set_offset(GetReceivedBytes()); 1718 download_params->set_offset(GetReceivedBytes());
1719 download_params->set_hash_state(GetHashState()); 1719 download_params->set_hash_state(GetHashState());
1720 download_params->set_last_modified(GetLastModifiedTime()); 1720 download_params->set_last_modified(GetLastModifiedTime());
1721 download_params->set_etag(GetETag()); 1721 download_params->set_etag(GetETag());
1722 download_params->set_callback( 1722 download_params->set_callback(
1723 base::Bind(&DownloadItemImpl::OnResumeRequestStarted, 1723 base::Bind(&DownloadItemImpl::OnResumeRequestStarted,
1724 weak_ptr_factory_.GetWeakPtr())); 1724 weak_ptr_factory_.GetWeakPtr()));
1725 1725
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 case RESUME_MODE_USER_CONTINUE: 1805 case RESUME_MODE_USER_CONTINUE:
1806 return "USER_CONTINUE"; 1806 return "USER_CONTINUE";
1807 case RESUME_MODE_USER_RESTART: 1807 case RESUME_MODE_USER_RESTART:
1808 return "USER_RESTART"; 1808 return "USER_RESTART";
1809 } 1809 }
1810 NOTREACHED() << "Unknown resume mode " << mode; 1810 NOTREACHED() << "Unknown resume mode " << mode;
1811 return "unknown"; 1811 return "unknown";
1812 } 1812 }
1813 1813
1814 } // namespace content 1814 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_item_impl_unittest.cc » ('j') | content/browser/download/url_downloader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698