Thunderbird:ShutdownService: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(New page: == Mailnews Shutdown Service == A new shutdown interface is being developed for core mailnews. The new service should make it easier for developers and extension writers to do some things ...)
 
No edit summary
 
Line 1: Line 1:
== Mailnews Shutdown Service ==
=== Mailnews Shutdown Service ===
A new shutdown interface is being developed for core mailnews. The new service should make it easier for developers and extension writers to do some things at shutdown time.
A new shutdown interface is being developed for core mailnews. The new service should make it easier for developers and extension writers to do some things at shutdown time.


Information about the implementation of the service is available at bug 397498.
Information about the implementation of the service is available at [https://bugzilla.mozilla.org/show_bug.cgi?id=397498 bug 397498].
 
Any class that wants to perform a shutdown task can simply inherit from <code>nsIObserver</code> and register for the task named: <code>"msg-shutdown"</code>:
 
  ...
  nsCOMPtr<nsIObserverService> observerService;
  observerService = do_GetService("@mozilla.org/observer-service;1");
  if (observerService)
    observerService->AddObserver(this, "msg-shutdown", PR_FALSE);
  ...
 
When the shutdown service detects a notification that the entire application wants to shutdown, it builds a to-do list of tasks by iterating through the <code>"msg-shutdown"</code> observers. Each observer is asked if it still needs to perform the task by calling <code>NeedsToRunTask()</code>. Setting the in-param in the <code>nsIMsgShutdownTask</code> instance will determine if the task will be queued or not.
 
When a <code>nsIMsgShutdownTask</code> instances turn is up to run, the shutdown service will call <code>DoShutdownTask()</code>. It is up to the <code>nsIMsgShutdownTask</code> instance to call <code>OnStopRunningUrl()</code> on the passed in <code>nsIUrlListener</code> in <code>DoShutdownTask()</code>
 
  NS_IMETHODIMP ShutdownTask::DoShutdownTask(nsIUrlListener *inUrlListener,
                                            nsIMsgWindow *inMsgWindow)
  {
    ...
    mUrlListener = inUrlListener;
  }
 
  ...
 
  nsresult ShutdownTask::ImDoneWithMyTask()
  {
    ...
    // Tell the shutdown service we are done running.
    mUrlListener->OnStopRunningUrl(nsnull, NS_OK);
  }
 
During the span of time when a task instance is running progress text can be modified by calling <code>nsMsgShutdownService::SetStatusText()</code>.
 
  ...
  nsCOMPtr<nsIMsgShutdownService> shutdownService;
  ...
  shutdownService->SetStatusText(NS_LITERAL_STRING("Hi Mom!"));
  ..
 
Note: Be sure to use a string-bundle for task title and progress strings. A initial .properties file has already been created (shutdownWindow.properties).

Latest revision as of 23:12, 28 October 2007

Mailnews Shutdown Service

A new shutdown interface is being developed for core mailnews. The new service should make it easier for developers and extension writers to do some things at shutdown time.

Information about the implementation of the service is available at bug 397498.

Any class that wants to perform a shutdown task can simply inherit from nsIObserver and register for the task named: "msg-shutdown":

 ...
 nsCOMPtr<nsIObserverService> observerService;
 observerService = do_GetService("@mozilla.org/observer-service;1");
 if (observerService)
   observerService->AddObserver(this, "msg-shutdown", PR_FALSE);
 ...

When the shutdown service detects a notification that the entire application wants to shutdown, it builds a to-do list of tasks by iterating through the "msg-shutdown" observers. Each observer is asked if it still needs to perform the task by calling NeedsToRunTask(). Setting the in-param in the nsIMsgShutdownTask instance will determine if the task will be queued or not.

When a nsIMsgShutdownTask instances turn is up to run, the shutdown service will call DoShutdownTask(). It is up to the nsIMsgShutdownTask instance to call OnStopRunningUrl() on the passed in nsIUrlListener in DoShutdownTask()

 NS_IMETHODIMP ShutdownTask::DoShutdownTask(nsIUrlListener *inUrlListener, 
                                            nsIMsgWindow *inMsgWindow)
 {
   ...
   mUrlListener = inUrlListener;
 }
 
 ...
 
 nsresult ShutdownTask::ImDoneWithMyTask()
 {
   ...
   // Tell the shutdown service we are done running.
   mUrlListener->OnStopRunningUrl(nsnull, NS_OK);
 }

During the span of time when a task instance is running progress text can be modified by calling nsMsgShutdownService::SetStatusText().

 ...
 nsCOMPtr<nsIMsgShutdownService> shutdownService;
 ...
 shutdownService->SetStatusText(NS_LITERAL_STRING("Hi Mom!"));
 ..

Note: Be sure to use a string-bundle for task title and progress strings. A initial .properties file has already been created (shutdownWindow.properties).