OLD | NEW |
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/base_file.h" | 5 #include "content/browser/download/base_file.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 bound_net_log_.BeginEvent( | 152 bound_net_log_.BeginEvent( |
153 net::NetLog::TYPE_DOWNLOAD_FILE_RENAMED, | 153 net::NetLog::TYPE_DOWNLOAD_FILE_RENAMED, |
154 base::Bind(&FileRenamedNetLogCallback, &full_path_, &new_path)); | 154 base::Bind(&FileRenamedNetLogCallback, &full_path_, &new_path)); |
155 Close(); | 155 Close(); |
156 base::CreateDirectory(new_path.DirName()); | 156 base::CreateDirectory(new_path.DirName()); |
157 | 157 |
158 // A simple rename wouldn't work here since we want the file to have | 158 // A simple rename wouldn't work here since we want the file to have |
159 // permissions / security descriptors that makes sense in the new directory. | 159 // permissions / security descriptors that makes sense in the new directory. |
160 rename_result = MoveFileAndAdjustPermissions(new_path); | 160 rename_result = MoveFileAndAdjustPermissions(new_path); |
161 | 161 |
162 if (rename_result == DOWNLOAD_INTERRUPT_REASON_NONE) | 162 if (rename_result == DOWNLOAD_INTERRUPT_REASON_NONE) { |
163 full_path_ = new_path; | 163 full_path_ = new_path; |
164 | 164 // Re-open the file if we were still using it. |
165 // Re-open the file if we were still using it regardless of the interrupt | 165 if (was_in_progress) |
166 // reason. | 166 rename_result = Open(); |
167 DownloadInterruptReason open_result = DOWNLOAD_INTERRUPT_REASON_NONE; | 167 } |
168 if (was_in_progress) | |
169 open_result = Open(); | |
170 | 168 |
171 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_RENAMED); | 169 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_RENAMED); |
172 return rename_result == DOWNLOAD_INTERRUPT_REASON_NONE ? open_result | 170 return rename_result; |
173 : rename_result; | |
174 } | 171 } |
175 | 172 |
176 void BaseFile::Detach() { | 173 void BaseFile::Detach() { |
177 detached_ = true; | 174 detached_ = true; |
178 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_DETACHED); | 175 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_DETACHED); |
179 } | 176 } |
180 | 177 |
181 void BaseFile::Cancel() { | 178 void BaseFile::Cancel() { |
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
183 DCHECK(!detached_); | 180 DCHECK(!detached_); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 bound_net_log_.AddEvent( | 319 bound_net_log_.AddEvent( |
323 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, | 320 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, |
324 base::Bind(&FileErrorNetLogCallback, operation, error)); | 321 base::Bind(&FileErrorNetLogCallback, operation, error)); |
325 return ConvertNetErrorToInterruptReason(error, DOWNLOAD_INTERRUPT_FROM_DISK); | 322 return ConvertNetErrorToInterruptReason(error, DOWNLOAD_INTERRUPT_FROM_DISK); |
326 } | 323 } |
327 | 324 |
328 DownloadInterruptReason BaseFile::LogSystemError( | 325 DownloadInterruptReason BaseFile::LogSystemError( |
329 const char* operation, | 326 const char* operation, |
330 logging::SystemErrorCode os_error) { | 327 logging::SystemErrorCode os_error) { |
331 // There's no direct conversion from a system error to an interrupt reason. | 328 // There's no direct conversion from a system error to an interrupt reason. |
332 base::File::Error file_error = base::File::OSErrorToFileError(os_error); | 329 net::Error net_error = net::MapSystemError(os_error); |
333 return LogInterruptReason( | 330 return LogInterruptReason( |
334 operation, os_error, | 331 operation, os_error, |
335 ConvertFileErrorToInterruptReason(file_error)); | 332 ConvertNetErrorToInterruptReason( |
| 333 net_error, DOWNLOAD_INTERRUPT_FROM_DISK)); |
336 } | 334 } |
337 | 335 |
338 DownloadInterruptReason BaseFile::LogInterruptReason( | 336 DownloadInterruptReason BaseFile::LogInterruptReason( |
339 const char* operation, | 337 const char* operation, |
340 int os_error, | 338 int os_error, |
341 DownloadInterruptReason reason) { | 339 DownloadInterruptReason reason) { |
342 bound_net_log_.AddEvent( | 340 bound_net_log_.AddEvent( |
343 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, | 341 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, |
344 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); | 342 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); |
345 return reason; | 343 return reason; |
346 } | 344 } |
347 | 345 |
348 } // namespace content | 346 } // namespace content |
OLD | NEW |