Bug 477862 Activity Manager: activity list doesn't clear permanently until restart. r=mkmelin
authorMark Banner <bugzilla@standard8.plus.com>
Mon, 09 Mar 2009 09:28:58 +0000
changeset 2161 36423d81646ff720872cd053fb41457282cdcc64
parent 2160 99320ed86776308bad01657cd5655caaf2ede04a
child 2162 c494329a5ba59218807f5b2eb689b88e37cc524d
push idunknown
push userunknown
push dateunknown
reviewersmkmelin
bugs477862
Bug 477862 Activity Manager: activity list doesn't clear permanently until restart. r=mkmelin
mail/components/activity/content/activity.js
mail/components/activity/nsActivityManager.js
mail/components/activity/nsIActivityManager.idl
--- a/mail/components/activity/content/activity.js
+++ b/mail/components/activity/content/activity.js
@@ -290,28 +290,22 @@ function replaceInsert(aText, aIndex, aV
 }
 
 /**
  * Remove all activities not in-progress from the activity list.
  */
 function clearActivityList()
 {
   gActivityLogger.debug("clearActivityList");
-  // Remove each activity starting from the end until we hit a activity
-  // that is in progress or the end.
-  let item;
-  for (let i = gActivitiesView.itemCount-1; i >= 0; i--) {
-    let child = gActivitiesView.getItemAtIndex(i);
-    if (child.inProgress)
-      continue;
 
-    if (!child)
-      break;
-    removeActivityBinding(child.getAttribute('actID'));
-  }
+  // If/when we implement search, we'll want to remove just the items that
+  // are on the search display, however for now, we'll just clear up everything.
+  Components.classes["@mozilla.org/activity-manager;1"]
+            .getService(Components.interfaces.nsIActivityManager)
+            .cleanUp();
 
   gActivitiesView.focus();
 }
 
 function processKeyEvent(event)
 {
   switch (event.keyCode) {
     case event.DOM_VK_RIGHT:
--- a/mail/components/activity/nsActivityManager.js
+++ b/mail/components/activity/nsActivityManager.js
@@ -1,8 +1,9 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
@@ -122,22 +123,22 @@ nsActivityManager.prototype = {
       // for some reason exceptions don't end up on the console if we don't
       // explicitly log them.
       this.log.error("Exception: " + e);
       throw(e);
     }
   },
   
   removeActivity: function (aID) {
-    // make sure that the activity is not in-progress state
     let activity = this._activities[aID];
  
     if (!activity)
       throw Cr.NS_ERROR_NOT_AVAILABLE;
     
+    // make sure that the activity is not in-progress state
     if (activity instanceof Ci.nsIActivityProcess &&
         activity.state == Ci.nsIActivityProcess.STATE_INPROGRESS)
       throw Cr.NS_ERROR_FAILURE;
     
     // remove the activity
     delete this._activities[aID];
     
     // notify all the listeners
@@ -146,16 +147,29 @@ nsActivityManager.prototype = {
         value.onRemovedActivity(aID);
       }
       catch(e) {
         // ignore the exception
       }
     }
   },
 
+  cleanUp: function () {
+    // Get the list of aIDs.
+    this.log.info("cleanUp\n");
+    for (var id in this._activities) {
+      let state = this._activities[id].state;
+      if (state != Ci.nsIActivityProcess.STATE_INPROGRESS ||
+          state != Ci.nsIActivityProcess.STATE_PAUSED ||
+          state != Ci.nsIActivityProcess.STATE_WAITINGFORINPUT ||
+          state != Ci.nsIActivityProcess.STATE_WAITINGFORRETRY)
+        this.removeActivity(id);
+    }
+  },
+
   getActivity: function(aID) {
     if (!this._activities[aID])
       throw Cr.NS_ERROR_NOT_AVAILABLE;
     return this._activities[aID];
   },
 
   containsActivity: function (aID) {
     return !!this._activities[aID];
--- a/mail/components/activity/nsIActivityManager.idl
+++ b/mail/components/activity/nsIActivityManager.idl
@@ -48,17 +48,17 @@ interface nsIVariant;
  * See https://wiki.mozilla.org/Thunderbird:Activity_Manager/Developer for UML
  * diagram and sample codes.
  */
 
 /**
  * An interface to get notified by the major Activity Manager events.
  * Mostly used by UI glue code in activity.js.
  */
-[scriptable, uuid(8ed29f45-e0c4-4259-ad80-6ff177f87aa6)]
+[scriptable, uuid(14cfad1c-3401-4c44-ab04-4a11b6662663)]
 interface nsIActivityMgrListener : nsISupports {
   /**
    * Called _after_ activity manager adds an activity into
    * the managed list.
    */
   void onAddedActivity(in unsigned long aID, in nsIActivity aActivity);
   
   /**
@@ -148,16 +148,21 @@ interface nsIActivityManager : nsISuppor
    * @return A read-only list of processes matching to given criteria.
    */
   void getProcessesByContext(in AString aContextType,
                              in nsIVariant aContextObject,
                              out unsigned long length,
                              [retval, array, size_is(length)] out nsIActivityProcess aProcesses);
 
   /**
+   *  Call to remove all activities apart from those that are in progress.
+   */
+  void cleanUp();
+
+  /**
    * The number of processes in the activity list.
    */
   readonly attribute long processCount;
   
   /**
    * Adds a listener.
    */
   void addListener(in nsIActivityMgrListener aListener);