33 if (typeof(
Cc) ==
"undefined")
34 var
Cc = Components.classes;
35 if (typeof(
Ci) ==
"undefined")
36 var
Ci = Components.interfaces;
37 if (typeof(
Cu) ==
"undefined")
38 var
Cu = Components.utils;
40 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
41 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
42 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
50 return this.
Application = Cc[
"@mozilla.org/fuel/application;1"]
51 .getService(Ci.fuelIApplication);
55 className:
"Songbird Device Error Monitor Service",
56 cid: Components.ID(
"{7a2a55d1-0270-4789-bc7c-12ffaa19b4cd}"),
57 contractID:
"@songbirdnest.com/device/error-monitor-service;1",
59 ifList: [ Ci.sbIDeviceEventListener,
60 Ci.sbIDeviceErrorMonitor,
66 category:
'app-startup',
67 entry:
'service-device-error-monitor',
68 value:
'service,@songbirdnest.com/device/error-monitor-service;1'
72 debugPref:
"songbird.device.errorMonitor.debug"
76 this._initialized =
false;
77 var obsSvc = Cc[
'@mozilla.org/observer-service;1']
78 .getService(Ci.nsIObserverService);
81 obsSvc.addObserver(
this,
'profile-after-change',
false);
82 obsSvc.addObserver(
this,
'quit-application',
false);
88 classID: deviceErrorMonitorConfig.cid,
89 contractID: deviceErrorMonitorConfig.contractID,
98 _direction: Ci.sbIDeviceStatus.EXPORT,
108 _init:
function deviceErrorMonitor__init() {
109 var deviceManagerSvc = Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
110 .getService(Ci.sbIDeviceManager2);
111 deviceManagerSvc.addEventListener(
this);
112 var sbs = Cc[
"@mozilla.org/intl/stringbundle;1"]
113 .getService(Ci.nsIStringBundleService);
114 this._sbStrings = sbs.createBundle(
"chrome://songbird/locale/songbird.properties");
116 this._debug =
Application.prefs.getValue(deviceErrorMonitorConfig.debugPref,
120 .getService(Ci.nsIConsoleService);
127 _shutdown:
function deviceErrorMonitor__shutdown() {
128 var deviceManagerSvc = Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
129 .getService(Ci.sbIDeviceManager2);
130 deviceManagerSvc.removeEventListener(
this);
131 while(this._deviceList.length > 0) {
132 if (this._deviceList[0].device) {
133 this._removeDevice(this._deviceList[0].device);
146 _addDevice:
function deviceErrorMonitor__addDevice(aDevice) {
147 var devIndex = this._findDeviceIndex(aDevice);
148 if (devIndex == -1) {
150 var newDeviceObj = {};
151 newDeviceObj.device = aDevice;
152 newDeviceObj.errorLists = { };
153 this._deviceList.push(newDeviceObj);
163 _removeDevice:
function deviceErrorMonitor__removeDevice(aDevice) {
164 var devIndex = this._findDeviceIndex(aDevice);
166 this._deviceList.splice(devIndex, 1);
176 _findDeviceIndex:
function deviceErrorMonitor__findDeviceIndex(aDevice) {
177 for (var
i = 0;
i < this._deviceList.length; ++
i) {
178 if (this._deviceList[
i].device.id.equals(aDevice.id)) {
192 _getContentType :
function deviceErrorMonitor__getContentType(aDeviceEvent) {
193 if (aDeviceEvent.data instanceof Ci.sbIMediaItem) {
194 return aDeviceEvent.data.contentType;
205 _getAllErrors :
function deviceErrorMonitor__getAllErrors(aDevIndex) {
206 var device = this._deviceList[aDevIndex];
212 for (var contentType in device.errorLists) {
213 errorList = errorList.concat(device.errorLists[contentType]);
226 _getErrorList :
function deviceErrorMonitor__getErrorList(aDevIndex,
229 let device = this._deviceList[aDevIndex];
230 let errorList = device.errorLists[aDirection + aContentType];
233 device.errorLists[aDirection + aContentType] = errorList;
244 _logError:
function deviceErrorMonitor__logError(aDeviceEvent, aErrorMsg) {
245 var device = aDeviceEvent.origin;
247 if (device instanceof Ci.sbIDevice) {
248 var devIndex = this._findDeviceIndex(device);
251 if (aDeviceEvent.data) {
252 if (aDeviceEvent.data instanceof Ci.sbIMediaList) {
253 mediaURL = aDeviceEvent.data.name;
254 mediaItem = aDeviceEvent.data;
255 }
else if (aDeviceEvent.data instanceof Ci.sbIMediaItem) {
256 mediaURL = aDeviceEvent.data.contentSrc.spec;
257 mediaURL = decodeURIComponent(mediaURL);
258 mediaItem = aDeviceEvent.data;
259 }
else if (aDeviceEvent.data instanceof Ci.nsIPropertyBag2) {
260 var bag = aDeviceEvent.data;
261 if (bag.hasKey(
"item")) {
262 mediaItem = bag.getPropertyAsInterface(
"item", Ci.sbIMediaItem);
263 mediaURL = mediaItem.contentSrc.spec;
264 mediaURL = decodeURIComponent(mediaURL);
266 }
else if (aDeviceEvent.data instanceof Ci.nsIFile) {
267 var
ios = Components.classes[
"@mozilla.org/network/io-service;1"]
268 .getService(Components.interfaces.nsIIOService);
269 var fileHandler = ios.getProtocolHandler(
"file")
270 .QueryInterface(Components.interfaces
271 .nsIFileProtocolHandler);
272 mediaURL = fileHandler.getURLSpecFromFile(aDeviceEvent.data);
275 mediaURL =
SBString(
"device.info.unknown");
279 var errorString = aErrorMsg;
281 errorString = this._sbStrings.formatStringFromName(
282 "device.error.format",
283 [aErrorMsg, mediaURL],
290 state : aDeviceEvent.deviceState
293 var contentType = this._getContentType(aDeviceEvent);
295 var errorList = this._getErrorList(devIndex,
300 if (errorInfo.item) {
301 for (var
i = 0;
i < errorList.length;
i++) {
302 var item = errorList[
i].item;
303 if (item && item.equals(errorInfo.item))
308 errorList.push(errorInfo);
310 this._notifyListeners(device);
321 _notifyListeners:
function deviceErrorMonitor__notifyListeners(aDevice) {
323 for (var
i = this._listenerList.length - 1;
i >= 0;
i--) {
325 this._listenerList[
i].onDeviceError(aDevice);
329 this._listenerList.splice(
i, 1);
344 deviceHasErrors:
function deviceErrorMonitor_deviceHasErrors(aDevice,
347 var devIndex = this._findDeviceIndex(aDevice);
349 var device = this._deviceList[devIndex];
351 if (!aContentType && !aDirection)
352 errorList = this._getAllErrors(devIndex);
353 else if (aContentType) {
354 errorList = this._getErrorList(devIndex, aContentType, aDirection);
357 throw Components.results.NS_ERROR_INVALID_ARG;
359 return (errorList ? (errorList.length > 0) :
false);
378 getDeviceErrors:
function deviceErrorMonitor_getDeviceErrors(aDevice,
381 var devIndex = this._findDeviceIndex(aDevice);
382 var errorList = Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
383 .createInstance(Ci.nsIMutableArray);
389 if (!aContentType && !aDirection)
390 jsErrorList = this._getAllErrors(devIndex);
391 else if (aContentType && aDirection) {
392 jsErrorList = this._getErrorList(devIndex, aContentType, aDirection);
395 throw Cr.NS_ERROR_INVALID_ARG;
397 for (var index = 0; index < jsErrorList.length; index++) {
399 var errorBag = Cc[
"@mozilla.org/hash-property-bag;1"]
400 .createInstance(Ci.nsIWritablePropertyBag2);
401 errorBag.setPropertyAsAString(
"msg", jsErrorList[index].
msg);
402 errorBag.setPropertyAsInterface(
"item",
403 jsErrorList[index].item,
405 errorBag.setPropertyAsUint32(
"state", jsErrorList[index].state);
407 errorList.appendElement(errorBag,
false);
418 clearErrorsForDevice:
function deviceErrorMonitor_clearErrorsForDevice(aDevice) {
419 var devIndex = this._findDeviceIndex(aDevice);
422 this._deviceList[devIndex].errorLists = {};
431 addListener:
function deviceErrorMonitor_addListener(aListener) {
432 if (this._listenerList.indexOf(aListener) < 0)
433 this._listenerList.push(aListener);
441 removeListener:
function deviceErrorMonitor_addListener(aListener) {
442 var listenerIndex = this._listenerList.indexOf(aListener);
443 if (listenerIndex >= 0)
444 this._listenerList.splice(listenerIndex, 1);
453 _getStateString:
function deviceErrorMonitor__getStateString(aDeviceState) {
454 var stateString =
"STATE_UNKNOWN";
455 switch (aDeviceState) {
456 case Ci.sbIDevice.STATE_IDLE:
457 stateString =
"STATE_IDLE";
459 case Ci.sbIDevice.STATE_SYNCING:
460 stateString =
"STATE_SYNCING";
462 case Ci.sbIDevice.STATE_COPYING:
463 stateString =
"STATE_COPYING";
465 case Ci.sbIDevice.STATE_DELETING:
466 stateString =
"STATE_DELETING";
468 case Ci.sbIDevice.STATE_UPDATING:
469 stateString =
"STATE_UPDATING";
471 case Ci.sbIDevice.STATE_MOUNTING:
472 stateString =
"STATE_MOUNTING";
474 case Ci.sbIDevice.STATE_DOWNLOADING:
475 stateString =
"STATE_DOWNLOADING";
477 case Ci.sbIDevice.STATE_UPLOADING:
478 stateString =
"STATE_UPLOADING";
480 case Ci.sbIDevice.STATE_DOWNLOAD_PAUSED:
481 stateString =
"STATE_DOWNLOAD_PAUSED";
483 case Ci.sbIDevice.STATE_UPLOAD_PAUSED:
484 stateString =
"STATE_UPLOAD_PAUSED";
486 case Ci.sbIDevice.STATE_DISCONNECTED:
487 stateString =
"STATE_DISCONNECTED";
489 case Ci.sbIDevice.STATE_BUSY:
490 stateString =
"STATE_BUSY";
492 case Ci.sbIDevice.STATE_CANCEL:
493 stateString =
"STATE_CANCEL";
495 case Ci.sbIDevice.STATE_TRANSCODE:
496 stateString =
"STATE_TRANSCODE";
498 case Ci.sbIDevice.STATE_FORMATTING:
499 stateString =
"STATE_FORMATTING";
501 case Ci.sbIDevice.STATE_SYNC_PREPARING:
502 stateString =
"STATE_SYNC_PREPARING";
504 case Ci.sbIDevice.STATE_SYNC_PLAYLIST:
505 stateString =
"STATE_SYNC_PLAYLIST";
507 case Ci.sbIDevice.STATE_COPY_PREPARING:
508 stateString =
"STATE_COPY_PREPARING";
510 case Ci.sbIDevice.STATE_SYNCING_TYPE:
511 stateString =
"STATE_SYNCING_TYPE";
513 case Ci.sbIDevice.STATE_COPYING_MUSIC:
514 stateString =
"STATE_COPYING_MUSIC";
516 case Ci.sbIDevice.STATE_COPYING_VIDEO:
517 stateString =
"STATE_COPYING_VIDEO";
521 return stateString +
" (" + aDeviceState +
")";
530 _getDeviceStateInformation:
531 function deviceErrorMonitor__getDeviceStateInformation(aDeviceEvent) {
533 var state = aDeviceEvent.deviceState;
534 var substate = aDeviceEvent.deviceSubState;
536 return this._getStateString(state) +
" - " + this._getStateString(substate);
544 _logDeviceEvent:
function deviceErrorMonitor__logDeviceEvent(aDeviceEvent) {
545 var evtMsg =
"Unknown Event";
551 device = aDeviceEvent.data.QueryInterface(Ci.sbIDevice);
554 switch (aDeviceEvent.type) {
555 case Ci.sbIDeviceEvent.EVENT_DEVICE_BASE:
556 evtMsg =
"EVENT_DEVICE_BASE";
558 case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED:
559 evtMsg =
"EVENT_DEVICE_ADDED";
561 case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED:
562 evtMsg =
"EVENT_DEVICE_REMOVED";
564 case Ci.sbIDeviceEvent.EVENT_DEVICE_RESET:
565 evtMsg =
"EVENT_DEVICE_RESET";
567 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_INSERTED:
568 evtMsg =
"EVENT_DEVICE_MEDIA_INSERTED";
570 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_REMOVED:
571 evtMsg =
"EVENT_DEVICE_MEDIA_REMOVED";
573 case Ci.sbIDeviceEvent.EVENT_DEVICE_READY:
574 evtMsg =
"EVENT_DEVICE_READY";
576 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_READ_START:
577 evtMsg =
"EVENT_DEVICE_MEDIA_READ_START";
579 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_READ_END:
580 evtMsg =
"EVENT_DEVICE_MEDIA_READ_END";
582 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_READ_FAILED:
583 evtMsg =
"EVENT_DEVICE_MEDIA_READ_FAILED";
585 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_WRITE_START:
586 evtMsg =
"EVENT_DEVICE_MEDIA_WRITE_START";
588 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_WRITE_END:
589 evtMsg =
"EVENT_DEVICE_MEDIA_WRITE_END";
591 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_WRITE_FAILED:
592 evtMsg =
"EVENT_DEVICE_MEDIA_WRITE_FAILED";
594 case Ci.sbIDeviceEvent.EVENT_DEVICE_INFO_CHANGED:
595 evtMsg =
"EVENT_DEVICE_INFO_CHANGED";
597 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_READ_UNSUPPORTED_TYPE:
598 evtMsg =
"EVENT_DEVICE_MEDIA_READ_UNSUPPORTED_TYPE";
600 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_WRITE_UNSUPPORTED_TYPE:
601 evtMsg =
"EVENT_DEVICE_MEDIA_WRITE_UNSUPPORTED_TYPE";
603 case Ci.sbIDeviceEvent.EVENT_DEVICE_ACCESS_DENIED:
604 evtMsg =
"EVENT_DEVICE_ACCESS_DENIED";
606 case Ci.sbIDeviceEvent.EVENT_DEVICE_NOT_ENOUGH_FREESPACE:
607 evtMsg =
"EVENT_DEVICE_NOT_ENOUGH_FREESPACE";
609 case Ci.sbIDeviceEvent.EVENT_DEVICE_NOT_AVAILABLE:
610 evtMsg =
"EVENT_DEVICE_NOT_AVAILABLE";
612 case Ci.sbIDeviceEvent.EVENT_DEVICE_ERROR_UNEXPECTED:
613 evtMsg =
"EVENT_DEVICE_ERROR_UNEXPECTED";
615 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSCODE_ERROR:
616 evtMsg =
"EVENT_DEVICE_TRANSCODE_ERROR";
618 case Ci.sbIDeviceEvent.EVENT_DEVICE_LIBRARY_ADDED:
619 evtMsg =
"EVENT_DEVICE_LIBRARY_ADDED";
621 case Ci.sbIDeviceEvent.EVENT_DEVICE_LIBRARY_REMOVED:
622 evtMsg =
"EVENT_DEVICE_LIBRARY_REMOVED";
624 case Ci.sbIDeviceEvent.EVENT_DEVICE_FILE_MISSING:
625 evtMsg =
"EVENT_DEVICE_FILE_MISSING";
627 case Ci.sbIDeviceEvent.EVENT_DEVICE_SCAN_START:
628 evtMsg =
"EVENT_DEVICE_SCAN_START";
630 case Ci.sbIDeviceEvent.EVENT_DEVICE_SCAN_END:
631 evtMsg =
"EVENT_DEVICE_SCAN_END";
633 case Ci.sbIDeviceEvent.EVENT_DEVICE_STATE_CHANGED:
634 evtMsg =
"EVENT_DEVICE_STATE_CHANGED";
636 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSFER_START:
637 evtMsg =
"EVENT_DEVICE_TRANSFER_START";
639 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSFER_PROGRESS:
640 evtMsg =
"EVENT_DEVICE_TRANSFER_PROGRESS";
642 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSFER_END:
643 evtMsg =
"EVENT_DEVICE_TRANSFER_END";
645 case Ci.sbIDeviceEvent.EVENT_DEVICE_MOUNTING_START:
646 evtMsg =
"EVENT_DEVICE_MOUNTING_START";
648 case Ci.sbIDeviceEvent.EVENT_DEVICE_MOUNTING_PROGRESS:
649 evtMsg =
"EVENT_DEVICE_MOUNTING_PROGRESS";
651 case Ci.sbIDeviceEvent.EVENT_DEVICE_MOUNTING_END:
652 evtMsg =
"EVENT_DEVICE_MOUNTING_END";
654 case Ci.sbIDeviceEvent.EVENT_DEVICE_PREFS_CHANGED:
655 evtMsg =
"EVENT_DEVICE_PREFS_CHANGED";
657 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSCODE_START:
658 evtMsg =
"EVENT_DEVICE_TRANSCODE_START";
660 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSCODE_PROGRESS:
661 evtMsg =
"EVENT_DEVICE_TRANSCODE_PROGRESS";
663 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSCODE_END:
664 evtMsg =
"EVENT_DEVICE_TRANSCODE_END";
666 case Ci.sbIDeviceEvent.EVENT_DEVICE_FORMATTING_START:
667 evtMsg =
"EVENT_DEVICE_FORMATTING_START";
669 case Ci.sbIDeviceEvent.EVENT_DEVICE_FORMATTING_PROGRESS:
670 evtMsg =
"EVENT_DEVICE_FORMATTING_PROGRESS";
672 case Ci.sbIDeviceEvent.EVENT_DEVICE_FORMATTING_END:
673 evtMsg =
"EVENT_DEVICE_FORMATTING_END";
677 var deviceGuid =
"{Unknown}";
679 deviceGuid = device.id +
"[" + device.name +
"]";
681 evtSubMsg = this._getDeviceStateInformation(aDeviceEvent);
683 var fullMsg =
"Device Event " + deviceGuid +
" - " + evtMsg +
": (" +
684 aDeviceEvent.type +
")\n" +
685 " State " + evtSubMsg +
"\n"
692 onDeviceEvent:
function deviceErrorMonitor_onDeviceEvent(aDeviceEvent) {
694 this._logDeviceEvent(aDeviceEvent);
696 switch(aDeviceEvent.type) {
697 case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED:
698 var device = aDeviceEvent.data.QueryInterface(Ci.sbIDevice);
699 this._addDevice(device);
702 case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED:
703 var device = aDeviceEvent.data.QueryInterface(Ci.sbIDevice);
704 this._removeDevice(device);
708 case Ci.sbIDeviceEvent.EVENT_DEVICE_ACCESS_DENIED:
709 this._logError(aDeviceEvent,
710 SBString(
"device.error.access_denied"));
712 case Ci.sbIDeviceEvent.EVENT_DEVICE_NOT_ENOUGH_FREESPACE:
713 this._logError(aDeviceEvent,
714 SBString(
"device.error.not_enough_free_space"));
716 case Ci.sbIDeviceEvent.EVENT_DEVICE_NOT_AVAILABLE:
717 this._logError(aDeviceEvent,
718 SBString(
"device.error.not_available"));
720 case Ci.sbIDeviceEvent.EVENT_DEVICE_ERROR_UNEXPECTED:
721 this._logError(aDeviceEvent,
722 SBString(
"device.error.unexpected"));
724 case Ci.sbIDeviceEvent.EVENT_DEVICE_FILE_MISSING:
725 this._logError(aDeviceEvent,
726 SBString(
"device.error.file_missing"));
728 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_WRITE_UNSUPPORTED_TYPE:
729 this._logError(aDeviceEvent,
730 SBString(
"device.error.unsupported_type"));
733 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSCODE_ERROR:
736 if (aDeviceEvent.data instanceof Ci.nsIPropertyBag2) {
737 message = aDeviceEvent.data.get(
"message");
738 if (!message && aDeviceEvent.data.hasKey(
"mediacore-error")) {
739 message = aDeviceEvent.data
740 .getPropertyAsInterface(
"mediacore-error",
741 Ci.sbIMediacoreError)
745 this._logError(aDeviceEvent, message);
748 case Ci.sbIDeviceEvent.EVENT_DEVICE_DOWNLOAD_ERROR:
751 if (aDeviceEvent.data instanceof Ci.nsIPropertyBag2) {
752 message = aDeviceEvent.data.get(
"message");
754 this._logError(aDeviceEvent, message);
757 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_READ_START:
759 this._direction = Ci.sbIDeviceStatus.IMPORT;
762 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_READ_END:
764 this._direction = Ci.sbIDeviceStatus.EXPORT;
769 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_WRITE_START:
771 this._direction = Ci.sbIDeviceStatus.EXPORT;
778 var obsSvc = Cc[
'@mozilla.org/observer-service;1']
779 .getService(Ci.nsIObserverService);
782 case 'quit-application':
783 obsSvc.removeObserver(
this,
'quit-application');
786 case 'profile-after-change':
787 obsSvc.removeObserver(
this,
'profile-after-change');
794 QueryInterface: XPCOMUtils.generateQI(deviceErrorMonitorConfig.ifList)
sbLibraryImporterManagerCfg categoryList
var deviceErrorMonitorConfig
sbOSDControlService prototype className
function NSGetModule(compMgr, fileSpec)
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function SBString(aKey, aDefault, aStringBundle)
function deviceErrorMonitor()
sbDeviceFirmwareAutoCheckForUpdate prototype classID
sbWindowsAutoPlayServiceCfg _xpcom_categories
__defineGetter__("Application", function(){delete this.Application;return this.Application=Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication);})
_getSelectedPageStyle s i
sbDeviceFirmwareAutoCheckForUpdate prototype observe