summaryrefslogtreecommitdiff
path: root/content/browser/download/download_interrupt_reasons_impl.cc
blob: 9a01f484f1deb8b68f5ec72aa8c8a5991754d444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/download/download_interrupt_reasons_impl.h"

#include "base/logging.h"

namespace content {

DownloadInterruptReason ConvertNetErrorToInterruptReason(
    net::Error net_error, DownloadInterruptSource source) {
  switch (net_error) {
    case net::OK:
      return DOWNLOAD_INTERRUPT_REASON_NONE;

    // File errors.

    // The file is too large.
    case net::ERR_FILE_TOO_BIG:
      return DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE;

    // Permission to access a resource, other than the network, was denied.
    case net::ERR_ACCESS_DENIED:
      return DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED;

    // There were not enough resources to complete the operation.
    case net::ERR_INSUFFICIENT_RESOURCES:
      return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR;

    // Memory allocation failed.
    case net::ERR_OUT_OF_MEMORY:
      return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR;

    // The path or file name is too long.
    case net::ERR_FILE_PATH_TOO_LONG:
      return DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG;

    // Not enough room left on the disk.
    case net::ERR_FILE_NO_SPACE:
      return DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE;

    // The file has a virus.
    case net::ERR_FILE_VIRUS_INFECTED:
      return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED;

    // The file was blocked by local policy.
    case net::ERR_BLOCKED_BY_CLIENT:
      return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED;

    // Network errors.

    // The network operation timed out.
    case net::ERR_TIMED_OUT:
      return DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT;

    // The network connection has been lost.
    case net::ERR_INTERNET_DISCONNECTED:
      return DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED;

    // The server has gone down.
    case net::ERR_CONNECTION_FAILED:
      return DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN;

    // Server responses.

    // The server does not support range requests.
    case net::ERR_REQUEST_RANGE_NOT_SATISFIABLE:
      return DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE;

    default: break;
  }

  // Handle errors that don't have mappings, depending on the source.
  switch (source) {
    case DOWNLOAD_INTERRUPT_FROM_DISK:
      return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED;
    case DOWNLOAD_INTERRUPT_FROM_NETWORK:
      return DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED;
    case DOWNLOAD_INTERRUPT_FROM_SERVER:
      return DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED;
    default:
      break;
  }

  NOTREACHED();

  return DOWNLOAD_INTERRUPT_REASON_NONE;
}

std::string DownloadInterruptReasonToString(DownloadInterruptReason error) {

#define INTERRUPT_REASON(name, value)  \
    case DOWNLOAD_INTERRUPT_REASON_##name: return #name;

  switch (error) {
    INTERRUPT_REASON(NONE, 0)

#include "content/public/browser/download_interrupt_reason_values.h"

    default:
      break;
  }

#undef INTERRUPT_REASON

  return "Unknown error";
}

}  // namespace content