Bug 517102 - App update slow, progressbar works poorly on Windows CE. (Part 3, Smoother progressbar) r=robstrong
authorJustin Dolske <dolske@mozilla.com>
Tue, 06 Oct 2009 16:39:51 -0700
changeset 33522 c2804e798aa2f99f09a333c44e034799ec1d130d
parent 33521 95f927ddb0e348fa0dfe71af54193ce5fc38247f
child 33523 b47363818f9f55600514a3661bffef78898e4d92
push idunknown
push userunknown
push dateunknown
reviewersrobstrong
bugs517102
milestone1.9.3a1pre
Bug 517102 - App update slow, progressbar works poorly on Windows CE. (Part 3, Smoother progressbar) r=robstrong
toolkit/mozapps/update/src/updater/updater.cpp
--- a/toolkit/mozapps/update/src/updater/updater.cpp
+++ b/toolkit/mozapps/update/src/updater/updater.cpp
@@ -113,16 +113,22 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <errno.h>
 
 #ifdef WINCE
 #include "updater_wince.h"
 #endif
 
+// 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
+
 #if defined(XP_MACOSX)
 // This function is defined in launchchild_osx.mm
 void LaunchChild(int argc, char **argv);
 #endif
 
 #ifndef _O_BINARY
 # define _O_BINARY 0
 #endif
@@ -1585,26 +1591,28 @@ ActionList::Prepare()
   // something has gone wrong. Otherwise we report success when nothing is
   // actually done. See bug 327140.
   if (mCount == 0) {
     LOG(("empty action list\n"));
     return UNEXPECTED_ERROR;
   }
 
   Action *a = mFirst;
+  int i = 0;
   while (a) {
     int rv = a->Prepare();
     if (rv)
       return rv;
 
+    float percent = float(++i) / float(mCount);
+    UpdateProgressUI(PROGRESS_PREPARE_SIZE * percent);
+
     a = a->mNext;
   }
 
-  UpdateProgressUI(1.0f);
-
   return OK;
 }
 
 int
 ActionList::Execute()
 {
   int currentProgress = 0, maxProgress = 0;
   Action *a = mFirst;
@@ -1618,39 +1626,45 @@ ActionList::Execute()
     int rv = a->Execute();
     if (rv) {
       LOG(("### execution failed\n"));
       return rv;
     }
 
     currentProgress += a->mProgressCost;
     float percent = float(currentProgress) / float(maxProgress);
-    UpdateProgressUI(1.0f + 99.0f * percent);
+    UpdateProgressUI(PROGRESS_PREPARE_SIZE +
+                     PROGRESS_EXECUTE_SIZE * percent);
 
     a = a->mNext;
   }
 
   return OK;
 }
 
 void
 ActionList::Finish(int status)
 {
   Action *a = mFirst;
+  int i = 0;
   while (a) {
     a->Finish(status);
+
+    float percent = float(++i) / float(mCount);
+    UpdateProgressUI(PROGRESS_PREPARE_SIZE +
+                     PROGRESS_EXECUTE_SIZE +
+                     PROGRESS_FINISH_SIZE * percent);
+
     a = a->mNext;
   }
 
 #ifdef XP_WIN
   if (status == OK)
     gSucceeded = TRUE;
 #endif
-
-  UpdateProgressUI(100.0f);
 }
 
 int DoUpdate()
 {
   NS_tchar manifest[MAXPATHLEN];
   NS_tsnprintf(manifest, MAXPATHLEN, NS_T("%s/update.manifest"), gSourcePath);
 
   // extract the manifest