27 const Cc = Components.classes;
28 const Ci = Components.interfaces;
29 const Cu = Components.utils;
30 const Cr = Components.results;
37 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
38 Cu.import(
"resource://app/jsmodules/WindowUtils.jsm");
39 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
49 .getService(
Ci.nsIObserverService);
50 observerService.addObserver(
this,
"quit-application-requested",
false);
60 _mShouldShutdown:
true,
61 _mShutdownFlags:
Ci.nsIAppStartup.eAttemptQuit,
62 _mStatus:
Ci.sbIJobProgress.STATUS_RUNNING,
66 if (aTopic ==
"quit-application-requested") {
69 .getService(
Ci.nsIObserverService);
72 observerService.enumerateObservers(
"songbird-shutdown");
73 while (listenerEnum.hasMoreElements()) {
76 listenerEnum.getNext().QueryInterface(
Ci.sbIShutdownJob);
78 if (curTask.needsToRunTask) {
79 this._mTasks.push(curTask);
87 if (this._mTasks.length > 0) {
89 var stopShutdown = aSubject.QueryInterface(
Ci.nsISupportsPRBool);
90 stopShutdown.data =
true;
94 if (
aData ==
"restart") {
95 this._mShutdownFlags |=
Ci.nsIAppStartup.eRestart;
101 this._mShouldShutdown =
false;
104 this._startProcessingTasks();
110 onJobProgress:
function(aJobProgress) {
111 this._notifyListeners();
113 switch (aJobProgress.status) {
114 case Ci.sbIJobProgress.STATUS_FAILED:
117 Cu.reportError(
"sbShutdownJobService - shutdown job failed!");
119 case Ci.sbIJobProgress.STATUS_SUCCEEDED:
121 var curTask = this._mTasks[this._mTaskIndex];
122 curTask.removeJobProgressListener(
this);
125 this._mProgress += this._mTasks[this._mTaskIndex].total;
129 this._processNextTask();
136 return this._mStatus;
144 var statusText = this._mTasks[this._mTaskIndex].statusText;
145 var remainingTasks = (this._mTasks.length - this._mTaskIndex) -1;
147 if (statusText ==
"") {
149 statusText =
SBString(
"shutdownservice.defaultstatustext");
152 if (remainingTasks == 0) {
157 [statusText, remainingTasks]);
162 return SBString(
"shutdownservice.statustitle");
166 return this._mProgress + this._mTasks[this._mTaskIndex].progress;
177 getErrorMessages:
function() {
182 addJobProgressListener:
function(aJobListener) {
183 this._mListeners.push(aJobListener);
186 removeJobProgressListener:
function(aJobListener) {
187 var listenerIndex = this._mListeners.indexOf(aJobListener);
188 if (listenerIndex > -1) {
189 this._mListeners.splice(listenerIndex, 1);
202 _startProcessingTasks:
function() {
204 for (var
i = 0;
i < this._mTasks.length;
i++) {
205 this._mTotal += this._mTasks[
i].total;
210 var winMediator =
Cc[
"@mozilla.org/appshell/window-mediator;1"]
211 .getService(
Ci.nsIWindowMediator);
212 var songbirdWin = winMediator.getMostRecentWindow(
"Songbird:Main");
217 var
args =
Cc[
"@mozilla.org/array;1"].createInstance(
Ci.nsIMutableArray);
218 args.appendElement(
this,
false);
222 var appShellService =
Cc[
"@mozilla.org/appshell/appShellService;1"]
223 .getService(
Ci.nsIAppShellService);
225 var parentWindow = appShellService.hiddenDOMWindow;
226 parentWindow.openDialog(
"chrome://songbird/content/xul/jobProgress.xul",
227 "job_progress_dialog",
228 "chrome,centerscreen",
231 this._processNextTask();
234 _processNextTask:
function() {
235 if (this._mTaskIndex < this._mTasks.length) {
236 this._notifyListeners();
238 var nextTask = this._mTasks[this._mTaskIndex];
240 nextTask.addJobProgressListener(
this);
241 nextTask.startTask(
this);
244 Cu.reportError(
"Error processing shutdown task!");
246 this._processNextTask();
254 _doShutdown:
function() {
258 this._notifyListeners();
262 this._mStatus =
Ci.sbIJobProgress.STATUS_SUCCEEDED;
263 this._notifyListeners();
266 this._mTasks.splice(0);
269 if (this._mShouldShutdown) {
270 var appStartup =
Cc[
"@mozilla.org/toolkit/app-startup;1"]
271 .getService(
Ci.nsIAppStartup);
272 appStartup.quit(this._mShutdownFlags);
276 _notifyListeners:
function() {
279 var listeners = [].concat(this._mListeners);
280 for (var
i = 0;
i < listeners.length;
i++) {
282 listeners[
i].onJobProgress(
this);
290 _sleep:
function(ms) {
291 var threadManager =
Cc[
"@mozilla.org/thread-manager;1"]
292 .getService(
Ci.nsIThreadManager);
293 var mainThread = threadManager.mainThread;
294 var then =
new Date().getTime(),
now = then;
295 for (;
now - then < ms;
now =
new Date().getTime()) {
296 mainThread.processNextEvent(
true);
306 Ci.sbIJobProgressListener,
308 Ci.sbIJobCancelable])
317 function(aCompMgr, aFileSpec, aLocation) {
318 XPCOMUtils.categoryManager.addCategoryEntry(
"app-startup",
const SB_SHUTDOWNSERVICE_CONTRACTID
static nsCOMPtr< nsIObserverService > observerService
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
sbOSDControlService prototype className
function NSGetModule(compMgr, fileSpec)
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
function sbShutdownJobService()
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function SBString(aKey, aDefault, aStringBundle)
const SB_SHUTDOWNSERVICE_DESC
const SB_SHUTDOWNSERVICE_CID
const SB_SHUTDOWNSERVICE_CLASSNAME
sbDeviceFirmwareAutoCheckForUpdate prototype classID
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe