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

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: Rename methods for consistency 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 271
269 observers_.RemoveObserver(observer); 272 observers_.RemoveObserver(observer);
270 } 273 }
271 274
272 void DownloadItemImpl::UpdateObservers() { 275 void DownloadItemImpl::UpdateObservers() {
273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
274 277
275 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this)); 278 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this));
276 } 279 }
277 280
278 void DownloadItemImpl::DangerousDownloadValidated() { 281 void DownloadItemImpl::ValidateDangerousDownload() {
279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
280 DCHECK_EQ(IN_PROGRESS, GetState()); 283 DCHECK_EQ(IN_PROGRESS, GetState());
281 DCHECK(IsDangerous()); 284 DCHECK(IsDangerous());
282 285
283 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); 286 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
284 287
285 if (GetState() != IN_PROGRESS) 288 if (GetState() != IN_PROGRESS)
286 return; 289 return;
287 290
288 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated", 291 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated",
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 368
366 if (state_ == IN_PROGRESS_INTERNAL) { 369 if (state_ == IN_PROGRESS_INTERNAL) {
367 // Cancel the originating URL request unless it's already been cancelled 370 // Cancel the originating URL request unless it's already been cancelled
368 // by interrupt. 371 // by interrupt.
369 request_handle_->CancelRequest(); 372 request_handle_->CancelRequest();
370 } 373 }
371 374
372 TransitionTo(CANCELLED_INTERNAL); 375 TransitionTo(CANCELLED_INTERNAL);
373 } 376 }
374 377
375 void DownloadItemImpl::Delete(DeleteReason reason) { 378 void DownloadItemImpl::DiscardDangerousDownload(
379 DeleteReason reason,
380 const AcquireFileCallback& callback) {
376 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); 381 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
383 DCHECK(IsDangerous());
378 384
379 switch (reason) { 385 switch (reason) {
380 case DELETE_DUE_TO_USER_DISCARD: 386 case DELETE_DUE_TO_USER_DISCARD:
381 UMA_HISTOGRAM_ENUMERATION( 387 UMA_HISTOGRAM_ENUMERATION(
382 "Download.UserDiscard", GetDangerType(), 388 "Download.UserDiscard", GetDangerType(),
383 DOWNLOAD_DANGER_TYPE_MAX); 389 DOWNLOAD_DANGER_TYPE_MAX);
384 break; 390 break;
385 case DELETE_DUE_TO_BROWSER_SHUTDOWN: 391 case DELETE_DUE_TO_BROWSER_SHUTDOWN:
386 UMA_HISTOGRAM_ENUMERATION( 392 UMA_HISTOGRAM_ENUMERATION(
387 "Download.Discard", GetDangerType(), 393 "Download.Discard", GetDangerType(),
388 DOWNLOAD_DANGER_TYPE_MAX); 394 DOWNLOAD_DANGER_TYPE_MAX);
389 break; 395 break;
390 default: 396 default:
391 NOTREACHED(); 397 NOTREACHED();
392 } 398 }
393 399
400 if (!callback.is_null()) {
401 if (download_file_) {
402 BrowserThread::PostTaskAndReplyWithResult(
403 BrowserThread::FILE,
404 FROM_HERE,
405 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)),
406 callback);
407 } else {
408 callback.Run(current_path_);
409 }
410 current_path_.clear();
411 }
412
394 // Delete the file if it exists and is not owned by a DownloadFile object. 413 // Delete the file if it exists and is not owned by a DownloadFile object.
395 // (In the latter case the DownloadFile object will delete it on cancel.) 414 // (In the latter case the DownloadFile object will delete it on cancel.)
396 if (!current_path_.empty() && download_file_.get() == NULL) { 415 if (!current_path_.empty() && download_file_.get() == NULL) {
397 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 416 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
398 base::Bind(&DeleteDownloadedFile, current_path_)); 417 base::Bind(&DeleteDownloadedFile, current_path_));
399 current_path_.clear(); 418 current_path_.clear();
400 } 419 }
401 Remove(); 420 Remove();
402 // We have now been deleted. 421 // We have now been deleted.
403 } 422 }
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 1417
1399 if (destroy_file) { 1418 if (destroy_file) {
1400 BrowserThread::PostTask( 1419 BrowserThread::PostTask(
1401 BrowserThread::FILE, FROM_HERE, 1420 BrowserThread::FILE, FROM_HERE,
1402 // Will be deleted at end of task execution. 1421 // Will be deleted at end of task execution.
1403 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); 1422 base::Bind(&DownloadFileCancel, base::Passed(&download_file_)));
1404 // Avoid attempting to reuse the intermediate file by clearing out 1423 // Avoid attempting to reuse the intermediate file by clearing out
1405 // current_path_. 1424 // current_path_.
1406 current_path_.clear(); 1425 current_path_.clear();
1407 } else { 1426 } else {
1408 BrowserThread::PostTask( 1427 BrowserThread::PostTask(BrowserThread::FILE,
1409 BrowserThread::FILE, FROM_HERE, 1428 FROM_HERE,
1410 // Will be deleted at end of task execution. 1429 // Will be deleted at end of task execution.
1411 base::Bind(&DownloadFileDetach, base::Passed(&download_file_))); 1430 base::Bind(base::IgnoreResult(&DownloadFileDetach),
1431 base::Passed(&download_file_)));
1412 } 1432 }
1413 // Don't accept any more messages from the DownloadFile, and null 1433 // Don't accept any more messages from the DownloadFile, and null
1414 // out any previous "all data received". This also breaks links to 1434 // out any previous "all data received". This also breaks links to
1415 // other entities we've given out weak pointers to. 1435 // other entities we've given out weak pointers to.
1416 weak_ptr_factory_.InvalidateWeakPtrs(); 1436 weak_ptr_factory_.InvalidateWeakPtrs();
1417 } 1437 }
1418 1438
1419 bool DownloadItemImpl::IsDownloadReadyForCompletion( 1439 bool DownloadItemImpl::IsDownloadReadyForCompletion(
1420 const base::Closure& state_change_notification) { 1440 const base::Closure& state_change_notification) {
1421 // If we don't have all the data, the download is not ready for 1441 // 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
1685 case RESUME_MODE_USER_CONTINUE: 1705 case RESUME_MODE_USER_CONTINUE:
1686 return "USER_CONTINUE"; 1706 return "USER_CONTINUE";
1687 case RESUME_MODE_USER_RESTART: 1707 case RESUME_MODE_USER_RESTART:
1688 return "USER_RESTART"; 1708 return "USER_RESTART";
1689 } 1709 }
1690 NOTREACHED() << "Unknown resume mode " << mode; 1710 NOTREACHED() << "Unknown resume mode " << mode;
1691 return "unknown"; 1711 return "unknown";
1692 } 1712 }
1693 1713
1694 } // namespace content 1714 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698