summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortommi@google.com <tommi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-14 16:52:11 +0000
committertommi@google.com <tommi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-14 16:52:11 +0000
commit3f85caafb239d5725ec85af9b8ce9f1b1de15770 (patch)
treedc5bdda66d8c915a1ae7b230c35130ab338ed703 /base
parentd92224288027cefbbd197bd9eed9080110aa9222 (diff)
downloadchromium_src-3f85caafb239d5725ec85af9b8ce9f1b1de15770.zip
chromium_src-3f85caafb239d5725ec85af9b8ce9f1b1de15770.tar.gz
chromium_src-3f85caafb239d5725ec85af9b8ce9f1b1de15770.tar.bz2
Save and restore the value of GetLastError() when [D]LOG/[D]CHECK etc on Windows.
Also for log levels higher than INFO, the value of GLE is tagged onto the log message. Review URL: http://codereview.chromium.org/73010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13667 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/logging.cc9
-rw-r--r--base/logging.h19
2 files changed, 28 insertions, 0 deletions
diff --git a/base/logging.cc b/base/logging.cc
index 41a0933..961ea6c 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -342,6 +342,15 @@ void DisplayDebugMessage(const std::string& str) {
#endif
}
+#if defined(OS_WIN)
+LogMessage::SaveLastError::SaveLastError() : last_error_(::GetLastError()) {
+}
+
+LogMessage::SaveLastError::~SaveLastError() {
+ ::SetLastError(last_error_);
+}
+#endif // defined(OS_WIN)
+
LogMessage::LogMessage(const char* file, int line, LogSeverity severity,
int ctr)
: severity_(severity) {
diff --git a/base/logging.h b/base/logging.h
index b3bba0b..6a58cf3 100644
--- a/base/logging.h
+++ b/base/logging.h
@@ -540,6 +540,25 @@ class LogMessage {
std::ostringstream stream_;
size_t message_start_; // Offset of the start of the message (past prefix
// info).
+#if defined(OS_WIN)
+ // Stores the current value of GetLastError in the constructor and restores
+ // it in the destructor by calling SetLastError.
+ // This is useful since the LogMessage class uses a lot of Win32 calls
+ // that will lose the value of GLE and the code that called the log function
+ // will have lost the thread error value when the log call returns.
+ class SaveLastError {
+ public:
+ SaveLastError();
+ ~SaveLastError();
+
+ unsigned long get_error() const { return last_error_; }
+
+ protected:
+ unsigned long last_error_;
+ };
+
+ SaveLastError last_error_;
+#endif
DISALLOW_COPY_AND_ASSIGN(LogMessage);
};