| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/download/download_file.h" | 5 #include "chrome/browser/download/download_file.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void DownloadFile::Cancel() { | 86 void DownloadFile::Cancel() { |
| 87 Close(); | 87 Close(); |
| 88 file_util::Delete(full_path_, false); | 88 file_util::Delete(full_path_, false); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // The UI has provided us with our finalized name. | 91 // The UI has provided us with our finalized name. |
| 92 bool DownloadFile::Rename(const FilePath& new_path) { | 92 bool DownloadFile::Rename(const FilePath& new_path) { |
| 93 #if defined(OS_WIN) | |
| 94 Close(); | 93 Close(); |
| 95 | 94 |
| 95 #if defined(OS_WIN) |
| 96 // We cannot rename because rename will keep the same security descriptor | 96 // We cannot rename because rename will keep the same security descriptor |
| 97 // on the destination file. We want to recreate the security descriptor | 97 // on the destination file. We want to recreate the security descriptor |
| 98 // with the security that makes sense in the new path. | 98 // with the security that makes sense in the new path. |
| 99 if (!file_util::RenameFileAndResetSecurityDescriptor(full_path_, new_path)) { | 99 if (!file_util::RenameFileAndResetSecurityDescriptor(full_path_, new_path)) |
| 100 return false; | 100 return false; |
| 101 } | 101 // TODO(estade): is this necessary? |
| 102 | |
| 103 file_util::Delete(full_path_, false); | 102 file_util::Delete(full_path_, false); |
| 103 #elif defined(OS_POSIX) |
| 104 // TODO(estade): Move() falls back to copying and deleting when a simple |
| 105 // rename fails. Copying sucks for large downloads. crbug.com/8737 |
| 106 if (!file_util::Move(full_path_, new_path)) |
| 107 return false; |
| 108 #endif |
| 104 | 109 |
| 105 full_path_ = new_path; | 110 full_path_ = new_path; |
| 106 path_renamed_ = true; | 111 path_renamed_ = true; |
| 107 | 112 |
| 108 // We don't need to re-open the file if we're done (finished or canceled). | 113 // We don't need to re-open the file if we're done (finished or canceled). |
| 109 if (!in_progress_) | 114 if (!in_progress_) |
| 110 return true; | 115 return true; |
| 111 | 116 |
| 112 if (!Open("a+b")) | 117 if (!Open("a+b")) |
| 113 return false; | 118 return false; |
| 114 return true; | 119 return true; |
| 115 #elif defined(OS_POSIX) | |
| 116 // TODO(port): Port this function to posix (we need file_util::Rename()). | |
| 117 NOTIMPLEMENTED(); | |
| 118 return false; | |
| 119 #endif | |
| 120 } | 120 } |
| 121 | 121 |
| 122 void DownloadFile::Close() { | 122 void DownloadFile::Close() { |
| 123 if (file_) { | 123 if (file_) { |
| 124 file_util::CloseFile(file_); | 124 file_util::CloseFile(file_); |
| 125 file_ = NULL; | 125 file_ = NULL; |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool DownloadFile::Open(const char* open_mode) { | 129 bool DownloadFile::Open(const char* open_mode) { |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 595 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 596 this, &DownloadFileManager::StopUpdateTimer)); | 596 this, &DownloadFileManager::StopUpdateTimer)); |
| 597 } | 597 } |
| 598 | 598 |
| 599 // static | 599 // static |
| 600 void DownloadFileManager::DeleteFile(const FilePath& path) { | 600 void DownloadFileManager::DeleteFile(const FilePath& path) { |
| 601 // Make sure we only delete files. | 601 // Make sure we only delete files. |
| 602 if (!file_util::DirectoryExists(path)) | 602 if (!file_util::DirectoryExists(path)) |
| 603 file_util::Delete(path, false); | 603 file_util::Delete(path, false); |
| 604 } | 604 } |
| OLD | NEW |