diff options
author | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-02 15:11:22 +0000 |
---|---|---|
committer | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-02 15:11:22 +0000 |
commit | a4feef8f23c9aed533bcd8b35e594fe3cf300a23 (patch) | |
tree | 9ce681a0ae7b0a30d00b54cb8bccc3a3ad7562c6 /chrome/browser/download | |
parent | 5f945e0f45394453602083b22206acb4cde3db4f (diff) | |
download | chromium_src-a4feef8f23c9aed533bcd8b35e594fe3cf300a23.zip chromium_src-a4feef8f23c9aed533bcd8b35e594fe3cf300a23.tar.gz chromium_src-a4feef8f23c9aed533bcd8b35e594fe3cf300a23.tar.bz2 |
Port some more of chrome/ to Linux.
Original review: http://codereview.chromium.org/4247
Patch from Pawel Hajdan Jr.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2793 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/save_file.cc | 31 | ||||
-rw-r--r-- | chrome/browser/download/save_file.h | 4 | ||||
-rw-r--r-- | chrome/browser/download/save_types.h | 4 |
3 files changed, 22 insertions, 17 deletions
diff --git a/chrome/browser/download/save_file.cc b/chrome/browser/download/save_file.cc index b92edf2..cc6315c 100644 --- a/chrome/browser/download/save_file.cc +++ b/chrome/browser/download/save_file.cc @@ -4,12 +4,16 @@ #include "chrome/browser/download/save_file.h" +#include "base/basictypes.h" #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" +#include "base/string_util.h" #include "chrome/browser/download/save_types.h" +#if defined(OS_WIN) #include "chrome/common/win_util.h" #include "chrome/common/win_safe_util.h" +#endif SaveFile::SaveFile(const SaveFileCreateInfo* info) : info_(info), @@ -20,7 +24,7 @@ SaveFile::SaveFile(const SaveFileCreateInfo* info) DCHECK(info); DCHECK(info->path.empty()); if (file_util::CreateTemporaryFileName(&full_path_)) - Open(L"wb"); + Open("wb"); } SaveFile::~SaveFile() { @@ -30,7 +34,7 @@ SaveFile::~SaveFile() { // Return false indicate that we got disk error, save file manager will tell // SavePackage this error, then SavePackage will call its Cancel() method to // cancel whole save job. -bool SaveFile::AppendDataToFile(const char* data, int data_len) { +bool SaveFile::AppendDataToFile(const char* data, size_t data_len) { if (file_) { if (data_len == fwrite(data, 1, data_len, file_)) { bytes_so_far_ += data_len; @@ -49,7 +53,7 @@ void SaveFile::Cancel() { // If this job has been canceled, and it has created file, // We need to delete this created file. if (!full_path_.empty()) { - DeleteFile(full_path_.c_str()); + file_util::Delete(full_path_, false); } } @@ -60,19 +64,17 @@ bool SaveFile::Rename(const std::wstring& new_path) { DCHECK(!path_renamed()); // 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 the last parameter - // is FALSE and the new file already exists, the function overwrites the - // existing file and succeeds. - if (!CopyFile(full_path_.c_str(), new_path.c_str(), FALSE)) + // with the security that makes sense in the new path. + if (!file_util::CopyFile(full_path_, new_path)) return false; - DeleteFile(full_path_.c_str()); + file_util::Delete(full_path_, false); full_path_ = new_path; path_renamed_ = true; // Still in saving process, reopen the file. - if (in_progress_ && !Open(L"a+b")) + if (in_progress_ && !Open("a+b")) return false; return true; } @@ -84,20 +86,23 @@ void SaveFile::Finish() { void SaveFile::Close() { if (file_) { - fclose(file_); + file_util::CloseFile(file_); file_ = NULL; } } -bool SaveFile::Open(const wchar_t* open_mode) { +bool SaveFile::Open(const char* open_mode) { DCHECK(!full_path_.empty()); - if (_wfopen_s(&file_, full_path_.c_str(), open_mode)) { - file_ = NULL; + file_ = file_util::OpenFile(full_path_, open_mode); + if (!file_) { return false; } +#if defined(OS_WIN) // Sets the zone to tell Windows that this file comes from the Internet. // We ignore the return value because a failure is not fatal. + // TODO(port): Similarly mark on Mac. win_util::SetInternetZoneIdentifier(full_path_); +#endif return true; } diff --git a/chrome/browser/download/save_file.h b/chrome/browser/download/save_file.h index 3d5e06c..361e20c 100644 --- a/chrome/browser/download/save_file.h +++ b/chrome/browser/download/save_file.h @@ -24,7 +24,7 @@ class SaveFile { ~SaveFile(); // Write a new chunk of data to the file. Returns true on success. - bool AppendDataToFile(const char* data, int data_len); + bool AppendDataToFile(const char* data, size_t data_len); // Abort the saving job and automatically close the file. void Cancel(); @@ -53,7 +53,7 @@ class SaveFile { // based on creation information passed to it, and automatically closed in // the destructor. void Close(); - bool Open(const wchar_t* open_mode); + bool Open(const char* open_mode); scoped_ptr<const SaveFileCreateInfo> info_; diff --git a/chrome/browser/download/save_types.h b/chrome/browser/download/save_types.h index 1a8832c..624aaa6 100644 --- a/chrome/browser/download/save_types.h +++ b/chrome/browser/download/save_types.h @@ -35,11 +35,11 @@ struct SaveFileCreateInfo { : path(path), url(url), save_id(save_id), - save_source(save_source), render_process_id(-1), render_view_id(-1), request_id(-1), - total_bytes(0) { + total_bytes(0), + save_source(save_source) { } SaveFileCreateInfo() : save_id(-1) {} |