Bug 800532. updater: Use low priority IO on OS X and Windows. r=bbondy
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Thu, 11 Oct 2012 16:47:52 -0400
changeset 110994 73976ead8d6c60384840e962e98ab62f965f15c9
parent 110993 3a9b5deb064355a7628b0b129ecd0f621b402cdd
child 110995 0c254f84cf6e345f81e6d9ac08b4cbd70955e169
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersbbondy
bugs800532
milestone19.0a1
Bug 800532. updater: Use low priority IO on OS X and Windows. r=bbondy Uses low priority IO when doing background updates with the hope that it will interfere less with the users system.
toolkit/mozapps/update/updater/updater.cpp
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -43,16 +43,24 @@
 #include <stdarg.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <errno.h>
 
+#ifdef XP_MACOSX
+#include <sys/resource.h>
+#endif
+
+#ifdef XP_WIN
+#include "nsWindowsHelpers.h"
+#endif
+
 #include "updatelogging.h"
 
 // Amount of the progress bar to use in each of the 3 update stages,
 // should total 100.0.
 #define PROGRESS_PREPARE_SIZE 20.0f
 #define PROGRESS_EXECUTE_SIZE 75.0f
 #define PROGRESS_FINISH_SIZE   5.0f
 
@@ -2045,23 +2053,37 @@ ReadMARChannelIDs(const NS_tchar *path, 
   strncpy(results->MARChannelID, updater_strings[0], MAX_TEXT_LEN - 1);
   results->MARChannelID[MAX_TEXT_LEN - 1] = 0;
 
   return result;
 }
 #endif
 
 static void
+LowerIOPriority()
+{
+#ifdef XP_WIN
+  if (IsVistaOrLater())
+      SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_BEGIN);
+#elif XP_MACOSX
+  setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE);
+#endif
+}
+
+static void
 UpdateThreadFunc(void *param)
 {
   // open ZIP archive and process...
   int rv;
   if (sReplaceRequest) {
     rv = ProcessReplaceRequest();
   } else {
+    if (sBackgroundUpdate) {
+        LowerIOPriority();
+    }
     NS_tchar dataFile[MAXPATHLEN];
     NS_tsnprintf(dataFile, sizeof(dataFile)/sizeof(dataFile[0]),
                  NS_T("%s/update.mar"), gSourcePath);
 
     rv = gArchiveReader.Open(dataFile);
 
 #ifdef MOZ_VERIFY_MAR_SIGNATURE
     if (rv == OK) {