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

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

Issue 1538933002: Enable download resumption by default. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forgot ChromeOS 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.
11 11
12 // A regular DownloadItem (created for a download in this session of the 12 // A regular DownloadItem (created for a download in this session of the
13 // browser) normally goes through the following states: 13 // browser) normally goes through the following states:
14 // * Created (when download starts) 14 // * Created (when download starts)
15 // * Destination filename determined 15 // * Destination filename determined
16 // * Entered into the history database. 16 // * Entered into the history database.
17 // * Made visible in the download shelf. 17 // * Made visible in the download shelf.
18 // * All the data is saved. Note that the actual data download occurs 18 // * All the data is saved. Note that the actual data download occurs
19 // in parallel with the above steps, but until those steps are 19 // in parallel with the above steps, but until those steps are
20 // complete, the state of the data save will be ignored. 20 // complete, the state of the data save will be ignored.
21 // * Download file is renamed to its final name, and possibly 21 // * Download file is renamed to its final name, and possibly
22 // auto-opened. 22 // auto-opened.
23 23
24 #include "content/browser/download/download_item_impl.h" 24 #include "content/browser/download/download_item_impl.h"
25 25
26 #include <vector> 26 #include <vector>
27 27
28 #include "base/basictypes.h" 28 #include "base/basictypes.h"
29 #include "base/bind.h" 29 #include "base/bind.h"
30 #include "base/command_line.h"
31 #include "base/files/file_util.h" 30 #include "base/files/file_util.h"
32 #include "base/format_macros.h" 31 #include "base/format_macros.h"
33 #include "base/logging.h" 32 #include "base/logging.h"
34 #include "base/metrics/histogram.h" 33 #include "base/metrics/histogram.h"
35 #include "base/stl_util.h" 34 #include "base/stl_util.h"
36 #include "base/strings/stringprintf.h" 35 #include "base/strings/stringprintf.h"
37 #include "base/strings/utf_string_conversions.h" 36 #include "base/strings/utf_string_conversions.h"
38 #include "content/browser/download/download_create_info.h" 37 #include "content/browser/download/download_create_info.h"
39 #include "content/browser/download/download_file.h" 38 #include "content/browser/download/download_file.h"
40 #include "content/browser/download/download_interrupt_reasons_impl.h" 39 #include "content/browser/download/download_interrupt_reasons_impl.h"
41 #include "content/browser/download/download_item_impl_delegate.h" 40 #include "content/browser/download/download_item_impl_delegate.h"
42 #include "content/browser/download/download_request_handle.h" 41 #include "content/browser/download/download_request_handle.h"
43 #include "content/browser/download/download_stats.h" 42 #include "content/browser/download/download_stats.h"
44 #include "content/browser/renderer_host/render_view_host_impl.h" 43 #include "content/browser/renderer_host/render_view_host_impl.h"
45 #include "content/browser/web_contents/web_contents_impl.h" 44 #include "content/browser/web_contents/web_contents_impl.h"
46 #include "content/public/browser/browser_context.h" 45 #include "content/public/browser/browser_context.h"
47 #include "content/public/browser/browser_thread.h" 46 #include "content/public/browser/browser_thread.h"
48 #include "content/public/browser/content_browser_client.h" 47 #include "content/public/browser/content_browser_client.h"
49 #include "content/public/browser/download_danger_type.h" 48 #include "content/public/browser/download_danger_type.h"
50 #include "content/public/browser/download_interrupt_reasons.h" 49 #include "content/public/browser/download_interrupt_reasons.h"
51 #include "content/public/browser/download_url_parameters.h" 50 #include "content/public/browser/download_url_parameters.h"
52 #include "content/public/common/content_switches.h" 51 #include "content/public/common/content_features.h"
53 #include "content/public/common/referrer.h" 52 #include "content/public/common/referrer.h"
54 #include "net/base/net_util.h" 53 #include "net/base/net_util.h"
55 54
56 namespace content { 55 namespace content {
57 56
58 namespace { 57 namespace {
59 58
60 bool DeleteDownloadedFile(const base::FilePath& path) { 59 bool DeleteDownloadedFile(const base::FilePath& path) {
61 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 60 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
62 61
(...skipping 23 matching lines...) Expand all
86 download_file->Detach(); 85 download_file->Detach();
87 return full_path; 86 return full_path;
88 } 87 }
89 88
90 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { 89 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) {
91 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 90 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
92 download_file->Cancel(); 91 download_file->Cancel();
93 } 92 }
94 93
95 bool IsDownloadResumptionEnabled() { 94 bool IsDownloadResumptionEnabled() {
96 return base::CommandLine::ForCurrentProcess()->HasSwitch( 95 return base::FeatureList::IsEnabled(features::kDownloadResumption);
97 switches::kEnableDownloadResumption);
98 } 96 }
99 97
100 } // namespace 98 } // namespace
101 99
102 const uint32 DownloadItem::kInvalidId = 0; 100 const uint32 DownloadItem::kInvalidId = 0;
103 101
104 const char DownloadItem::kEmptyFileHash[] = ""; 102 const char DownloadItem::kEmptyFileHash[] = "";
105 103
106 // The maximum number of attempts we will make to resume automatically. 104 // The maximum number of attempts we will make to resume automatically.
107 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5; 105 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5;
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 return; 1663 return;
1666 } 1664 }
1667 1665
1668 auto_resume_count_++; 1666 auto_resume_count_++;
1669 1667
1670 ResumeInterruptedDownload(); 1668 ResumeInterruptedDownload();
1671 } 1669 }
1672 1670
1673 void DownloadItemImpl::ResumeInterruptedDownload() { 1671 void DownloadItemImpl::ResumeInterruptedDownload() {
1674 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1672 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1675 1673 if (!IsDownloadResumptionEnabled())
1676 // If the flag for downloads resumption isn't enabled, ignore
1677 // this request.
1678 const base::CommandLine& command_line =
1679 *base::CommandLine::ForCurrentProcess();
1680 if (!command_line.HasSwitch(switches::kEnableDownloadResumption))
1681 return; 1674 return;
1682 1675
1683 // If we're not interrupted, ignore the request; our caller is drunk. 1676 // If we're not interrupted, ignore the request; our caller is drunk.
1684 if (state_ != INTERRUPTED_INTERNAL) 1677 if (state_ != INTERRUPTED_INTERNAL)
1685 return; 1678 return;
1686 1679
1687 // Reset the appropriate state if restarting. 1680 // Reset the appropriate state if restarting.
1688 ResumeMode mode = GetResumeMode(); 1681 ResumeMode mode = GetResumeMode();
1689 if (mode == RESUME_MODE_IMMEDIATE_RESTART || 1682 if (mode == RESUME_MODE_IMMEDIATE_RESTART ||
1690 mode == RESUME_MODE_USER_RESTART) { 1683 mode == RESUME_MODE_USER_RESTART) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1794 case RESUME_MODE_USER_CONTINUE: 1787 case RESUME_MODE_USER_CONTINUE:
1795 return "USER_CONTINUE"; 1788 return "USER_CONTINUE";
1796 case RESUME_MODE_USER_RESTART: 1789 case RESUME_MODE_USER_RESTART:
1797 return "USER_RESTART"; 1790 return "USER_RESTART";
1798 } 1791 }
1799 NOTREACHED() << "Unknown resume mode " << mode; 1792 NOTREACHED() << "Unknown resume mode " << mode;
1800 return "unknown"; 1793 return "unknown";
1801 } 1794 }
1802 1795
1803 } // namespace content 1796 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_browsertest.cc ('k') | content/browser/download/download_item_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698