| 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 <windows.h> | 7 #include <windows.h> |
| 8 #include <cguid.h> | 8 #include <cguid.h> |
| 9 #include <objbase.h> | 9 #include <objbase.h> |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| 11 | 11 |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/files/file.h" | |
| 14 #include "base/guid.h" | 13 #include "base/guid.h" |
| 15 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 18 #include "content/browser/download/download_interrupt_reasons_impl.h" | 17 #include "content/browser/download/download_interrupt_reasons_impl.h" |
| 19 #include "content/browser/download/download_stats.h" | 18 #include "content/browser/download/download_stats.h" |
| 20 #include "content/browser/safe_util_win.h" | 19 #include "content/browser/safe_util_win.h" |
| 21 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 22 | 21 |
| 23 namespace content { | 22 namespace content { |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 const int kAllSpecialShFileOperationCodes[] = { | 25 const int kAllSpecialShFileOperationCodes[] = { |
| 27 // Should be kept in sync with the case statement below. | 26 // Should be kept in sync with the case statement below. |
| 28 ERROR_ACCESS_DENIED, | 27 ERROR_ACCESS_DENIED, |
| 29 ERROR_SHARING_VIOLATION, | |
| 30 ERROR_INVALID_PARAMETER, | |
| 31 0x71, | 28 0x71, |
| 32 0x72, | 29 0x72, |
| 33 0x73, | 30 0x73, |
| 34 0x74, | 31 0x74, |
| 35 0x75, | 32 0x75, |
| 36 0x76, | 33 0x76, |
| 37 0x78, | 34 0x78, |
| 38 0x79, | 35 0x79, |
| 39 0x7A, | 36 0x7A, |
| 40 0x7C, | 37 0x7C, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 65 // See http://msdn.microsoft.com/en-us/library/bb762164(VS.85).aspx. | 62 // See http://msdn.microsoft.com/en-us/library/bb762164(VS.85).aspx. |
| 66 DownloadInterruptReason MapShFileOperationCodes(int code) { | 63 DownloadInterruptReason MapShFileOperationCodes(int code) { |
| 67 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; | 64 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 68 | 65 |
| 69 // Check these pre-Win32 error codes first, then check for matches | 66 // Check these pre-Win32 error codes first, then check for matches |
| 70 // in Winerror.h. | 67 // in Winerror.h. |
| 71 // This switch statement should be kept in sync with the list of codes | 68 // This switch statement should be kept in sync with the list of codes |
| 72 // above. | 69 // above. |
| 73 switch (code) { | 70 switch (code) { |
| 74 // Not a pre-Win32 error code; here so that this particular | 71 // Not a pre-Win32 error code; here so that this particular |
| 75 // case shows up in our histograms. | 72 // case shows up in our histograms. This is redundant with the |
| 73 // mapping function net::MapSystemError used later. |
| 76 case ERROR_ACCESS_DENIED: // Access is denied. | 74 case ERROR_ACCESS_DENIED: // Access is denied. |
| 77 result = DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR; | 75 result = DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED; |
| 78 break; | |
| 79 | |
| 80 // This isn't documented but returned from SHFileOperation. Sharing | |
| 81 // violations indicate that another process had the file open while we were | |
| 82 // trying to rename. Anti-virus is believed to be the cause of this error in | |
| 83 // the wild. Treated as a transient error on the assumption that the file | |
| 84 // will be made available for renaming at a later time. | |
| 85 case ERROR_SHARING_VIOLATION: | |
| 86 result = DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR; | |
| 87 break; | |
| 88 | |
| 89 // This is also not a documented return value of SHFileOperation, but has | |
| 90 // been observed in the wild. We are treating it as a transient error based | |
| 91 // on the cases we have seen so far. See http://crbug.com/368455. | |
| 92 case ERROR_INVALID_PARAMETER: | |
| 93 result = DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR; | |
| 94 break; | 76 break; |
| 95 | 77 |
| 96 // The source and destination files are the same file. | 78 // The source and destination files are the same file. |
| 97 // DE_SAMEFILE == 0x71 | 79 // DE_SAMEFILE == 0x71 |
| 98 case 0x71: | 80 case 0x71: |
| 99 result = DOWNLOAD_INTERRUPT_REASON_FILE_FAILED; | 81 result = DOWNLOAD_INTERRUPT_REASON_FILE_FAILED; |
| 100 break; | 82 break; |
| 101 | 83 |
| 102 // The operation was canceled by the user, or silently canceled if the | 84 // The operation was canceled by the user, or silently canceled if the |
| 103 // appropriate flags were supplied to SHFileOperation. | 85 // appropriate flags were supplied to SHFileOperation. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 } | 243 } |
| 262 | 244 |
| 263 if (result == DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED) { | 245 if (result == DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED) { |
| 264 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | 246 UMA_HISTOGRAM_CUSTOM_ENUMERATION( |
| 265 "Download.MapWinShErrorAccessDenied", code, | 247 "Download.MapWinShErrorAccessDenied", code, |
| 266 base::CustomHistogram::ArrayToCustomRanges( | 248 base::CustomHistogram::ArrayToCustomRanges( |
| 267 kAllSpecialShFileOperationCodes, | 249 kAllSpecialShFileOperationCodes, |
| 268 arraysize(kAllSpecialShFileOperationCodes))); | 250 arraysize(kAllSpecialShFileOperationCodes))); |
| 269 } | 251 } |
| 270 | 252 |
| 271 if (result == DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR) { | |
| 272 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | |
| 273 "Download.MapWinShErrorTransientError", code, | |
| 274 base::CustomHistogram::ArrayToCustomRanges( | |
| 275 kAllSpecialShFileOperationCodes, | |
| 276 arraysize(kAllSpecialShFileOperationCodes))); | |
| 277 } | |
| 278 | |
| 279 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) | 253 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) |
| 280 return result; | 254 return result; |
| 281 | 255 |
| 282 // If not one of the above codes, it should be a standard Windows error code. | 256 // If not one of the above codes, it should be a standard Windows error code. |
| 283 return ConvertFileErrorToInterruptReason( | 257 return ConvertNetErrorToInterruptReason( |
| 284 base::File::OSErrorToFileError(code)); | 258 net::MapSystemError(code), DOWNLOAD_INTERRUPT_FROM_DISK); |
| 285 } | 259 } |
| 286 | 260 |
| 287 // Maps a return code from ScanAndSaveDownloadedFile() to a | 261 // Maps a return code from ScanAndSaveDownloadedFile() to a |
| 288 // DownloadInterruptReason. The return code in |result| is usually from the | 262 // DownloadInterruptReason. The return code in |result| is usually from the |
| 289 // final IAttachmentExecute::Save() call. | 263 // final IAttachmentExecute::Save() call. |
| 290 DownloadInterruptReason MapScanAndSaveErrorCodeToInterruptReason( | 264 DownloadInterruptReason MapScanAndSaveErrorCodeToInterruptReason( |
| 291 HRESULT result) { | 265 HRESULT result) { |
| 292 if (SUCCEEDED(result)) | 266 if (SUCCEEDED(result)) |
| 293 return DOWNLOAD_INTERRUPT_REASON_NONE; | 267 return DOWNLOAD_INTERRUPT_REASON_NONE; |
| 294 | 268 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 RecordDownloadCount(FILE_MISSING_AFTER_SUCCESSFUL_SCAN_COUNT); | 358 RecordDownloadCount(FILE_MISSING_AFTER_SUCCESSFUL_SCAN_COUNT); |
| 385 result = DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED; | 359 result = DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED; |
| 386 } | 360 } |
| 387 LogInterruptReason("ScanAndSaveDownloadedFile", hr, result); | 361 LogInterruptReason("ScanAndSaveDownloadedFile", hr, result); |
| 388 } | 362 } |
| 389 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); | 363 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); |
| 390 return result; | 364 return result; |
| 391 } | 365 } |
| 392 | 366 |
| 393 } // namespace content | 367 } // namespace content |
| OLD | NEW |