Bug 517102 - App update slow, progressbar works poorly on Windows CE. (Part 2, Progress ignores missing files) r=robstrong
authorJustin Dolske <dolske@mozilla.com>
Tue, 06 Oct 2009 16:39:51 -0700
changeset 33521 95f927ddb0e348fa0dfe71af54193ce5fc38247f
parent 33520 d9bee5b4a68f2e9969351397b5febdd286d618bb
child 33522 c2804e798aa2f99f09a333c44e034799ec1d130d
push id9571
push userjdolske@mozilla.com
push dateTue, 06 Oct 2009 23:40:36 +0000
treeherdermozilla-central@052d562cc791 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobstrong
bugs517102
milestone1.9.3a1pre
Bug 517102 - App update slow, progressbar works poorly on Windows CE. (Part 2, Progress ignores missing files) 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
@@ -601,17 +601,17 @@ static void backup_finish(const NS_tchar
 
 static int DoUpdate();
 
 static const int ACTION_DESCRIPTION_BUFSIZE = 256;
 
 class Action
 {
 public:
-  Action() : mNext(NULL) { }
+  Action() : mProgressCost(1), mNext(NULL) { }
   virtual ~Action() { }
 
   virtual int Parse(char *line) = 0;
 
   // Do any preprocessing to ensure that the action can be performed.  Execute
   // will be called if this Action and all others return OK from this method.
   virtual int Prepare() = 0;
 
@@ -619,16 +619,17 @@ public:
   // have been executed, Finish will be called.  A requirement of Execute is
   // that its operation be reversable from Finish.
   virtual int Execute() = 0;
   
   // Finish is called after execution of all actions.  If status is OK, then
   // all actions were successfully executed.  Otherwise, some action failed.
   virtual void Finish(int status) = 0;
 
+  int mProgressCost;
 private:
   Action* mNext;
 
   friend class ActionList;
 };
 
 class RemoveFile : public Action
 {
@@ -671,16 +672,17 @@ RemoveFile::Prepare()
 {
   LOG(("PREPARE REMOVE " LOG_S "\n", mDestFile));
 
   // We expect the file to exist if we are to remove it.
   int rv = NS_taccess(mDestFile, F_OK);
   if (rv) {
     LOG(("file does not exist; skipping\n"));
     mSkip = 1;
+    mProgressCost = 0;
     return OK;
   }
 
 #ifndef WINCE
   NS_tchar *slash = (NS_tchar *) NS_tstrrchr(mDestFile, NS_T('/'));
   if (slash) {
     *slash = NS_T('\0');
     rv = NS_taccess(mDestFile, W_OK);
@@ -1599,29 +1601,35 @@ ActionList::Prepare()
   UpdateProgressUI(1.0f);
 
   return OK;
 }
 
 int
 ActionList::Execute()
 {
-  int i = 0;
-  float divisor = mCount / 98.0f;
-
+  int currentProgress = 0, maxProgress = 0;
   Action *a = mFirst;
   while (a) {
-    UpdateProgressUI(1.0f + float(i++) / divisor);
+    maxProgress += a->mProgressCost;
+    a = a->mNext;
+  }
 
+  a = mFirst;
+  while (a) {
     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);
+
     a = a->mNext;
   }
 
   return OK;
 }
 
 void
 ActionList::Finish(int status)