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

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

Issue 10704052: Download filename determination refactor (3/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 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 3c9521d314180cf38803328d6e5e1da5d7dda4e0..2ae28fefd9515df2a1b503c113ee7a8b6b89da99 100644
--- a/content/browser/download/download_item_impl.cc
+++ b/content/browser/download/download_item_impl.cc
@@ -867,21 +867,35 @@ DownloadItem::TargetDisposition DownloadItemImpl::GetTargetDisposition() const {
return target_disposition_;
}
-void DownloadItemImpl::OnTargetPathDetermined(
+void DownloadItemImpl::OnDownloadTargetDetermined(
const FilePath& target_path,
TargetDisposition disposition,
- content::DownloadDangerType danger_type) {
+ content::DownloadDangerType danger_type,
+ const FilePath& intermediate_path) {
// TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
target_path_ = target_path;
target_disposition_ = disposition;
SetDangerType(danger_type);
-}
-void DownloadItemImpl::OnTargetPathSelected(const FilePath& target_path) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK_EQ(TARGET_DISPOSITION_PROMPT, target_disposition_);
- target_path_ = target_path;
+ // We want the intermediate and target paths to refer to the same directory so
+ // that they are both on the same device and subject to same
+ // space/permission/availability constraints.
+ DCHECK(intermediate_path.DirName() == target_path.DirName());
+
+ // Rename to intermediate name.
+ // TODO(asanka): Skip this rename if download->AllDataSaved() is true. This
+ // avoids a spurious rename when we can just rename to the final
+ // filename. Unnecessary renames may cause bugs like
+ // http://crbug.com/74187.
+ DownloadFileManager::RenameCompletionCallback callback =
+ base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName,
+ weak_ptr_factory_.GetWeakPtr());
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&DownloadFileManager::RenameDownloadFile,
+ delegate_->GetDownloadFileManager(), GetGlobalId(),
+ intermediate_path, false, callback));
}
void DownloadItemImpl::OnContentCheckCompleted(
@@ -892,19 +906,6 @@ void DownloadItemImpl::OnContentCheckCompleted(
SetDangerType(danger_type);
}
-void DownloadItemImpl::OnIntermediatePathDetermined(
- DownloadFileManager* file_manager,
- const FilePath& intermediate_path) {
- DownloadFileManager::RenameCompletionCallback callback =
- base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName,
- weak_ptr_factory_.GetWeakPtr());
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&DownloadFileManager::RenameDownloadFile,
- file_manager, GetGlobalId(), intermediate_path,
- false, callback));
-}
-
const FilePath& DownloadItemImpl::GetFullPath() const {
return current_path_;
}

Powered by Google App Engine
This is Rietveld 408576698