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

Side by Side 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: Use a callback with DetermineDownloadTarget(). Created 8 years, 5 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 #include "content/browser/download/download_item_impl.h" 5 #include "content/browser/download/download_item_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 } 860 }
861 861
862 const FilePath& DownloadItemImpl::GetTargetFilePath() const { 862 const FilePath& DownloadItemImpl::GetTargetFilePath() const {
863 return target_path_; 863 return target_path_;
864 } 864 }
865 865
866 DownloadItem::TargetDisposition DownloadItemImpl::GetTargetDisposition() const { 866 DownloadItem::TargetDisposition DownloadItemImpl::GetTargetDisposition() const {
867 return target_disposition_; 867 return target_disposition_;
868 } 868 }
869 869
870 void DownloadItemImpl::OnTargetPathDetermined( 870 void DownloadItemImpl::OnDownloadTargetDetermined(
871 const FilePath& target_path, 871 const FilePath& target_path,
872 TargetDisposition disposition, 872 TargetDisposition disposition,
873 content::DownloadDangerType danger_type) { 873 content::DownloadDangerType danger_type,
874 const FilePath& intermediate_path) {
874 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 875 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 876 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
876 target_path_ = target_path; 877 target_path_ = target_path;
877 target_disposition_ = disposition; 878 target_disposition_ = disposition;
878 SetDangerType(danger_type); 879 SetDangerType(danger_type);
879 }
880 880
881 void DownloadItemImpl::OnTargetPathSelected(const FilePath& target_path) { 881 // We want the intermediate and target paths to refer to the same directory so
882 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 882 // that they are both on the same device and subject to same
883 DCHECK_EQ(TARGET_DISPOSITION_PROMPT, target_disposition_); 883 // space/permission/availability constraints.
884 target_path_ = target_path; 884 DCHECK(intermediate_path.DirName() == target_path.DirName());
885
886 // Rename to intermediate name.
887 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a
888 // spurious rename when we can just rename to the final
889 // filename. Unnecessary renames may cause bugs like
890 // http://crbug.com/74187.
891 DownloadFileManager::RenameCompletionCallback callback =
892 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName,
893 weak_ptr_factory_.GetWeakPtr());
894 BrowserThread::PostTask(
895 BrowserThread::FILE, FROM_HERE,
896 base::Bind(&DownloadFileManager::RenameDownloadFile,
897 delegate_->GetDownloadFileManager(), GetGlobalId(),
898 intermediate_path, false, callback));
885 } 899 }
886 900
887 void DownloadItemImpl::OnContentCheckCompleted( 901 void DownloadItemImpl::OnContentCheckCompleted(
888 content::DownloadDangerType danger_type) { 902 content::DownloadDangerType danger_type) {
889 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 903 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
890 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 904 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
891 DCHECK(AllDataSaved()); 905 DCHECK(AllDataSaved());
892 SetDangerType(danger_type); 906 SetDangerType(danger_type);
893 } 907 }
894 908
895 void DownloadItemImpl::OnIntermediatePathDetermined(
896 DownloadFileManager* file_manager,
897 const FilePath& intermediate_path) {
898 DownloadFileManager::RenameCompletionCallback callback =
899 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName,
900 weak_ptr_factory_.GetWeakPtr());
901 BrowserThread::PostTask(
902 BrowserThread::FILE, FROM_HERE,
903 base::Bind(&DownloadFileManager::RenameDownloadFile,
904 file_manager, GetGlobalId(), intermediate_path,
905 false, callback));
906 }
907
908 const FilePath& DownloadItemImpl::GetFullPath() const { 909 const FilePath& DownloadItemImpl::GetFullPath() const {
909 return current_path_; 910 return current_path_;
910 } 911 }
911 912
912 FilePath DownloadItemImpl::GetFileNameToReportUser() const { 913 FilePath DownloadItemImpl::GetFileNameToReportUser() const {
913 if (!display_name_.empty()) 914 if (!display_name_.empty())
914 return display_name_; 915 return display_name_;
915 return target_path_.BaseName(); 916 return target_path_.BaseName();
916 } 917 }
917 918
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 std::map<const void*, ExternalData*>::iterator it = 1187 std::map<const void*, ExternalData*>::iterator it =
1187 external_data_map_.find(key); 1188 external_data_map_.find(key);
1188 1189
1189 if (it == external_data_map_.end()) { 1190 if (it == external_data_map_.end()) {
1190 external_data_map_[key] = data; 1191 external_data_map_[key] = data;
1191 } else if (it->second != data) { 1192 } else if (it->second != data) {
1192 delete it->second; 1193 delete it->second;
1193 it->second = data; 1194 it->second = data;
1194 } 1195 }
1195 } 1196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698