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

Unified Diff: content/browser/download/download_item_impl.cc

Issue 11366121: Split DownloadFile::Rename into RenameAndUniquify and RenameAndAnnotate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to LKGR. Created 8 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/download/download_item_impl.cc
diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc
index cb21ccb45e3588b62a8b82b3f53ff76674fbf4d5..f23248c8fade6294e60a5e5306e94e5c4ad92a60 100644
--- a/content/browser/download/download_item_impl.cc
+++ b/content/browser/download/download_item_impl.cc
@@ -99,11 +99,9 @@ class NullDownloadRequestHandle : public DownloadRequestHandleInterface {
// Wrapper around DownloadFile::Detach and DownloadFile::Cancel that
// takes ownership of the DownloadFile and hence implicitly destroys it
// at the end of the function.
-static void DownloadFileDetach(
- scoped_ptr<DownloadFile> download_file,
- const DownloadFile::DetachCompletionCallback& callback) {
+static void DownloadFileDetach(scoped_ptr<DownloadFile> download_file) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- download_file->Detach(callback);
+ download_file->Detach();
}
static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) {
@@ -1074,10 +1072,10 @@ void DownloadItemImpl::OnDownloadTargetDetermined(
weak_ptr_factory_.GetWeakPtr());
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
- base::Bind(&DownloadFile::Rename,
+ base::Bind(&DownloadFile::RenameAndUniquify,
// Safe because we control download file lifetime.
base::Unretained(download_file_.get()),
- intermediate_path, false, callback));
+ intermediate_path, callback));
}
void DownloadItemImpl::OnDownloadRenamedToIntermediateName(
@@ -1105,6 +1103,7 @@ void DownloadItemImpl::OnDownloadRenamedToIntermediateName(
// complete.
void DownloadItemImpl::MaybeCompleteDownload() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!is_save_package_download_);
if (!IsDownloadReadyForCompletion())
return;
@@ -1144,7 +1143,6 @@ void DownloadItemImpl::ReadyForDownloadCompletionDone() {
return;
VLOG(20) << __FUNCTION__ << "()"
- << " needs rename = " << NeedsRename()
<< " " << DebugString(true);
DCHECK(!GetTargetFilePath().empty());
DCHECK_NE(DANGEROUS, GetSafetyState());
@@ -1153,29 +1151,31 @@ void DownloadItemImpl::ReadyForDownloadCompletionDone() {
if (is_save_package_download_) {
// Avoid doing anything on the file thread; there's nothing we control
// there.
- OnDownloadFileReleased(DOWNLOAD_INTERRUPT_REASON_NONE);
+ // Strictly speaking, this skips giving the embedder a chance to open
+ // the download. But on a save package download, there's no real
+ // concept of opening.
+ Completed();
return;
}
DCHECK(download_file_.get());
- if (NeedsRename()) {
- DownloadFile::RenameCompletionCallback callback =
- base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName,
- weak_ptr_factory_.GetWeakPtr());
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&DownloadFile::Rename,
- base::Unretained(download_file_.get()),
- GetTargetFilePath(), true, callback));
- } else {
- ReleaseDownloadFile();
- }
+ // Unilaterally rename; even if it already has the right name,
+ // we need theannotation.
+ DownloadFile::RenameCompletionCallback callback =
+ base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName,
+ weak_ptr_factory_.GetWeakPtr());
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&DownloadFile::RenameAndAnnotate,
+ base::Unretained(download_file_.get()),
+ GetTargetFilePath(), callback));
}
void DownloadItemImpl::OnDownloadRenamedToFinalName(
DownloadInterruptReason reason,
const FilePath& full_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!is_save_package_download_);
// If a cancel or interrupt hit, we'll cancel the DownloadFile, which
// will result in deleting the file on the file thread. So we don't
@@ -1185,46 +1185,34 @@ void DownloadItemImpl::OnDownloadRenamedToFinalName(
VLOG(20) << __FUNCTION__ << "()"
<< " full_path = \"" << full_path.value() << "\""
- << " needed rename = " << NeedsRename()
<< " " << DebugString(false);
- DCHECK(NeedsRename());
if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) {
Interrupt(reason);
return;
}
- // full_path is now the current and target file path.
- DCHECK(!full_path.empty());
- target_path_ = full_path;
- SetFullPath(full_path);
- delegate_->DownloadRenamedToFinalName(this);
+ DCHECK(target_path_ == full_path);
- ReleaseDownloadFile();
-}
+ if (full_path != current_path_) {
+ // full_path is now the current and target file path.
+ DCHECK(!full_path.empty());
+ SetFullPath(full_path);
+ delegate_->DownloadRenamedToFinalName(this);
+ }
-void DownloadItemImpl::ReleaseDownloadFile() {
// Complete the download and release the DownloadFile.
- DCHECK(!is_save_package_download_);
DCHECK(download_file_.get());
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
- base::Bind(&DownloadFileDetach, base::Passed(download_file_.Pass()),
- base::Bind(&DownloadItemImpl::OnDownloadFileReleased,
- weak_ptr_factory_.GetWeakPtr())));
+ base::Bind(&DownloadFileDetach, base::Passed(download_file_.Pass())));
// We're not completely done with the download item yet, but at this
// point we're committed to complete the download. Cancels (or Interrupts,
// though it's not clear how they could happen) after this point will be
// ignored.
TransitionTo(COMPLETING_INTERNAL);
-}
-void DownloadItemImpl::OnDownloadFileReleased(DownloadInterruptReason reason) {
- if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) {
- Interrupt(reason);
- return;
- }
if (delegate_->ShouldOpenDownload(
this, base::Bind(&DownloadItemImpl::DelayedDownloadOpened,
weak_ptr_factory_.GetWeakPtr()))) {
@@ -1280,7 +1268,7 @@ void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) {
// interrupts to race with cancels.
// Whatever happens, the first one to hit the UI thread wins.
- if (state_ != IN_PROGRESS_INTERNAL && state_ != COMPLETING_INTERNAL)
+ if (state_ != IN_PROGRESS_INTERNAL)
return;
last_reason_ = reason;
@@ -1333,11 +1321,6 @@ bool DownloadItemImpl::IsDownloadReadyForCompletion() {
return true;
}
-bool DownloadItemImpl::NeedsRename() const {
- DCHECK(target_path_.DirName() == current_path_.DirName());
- return target_path_ != current_path_;
-}
-
void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) {
if (state_ == new_state)
return;
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_item_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698