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
3 // found in the LICENSE file.
5 #include "content/browser/download/download_interrupt_reasons_impl.h"
7 #include "base/logging.h"
11 DownloadInterruptReason
ConvertFileErrorToInterruptReason(
12 base::File::Error file_error
) {
14 case base::File::FILE_OK
:
15 return DOWNLOAD_INTERRUPT_REASON_NONE
;
17 case base::File::FILE_ERROR_IN_USE
:
18 return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR
;
20 case base::File::FILE_ERROR_ACCESS_DENIED
:
21 return DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED
;
23 case base::File::FILE_ERROR_TOO_MANY_OPENED
:
24 return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR
;
26 case base::File::FILE_ERROR_NO_MEMORY
:
27 return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR
;
29 case base::File::FILE_ERROR_NO_SPACE
:
30 return DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE
;
32 case base::File::FILE_ERROR_SECURITY
:
33 return DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED
;
36 return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED
;
40 DownloadInterruptReason
ConvertNetErrorToInterruptReason(
41 net::Error net_error
, DownloadInterruptSource source
) {
44 return DOWNLOAD_INTERRUPT_REASON_NONE
;
48 // The file is too large.
49 case net::ERR_FILE_TOO_BIG
:
50 return DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE
;
52 // Permission to access a resource, other than the network, was denied.
53 case net::ERR_ACCESS_DENIED
:
54 return DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED
;
56 // There were not enough resources to complete the operation.
57 case net::ERR_INSUFFICIENT_RESOURCES
:
58 return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR
;
60 // Memory allocation failed.
61 case net::ERR_OUT_OF_MEMORY
:
62 return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR
;
64 // The path or file name is too long.
65 case net::ERR_FILE_PATH_TOO_LONG
:
66 return DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG
;
68 // Not enough room left on the disk.
69 case net::ERR_FILE_NO_SPACE
:
70 return DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE
;
72 // The file has a virus.
73 case net::ERR_FILE_VIRUS_INFECTED
:
74 return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED
;
76 // The file was blocked by local policy.
77 case net::ERR_BLOCKED_BY_CLIENT
:
78 return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED
;
82 // The network operation timed out.
83 case net::ERR_TIMED_OUT
:
84 return DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT
;
86 // The network connection has been lost.
87 case net::ERR_INTERNET_DISCONNECTED
:
88 return DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED
;
90 // The server has gone down.
91 case net::ERR_CONNECTION_FAILED
:
92 return DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN
;
96 // The server does not support range requests.
97 case net::ERR_REQUEST_RANGE_NOT_SATISFIABLE
:
98 return DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE
;
103 // Handle errors that don't have mappings, depending on the source.
105 case DOWNLOAD_INTERRUPT_FROM_DISK
:
106 return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED
;
107 case DOWNLOAD_INTERRUPT_FROM_NETWORK
:
108 return DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED
;
109 case DOWNLOAD_INTERRUPT_FROM_SERVER
:
110 return DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED
;
117 return DOWNLOAD_INTERRUPT_REASON_NONE
;
120 std::string
DownloadInterruptReasonToString(DownloadInterruptReason error
) {
122 #define INTERRUPT_REASON(name, value) \
123 case DOWNLOAD_INTERRUPT_REASON_##name: return #name;
126 INTERRUPT_REASON(NONE
, 0)
128 #include "content/public/browser/download_interrupt_reason_values.h"
134 #undef INTERRUPT_REASON
136 return "Unknown error";
139 } // namespace content