Bug 845342 - Move about:memory and related dump files to the downloads dir on android. r=njn
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 27 Feb 2013 08:58:29 -0500
changeset 123150 36b60ec153af1319f15a4ad0454ed0d8b8656218
parent 123149 e78cc3311ad3fda058d119a8323b1b97df344d02
child 123151 f223a4961926e7feed750ea41df1466c39fef185
push id23691
push userkgupta@mozilla.com
push dateWed, 27 Feb 2013 13:58:49 +0000
treeherdermozilla-inbound@36b60ec153af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs845342
milestone22.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 845342 - Move about:memory and related dump files to the downloads dir on android. r=njn
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"
@@ -1403,45 +1400,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];