Home | History | Annotate | Download | only in plugin
      1 /*
      2  * Copyright (c) 2011 The Chromium Authors. All rights reserved.
      3  * Use of this source code is governed by a BSD-style license that can be
      4  * found in the LICENSE file.
      5  */
      6 
      7 /*
      8  * Error codes and data structures used to report errors when loading a nexe.
      9  */
     10 
     11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_ERROR_H
     12 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_ERROR_H
     13 
     14 #include <string>
     15 
     16 #include "native_client/src/include/nacl_macros.h"
     17 
     18 namespace plugin {
     19 
     20 // These error codes are reported via UMA so, if you edit them:
     21 // 1) make sure you understand UMA, first.
     22 // 2) update src/tools/histograms/histograms.xml in
     23 //  svn://svn.chromium.org/chrome-internal/trunk/src-internal
     24 // Values are explicitly specified to make sure they don't shift around when
     25 // edited, and also to make reading about:histograms easier.
     26 enum PluginErrorCode {
     27   ERROR_LOAD_SUCCESS = 0,
     28   ERROR_LOAD_ABORTED = 1,
     29   ERROR_UNKNOWN = 2,
     30   ERROR_MANIFEST_RESOLVE_URL = 3,
     31   ERROR_MANIFEST_LOAD_URL = 4,
     32   ERROR_MANIFEST_STAT = 5,
     33   ERROR_MANIFEST_TOO_LARGE = 6,
     34   ERROR_MANIFEST_OPEN = 7,
     35   ERROR_MANIFEST_MEMORY_ALLOC = 8,
     36   ERROR_MANIFEST_READ = 9,
     37   ERROR_MANIFEST_PARSING = 10,
     38   ERROR_MANIFEST_SCHEMA_VALIDATE = 11,
     39   ERROR_MANIFEST_GET_NEXE_URL = 12,
     40   ERROR_NEXE_LOAD_URL = 13,
     41   ERROR_NEXE_ORIGIN_PROTOCOL = 14,
     42   ERROR_NEXE_FH_DUP = 15,
     43   ERROR_NEXE_STAT = 16,
     44   ERROR_ELF_CHECK_IO = 17,
     45   ERROR_ELF_CHECK_FAIL = 18,
     46   ERROR_SEL_LDR_INIT = 19,
     47   ERROR_SEL_LDR_CREATE_LAUNCHER = 20,
     48   ERROR_SEL_LDR_FD = 21,
     49   ERROR_SEL_LDR_LAUNCH = 22,
     50   // Deprecated, safe to reuse the # because never logged in UMA.
     51   // ERROR_SEL_LDR_COMMUNICATION = 23,
     52   ERROR_SEL_LDR_SEND_NEXE = 24,
     53   ERROR_SEL_LDR_HANDLE_PASSING = 25,
     54   ERROR_SEL_LDR_START_MODULE = 26,
     55   ERROR_SEL_LDR_START_STATUS = 27,
     56   ERROR_SRPC_CONNECTION_FAIL = 28,
     57   ERROR_START_PROXY_CHECK_PPP = 29,
     58   ERROR_START_PROXY_ALLOC = 30,
     59   ERROR_START_PROXY_MODULE = 31,
     60   ERROR_START_PROXY_INSTANCE = 32,
     61   ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL = 33,
     62   ERROR_SEL_LDR_COMMUNICATION_REV_SETUP = 34,
     63   ERROR_SEL_LDR_COMMUNICATION_WRAPPER = 35,
     64   ERROR_SEL_LDR_COMMUNICATION_REV_SERVICE = 36,
     65   ERROR_START_PROXY_CRASH = 37,
     66   ERROR_MANIFEST_PROGRAM_MISSING_ARCH = 38,
     67   ERROR_PNACL_CACHE_OPEN_INPROGRESS = 39,
     68   ERROR_PNACL_CACHE_OPEN_NOACCESS = 40,
     69   ERROR_PNACL_CACHE_OPEN_NOQUOTA = 41,
     70   ERROR_PNACL_CACHE_OPEN_NOSPACE = 42,
     71   ERROR_PNACL_CACHE_OPEN_OTHER = 43,
     72   ERROR_PNACL_CACHE_DIRECTORY_CREATE = 44,
     73   ERROR_PNACL_CACHE_FILEOPEN_NOACCESS = 45,
     74   ERROR_PNACL_CACHE_FILEOPEN_NOQUOTA = 46,
     75   ERROR_PNACL_CACHE_FILEOPEN_NOSPACE = 47,
     76   ERROR_PNACL_CACHE_FILEOPEN_NOTAFILE = 48,
     77   ERROR_PNACL_CACHE_FILEOPEN_OTHER = 49,
     78   ERROR_PNACL_CACHE_FETCH_NOACCESS = 50,
     79   ERROR_PNACL_CACHE_FETCH_NOTFOUND = 51,
     80   ERROR_PNACL_CACHE_FETCH_OTHER = 52,
     81   ERROR_PNACL_CACHE_FINALIZE_COPY_NOQUOTA = 53,
     82   ERROR_PNACL_CACHE_FINALIZE_COPY_NOSPACE = 54,
     83   ERROR_PNACL_CACHE_FINALIZE_COPY_OTHER = 55,
     84   ERROR_PNACL_CACHE_FINALIZE_RENAME_NOACCESS = 56,
     85   ERROR_PNACL_CACHE_FINALIZE_RENAME_OTHER = 57,
     86   ERROR_PNACL_RESOURCE_FETCH = 58,
     87   ERROR_PNACL_PEXE_FETCH_ABORTED = 59,
     88   ERROR_PNACL_PEXE_FETCH_NOACCESS = 60,
     89   ERROR_PNACL_PEXE_FETCH_OTHER = 61,
     90   ERROR_PNACL_THREAD_CREATE = 62,
     91   ERROR_PNACL_LLC_SETUP = 63,
     92   ERROR_PNACL_LD_SETUP = 64,
     93   ERROR_PNACL_LLC_INTERNAL = 65,
     94   ERROR_PNACL_LD_INTERNAL = 66,
     95   ERROR_PNACL_CREATE_TEMP = 67,
     96   // This entry is no longer used, but should not be removed, because UMA
     97   // numbers need to be kept consistent.
     98   ERROR_PNACL_NOT_ENABLED = 68,
     99   ERROR_MANIFEST_NOACCESS_URL = 69,
    100   ERROR_NEXE_NOACCESS_URL = 70,
    101   ERROR_PNACL_CRASH_THROTTLED = 71,
    102   // If you add a code, read the enum comment above on how to update histograms.
    103   ERROR_MAX
    104 };
    105 
    106 class ErrorInfo {
    107  public:
    108   ErrorInfo() {
    109     Reset();
    110   }
    111 
    112   void Reset() {
    113     SetReport(ERROR_UNKNOWN, std::string());
    114   }
    115 
    116   void SetReport(PluginErrorCode error_code, const std::string& message) {
    117     error_code_ = error_code;
    118     message_ = message;
    119     console_message_ = message;
    120   }
    121 
    122   // console_message is a part of the error that is logged to
    123   // the JavaScript console but is not reported to JavaScript via
    124   // the lastError property.  This is used to report internal errors which
    125   // may easily change in new versions of the browser and we don't want apps
    126   // to come to depend on the details of these errors.
    127   void SetReportWithConsoleOnlyError(PluginErrorCode error_code,
    128                                      const std::string& message,
    129                                      const std::string& console_message) {
    130     error_code_ = error_code;
    131     message_ = message;
    132     console_message_ = message + "; " + console_message;
    133   }
    134 
    135   PluginErrorCode error_code() const {
    136     return error_code_;
    137   }
    138 
    139   void PrependMessage(const std::string& prefix) {
    140     message_ = prefix + message_;
    141     console_message_ = prefix + console_message_;
    142   }
    143 
    144   const std::string& message() const {
    145     return message_;
    146   }
    147 
    148   const std::string& console_message() const {
    149     return console_message_;
    150   }
    151 
    152  private:
    153   PluginErrorCode error_code_;
    154   std::string message_;
    155   std::string console_message_;
    156   NACL_DISALLOW_COPY_AND_ASSIGN(ErrorInfo);
    157 };
    158 
    159 }  // namespace plugin
    160 
    161 #endif  // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_ERROR_H
    162