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

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 Mock for GetBrowserContext. Created 5 years, 1 month 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
508 // isn't currently the case. See ResumeInterruptedDownload().
509 if (!GetWebContents())
510 return false;
511
512 ResumeMode resume_mode = GetResumeMode(); 507 ResumeMode resume_mode = GetResumeMode();
513 return IsDownloadResumptionEnabled() && 508 return IsDownloadResumptionEnabled() && GetURL().SchemeIsHTTPOrHTTPS() &&
asanka 2015/11/25 15:53:57 Nit: You can move the SchemeIs.. check into it's o
svaldez 2015/11/25 17:53:28 Done.
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:
522 return false; 517 return false;
523 518
524 case COMPLETE_INTERNAL: 519 case COMPLETE_INTERNAL:
525 case CANCELLED_INTERNAL: 520 case CANCELLED_INTERNAL:
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
asanka 2015/11/25 15:53:57 Oh boy. I just noticed that we are calling GetOrig
svaldez 2015/11/25 17:53:28 Acknowledged.
1705 } else if (GetBrowserContext()) {
1706 download_params = make_scoped_ptr(
1707 new DownloadUrlParameters(GetOriginalUrl(), -1, -1, -1,
1708 GetBrowserContext()->GetResourceContext()));
1709 } else {
1710 return;
1711 }
1716 1712
1717 download_params->set_file_path(GetFullPath()); 1713 download_params->set_file_path(GetFullPath());
1718 download_params->set_offset(GetReceivedBytes()); 1714 download_params->set_offset(GetReceivedBytes());
1719 download_params->set_hash_state(GetHashState()); 1715 download_params->set_hash_state(GetHashState());
1720 download_params->set_last_modified(GetLastModifiedTime()); 1716 download_params->set_last_modified(GetLastModifiedTime());
1721 download_params->set_etag(GetETag()); 1717 download_params->set_etag(GetETag());
1722 download_params->set_callback( 1718 download_params->set_callback(
1723 base::Bind(&DownloadItemImpl::OnResumeRequestStarted, 1719 base::Bind(&DownloadItemImpl::OnResumeRequestStarted,
1724 weak_ptr_factory_.GetWeakPtr())); 1720 weak_ptr_factory_.GetWeakPtr()));
1725 1721
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 case RESUME_MODE_USER_CONTINUE: 1801 case RESUME_MODE_USER_CONTINUE:
1806 return "USER_CONTINUE"; 1802 return "USER_CONTINUE";
1807 case RESUME_MODE_USER_RESTART: 1803 case RESUME_MODE_USER_RESTART:
1808 return "USER_RESTART"; 1804 return "USER_RESTART";
1809 } 1805 }
1810 NOTREACHED() << "Unknown resume mode " << mode; 1806 NOTREACHED() << "Unknown resume mode " << mode;
1811 return "unknown"; 1807 return "unknown";
1812 } 1808 }
1813 1809
1814 } // namespace content 1810 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698