Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / nacl / renderer / plugin / utility.h
blob78091d3021d01fc1651b2274bd089295924e395c
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 */
7 // A collection of debugging related interfaces.
9 #ifndef COMPONENTS_NACL_RENDERER_PLUGIN_UTILITY_H_
10 #define COMPONENTS_NACL_RENDERER_PLUGIN_UTILITY_H_
12 #include "components/nacl/renderer/ppb_nacl_private.h"
13 #include "native_client/src/include/nacl_macros.h"
14 #include "native_client/src/include/portability.h"
15 #include "native_client/src/shared/platform/nacl_threads.h"
16 #include "native_client/src/shared/platform/nacl_time.h"
17 #include "ppapi/c/private/pp_file_handle.h"
19 #define SRPC_PLUGIN_DEBUG 1
21 namespace plugin {
23 // Tests that a string is a valid JavaScript identifier. According to the
24 // ECMAScript spec, this should be done in terms of unicode character
25 // categories. For now, we are simply limiting identifiers to the ASCII
26 // subset of that spec. If successful, it returns the length of the
27 // identifier in the location pointed to by length (if it is not NULL).
28 // TODO(sehr): add Unicode identifier support.
29 bool IsValidIdentifierString(const char* strval, uint32_t* length);
31 const PPB_NaCl_Private* GetNaClInterface();
32 void SetNaClInterface(const PPB_NaCl_Private* nacl_interface);
34 void CloseFileHandle(PP_FileHandle file_handle);
36 // Debugging print utility
37 extern int gNaClPluginDebugPrintEnabled;
38 extern int NaClPluginPrintLog(const char *format, ...);
39 extern int NaClPluginDebugPrintCheckEnv();
40 #if SRPC_PLUGIN_DEBUG
41 #define INIT_PLUGIN_LOGGING() do { \
42 if (-1 == ::plugin::gNaClPluginDebugPrintEnabled) { \
43 ::plugin::gNaClPluginDebugPrintEnabled = \
44 ::plugin::NaClPluginDebugPrintCheckEnv(); \
45 } \
46 } while (0)
48 #define PLUGIN_PRINTF(args) do { \
49 INIT_PLUGIN_LOGGING(); \
50 if (0 != ::plugin::gNaClPluginDebugPrintEnabled) { \
51 ::plugin::NaClPluginPrintLog("PLUGIN %" NACL_PRIu64 ": ", \
52 NaClGetTimeOfDayMicroseconds()); \
53 ::plugin::NaClPluginPrintLog args; \
54 } \
55 } while (0)
57 // MODULE_PRINTF is used in the module because PLUGIN_PRINTF uses a
58 // a timer that may not yet be initialized.
59 #define MODULE_PRINTF(args) do { \
60 INIT_PLUGIN_LOGGING(); \
61 if (0 != ::plugin::gNaClPluginDebugPrintEnabled) { \
62 ::plugin::NaClPluginPrintLog("MODULE: "); \
63 ::plugin::NaClPluginPrintLog args; \
64 } \
65 } while (0)
66 #else
67 # define PLUGIN_PRINTF(args) do { if (0) { printf args; } } while (0)
68 # define MODULE_PRINTF(args) do { if (0) { printf args; } } while (0)
69 /* allows DCE but compiler can still do format string checks */
70 #endif
72 } // namespace plugin
74 #endif // COMPONENTS_NACL_RENDERER_PLUGIN_UTILITY_H_