Bug 1188970: Fix usage of forward slash in constructing webrtc trace file path. r=rjesup
authorPaul Kerr [:pkerr] <pkerr@mozilla.com>
Fri, 07 Aug 2015 13:46:55 -0700
changeset 288544 2fa6cc610bd43cca35e867e42b7e188f2dbb6ab6
parent 288534 e102197e30343e1ac789eca738ee44cb14cad861
child 288545 daef3729bce246fa8194c094ac34f3bb4cce4faf
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrjesup
bugs1188970
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1188970: Fix usage of forward slash in constructing webrtc trace file path. r=rjesup Replaced the chain of logic that attempted to determine the location of the temporary directory with a call to nsDirectoryService. Use nsIFile object to append file name to path in an OS independent manner.
media/webrtc/signaling/src/common/browser_logging/WebRtcLog.cpp
--- a/media/webrtc/signaling/src/common/browser_logging/WebRtcLog.cpp
+++ b/media/webrtc/signaling/src/common/browser_logging/WebRtcLog.cpp
@@ -14,22 +14,30 @@
 #include "nsXULAppAPI.h"
 #if !defined(MOZILLA_XPCOMRT_API)
 #include "mozilla/Preferences.h"
 #endif // !defined(MOZILLA_XPCOMRT_API)
 #else
 #include "nsStringAPI.h"
 #endif
 
+#include "nsIFile.h"
+#include "nsDirectoryServiceUtils.h"
+#include "nsDirectoryServiceDefs.h"
+
 using mozilla::LogLevel;
 
 static int gWebRtcTraceLoggingOn = 0;
 
-#ifndef ANDROID
-static const char *default_log = "WebRTC.log";
+
+#if defined(ANDROID)
+static const char *default_tmp_dir = "/dev/null";
+static const char *default_log_name = "nspr";
+#else // Assume a POSIX environment
+NS_NAMED_LITERAL_CSTRING(default_log_name, "WebRTC.log");
 #endif
 
 static PRLogModuleInfo* GetWebRtcTraceLog()
 {
   static PRLogModuleInfo *sLog;
   if (!sLog) {
     sLog = PR_NewLogModule("webrtc_trace");
   }
@@ -101,49 +109,44 @@ void CheckOverrides(uint32_t *aTraceMask
 }
 
 void ConfigWebRtcLog(uint32_t trace_mask, nsCString &aLogFile, nsCString &aAECLogDir, bool multi_log)
 {
   if (gWebRtcTraceLoggingOn) {
     return;
   }
 
-  nsCString logFile;
-  nsCString aecLogDir;
-#if defined(XP_WIN)
-  // Use the Windows TEMP environment variable as part of the default location.
-  const char *temp_dir = PR_GetEnv("TEMP");
-  if (!temp_dir) {
-    logFile.Assign(default_log);
-  } else {
-    logFile.Assign(temp_dir);
-    logFile.Append('/');
-    aecLogDir = logFile;
-    logFile.Append(default_log);
-  }
-#elif defined(ANDROID)
+#if defined(ANDROID)
   // Special case: use callback to pipe to NSPR logging.
-  logFile.Assign("nspr");
-  // for AEC, force the user to specify a directory
-  aecLogDir.Assign("/dev/null");
+  aLogFile.Assign(default_log_name);
+  // For AEC, do not use a default value: force the user to specify a directory.
+  if (aAECLogDir.IsEmpty()) {
+    aAECLogDir.Assign(default_tmp_dir);
+  }
 #else
-  // UNIX-like place for the others
-  logFile.Assign("/tmp/");
-  aecLogDir = logFile;
-  logFile.Append(default_log);
+  if (aLogFile.IsEmpty() || aAECLogDir.IsEmpty()) {
+    nsCOMPtr<nsIFile> tempDir;
+    nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tempDir));
+
+    if (NS_SUCCEEDED(rv)) {
+      if (aAECLogDir.IsEmpty()) {
+        tempDir->GetNativePath(aAECLogDir);
+      }
+
+      if (aLogFile.IsEmpty()) {
+        tempDir->AppendNative(default_log_name);
+        tempDir->GetNativePath(aLogFile);
+      }
+    }
+  }
 #endif
-  if (aLogFile.IsEmpty()) {
-    aLogFile = logFile;
-  }
-  if (aAECLogDir.IsEmpty()) {
-    aAECLogDir = aecLogDir;
-  }
 
   webrtc::Trace::set_level_filter(trace_mask);
   webrtc::Trace::set_aec_debug_filename(aAECLogDir.get());
+
   if (trace_mask != 0) {
     if (aLogFile.EqualsLiteral("nspr")) {
       webrtc::Trace::SetTraceCallback(&gWebRtcCallback);
     } else {
       webrtc::Trace::SetTraceFile(aLogFile.get(), multi_log);
     }
   }
 #if !defined(MOZILLA_EXTERNAL_LINKAGE)