diff options
author | hansl@google.com <hansl@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 17:16:58 +0000 |
---|---|---|
committer | hansl@google.com <hansl@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 17:16:58 +0000 |
commit | 5f95d531864a5c74184adac6c6e3bcca1b02287c (patch) | |
tree | e0624ee25c9346adfe8f19d9f6501013427e79c6 /base/logging.cc | |
parent | 8807b329539d919dd9250ffe1903523dc072225f (diff) | |
download | chromium_src-5f95d531864a5c74184adac6c6e3bcca1b02287c.zip chromium_src-5f95d531864a5c74184adac6c6e3bcca1b02287c.tar.gz chromium_src-5f95d531864a5c74184adac6c6e3bcca1b02287c.tar.bz2 |
Solved a problem where a string was supposed to be passed as a reference but was instead passed by value.
Also, if CreateMutex returns NULL (for the lock), try to call the Debugger and return nicely.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/3589002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61191 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/logging.cc')
-rw-r--r-- | base/logging.cc | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/base/logging.cc b/base/logging.cc index f0c6217..4a0ef23a 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -163,20 +163,22 @@ void DeleteFilePath(const PathString& log_name) { #endif } -void GetDefaultLogFile(PathString default_log_file) { +PathString GetDefaultLogFile() { #if defined(OS_WIN) // On Windows we use the same path as the exe. wchar_t module_name[MAX_PATH]; GetModuleFileName(NULL, module_name, MAX_PATH); - default_log_file = module_name; - std::wstring::size_type last_backslash = - default_log_file.rfind('\\', default_log_file.size()); - if (last_backslash != std::wstring::npos) - default_log_file.erase(last_backslash + 1); - default_log_file += L"debug.log"; + + PathString log_file = module_name; + PathString::size_type last_backslash = + log_file.rfind('\\', log_file.size()); + if (last_backslash != PathString::npos) + log_file.erase(last_backslash + 1); + log_file += L"debug.log"; + return log_file; #elif defined(OS_POSIX) // On other platforms we just use the current directory. - default_log_file = "debug.log"; + return PathString("debug.log"); #endif } @@ -207,12 +209,22 @@ class LoggingLock { if (new_log_file) safe_name = new_log_file; else - GetDefaultLogFile(safe_name); + safe_name = GetDefaultLogFile(); // \ is not a legal character in mutex names so we replace \ with / std::replace(safe_name.begin(), safe_name.end(), '\\', '/'); std::wstring t(L"Global\\"); t.append(safe_name); log_mutex = ::CreateMutex(NULL, FALSE, t.c_str()); + + if (log_mutex == NULL) { +#if DEBUG + // Keep the error code for debugging + int error = GetLastError(); // NOLINT + DebugUtil::BreakDebugger(); +#endif + // Return nicely without putting initialized to true. + return; + } } #endif } else { @@ -293,8 +305,7 @@ bool InitializeLogFileHandle() { if (!log_file_name) { // Nobody has called InitLogging to specify a debug log file, so here we // initialize the log file name to a default. - log_file_name = new PathString(); - GetDefaultLogFile(*log_file_name); + log_file_name = new PathString(GetDefaultLogFile()); } if (logging_destination == LOG_ONLY_TO_FILE || @@ -367,7 +378,6 @@ void BaseInitLoggingImpl(const PathChar* new_log_file, DeleteFilePath(*log_file_name); InitializeLogFileHandle(); - } void SetMinLogLevel(int level) { |