summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/download_file.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/download/download_file.cc')
-rw-r--r--chrome/browser/download/download_file.cc39
1 files changed, 17 insertions, 22 deletions
diff --git a/chrome/browser/download/download_file.cc b/chrome/browser/download/download_file.cc
index b06be04..a33d34b 100644
--- a/chrome/browser/download/download_file.cc
+++ b/chrome/browser/download/download_file.cc
@@ -85,22 +85,22 @@ bool DownloadFile::AppendDataToFile(const char* data, int data_len) {
void DownloadFile::Cancel() {
Close();
- DeleteFile(full_path_.c_str());
+ file_util::Delete(full_path_, false);
}
// The UI has provided us with our finalized name.
-bool DownloadFile::Rename(const std::wstring& new_path) {
+bool DownloadFile::Rename(const FilePath& new_path) {
Close();
// We cannot rename because rename will keep the same security descriptor
// on the destination file. We want to recreate the security descriptor
// with the security that makes sense in the new path.
- if (!file_util::RenameFileAndResetSecurityDescriptor(full_path_.c_str(),
- new_path.c_str())) {
+ if (!file_util::RenameFileAndResetSecurityDescriptor(
+ full_path_.value().c_str(), new_path.value().c_str())) {
return false;
}
- DeleteFile(full_path_.c_str());
+ file_util::Delete(full_path_, false);
full_path_ = new_path;
path_renamed_ = true;
@@ -129,7 +129,7 @@ bool DownloadFile::Open(const char* open_mode) {
}
// Sets the Zone to tell Windows that this file comes from the internet.
// We ignore the return value because a failure is not fatal.
- win_util::SetInternetZoneIdentifier(full_path_);
+ win_util::SetInternetZoneIdentifier(full_path_.value());
return true;
}
@@ -512,22 +512,23 @@ void DownloadFileManager::OnDownloadUrl(const GURL& url,
// Open a download, or show it in a Windows Explorer window. We run on this
// thread to avoid blocking the UI with (potentially) slow Shell operations.
// TODO(paulg): File 'stat' operations.
-void DownloadFileManager::OnShowDownloadInShell(const std::wstring full_path) {
+void DownloadFileManager::OnShowDownloadInShell(const FilePath& full_path) {
DCHECK(MessageLoop::current() == file_loop_);
- win_util::ShowItemInFolder(full_path);
+ win_util::ShowItemInFolder(full_path.value());
}
// Launches the selected download using ShellExecute 'open' verb. If there is
// a valid parent window, the 'safer' version will be used which can
// display a modal dialog asking for user consent on dangerous files.
-void DownloadFileManager::OnOpenDownloadInShell(const std::wstring full_path,
+void DownloadFileManager::OnOpenDownloadInShell(const FilePath& full_path,
const std::wstring& url,
HWND parent_window) {
DCHECK(MessageLoop::current() == file_loop_);
if (NULL != parent_window) {
- win_util::SaferOpenItemViaShell(parent_window, L"", full_path, url, true);
+ win_util::SaferOpenItemViaShell(parent_window, L"", full_path.value(),
+ url, true);
} else {
- win_util::OpenItemViaShell(full_path, true);
+ win_util::OpenItemViaShell(full_path.value(), true);
}
}
@@ -535,15 +536,13 @@ void DownloadFileManager::OnOpenDownloadInShell(const std::wstring full_path,
// download specified by 'id'. Rename the in progress download, and remove it
// from our table if it has been completed or cancelled already.
void DownloadFileManager::OnFinalDownloadName(int id,
- const std::wstring& full_path) {
+ const FilePath& full_path) {
DCHECK(MessageLoop::current() == file_loop_);
DownloadFileMap::iterator it = downloads_.find(id);
if (it == downloads_.end())
return;
- std::wstring download_dir = file_util::GetDirectoryFromPath(full_path);
- if (!file_util::PathExists(download_dir))
- file_util::CreateDirectory(download_dir);
+ file_util::CreateDirectory(full_path.DirName());
DownloadFile* download = it->second;
if (!download->Rename(full_path)) {
@@ -576,13 +575,9 @@ void DownloadFileManager::OnFinalDownloadName(int id,
this, &DownloadFileManager::StopUpdateTimer));
}
-void DownloadFileManager::CreateDirectory(const std::wstring& directory) {
- if (!file_util::PathExists(directory))
- file_util::CreateDirectory(directory);
-}
-
-void DownloadFileManager::DeleteFile(const std::wstring& path) {
+// static
+void DownloadFileManager::DeleteFile(const FilePath& path) {
// Make sure we only delete files.
- if (file_util::PathExists(path) && !file_util::DirectoryExists(path))
+ if (!file_util::DirectoryExists(path))
file_util::Delete(path, false);
}