image/public/ImageLogging.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 *
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef ImageLogging_h
michael@0 8 #define ImageLogging_h
michael@0 9
michael@0 10 // In order for FORCE_PR_LOG below to work, we have to define it before the
michael@0 11 // first time prlog is #included.
michael@0 12 #if defined(PR_LOG)
michael@0 13 #error "Must #include ImageLogging.h before before any IPDL-generated files or other files that #include prlog.h."
michael@0 14 #endif
michael@0 15
michael@0 16 #if defined(MOZ_LOGGING)
michael@0 17 #define FORCE_PR_LOG
michael@0 18 #endif
michael@0 19
michael@0 20 #include "prlog.h"
michael@0 21 #include "prinrval.h"
michael@0 22 #include "nsString.h"
michael@0 23
michael@0 24 #if defined(PR_LOGGING)
michael@0 25 // Declared in imgRequest.cpp.
michael@0 26 extern PRLogModuleInfo *GetImgLog();
michael@0 27
michael@0 28 #define GIVE_ME_MS_NOW() PR_IntervalToMilliseconds(PR_IntervalNow())
michael@0 29
michael@0 30 class LogScope {
michael@0 31 public:
michael@0 32 LogScope(PRLogModuleInfo *aLog, void *from, const char *fn) :
michael@0 33 mLog(aLog), mFrom(from), mFunc(fn)
michael@0 34 {
michael@0 35 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {ENTER}\n",
michael@0 36 GIVE_ME_MS_NOW(), mFrom, mFunc));
michael@0 37 }
michael@0 38
michael@0 39 /* const char * constructor */
michael@0 40 LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
michael@0 41 const char *paramName, const char *paramValue) :
michael@0 42 mLog(aLog), mFrom(from), mFunc(fn)
michael@0 43 {
michael@0 44 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n",
michael@0 45 GIVE_ME_MS_NOW(), mFrom, mFunc,
michael@0 46 paramName, paramValue));
michael@0 47 }
michael@0 48
michael@0 49 /* void ptr constructor */
michael@0 50 LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
michael@0 51 const char *paramName, const void *paramValue) :
michael@0 52 mLog(aLog), mFrom(from), mFunc(fn)
michael@0 53 {
michael@0 54 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=%p) {ENTER}\n",
michael@0 55 GIVE_ME_MS_NOW(), mFrom, mFunc,
michael@0 56 paramName, paramValue));
michael@0 57 }
michael@0 58
michael@0 59 /* int32_t constructor */
michael@0 60 LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
michael@0 61 const char *paramName, int32_t paramValue) :
michael@0 62 mLog(aLog), mFrom(from), mFunc(fn)
michael@0 63 {
michael@0 64 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
michael@0 65 GIVE_ME_MS_NOW(), mFrom, mFunc,
michael@0 66 paramName, paramValue));
michael@0 67 }
michael@0 68
michael@0 69 /* uint32_t constructor */
michael@0 70 LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
michael@0 71 const char *paramName, uint32_t paramValue) :
michael@0 72 mLog(aLog), mFrom(from), mFunc(fn)
michael@0 73 {
michael@0 74 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
michael@0 75 GIVE_ME_MS_NOW(), mFrom, mFunc,
michael@0 76 paramName, paramValue));
michael@0 77 }
michael@0 78
michael@0 79
michael@0 80 ~LogScope() {
michael@0 81 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {EXIT}\n",
michael@0 82 GIVE_ME_MS_NOW(), mFrom, mFunc));
michael@0 83 }
michael@0 84
michael@0 85 private:
michael@0 86 PRLogModuleInfo *mLog;
michael@0 87 void *mFrom;
michael@0 88 const char *mFunc;
michael@0 89 };
michael@0 90
michael@0 91
michael@0 92 class LogFunc {
michael@0 93 public:
michael@0 94 LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn)
michael@0 95 {
michael@0 96 PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s\n",
michael@0 97 GIVE_ME_MS_NOW(), from, fn));
michael@0 98 }
michael@0 99
michael@0 100 LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn,
michael@0 101 const char *paramName, const char *paramValue)
michael@0 102 {
michael@0 103 PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\")\n",
michael@0 104 GIVE_ME_MS_NOW(), from, fn,
michael@0 105 paramName, paramValue));
michael@0 106 }
michael@0 107
michael@0 108 LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn,
michael@0 109 const char *paramName, const void *paramValue)
michael@0 110 {
michael@0 111 PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%p\")\n",
michael@0 112 GIVE_ME_MS_NOW(), from, fn,
michael@0 113 paramName, paramValue));
michael@0 114 }
michael@0 115
michael@0 116
michael@0 117 LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn,
michael@0 118 const char *paramName, uint32_t paramValue)
michael@0 119 {
michael@0 120 PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\")\n",
michael@0 121 GIVE_ME_MS_NOW(), from,
michael@0 122 fn,
michael@0 123 paramName, paramValue));
michael@0 124 }
michael@0 125
michael@0 126 };
michael@0 127
michael@0 128
michael@0 129 class LogMessage {
michael@0 130 public:
michael@0 131 LogMessage(PRLogModuleInfo *aLog, void *from, const char *fn,
michael@0 132 const char *msg)
michael@0 133 {
michael@0 134 PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s -- %s\n",
michael@0 135 GIVE_ME_MS_NOW(), from, fn, msg));
michael@0 136 }
michael@0 137 };
michael@0 138
michael@0 139 #define LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) id ## line
michael@0 140 #define LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, line) LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line)
michael@0 141 #define LOG_SCOPE_APPEND_LINE_NUMBER(id) LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, __LINE__)
michael@0 142
michael@0 143 #define LOG_SCOPE(l, s) \
michael@0 144 LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s)
michael@0 145
michael@0 146 #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) \
michael@0 147 LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s, pn, pv)
michael@0 148
michael@0 149 #define LOG_FUNC(l, s) LogFunc(l, this, s)
michael@0 150
michael@0 151 #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, this, s, pn, pv)
michael@0 152
michael@0 153 #define LOG_STATIC_FUNC(l, s) LogFunc(l, nullptr, s)
michael@0 154
michael@0 155 #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, nullptr, s, pn, pv)
michael@0 156
michael@0 157
michael@0 158
michael@0 159 #define LOG_MSG(l, s, m) LogMessage(l, this, s, m)
michael@0 160
michael@0 161 #else
michael@0 162
michael@0 163 #define LOG_SCOPE(l, s)
michael@0 164 #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv)
michael@0 165 #define LOG_FUNC(l, s)
michael@0 166 #define LOG_FUNC_WITH_PARAM(l, s, pn, pv)
michael@0 167 #define LOG_STATIC_FUNC(l, s)
michael@0 168 #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv)
michael@0 169 #define LOG_MSG(l, s, m)
michael@0 170
michael@0 171 #endif // if defined(PR_LOGGING)
michael@0 172
michael@0 173 #define LOG_MSG_WITH_PARAM LOG_FUNC_WITH_PARAM
michael@0 174
michael@0 175 #endif // ifndef ImageLogging_h

mercurial