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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 namespace { | 58 namespace { |
59 | 59 |
60 void DeleteDownloadedFile(const base::FilePath& path) { | 60 void DeleteDownloadedFile(const base::FilePath& path) { |
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
62 | 62 |
63 // Make sure we only delete files. | 63 // Make sure we only delete files. |
64 if (!file_util::DirectoryExists(path)) | 64 if (!file_util::DirectoryExists(path)) |
65 file_util::Delete(path, false); | 65 file_util::Delete(path, false); |
66 } | 66 } |
67 | 67 |
68 // Classes to null out request handle calls (for SavePage DownloadItems, which | |
69 // may have, e.g., Cancel() called on them without it doing anything) | |
70 // and to DCHECK on them (for history DownloadItems, which should never have | |
71 // any operation that implies an off-thread component, since they don't | |
72 // have any). | |
73 class NullDownloadRequestHandle : public DownloadRequestHandleInterface { | |
74 public: | |
75 NullDownloadRequestHandle() {} | |
76 | |
77 // DownloadRequestHandleInterface calls | |
78 virtual WebContents* GetWebContents() const OVERRIDE { | |
79 return NULL; | |
80 } | |
81 virtual DownloadManager* GetDownloadManager() const OVERRIDE { | |
82 return NULL; | |
83 } | |
84 virtual void PauseRequest() const OVERRIDE {} | |
85 virtual void ResumeRequest() const OVERRIDE {} | |
86 virtual void CancelRequest() const OVERRIDE {} | |
87 virtual std::string DebugString() const OVERRIDE { | |
88 return "Null DownloadRequestHandle"; | |
89 } | |
90 }; | |
91 | |
92 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that | 68 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that |
93 // takes ownership of the DownloadFile and hence implicitly destroys it | 69 // takes ownership of the DownloadFile and hence implicitly destroys it |
94 // at the end of the function. | 70 // at the end of the function. |
95 static void DownloadFileDetach(scoped_ptr<DownloadFile> download_file) { | 71 static void DownloadFileDetach(scoped_ptr<DownloadFile> download_file) { |
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
97 download_file->Detach(); | 73 download_file->Detach(); |
98 } | 74 } |
99 | 75 |
100 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { | 76 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { |
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 bound_net_log_.AddEvent( | 186 bound_net_log_.AddEvent( |
211 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST, | 187 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST, |
212 info.request_bound_net_log.source().ToEventParametersCallback()); | 188 info.request_bound_net_log.source().ToEventParametersCallback()); |
213 | 189 |
214 info.request_bound_net_log.AddEvent( | 190 info.request_bound_net_log.AddEvent( |
215 net::NetLog::TYPE_DOWNLOAD_STARTED, | 191 net::NetLog::TYPE_DOWNLOAD_STARTED, |
216 bound_net_log_.source().ToEventParametersCallback()); | 192 bound_net_log_.source().ToEventParametersCallback()); |
217 } | 193 } |
218 | 194 |
219 // Constructing for the "Save Page As..." feature: | 195 // Constructing for the "Save Page As..." feature: |
220 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, | 196 DownloadItemImpl::DownloadItemImpl( |
221 const base::FilePath& path, | 197 DownloadItemImplDelegate* delegate, |
222 const GURL& url, | 198 const base::FilePath& path, |
223 DownloadId download_id, | 199 const GURL& url, |
224 const std::string& mime_type, | 200 DownloadId download_id, |
225 const net::BoundNetLog& bound_net_log) | 201 const std::string& mime_type, |
| 202 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
| 203 const net::BoundNetLog& bound_net_log) |
226 : is_save_package_download_(true), | 204 : is_save_package_download_(true), |
227 request_handle_(new NullDownloadRequestHandle()), | 205 request_handle_(request_handle.Pass()), |
228 download_id_(download_id), | 206 download_id_(download_id), |
229 current_path_(path), | 207 current_path_(path), |
230 target_path_(path), | 208 target_path_(path), |
231 target_disposition_(TARGET_DISPOSITION_OVERWRITE), | 209 target_disposition_(TARGET_DISPOSITION_OVERWRITE), |
232 url_chain_(1, url), | 210 url_chain_(1, url), |
233 referrer_url_(GURL()), | 211 referrer_url_(GURL()), |
234 transition_type_(PAGE_TRANSITION_LINK), | 212 transition_type_(PAGE_TRANSITION_LINK), |
235 has_user_gesture_(false), | 213 has_user_gesture_(false), |
236 mime_type_(mime_type), | 214 mime_type_(mime_type), |
237 original_mime_type_(mime_type), | 215 original_mime_type_(mime_type), |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 // fails isn't a good one. Can we hack up a name based on the | 1097 // fails isn't a good one. Can we hack up a name based on the |
1120 // URLRequest? We'll need to make sure that initialization happens | 1098 // URLRequest? We'll need to make sure that initialization happens |
1121 // properly. Possibly the right thing is to have the UI handle | 1099 // properly. Possibly the right thing is to have the UI handle |
1122 // this case specially. | 1100 // this case specially. |
1123 return; | 1101 return; |
1124 } | 1102 } |
1125 | 1103 |
1126 // If we're resuming an interrupted download, we may already know | 1104 // If we're resuming an interrupted download, we may already know |
1127 // the download target so we can skip target name determination. | 1105 // the download target so we can skip target name determination. |
1128 if (!GetTargetFilePath().empty() && !GetFullPath().empty()) { | 1106 if (!GetTargetFilePath().empty() && !GetFullPath().empty()) { |
1129 delegate_->ShowDownloadInBrowser(this); | |
1130 MaybeCompleteDownload(); | 1107 MaybeCompleteDownload(); |
1131 return; | 1108 return; |
1132 } | 1109 } |
1133 | 1110 |
1134 // The target path might be set and the full path empty if we failed | 1111 // The target path might be set and the full path empty if we failed |
1135 // the intermediate rename--re-do file name determination in this case. | 1112 // the intermediate rename--re-do file name determination in this case. |
1136 // TODO(rdsmith,asanka): Clean up this logic. | 1113 // TODO(rdsmith,asanka): Clean up this logic. |
1137 target_path_ = base::FilePath(); | 1114 target_path_ = base::FilePath(); |
1138 | 1115 |
1139 delegate_->DetermineDownloadTarget( | 1116 delegate_->DetermineDownloadTarget( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 intermediate_path, callback)); | 1173 intermediate_path, callback)); |
1197 } | 1174 } |
1198 | 1175 |
1199 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( | 1176 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( |
1200 DownloadInterruptReason reason, | 1177 DownloadInterruptReason reason, |
1201 const base::FilePath& full_path) { | 1178 const base::FilePath& full_path) { |
1202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1203 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 1180 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
1204 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { | 1181 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { |
1205 Interrupt(reason); | 1182 Interrupt(reason); |
1206 // MaybeCompleteDownload() is a no-op if we've been interrupted, | |
1207 // so it's safe to fall through. | |
1208 } else { | 1183 } else { |
1209 SetFullPath(full_path); | 1184 SetFullPath(full_path); |
| 1185 MaybeCompleteDownload(); |
1210 } | 1186 } |
1211 delegate_->ShowDownloadInBrowser(this); | |
1212 | |
1213 MaybeCompleteDownload(); | |
1214 } | 1187 } |
1215 | 1188 |
1216 // When SavePackage downloads MHTML to GData (see | 1189 // When SavePackage downloads MHTML to GData (see |
1217 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it | 1190 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it |
1218 // does for non-SavePackage downloads, but SavePackage downloads never satisfy | 1191 // does for non-SavePackage downloads, but SavePackage downloads never satisfy |
1219 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls | 1192 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls |
1220 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage | 1193 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage |
1221 // notices that the upload has completed and runs its normal Finish() pathway. | 1194 // notices that the upload has completed and runs its normal Finish() pathway. |
1222 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes | 1195 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes |
1223 // downloads. SavePackage always uses its own Finish() to mark downloads | 1196 // downloads. SavePackage always uses its own Finish() to mark downloads |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 case RESUME_MODE_USER_CONTINUE: | 1608 case RESUME_MODE_USER_CONTINUE: |
1636 return "USER_CONTINUE"; | 1609 return "USER_CONTINUE"; |
1637 case RESUME_MODE_USER_RESTART: | 1610 case RESUME_MODE_USER_RESTART: |
1638 return "USER_RESTART"; | 1611 return "USER_RESTART"; |
1639 } | 1612 } |
1640 NOTREACHED() << "Unknown resume mode " << mode; | 1613 NOTREACHED() << "Unknown resume mode " << mode; |
1641 return "unknown"; | 1614 return "unknown"; |
1642 } | 1615 } |
1643 | 1616 |
1644 } // namespace content | 1617 } // namespace content |
OLD | NEW |