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