Home | History | Annotate | Download | only in download
      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.
      4 
      5 #include "content/browser/download/download_interrupt_reasons_impl.h"
      6 
      7 #include "base/logging.h"
      8 
      9 namespace content {
     10 
     11 DownloadInterruptReason ConvertNetErrorToInterruptReason(
     12     net::Error net_error, DownloadInterruptSource source) {
     13   switch (net_error) {
     14     case net::OK:
     15       return DOWNLOAD_INTERRUPT_REASON_NONE;
     16 
     17     // File errors.
     18 
     19     // The file is too large.
     20     case net::ERR_FILE_TOO_BIG:
     21       return DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE;
     22 
     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;
     26 
     27     // There were not enough resources to complete the operation.
     28     case net::ERR_INSUFFICIENT_RESOURCES:
     29       return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR;
     30 
     31     // Memory allocation failed.
     32     case net::ERR_OUT_OF_MEMORY:
     33       return DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR;
     34 
     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;
     38 
     39     // Not enough room left on the disk.
     40     case net::ERR_FILE_NO_SPACE:
     41       return DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE;
     42 
     43     // The file has a virus.
     44     case net::ERR_FILE_VIRUS_INFECTED:
     45       return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED;
     46 
     47     // The file was blocked by local policy.
     48     case net::ERR_BLOCKED_BY_CLIENT:
     49       return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED;
     50 
     51     // Network errors.
     52 
     53     // The network operation timed out.
     54     case net::ERR_TIMED_OUT:
     55       return DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT;
     56 
     57     // The network connection has been lost.
     58     case net::ERR_INTERNET_DISCONNECTED:
     59       return DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED;
     60 
     61     // The server has gone down.
     62     case net::ERR_CONNECTION_FAILED:
     63       return DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN;
     64 
     65     // Server responses.
     66 
     67     // The server does not support range requests.
     68     case net::ERR_REQUEST_RANGE_NOT_SATISFIABLE:
     69       return DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE;
     70 
     71     default: break;
     72   }
     73 
     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;
     84   }
     85 
     86   NOTREACHED();
     87 
     88   return DOWNLOAD_INTERRUPT_REASON_NONE;
     89 }
     90 
     91 std::string DownloadInterruptReasonToString(DownloadInterruptReason error) {
     92 
     93 #define INTERRUPT_REASON(name, value)  \
     94     case DOWNLOAD_INTERRUPT_REASON_##name: return #name;
     95 
     96   switch (error) {
     97     INTERRUPT_REASON(NONE, 0)
     98 
     99 #include "content/public/browser/download_interrupt_reason_values.h"
    100 
    101     default:
    102       break;
    103   }
    104 
    105 #undef INTERRUPT_REASON
    106 
    107   return "Unknown error";
    108 }
    109 
    110 }  // namespace content
    111