Bug 845342 - Move about:memory and related dump files to the downloads dir on android. r=njn a=lsblakk
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 27 Feb 2013 08:58:29 -0500
changeset 128518 633557c901a9bc813d42a79270e9ad3fafca672d
parent 128517 f6b3614c067e12931df82f21c120713904a08bb6
child 128519 989f15f6ee61288e9769a306911a6ca651446c04
push id3457
push userkgupta@mozilla.com
push dateWed, 06 Mar 2013 23:11:17 +0000
treeherdermozilla-aurora@633557c901a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn, lsblakk
bugs845342
milestone21.0a2
Bug 845342 - Move about:memory and related dump files to the downloads dir on android. r=njn a=lsblakk
xpcom/base/nsCycleCollector.cpp
xpcom/base/nsMemoryInfoDumper.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -127,19 +127,16 @@
 #include "nsXPCOMPrivate.h"
 #include "sampler.h"
 #include <stdio.h>
 #include <string.h>
 #ifdef WIN32
 #include <io.h>
 #include <process.h>
 #endif
-#ifdef ANDROID
-#include <sys/stat.h>
-#endif
 
 #ifdef XP_WIN
 #include <windows.h>
 #endif
 
 #include "mozilla/CondVar.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Mutex.h"
@@ -1592,45 +1589,42 @@ private:
     {
         nsPrintfCString filename("%s.%d%s%s.log",
             aPrefix,
             base::GetCurrentProcId(),
             mFilenameIdentifier.IsEmpty() ? "" : ".",
             NS_ConvertUTF16toUTF8(mFilenameIdentifier).get());
 
         // Get the log directory either from $MOZ_CC_LOG_DIRECTORY or from our
-        // platform's temp directory.
+        // platform's temp directory. For Android, first try the downloads
+        // directory which is world-readable rather than the temp directory
+        // which is not.
         nsCOMPtr<nsIFile> logFile;
-        if (char* env = PR_GetEnv("MOZ_CC_LOG_DIRECTORY")) {
+        char* env;
+        if (env = PR_GetEnv("MOZ_CC_LOG_DIRECTORY")) {
             NS_NewNativeLocalFile(nsCString(env), /* followLinks = */ true,
                                   getter_AddRefs(logFile));
-        } else {
+        }
+#ifdef ANDROID
+        if (!logFile && (env = PR_GetEnv("DOWNLOADS_DIRECTORY"))) {
+            NS_NewNativeLocalFile(nsCString(env), /* followLinks = */ true,
+                                  getter_AddRefs(logFile));
+        }
+#endif
+        if (!logFile) {
             // Ask NSPR to point us to the temp directory.
             NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(logFile));
         }
         NS_ENSURE_TRUE(logFile, nullptr);
 
         nsresult rv = logFile->AppendNative(filename);
         NS_ENSURE_SUCCESS(rv, nullptr);
 
         rv = logFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0644);
         NS_ENSURE_SUCCESS(rv, nullptr);
-#ifdef ANDROID
-        {
-            // On android the default system umask is 0077 which makes these files
-            // unreadable to the shell user. In order to pull the dumps off a non-rooted
-            // device we need to chmod them to something world-readable.
-            // XXX why not logFile->SetPermissions(0644);
-            nsAutoCString path;
-            rv = logFile->GetNativePath(path);
-            if (NS_SUCCEEDED(rv)) {
-                chmod(path.get(), 0644);
-            }
-        }
-#endif
 
         return logFile.forget();
     }
 
     FILE *mStream;
     nsCOMPtr<nsIFile> mOutFile;
     bool mWantAllTraces;
     bool mDisableLog;
--- a/xpcom/base/nsMemoryInfoDumper.cpp
+++ b/xpcom/base/nsMemoryInfoDumper.cpp
@@ -734,39 +734,36 @@ MakeFilename(const char *aPrefix, const 
                             aPrefix,
                             NS_ConvertUTF16toUTF8(aIdentifier).get(),
                             getpid(), aSuffix);
 }
 
 static nsresult
 OpenTempFile(const nsACString &aFilename, nsIFile* *aFile)
 {
-  nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, aFile);
-  NS_ENSURE_SUCCESS(rv, rv);
+#ifdef ANDROID
+  // For Android, first try the downloads directory which is world-readable
+  // rather than the temp directory which is not.
+  if (char *env = PR_GetEnv("DOWNLOADS_DIRECTORY")) {
+    NS_NewNativeLocalFile(nsCString(env), /* followLinks = */ true, aFile);
+  }
+#endif
+  nsresult rv;
+  if (!*aFile) {
+    rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, aFile);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   nsCOMPtr<nsIFile> file(*aFile);
 
   rv = file->AppendNative(aFilename);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = file->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0644);
   NS_ENSURE_SUCCESS(rv, rv);
-#ifdef ANDROID
-  {
-    // On android the default system umask is 0077 which makes these files
-    // unreadable to the shell user. In order to pull the dumps off a non-rooted
-    // device we need to chmod them to something world-readable.
-    // XXX why not logFile->SetPermissions(0644);
-    nsAutoCString path;
-    rv = file->GetNativePath(path);
-    if (NS_SUCCEEDED(rv)) {
-      chmod(path.get(), 0644);
-    }
-  }
-#endif
   return NS_OK;
 }
 
 #ifdef MOZ_DMD
 struct DMDWriteState
 {
   static const size_t kBufSize = 4096;
   char mBuf[kBufSize];