Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

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

Issue 14947007: [Downloads] Allow acquiring dangerous download file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with r201622 Created 7 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 | Annotate | Revision Log
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that 68 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that
69 // takes ownership of the DownloadFile and hence implicitly destroys it 69 // takes ownership of the DownloadFile and hence implicitly destroys it
70 // at the end of the function. 70 // at the end of the function.
71 static void DownloadFileDetach(scoped_ptr<DownloadFile> download_file) { 71 static base::FilePath DownloadFileDetach(
72 scoped_ptr<DownloadFile> download_file) {
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
74 base::FilePath full_path = download_file->FullPath();
73 download_file->Detach(); 75 download_file->Detach();
76 return full_path;
74 } 77 }
75 78
76 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { 79 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
78 download_file->Cancel(); 81 download_file->Cancel();
79 } 82 }
80 83
81 bool IsDownloadResumptionEnabled() { 84 bool IsDownloadResumptionEnabled() {
82 return CommandLine::ForCurrentProcess()->HasSwitch( 85 return CommandLine::ForCurrentProcess()->HasSwitch(
83 switches::kEnableDownloadResumption); 86 switches::kEnableDownloadResumption);
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // (In the latter case the DownloadFile object will delete it on cancel.) 398 // (In the latter case the DownloadFile object will delete it on cancel.)
396 if (!current_path_.empty() && download_file_.get() == NULL) { 399 if (!current_path_.empty() && download_file_.get() == NULL) {
397 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 400 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
398 base::Bind(&DeleteDownloadedFile, current_path_)); 401 base::Bind(&DeleteDownloadedFile, current_path_));
399 current_path_.clear(); 402 current_path_.clear();
400 } 403 }
401 Remove(); 404 Remove();
402 // We have now been deleted. 405 // We have now been deleted.
403 } 406 }
404 407
408 void DownloadItemImpl::AcquireFileAndDeleteDownload(
409 const AcquireFileCallback& callback) {
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
411
412 if (download_file_) {
413 BrowserThread::PostTaskAndReplyWithResult(
414 BrowserThread::FILE,
415 FROM_HERE,
416 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)),
417 callback);
418 } else {
419 callback.Run(current_path_);
Randy Smith (Not in Mondays) 2013/05/23 13:56:43 Under what circumstances will we take this path?
asanka 2013/05/24 01:17:11 It could also be interrupted.
420 }
421 current_path_.clear();
422 Delete(DELETE_DUE_TO_USER_DISCARD);
423 }
424
405 void DownloadItemImpl::Remove() { 425 void DownloadItemImpl::Remove() {
406 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); 426 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
408 428
409 // Remove the intermediate file if we are removing an interrupted download. 429 // Remove the intermediate file if we are removing an interrupted download.
410 // Continuable interruptions leave the intermediate file around. However, the 430 // Continuable interruptions leave the intermediate file around. However, the
411 // intermediate file will be unusable if the download item is removed. 431 // intermediate file will be unusable if the download item is removed.
412 if (!current_path_.empty() && IsInterrupted() && !download_file_.get()) { 432 if (!current_path_.empty() && IsInterrupted() && !download_file_.get()) {
413 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 433 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
414 base::Bind(&DeleteDownloadedFile, current_path_)); 434 base::Bind(&DeleteDownloadedFile, current_path_));
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 1411
1392 if (destroy_file) { 1412 if (destroy_file) {
1393 BrowserThread::PostTask( 1413 BrowserThread::PostTask(
1394 BrowserThread::FILE, FROM_HERE, 1414 BrowserThread::FILE, FROM_HERE,
1395 // Will be deleted at end of task execution. 1415 // Will be deleted at end of task execution.
1396 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); 1416 base::Bind(&DownloadFileCancel, base::Passed(&download_file_)));
1397 // Avoid attempting to reuse the intermediate file by clearing out 1417 // Avoid attempting to reuse the intermediate file by clearing out
1398 // current_path_. 1418 // current_path_.
1399 current_path_.clear(); 1419 current_path_.clear();
1400 } else { 1420 } else {
1401 BrowserThread::PostTask( 1421 BrowserThread::PostTask(BrowserThread::FILE,
1402 BrowserThread::FILE, FROM_HERE, 1422 FROM_HERE,
1403 // Will be deleted at end of task execution. 1423 // Will be deleted at end of task execution.
Randy Smith (Not in Mondays) 2013/05/23 13:56:43 Could you move this comment down a line to make cl
asanka 2013/05/24 01:17:11 Done.
1404 base::Bind(&DownloadFileDetach, base::Passed(&download_file_))); 1424 base::Bind(base::IgnoreResult(&DownloadFileDetach),
1425 base::Passed(&download_file_)));
1405 } 1426 }
1406 // Don't accept any more messages from the DownloadFile, and null 1427 // Don't accept any more messages from the DownloadFile, and null
1407 // out any previous "all data received". This also breaks links to 1428 // out any previous "all data received". This also breaks links to
1408 // other entities we've given out weak pointers to. 1429 // other entities we've given out weak pointers to.
1409 weak_ptr_factory_.InvalidateWeakPtrs(); 1430 weak_ptr_factory_.InvalidateWeakPtrs();
1410 } 1431 }
1411 1432
1412 bool DownloadItemImpl::IsDownloadReadyForCompletion( 1433 bool DownloadItemImpl::IsDownloadReadyForCompletion(
1413 const base::Closure& state_change_notification) { 1434 const base::Closure& state_change_notification) {
1414 // If we don't have all the data, the download is not ready for 1435 // If we don't have all the data, the download is not ready for
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 case RESUME_MODE_USER_CONTINUE: 1699 case RESUME_MODE_USER_CONTINUE:
1679 return "USER_CONTINUE"; 1700 return "USER_CONTINUE";
1680 case RESUME_MODE_USER_RESTART: 1701 case RESUME_MODE_USER_RESTART:
1681 return "USER_RESTART"; 1702 return "USER_RESTART";
1682 } 1703 }
1683 NOTREACHED() << "Unknown resume mode " << mode; 1704 NOTREACHED() << "Unknown resume mode " << mode;
1684 return "unknown"; 1705 return "unknown";
1685 } 1706 }
1686 1707
1687 } // namespace content 1708 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698