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

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

Issue 8413016: Replace NewRunnableMethod with Callback in DownloadItem. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "content/browser/download/download_item.h" 5 #include "content/browser/download/download_item.h"
6 6
7 #include <vector>
8
9 #include "base/bind.h"
7 #include "base/basictypes.h" 10 #include "base/basictypes.h"
8 #include "base/file_util.h" 11 #include "base/file_util.h"
9 #include "base/format_macros.h" 12 #include "base/format_macros.h"
10 #include "base/i18n/case_conversion.h" 13 #include "base/i18n/case_conversion.h"
11 #include "base/i18n/string_search.h" 14 #include "base/i18n/string_search.h"
12 #include "base/logging.h" 15 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
14 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
15 #include "base/timer.h" 18 #include "base/timer.h"
16 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 break; 502 break;
500 case DELETE_DUE_TO_BROWSER_SHUTDOWN: 503 case DELETE_DUE_TO_BROWSER_SHUTDOWN:
501 UMA_HISTOGRAM_ENUMERATION("Download.Discard", GetDangerType(), 504 UMA_HISTOGRAM_ENUMERATION("Download.Discard", GetDangerType(),
502 DANGEROUS_TYPE_MAX); 505 DANGEROUS_TYPE_MAX);
503 break; 506 break;
504 default: 507 default:
505 NOTREACHED(); 508 NOTREACHED();
506 } 509 }
507 510
508 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 511 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
509 NewRunnableFunction(&DeleteDownloadedFile, full_path_)); 512 base::Bind(&DeleteDownloadedFile, full_path_));
510 Remove(); 513 Remove();
511 // We have now been deleted. 514 // We have now been deleted.
512 } 515 }
513 516
514 void DownloadItem::Remove() { 517 void DownloadItem::Remove() {
515 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 518 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
516 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 519 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
517 520
518 download_manager_->AssertQueueStateConsistent(this); 521 download_manager_->AssertQueueStateConsistent(this);
519 Cancel(true); 522 Cancel(true);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 591 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
589 592
590 VLOG(20) << __FUNCTION__ << "()" 593 VLOG(20) << __FUNCTION__ << "()"
591 << " needs rename = " << NeedsRename() 594 << " needs rename = " << NeedsRename()
592 << " " << DebugString(true); 595 << " " << DebugString(true);
593 DCHECK_NE(DANGEROUS, safety_state()); 596 DCHECK_NE(DANGEROUS, safety_state());
594 DCHECK(file_manager); 597 DCHECK(file_manager);
595 598
596 if (NeedsRename()) { 599 if (NeedsRename()) {
597 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 600 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
598 NewRunnableMethod(file_manager, 601 base::Bind(&DownloadFileManager::RenameCompletingDownloadFile,
599 &DownloadFileManager::RenameCompletingDownloadFile, global_id(), 602 file_manager, global_id(),
600 GetTargetFilePath(), safety_state() == SAFE)); 603 GetTargetFilePath(), safety_state() == SAFE));
601 return; 604 return;
602 } 605 }
603 606
604 Completed(); 607 Completed();
605 608
606 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, NewRunnableMethod( 609 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
607 file_manager, &DownloadFileManager::CompleteDownload, global_id())); 610 base::Bind(&DownloadFileManager::CompleteDownload,
611 file_manager, global_id()));
608 } 612 }
609 613
610 void DownloadItem::OnDownloadRenamedToFinalName(const FilePath& full_path) { 614 void DownloadItem::OnDownloadRenamedToFinalName(const FilePath& full_path) {
611 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 615 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
612 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 616 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
613 617
614 VLOG(20) << __FUNCTION__ << "()" 618 VLOG(20) << __FUNCTION__ << "()"
615 << " full_path = \"" << full_path.value() << "\"" 619 << " full_path = \"" << full_path.value() << "\""
616 << " needed rename = " << NeedsRename() 620 << " needed rename = " << NeedsRename()
617 << " " << DebugString(false); 621 << " " << DebugString(false);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 721
718 FilePath DownloadItem::GetUserVerifiedFilePath() const { 722 FilePath DownloadItem::GetUserVerifiedFilePath() const {
719 return (safety_state_ == DownloadItem::SAFE) ? 723 return (safety_state_ == DownloadItem::SAFE) ?
720 GetTargetFilePath() : full_path_; 724 GetTargetFilePath() : full_path_;
721 } 725 }
722 726
723 void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) { 727 void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) {
724 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
725 request_handle_.CancelRequest(); 729 request_handle_.CancelRequest();
726 730
727 BrowserThread::PostTask( 731 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
728 BrowserThread::FILE, FROM_HERE, 732 base::Bind(&DownloadFileManager::CancelDownload,
729 NewRunnableMethod( 733 file_manager, global_id()));
730 file_manager, &DownloadFileManager::CancelDownload, global_id()));
731 } 734 }
732 735
733 void DownloadItem::Init(bool active) { 736 void DownloadItem::Init(bool active) {
734 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 737 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
735 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 738 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
736 739
737 UpdateTarget(); 740 UpdateTarget();
738 if (active) { 741 if (active) {
739 StartProgressTimer(); 742 StartProgressTimer();
740 download_stats::RecordDownloadCount(download_stats::START_COUNT); 743 download_stats::RecordDownloadCount(download_stats::START_COUNT);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 state_info_.target_name.value().c_str(), 815 state_info_.target_name.value().c_str(),
813 full_path().value().c_str()); 816 full_path().value().c_str());
814 } else { 817 } else {
815 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 818 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
816 } 819 }
817 820
818 description += " }"; 821 description += " }";
819 822
820 return description; 823 return description;
821 } 824 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698