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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // takes ownership of the DownloadFile and hence implicitly destroys it | 86 // takes ownership of the DownloadFile and hence implicitly destroys it |
87 // at the end of the function. | 87 // at the end of the function. |
88 static base::FilePath DownloadFileDetach( | 88 static base::FilePath DownloadFileDetach( |
89 std::unique_ptr<DownloadFile> download_file) { | 89 std::unique_ptr<DownloadFile> download_file) { |
90 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 90 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
91 base::FilePath full_path = download_file->FullPath(); | 91 base::FilePath full_path = download_file->FullPath(); |
92 download_file->Detach(); | 92 download_file->Detach(); |
93 return full_path; | 93 return full_path; |
94 } | 94 } |
95 | 95 |
| 96 static base::FilePath MakeCopyOfDownloadFile( |
| 97 DownloadFile* download_file) { |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 99 base::FilePath temp_file_path; |
| 100 if(base::CreateTemporaryFile(&temp_file_path) && |
| 101 base::CopyFile(download_file->FullPath(), temp_file_path)) { |
| 102 return temp_file_path; |
| 103 } else { |
| 104 // Deletes the file at |temp_file_path|. |
| 105 if (!base::DirectoryExists(temp_file_path)) |
| 106 base::DeleteFile(temp_file_path, false); |
| 107 temp_file_path.clear(); |
| 108 return base::FilePath(); |
| 109 } |
| 110 } |
| 111 |
96 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { | 112 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { |
97 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 113 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
98 download_file->Cancel(); | 114 download_file->Cancel(); |
99 } | 115 } |
100 | 116 |
101 } // namespace | 117 } // namespace |
102 | 118 |
103 const uint32_t DownloadItem::kInvalidId = 0; | 119 const uint32_t DownloadItem::kInvalidId = 0; |
104 | 120 |
105 // The maximum number of attempts we will make to resume automatically. | 121 // The maximum number of attempts we will make to resume automatically. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); | 308 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); |
293 | 309 |
294 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download | 310 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download |
295 // may not be in a consistent state or around at all after | 311 // may not be in a consistent state or around at all after |
296 // invoking observers. http://crbug.com/586610 | 312 // invoking observers. http://crbug.com/586610 |
297 | 313 |
298 MaybeCompleteDownload(); | 314 MaybeCompleteDownload(); |
299 } | 315 } |
300 | 316 |
301 void DownloadItemImpl::StealDangerousDownload( | 317 void DownloadItemImpl::StealDangerousDownload( |
| 318 bool delete_file_afterward, |
302 const AcquireFileCallback& callback) { | 319 const AcquireFileCallback& callback) { |
303 DVLOG(20) << __func__ << "() download = " << DebugString(true); | 320 DVLOG(20) << __func__ << "() download = " << DebugString(true); |
304 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 321 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
305 DCHECK(IsDangerous()); | 322 DCHECK(IsDangerous()); |
| 323 DCHECK(AllDataSaved()); |
306 | 324 |
307 if (download_file_) { | 325 if (delete_file_afterward) { |
| 326 if (download_file_){ |
| 327 BrowserThread::PostTaskAndReplyWithResult( |
| 328 BrowserThread::FILE, |
| 329 FROM_HERE, |
| 330 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), |
| 331 callback); |
| 332 } else { |
| 333 callback.Run(current_path_); |
| 334 } |
| 335 current_path_.clear(); |
| 336 Remove(); |
| 337 // Download item has now been deleted. |
| 338 } else if (download_file_) { |
308 BrowserThread::PostTaskAndReplyWithResult( | 339 BrowserThread::PostTaskAndReplyWithResult( |
309 BrowserThread::FILE, | 340 BrowserThread::FILE, |
310 FROM_HERE, | 341 FROM_HERE, |
311 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), | 342 base::Bind(&MakeCopyOfDownloadFile, download_file_.get()), |
312 callback); | 343 callback); |
313 } else { | 344 } else { |
314 callback.Run(current_path_); | 345 callback.Run(current_path_); |
315 } | 346 } |
316 current_path_.clear(); | |
317 Remove(); | |
318 // We have now been deleted. | |
319 } | 347 } |
320 | 348 |
321 void DownloadItemImpl::Pause() { | 349 void DownloadItemImpl::Pause() { |
322 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 350 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
323 | 351 |
324 // Ignore irrelevant states. | 352 // Ignore irrelevant states. |
325 if (is_paused_) | 353 if (is_paused_) |
326 return; | 354 return; |
327 | 355 |
328 switch (state_) { | 356 switch (state_) { |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 // downloads. SavePackage always uses its own Finish() to mark downloads | 1396 // downloads. SavePackage always uses its own Finish() to mark downloads |
1369 // complete. | 1397 // complete. |
1370 void DownloadItemImpl::MaybeCompleteDownload() { | 1398 void DownloadItemImpl::MaybeCompleteDownload() { |
1371 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1399 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1372 DCHECK(!is_save_package_download_); | 1400 DCHECK(!is_save_package_download_); |
1373 | 1401 |
1374 if (!IsDownloadReadyForCompletion( | 1402 if (!IsDownloadReadyForCompletion( |
1375 base::Bind(&DownloadItemImpl::MaybeCompleteDownload, | 1403 base::Bind(&DownloadItemImpl::MaybeCompleteDownload, |
1376 weak_ptr_factory_.GetWeakPtr()))) | 1404 weak_ptr_factory_.GetWeakPtr()))) |
1377 return; | 1405 return; |
1378 | |
1379 // Confirm we're in the proper set of states to be here; have all data, have a | 1406 // Confirm we're in the proper set of states to be here; have all data, have a |
1380 // history handle, (validated or safe). | 1407 // history handle, (validated or safe). |
1381 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); | 1408 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); |
1382 DCHECK(!IsDangerous()); | 1409 DCHECK(!IsDangerous()); |
1383 DCHECK(all_data_saved_); | 1410 DCHECK(all_data_saved_); |
1384 | 1411 |
1385 OnDownloadCompleting(); | 1412 OnDownloadCompleting(); |
1386 } | 1413 } |
1387 | 1414 |
1388 // Called by MaybeCompleteDownload() when it has determined that the download | 1415 // Called by MaybeCompleteDownload() when it has determined that the download |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2093 case RESUME_MODE_USER_CONTINUE: | 2120 case RESUME_MODE_USER_CONTINUE: |
2094 return "USER_CONTINUE"; | 2121 return "USER_CONTINUE"; |
2095 case RESUME_MODE_USER_RESTART: | 2122 case RESUME_MODE_USER_RESTART: |
2096 return "USER_RESTART"; | 2123 return "USER_RESTART"; |
2097 } | 2124 } |
2098 NOTREACHED() << "Unknown resume mode " << mode; | 2125 NOTREACHED() << "Unknown resume mode " << mode; |
2099 return "unknown"; | 2126 return "unknown"; |
2100 } | 2127 } |
2101 | 2128 |
2102 } // namespace content | 2129 } // namespace content |
OLD | NEW |