Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / download / download_interrupt_reasons_impl.cc
blob9a01f484f1deb8b68f5ec72aa8c8a5991754d444
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"
9 namespace content {
11 DownloadInterruptReason ConvertNetErrorToInterruptReason(
12 net::Error net_error, DownloadInterruptSource source) {
13 switch (net_error) {
14 case net::OK:
15 return DOWNLOAD_INTERRUPT_REASON_NONE;
17 // File errors.
19 // The file is too large.
20 case net::ERR_FILE_TOO_BIG:
21 return DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE;
23 // Permission to access a resource, other than the network, was denied.
24 case net::ERR_ACCESS_DENIED:
25 return DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED;
27 // There were not enough resources to complete the operation.
28 case net::ERR_INSUFFICIENT_RESOURCES:
29 return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR;
31 // Memory allocation failed.
32 case net::ERR_OUT_OF_MEMORY:
33 return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR;
35 // The path or file name is too long.
36 case net::ERR_FILE_PATH_TOO_LONG:
37 return DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG;
39 // Not enough room left on the disk.
40 case net::ERR_FILE_NO_SPACE:
41 return DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE;
43 // The file has a virus.
44 case net::ERR_FILE_VIRUS_INFECTED:
45 return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED;
47 // The file was blocked by local policy.
48 case net::ERR_BLOCKED_BY_CLIENT:
49 return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED;
51 // Network errors.
53 // The network operation timed out.
54 case net::ERR_TIMED_OUT:
55 return DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT;
57 // The network connection has been lost.
58 case net::ERR_INTERNET_DISCONNECTED:
59 return DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED;
61 // The server has gone down.
62 case net::ERR_CONNECTION_FAILED:
63 return DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN;
65 // Server responses.
67 // The server does not support range requests.
68 case net::ERR_REQUEST_RANGE_NOT_SATISFIABLE:
69 return DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE;
71 default: break;
74 // Handle errors that don't have mappings, depending on the source.
75 switch (source) {
76 case DOWNLOAD_INTERRUPT_FROM_DISK:
77 return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED;
78 case DOWNLOAD_INTERRUPT_FROM_NETWORK:
79 return DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED;
80 case DOWNLOAD_INTERRUPT_FROM_SERVER:
81 return DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED;
82 default:
83 break;
86 NOTREACHED();
88 return DOWNLOAD_INTERRUPT_REASON_NONE;
91 std::string DownloadInterruptReasonToString(DownloadInterruptReason error) {
93 #define INTERRUPT_REASON(name, value) \
94 case DOWNLOAD_INTERRUPT_REASON_##name: return #name;
96 switch (error) {
97 INTERRUPT_REASON(NONE, 0)
99 #include "content/public/browser/download_interrupt_reason_values.h"
101 default:
102 break;
105 #undef INTERRUPT_REASON
107 return "Unknown error";
110 } // namespace content