OLD | NEW |
---|---|
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 Loading... | |
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 | |
508 // isn't currently the case. See ResumeInterruptedDownload(). | |
509 if (!GetWebContents()) | |
510 return false; | |
511 | |
asanka
2015/11/20 19:57:46
In addition, let's check that the download URL Sch
svaldez
2015/11/23 15:18:56
Done.
| |
512 ResumeMode resume_mode = GetResumeMode(); | 507 ResumeMode resume_mode = GetResumeMode(); |
513 return IsDownloadResumptionEnabled() && | 508 return IsDownloadResumptionEnabled() && |
514 (resume_mode == RESUME_MODE_USER_RESTART || | 509 (resume_mode == RESUME_MODE_USER_RESTART || |
515 resume_mode == RESUME_MODE_USER_CONTINUE); | 510 resume_mode == RESUME_MODE_USER_CONTINUE); |
516 } | 511 } |
517 | 512 |
518 bool DownloadItemImpl::IsDone() const { | 513 bool DownloadItemImpl::IsDone() const { |
519 switch (state_) { | 514 switch (state_) { |
520 case IN_PROGRESS_INTERNAL: | 515 case IN_PROGRESS_INTERNAL: |
521 case COMPLETING_INTERNAL: | 516 case COMPLETING_INTERNAL: |
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1686 // this request. | 1681 // this request. |
1687 const base::CommandLine& command_line = | 1682 const base::CommandLine& command_line = |
1688 *base::CommandLine::ForCurrentProcess(); | 1683 *base::CommandLine::ForCurrentProcess(); |
1689 if (!command_line.HasSwitch(switches::kEnableDownloadResumption)) | 1684 if (!command_line.HasSwitch(switches::kEnableDownloadResumption)) |
1690 return; | 1685 return; |
1691 | 1686 |
1692 // If we're not interrupted, ignore the request; our caller is drunk. | 1687 // If we're not interrupted, ignore the request; our caller is drunk. |
1693 if (state_ != INTERRUPTED_INTERNAL) | 1688 if (state_ != INTERRUPTED_INTERNAL) |
1694 return; | 1689 return; |
1695 | 1690 |
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. | 1691 // Reset the appropriate state if restarting. |
1704 ResumeMode mode = GetResumeMode(); | 1692 ResumeMode mode = GetResumeMode(); |
1705 if (mode == RESUME_MODE_IMMEDIATE_RESTART || | 1693 if (mode == RESUME_MODE_IMMEDIATE_RESTART || |
1706 mode == RESUME_MODE_USER_RESTART) { | 1694 mode == RESUME_MODE_USER_RESTART) { |
1707 received_bytes_ = 0; | 1695 received_bytes_ = 0; |
1708 hash_state_ = ""; | 1696 hash_state_ = ""; |
1709 last_modified_time_ = ""; | 1697 last_modified_time_ = ""; |
1710 etag_ = ""; | 1698 etag_ = ""; |
1711 } | 1699 } |
1712 | 1700 |
1713 scoped_ptr<DownloadUrlParameters> download_params( | 1701 scoped_ptr<DownloadUrlParameters> download_params; |
1714 DownloadUrlParameters::FromWebContents(GetWebContents(), | 1702 if (GetWebContents()) { |
1715 GetOriginalUrl())); | 1703 download_params = DownloadUrlParameters::FromWebContents(GetWebContents(), |
1704 GetOriginalUrl()); | |
1705 } else { | |
1706 download_params = make_scoped_ptr( | |
1707 new DownloadUrlParameters(GetOriginalUrl(), -1, -1, -1, | |
1708 GetBrowserContext()->GetResourceContext())); | |
asanka
2015/11/20 19:57:46
Do we need to worry about storage partitions here?
svaldez
2015/11/23 15:18:56
Not sure. I think this defaults in the correct way
| |
1709 } | |
1716 | 1710 |
1717 download_params->set_file_path(GetFullPath()); | 1711 download_params->set_file_path(GetFullPath()); |
1718 download_params->set_offset(GetReceivedBytes()); | 1712 download_params->set_offset(GetReceivedBytes()); |
1719 download_params->set_hash_state(GetHashState()); | 1713 download_params->set_hash_state(GetHashState()); |
1720 download_params->set_last_modified(GetLastModifiedTime()); | 1714 download_params->set_last_modified(GetLastModifiedTime()); |
1721 download_params->set_etag(GetETag()); | 1715 download_params->set_etag(GetETag()); |
1722 download_params->set_callback( | 1716 download_params->set_callback( |
1723 base::Bind(&DownloadItemImpl::OnResumeRequestStarted, | 1717 base::Bind(&DownloadItemImpl::OnResumeRequestStarted, |
1724 weak_ptr_factory_.GetWeakPtr())); | 1718 weak_ptr_factory_.GetWeakPtr())); |
1725 | 1719 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1805 case RESUME_MODE_USER_CONTINUE: | 1799 case RESUME_MODE_USER_CONTINUE: |
1806 return "USER_CONTINUE"; | 1800 return "USER_CONTINUE"; |
1807 case RESUME_MODE_USER_RESTART: | 1801 case RESUME_MODE_USER_RESTART: |
1808 return "USER_RESTART"; | 1802 return "USER_RESTART"; |
1809 } | 1803 } |
1810 NOTREACHED() << "Unknown resume mode " << mode; | 1804 NOTREACHED() << "Unknown resume mode " << mode; |
1811 return "unknown"; | 1805 return "unknown"; |
1812 } | 1806 } |
1813 | 1807 |
1814 } // namespace content | 1808 } // namespace content |
OLD | NEW |