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 // Re-open the file if we were still using it. | 164 |
165 if (was_in_progress) | 165 // Re-open the file if we were still using it regardless of the interrupt |
166 rename_result = Open(); | 166 // reason. |
167 } | 167 DownloadInterruptReason open_result = DOWNLOAD_INTERRUPT_REASON_NONE; |
168 if (was_in_progress) | |
169 open_result = Open(); | |
168 | 170 |
169 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_RENAMED); | 171 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_RENAMED); |
170 return rename_result; | 172 return rename_result == DOWNLOAD_INTERRUPT_REASON_NONE ? open_result |
173 : rename_result; | |
Randy Smith (Not in Mondays)
2014/06/11 18:07:29
This feels a bit funny, though maybe it's ok. I'm
asanka
2014/06/12 20:02:37
The invariants are:
* full_path() always returns t
Randy Smith (Not in Mondays)
2014/06/12 22:10:30
Ah, that makes sense. Thanks for taking me throug
| |
171 } | 174 } |
172 | 175 |
173 void BaseFile::Detach() { | 176 void BaseFile::Detach() { |
174 detached_ = true; | 177 detached_ = true; |
175 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_DETACHED); | 178 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_DETACHED); |
176 } | 179 } |
177 | 180 |
178 void BaseFile::Cancel() { | 181 void BaseFile::Cancel() { |
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
180 DCHECK(!detached_); | 183 DCHECK(!detached_); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 bound_net_log_.AddEvent( | 322 bound_net_log_.AddEvent( |
320 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, | 323 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, |
321 base::Bind(&FileErrorNetLogCallback, operation, error)); | 324 base::Bind(&FileErrorNetLogCallback, operation, error)); |
322 return ConvertNetErrorToInterruptReason(error, DOWNLOAD_INTERRUPT_FROM_DISK); | 325 return ConvertNetErrorToInterruptReason(error, DOWNLOAD_INTERRUPT_FROM_DISK); |
323 } | 326 } |
324 | 327 |
325 DownloadInterruptReason BaseFile::LogSystemError( | 328 DownloadInterruptReason BaseFile::LogSystemError( |
326 const char* operation, | 329 const char* operation, |
327 logging::SystemErrorCode os_error) { | 330 logging::SystemErrorCode os_error) { |
328 // There's no direct conversion from a system error to an interrupt reason. | 331 // There's no direct conversion from a system error to an interrupt reason. |
329 net::Error net_error = net::MapSystemError(os_error); | 332 base::File::Error file_error = base::File::OSErrorToFileError(os_error); |
330 return LogInterruptReason( | 333 return LogInterruptReason( |
331 operation, os_error, | 334 operation, os_error, |
332 ConvertNetErrorToInterruptReason( | 335 ConvertFileErrorToInterruptReason(file_error)); |
333 net_error, DOWNLOAD_INTERRUPT_FROM_DISK)); | |
334 } | 336 } |
335 | 337 |
336 DownloadInterruptReason BaseFile::LogInterruptReason( | 338 DownloadInterruptReason BaseFile::LogInterruptReason( |
337 const char* operation, | 339 const char* operation, |
338 int os_error, | 340 int os_error, |
339 DownloadInterruptReason reason) { | 341 DownloadInterruptReason reason) { |
340 bound_net_log_.AddEvent( | 342 bound_net_log_.AddEvent( |
341 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, | 343 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, |
342 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); | 344 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); |
343 return reason; | 345 return reason; |
344 } | 346 } |
345 | 347 |
346 } // namespace content | 348 } // namespace content |
OLD | NEW |