| 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 <Windows.h> | 5 #include <Windows.h> |
| 6 #include <objbase.h> | 6 #include <objbase.h> |
| 7 | 7 |
| 8 #include "chrome/browser/download/download_file.h" | 8 #include "chrome/browser/download/download_file.h" |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 path_renamed_(false), | 60 path_renamed_(false), |
| 61 in_progress_(true) { | 61 in_progress_(true) { |
| 62 } | 62 } |
| 63 | 63 |
| 64 DownloadFile::~DownloadFile() { | 64 DownloadFile::~DownloadFile() { |
| 65 Close(); | 65 Close(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool DownloadFile::Initialize() { | 68 bool DownloadFile::Initialize() { |
| 69 if (file_util::CreateTemporaryFileName(&full_path_)) | 69 if (file_util::CreateTemporaryFileName(&full_path_)) |
| 70 return Open(L"wb"); | 70 return Open("wb"); |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // FIXME bug 595247: handle errors on file writes. | 74 // FIXME bug 595247: handle errors on file writes. |
| 75 bool DownloadFile::AppendDataToFile(const char* data, int data_len) { | 75 bool DownloadFile::AppendDataToFile(const char* data, int data_len) { |
| 76 if (file_) { | 76 if (file_) { |
| 77 fwrite(data, 1, data_len, file_); | 77 fwrite(data, 1, data_len, file_); |
| 78 bytes_so_far_ += data_len; | 78 bytes_so_far_ += data_len; |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 100 | 100 |
| 101 DeleteFile(full_path_.c_str()); | 101 DeleteFile(full_path_.c_str()); |
| 102 | 102 |
| 103 full_path_ = new_path; | 103 full_path_ = new_path; |
| 104 path_renamed_ = true; | 104 path_renamed_ = true; |
| 105 | 105 |
| 106 // We don't need to re-open the file if we're done (finished or canceled). | 106 // We don't need to re-open the file if we're done (finished or canceled). |
| 107 if (!in_progress_) | 107 if (!in_progress_) |
| 108 return true; | 108 return true; |
| 109 | 109 |
| 110 if (!Open(L"a+b")) | 110 if (!Open("a+b")) |
| 111 return false; | 111 return false; |
| 112 return true; | 112 return true; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void DownloadFile::Close() { | 115 void DownloadFile::Close() { |
| 116 if (file_) { | 116 if (file_) { |
| 117 fclose(file_); | 117 file_util::CloseFile(file_); |
| 118 file_ = NULL; | 118 file_ = NULL; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool DownloadFile::Open(const wchar_t* open_mode) { | 122 bool DownloadFile::Open(const char* open_mode) { |
| 123 DCHECK(!full_path_.empty()); | 123 DCHECK(!full_path_.empty()); |
| 124 if (_wfopen_s(&file_, full_path_.c_str(), open_mode)) { | 124 file_ = file_util::OpenFile(full_path_, open_mode); |
| 125 file_ = NULL; | 125 if (!file_) { |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 // Sets the Zone to tell Windows that this file comes from the internet. | 128 // Sets the Zone to tell Windows that this file comes from the internet. |
| 129 // We ignore the return value because a failure is not fatal. | 129 // We ignore the return value because a failure is not fatal. |
| 130 win_util::SetInternetZoneIdentifier(full_path_); | 130 win_util::SetInternetZoneIdentifier(full_path_); |
| 131 return true; | 131 return true; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // DownloadFileManager implementation ------------------------------------------ | 134 // DownloadFileManager implementation ------------------------------------------ |
| 135 | 135 |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 | 571 |
| 572 if (downloads_.empty()) | 572 if (downloads_.empty()) |
| 573 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 573 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 574 this, &DownloadFileManager::StopUpdateTimer)); | 574 this, &DownloadFileManager::StopUpdateTimer)); |
| 575 } | 575 } |
| 576 | 576 |
| 577 void DownloadFileManager::CreateDirectory(const std::wstring& directory) { | 577 void DownloadFileManager::CreateDirectory(const std::wstring& directory) { |
| 578 if (!file_util::PathExists(directory)) | 578 if (!file_util::PathExists(directory)) |
| 579 file_util::CreateDirectory(directory); | 579 file_util::CreateDirectory(directory); |
| 580 } | 580 } |
| OLD | NEW |