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

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

Issue 1979783002: [Merge M51][Downloads] Use the initiating StoragePartition for resumption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 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 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "content/browser/download/download_request_handle.h" 44 #include "content/browser/download/download_request_handle.h"
45 #include "content/browser/download/download_stats.h" 45 #include "content/browser/download/download_stats.h"
46 #include "content/browser/renderer_host/render_view_host_impl.h" 46 #include "content/browser/renderer_host/render_view_host_impl.h"
47 #include "content/browser/web_contents/web_contents_impl.h" 47 #include "content/browser/web_contents/web_contents_impl.h"
48 #include "content/public/browser/browser_context.h" 48 #include "content/public/browser/browser_context.h"
49 #include "content/public/browser/browser_thread.h" 49 #include "content/public/browser/browser_thread.h"
50 #include "content/public/browser/content_browser_client.h" 50 #include "content/public/browser/content_browser_client.h"
51 #include "content/public/browser/download_danger_type.h" 51 #include "content/public/browser/download_danger_type.h"
52 #include "content/public/browser/download_interrupt_reasons.h" 52 #include "content/public/browser/download_interrupt_reasons.h"
53 #include "content/public/browser/download_url_parameters.h" 53 #include "content/public/browser/download_url_parameters.h"
54 #include "content/public/browser/storage_partition.h"
54 #include "content/public/common/content_features.h" 55 #include "content/public/common/content_features.h"
55 #include "content/public/common/referrer.h" 56 #include "content/public/common/referrer.h"
56 57
57 namespace content { 58 namespace content {
58 59
59 namespace { 60 namespace {
60 61
61 bool DeleteDownloadedFile(const base::FilePath& path) { 62 bool DeleteDownloadedFile(const base::FilePath& path) {
62 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 63 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
63 64
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5; 106 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5;
106 107
107 // Constructor for reading from the history service. 108 // Constructor for reading from the history service.
108 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, 109 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
109 const std::string& guid, 110 const std::string& guid,
110 uint32_t download_id, 111 uint32_t download_id,
111 const base::FilePath& current_path, 112 const base::FilePath& current_path,
112 const base::FilePath& target_path, 113 const base::FilePath& target_path,
113 const std::vector<GURL>& url_chain, 114 const std::vector<GURL>& url_chain,
114 const GURL& referrer_url, 115 const GURL& referrer_url,
116 const GURL& site_url,
115 const GURL& tab_url, 117 const GURL& tab_url,
116 const GURL& tab_refererr_url, 118 const GURL& tab_refererr_url,
117 const std::string& mime_type, 119 const std::string& mime_type,
118 const std::string& original_mime_type, 120 const std::string& original_mime_type,
119 const base::Time& start_time, 121 const base::Time& start_time,
120 const base::Time& end_time, 122 const base::Time& end_time,
121 const std::string& etag, 123 const std::string& etag,
122 const std::string& last_modified, 124 const std::string& last_modified,
123 int64_t received_bytes, 125 int64_t received_bytes,
124 int64_t total_bytes, 126 int64_t total_bytes,
125 const std::string& hash, 127 const std::string& hash,
126 DownloadItem::DownloadState state, 128 DownloadItem::DownloadState state,
127 DownloadDangerType danger_type, 129 DownloadDangerType danger_type,
128 DownloadInterruptReason interrupt_reason, 130 DownloadInterruptReason interrupt_reason,
129 bool opened, 131 bool opened,
130 const net::BoundNetLog& bound_net_log) 132 const net::BoundNetLog& bound_net_log)
131 : guid_(base::ToUpperASCII(guid)), 133 : guid_(base::ToUpperASCII(guid)),
132 download_id_(download_id), 134 download_id_(download_id),
133 target_path_(target_path), 135 target_path_(target_path),
134 url_chain_(url_chain), 136 url_chain_(url_chain),
135 referrer_url_(referrer_url), 137 referrer_url_(referrer_url),
138 site_url_(site_url),
136 tab_url_(tab_url), 139 tab_url_(tab_url),
137 tab_referrer_url_(tab_refererr_url), 140 tab_referrer_url_(tab_refererr_url),
138 mime_type_(mime_type), 141 mime_type_(mime_type),
139 original_mime_type_(original_mime_type), 142 original_mime_type_(original_mime_type),
140 total_bytes_(total_bytes), 143 total_bytes_(total_bytes),
141 last_reason_(interrupt_reason), 144 last_reason_(interrupt_reason),
142 start_tick_(base::TimeTicks()), 145 start_tick_(base::TimeTicks()),
143 state_(ExternalToInternalState(state)), 146 state_(ExternalToInternalState(state)),
144 danger_type_(danger_type), 147 danger_type_(danger_type),
145 start_time_(start_time), 148 start_time_(start_time),
(...skipping 20 matching lines...) Expand all
166 uint32_t download_id, 169 uint32_t download_id,
167 const DownloadCreateInfo& info, 170 const DownloadCreateInfo& info,
168 const net::BoundNetLog& bound_net_log) 171 const net::BoundNetLog& bound_net_log)
169 : guid_(base::ToUpperASCII(base::GenerateGUID())), 172 : guid_(base::ToUpperASCII(base::GenerateGUID())),
170 download_id_(download_id), 173 download_id_(download_id),
171 target_disposition_((info.save_info->prompt_for_save_location) 174 target_disposition_((info.save_info->prompt_for_save_location)
172 ? TARGET_DISPOSITION_PROMPT 175 ? TARGET_DISPOSITION_PROMPT
173 : TARGET_DISPOSITION_OVERWRITE), 176 : TARGET_DISPOSITION_OVERWRITE),
174 url_chain_(info.url_chain), 177 url_chain_(info.url_chain),
175 referrer_url_(info.referrer_url), 178 referrer_url_(info.referrer_url),
179 site_url_(info.site_url),
176 tab_url_(info.tab_url), 180 tab_url_(info.tab_url),
177 tab_referrer_url_(info.tab_referrer_url), 181 tab_referrer_url_(info.tab_referrer_url),
178 suggested_filename_(base::UTF16ToUTF8(info.save_info->suggested_name)), 182 suggested_filename_(base::UTF16ToUTF8(info.save_info->suggested_name)),
179 forced_file_path_(info.save_info->file_path), 183 forced_file_path_(info.save_info->file_path),
180 transition_type_(info.transition_type), 184 transition_type_(info.transition_type),
181 has_user_gesture_(info.has_user_gesture), 185 has_user_gesture_(info.has_user_gesture),
182 content_disposition_(info.content_disposition), 186 content_disposition_(info.content_disposition),
183 mime_type_(info.mime_type), 187 mime_type_(info.mime_type),
184 original_mime_type_(info.original_mime_type), 188 original_mime_type_(info.original_mime_type),
185 remote_address_(info.remote_address), 189 remote_address_(info.remote_address),
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 const GURL& DownloadItemImpl::GetOriginalUrl() const { 528 const GURL& DownloadItemImpl::GetOriginalUrl() const {
525 // Be careful about taking the front() of possibly-empty vectors! 529 // Be careful about taking the front() of possibly-empty vectors!
526 // http://crbug.com/190096 530 // http://crbug.com/190096
527 return url_chain_.empty() ? GURL::EmptyGURL() : url_chain_.front(); 531 return url_chain_.empty() ? GURL::EmptyGURL() : url_chain_.front();
528 } 532 }
529 533
530 const GURL& DownloadItemImpl::GetReferrerUrl() const { 534 const GURL& DownloadItemImpl::GetReferrerUrl() const {
531 return referrer_url_; 535 return referrer_url_;
532 } 536 }
533 537
538 const GURL& DownloadItemImpl::GetSiteUrl() const {
539 return site_url_;
540 }
541
534 const GURL& DownloadItemImpl::GetTabUrl() const { 542 const GURL& DownloadItemImpl::GetTabUrl() const {
535 return tab_url_; 543 return tab_url_;
536 } 544 }
537 545
538 const GURL& DownloadItemImpl::GetTabReferrerUrl() const { 546 const GURL& DownloadItemImpl::GetTabReferrerUrl() const {
539 return tab_referrer_url_; 547 return tab_referrer_url_;
540 } 548 }
541 549
542 std::string DownloadItemImpl::GetSuggestedFilename() const { 550 std::string DownloadItemImpl::GetSuggestedFilename() const {
543 return suggested_filename_; 551 return suggested_filename_;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 " reason = %s" 810 " reason = %s"
803 " paused = %c" 811 " paused = %c"
804 " resume_mode = %s" 812 " resume_mode = %s"
805 " auto_resume_count = %d" 813 " auto_resume_count = %d"
806 " danger = %d" 814 " danger = %d"
807 " all_data_saved = %c" 815 " all_data_saved = %c"
808 " last_modified = '%s'" 816 " last_modified = '%s'"
809 " etag = '%s'" 817 " etag = '%s'"
810 " has_download_file = %s" 818 " has_download_file = %s"
811 " url_chain = \n\t\"%s\"\n\t" 819 " url_chain = \n\t\"%s\"\n\t"
812 " current_path = \"%" PRFilePath "\"\n\t" 820 " current_path = \"%" PRFilePath
813 " target_path = \"%" PRFilePath "\"" 821 "\"\n\t"
814 " referrer = \"%s\"", 822 " target_path = \"%" PRFilePath
815 GetTotalBytes(), 823 "\""
816 GetReceivedBytes(), 824 " referrer = \"%s\""
825 " site_url = \"%s\"",
826 GetTotalBytes(), GetReceivedBytes(),
817 DownloadInterruptReasonToString(last_reason_).c_str(), 827 DownloadInterruptReasonToString(last_reason_).c_str(),
818 IsPaused() ? 'T' : 'F', 828 IsPaused() ? 'T' : 'F', DebugResumeModeString(GetResumeMode()),
819 DebugResumeModeString(GetResumeMode()), 829 auto_resume_count_, GetDangerType(), AllDataSaved() ? 'T' : 'F',
820 auto_resume_count_, 830 GetLastModifiedTime().c_str(), GetETag().c_str(),
821 GetDangerType(), 831 download_file_.get() ? "true" : "false", url_list.c_str(),
822 AllDataSaved() ? 'T' : 'F', 832 GetFullPath().value().c_str(), GetTargetFilePath().value().c_str(),
823 GetLastModifiedTime().c_str(), 833 GetReferrerUrl().spec().c_str(), GetSiteUrl().spec().c_str());
824 GetETag().c_str(),
825 download_file_.get() ? "true" : "false",
826 url_list.c_str(),
827 GetFullPath().value().c_str(),
828 GetTargetFilePath().value().c_str(),
829 GetReferrerUrl().spec().c_str());
830 } else { 834 } else {
831 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 835 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
832 } 836 }
833 837
834 description += " }"; 838 description += " }";
835 839
836 return description; 840 return description;
837 } 841 }
838 842
839 DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const { 843 DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const {
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 ResumeMode mode = GetResumeMode(); 1896 ResumeMode mode = GetResumeMode();
1893 if (mode == RESUME_MODE_IMMEDIATE_RESTART || 1897 if (mode == RESUME_MODE_IMMEDIATE_RESTART ||
1894 mode == RESUME_MODE_USER_RESTART) { 1898 mode == RESUME_MODE_USER_RESTART) {
1895 received_bytes_ = 0; 1899 received_bytes_ = 0;
1896 last_modified_time_.clear(); 1900 last_modified_time_.clear();
1897 etag_.clear(); 1901 etag_.clear();
1898 hash_.clear(); 1902 hash_.clear();
1899 hash_state_.reset(); 1903 hash_state_.reset();
1900 } 1904 }
1901 1905
1906 StoragePartition* storage_partition =
1907 BrowserContext::GetStoragePartitionForSite(GetBrowserContext(),
1908 site_url_);
1909
1902 // Avoid using the WebContents even if it's still around. Resumption requests 1910 // Avoid using the WebContents even if it's still around. Resumption requests
1903 // are consistently routed through the no-renderer code paths so that the 1911 // are consistently routed through the no-renderer code paths so that the
1904 // request will not be dropped if the WebContents (and by extension, the 1912 // request will not be dropped if the WebContents (and by extension, the
1905 // associated renderer) goes away before a response is received. 1913 // associated renderer) goes away before a response is received.
1906 scoped_ptr<DownloadUrlParameters> download_params(new DownloadUrlParameters( 1914 scoped_ptr<DownloadUrlParameters> download_params(
1907 GetURL(), -1, -1, -1, GetBrowserContext()->GetResourceContext())); 1915 new DownloadUrlParameters(GetURL(), -1, -1, -1,
1916 storage_partition->GetURLRequestContext()));
1908 download_params->set_file_path(GetFullPath()); 1917 download_params->set_file_path(GetFullPath());
1909 download_params->set_offset(GetReceivedBytes()); 1918 download_params->set_offset(GetReceivedBytes());
1910 download_params->set_last_modified(GetLastModifiedTime()); 1919 download_params->set_last_modified(GetLastModifiedTime());
1911 download_params->set_etag(GetETag()); 1920 download_params->set_etag(GetETag());
1912 download_params->set_hash_of_partial_file(hash_); 1921 download_params->set_hash_of_partial_file(hash_);
1913 download_params->set_hash_state(std::move(hash_state_)); 1922 download_params->set_hash_state(std::move(hash_state_));
1914 1923
1915 // Note that resumed downloads disallow redirects. Hence the referrer URL 1924 // Note that resumed downloads disallow redirects. Hence the referrer URL
1916 // (which is the contents of the Referer header for the last download request) 1925 // (which is the contents of the Referer header for the last download request)
1917 // will only be sent to the URL returned by GetURL(). 1926 // will only be sent to the URL returned by GetURL().
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 case RESUME_MODE_USER_CONTINUE: 2103 case RESUME_MODE_USER_CONTINUE:
2095 return "USER_CONTINUE"; 2104 return "USER_CONTINUE";
2096 case RESUME_MODE_USER_RESTART: 2105 case RESUME_MODE_USER_RESTART:
2097 return "USER_RESTART"; 2106 return "USER_RESTART";
2098 } 2107 }
2099 NOTREACHED() << "Unknown resume mode " << mode; 2108 NOTREACHED() << "Unknown resume mode " << mode;
2100 return "unknown"; 2109 return "unknown";
2101 } 2110 }
2102 2111
2103 } // namespace content 2112 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_item_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698