Home | History | Annotate | Download | only in host
      1 // Copyright 2013 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 "ppapi/host/error_conversion.h"
      6 
      7 #include "base/safe_numerics.h"
      8 #include "net/base/net_errors.h"
      9 #include "ppapi/c/pp_errors.h"
     10 
     11 namespace ppapi {
     12 namespace host {
     13 
     14 int32_t NetErrorToPepperError(int net_error) {
     15   if (net_error > 0)
     16     return base::checked_numeric_cast<int32_t>(net_error);
     17 
     18   switch (net_error) {
     19     case net::OK:
     20       return PP_OK;
     21     case net::ERR_IO_PENDING:
     22       return PP_OK_COMPLETIONPENDING;
     23     case net::ERR_ABORTED:
     24       return PP_ERROR_ABORTED;
     25     case net::ERR_INVALID_ARGUMENT:
     26       return PP_ERROR_BADARGUMENT;
     27     case net::ERR_INVALID_HANDLE:
     28       return PP_ERROR_BADARGUMENT;
     29     case net::ERR_FILE_NOT_FOUND:
     30       return PP_ERROR_FILENOTFOUND;
     31     case net::ERR_TIMED_OUT:
     32       return PP_ERROR_TIMEDOUT;
     33     case net::ERR_FILE_TOO_BIG:
     34       return PP_ERROR_FILETOOBIG;
     35     case net::ERR_ACCESS_DENIED:
     36       return PP_ERROR_NOACCESS;
     37     case net::ERR_NOT_IMPLEMENTED:
     38       return PP_ERROR_NOTSUPPORTED;
     39     case net::ERR_OUT_OF_MEMORY:
     40       return PP_ERROR_NOMEMORY;
     41     case net::ERR_FILE_EXISTS:
     42       return PP_ERROR_FILEEXISTS;
     43     case net::ERR_FILE_NO_SPACE:
     44       return PP_ERROR_NOSPACE;
     45     case net::ERR_CONNECTION_CLOSED:
     46       return PP_ERROR_CONNECTION_CLOSED;
     47     case net::ERR_CONNECTION_RESET:
     48       return PP_ERROR_CONNECTION_RESET;
     49     case net::ERR_CONNECTION_REFUSED:
     50       return PP_ERROR_CONNECTION_REFUSED;
     51     case net::ERR_CONNECTION_ABORTED:
     52       return PP_ERROR_CONNECTION_ABORTED;
     53     case net::ERR_CONNECTION_FAILED:
     54       return PP_ERROR_CONNECTION_FAILED;
     55     case net::ERR_NAME_NOT_RESOLVED:
     56       return PP_ERROR_NAME_NOT_RESOLVED;
     57     case net::ERR_ADDRESS_INVALID:
     58       return PP_ERROR_ADDRESS_INVALID;
     59     case net::ERR_ADDRESS_UNREACHABLE:
     60       return PP_ERROR_ADDRESS_UNREACHABLE;
     61     case net::ERR_CONNECTION_TIMED_OUT:
     62       return PP_ERROR_CONNECTION_TIMEDOUT;
     63     case net::ERR_NETWORK_ACCESS_DENIED:
     64       return PP_ERROR_NOACCESS;
     65     case net::ERR_MSG_TOO_BIG:
     66       return PP_ERROR_MESSAGE_TOO_BIG;
     67     case net::ERR_ADDRESS_IN_USE:
     68       return PP_ERROR_ADDRESS_IN_USE;
     69     default:
     70       return PP_ERROR_FAILED;
     71   }
     72 }
     73 
     74 }  // namespace host
     75 }  // namespace ppapi
     76