Bug 1393692 (part 1) - Convert nsIAtom arguments to strings before checking their value. r=jorgk
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 25 Aug 2017 16:35:44 +1000
changeset 22040 ac14ca6da23824d04c49339e1dc2f913babdbac5
parent 22039 aaf42ebb0c89b2b1e4d95fe8e395fe7b3d0df188
child 22041 40598e80284974c52925d38b04031c54783e0adc
push id13454
push usermozilla@jorgk.com
push dateFri, 25 Aug 2017 20:03:46 +0000
treeherdercomm-central@0a3658e44fd7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1393692
Bug 1393692 (part 1) - Convert nsIAtom arguments to strings before checking their value. r=jorgk A number of OnItem*() methods have nsIAtom parameters. Some of these methods convert those nsIAtoms to strings and then check their value against another string. Others check their value against an atom obtained from nsIAtomService. This patch changes the latter methods to be like the former methods, thus removing numerous uses of nsIAtomService.
mailnews/db/gloda/modules/index_msg.js
mailnews/imap/test/unit/test_imapHdrChunking.js
mailnews/news/test/unit/test_internalUris.js
mailnews/test/resources/mailTestUtils.js
--- a/mailnews/db/gloda/modules/index_msg.js
+++ b/mailnews/db/gloda/modules/index_msg.js
@@ -32,20 +32,16 @@ Cu.import("resource:///modules/gloda/dat
 Cu.import("resource:///modules/gloda/gloda.js");
 Cu.import("resource:///modules/gloda/collection.js");
 Cu.import("resource:///modules/gloda/connotent.js");
 
 Cu.import("resource:///modules/gloda/indexer.js");
 
 Cu.import("resource:///modules/gloda/mimemsg.js");
 
-XPCOMUtils.defineLazyServiceGetter(this, "atomService",
-                                   "@mozilla.org/atom-service;1",
-                                   "nsIAtomService");
-
 // Components.results does not have mailnews error codes!
 var NS_MSG_ERROR_FOLDER_SUMMARY_OUT_OF_DATE = 0x80550005;
 
 var GLODA_MESSAGE_ID_PROPERTY = "gloda-id";
 /**
  * Message header property to track dirty status; one of
  *  |GlodaIndexer.kMessageClean|, |GlodaIndexer.kMessageDirty|,
  *  |GlodaIndexer.kMessageFilthy|.
@@ -2764,54 +2760,31 @@ var GlodaMsgIndexer = {
    */
   _folderListener: {
     indexer: null,
 
     _init: function gloda_indexer_fl_init(aIndexer) {
       this.indexer = aIndexer;
     },
 
-    // We explicitly know about these things rather than bothering with some
-    // form of registration scheme because these aren't going to change much.
-    get _kFolderLoadedAtom() {
-      delete this._kFolderLoadedAtom;
-      return this._kFolderLoadedAtom = atomService.getAtom("FolderLoaded");
-    },
-    get _kKeywordsAtom() {
-      delete this._kKeywordsAtom;
-      return this._kKeywordsAtom = atomService.getAtom("Keywords");
-    },
-    get _kStatusAtom() {
-      delete this._kStatusAtom;
-      return this._kStatusAtom = atomService.getAtom("Status");
-    },
-    get _kFlaggedAtom() {
-      delete this._kFlaggedAtom;
-      return this._kFlaggedAtom = atomService.getAtom("Flagged");
-    },
-    get _kFolderFlagAtom() {
-      delete this._kFolderFlagAtom;
-      return this._kFolderFlagAtom = atomService.getAtom("FolderFlag");
-    },
-
     OnItemAdded: function gloda_indexer_OnItemAdded(aParentItem, aItem) {
     },
     OnItemRemoved: function gloda_indexer_OnItemRemoved(aParentItem, aItem) {
     },
     OnItemPropertyChanged: function gloda_indexer_OnItemPropertyChanged(
                              aItem, aProperty, aOldValue, aNewValue) {
     },
     /**
      * Detect changes to folder flags and reset our indexing priority.  This
      * is important because (all?) folders start out without any flags and
      * then get their flags added to them.
      */
     OnItemIntPropertyChanged: function gloda_indexer_OnItemIntPropertyChanged(
                                 aFolderItem, aProperty, aOldValue, aNewValue) {
-      if (aProperty !== this._kFolderFlagAtom)
+      if (aProperty.toString() !== "FolderFlag")
         return;
       if (!GlodaMsgIndexer.shouldIndexFolder(aFolderItem))
         return;
       // Only reset priority if folder Special Use changes.
       if ((aOldValue & Ci.nsMsgFolderFlags.SpecialUse) ==
           (aNewValue & Ci.nsMsgFolderFlags.SpecialUse))
         return;
       GlodaMsgIndexer.resetFolderIndexingPriority(aFolderItem);
@@ -2825,34 +2798,35 @@ var GlodaMsgIndexer = {
 
     },
     /**
      * Notice when user activity adds/removes tags or changes a message's
      *  status.
      */
     OnItemPropertyFlagChanged: function gloda_indexer_OnItemPropertyFlagChanged(
                                 aMsgHdr, aProperty, aOldValue, aNewValue) {
-      if (aProperty == this._kKeywordsAtom ||
+      let propertyString = aProperty.toString();
+      if (propertyString == "Keywords" ||
           // We could care less about the new flag changing.
-          (aProperty == this._kStatusAtom &&
+          (propertyString == "Status" &&
            (aOldValue ^ aNewValue) != nsMsgMessageFlags.New &&
            // We do care about IMAP deletion, but msgsDeleted tells us that, so
            //  ignore IMAPDeleted too...
            (aOldValue ^ aNewValue) != nsMsgMessageFlags.IMAPDeleted) ||
-          aProperty == this._kFlaggedAtom) {
+          propertyString == "Flagged") {
         GlodaMsgIndexer._reindexChangedMessages([aMsgHdr], true);
       }
     },
 
     /**
      * Get folder loaded notifications for folders that had to do some
      *  (asynchronous) processing before they could be opened.
      */
     OnItemEvent: function gloda_indexer_OnItemEvent(aFolder, aEvent) {
-      if (aEvent == this._kFolderLoadedAtom)
+      if (aEvent.toString() == "FolderLoaded")
         this.indexer._onFolderLoaded(aFolder);
     },
   },
 
   /* ***** Rebuilding / Reindexing ***** */
   /**
    * Allow us to invalidate an outstanding folder traversal because the
    *  underlying database is going away.  We use other means for detecting
--- a/mailnews/imap/test/unit/test_imapHdrChunking.js
+++ b/mailnews/imap/test/unit/test_imapHdrChunking.js
@@ -13,31 +13,28 @@ load("../../../resources/messageGenerato
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource:///modules/mailServices.js");
 // javascript mime emitter functions
 
 // IMAP pump
 
 setupIMAPPump();
 
-var kBiffStateAtom = Cc["@mozilla.org/atom-service;1"]
-                         .getService(Ci.nsIAtomService)
-                         .getAtom("BiffState");
 // Dummy message window so we can say the inbox is open in a window.
 var dummyMsgWindow =
 {
   openFolder : IMAPPump.inbox,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIMsgWindow,
                                          Ci.nsISupportsWeakReference])
 };
 
 var gFolderListener = {
   _gotNewMailBiff: false,
   OnItemIntPropertyChanged : function(aItem, aProperty, aOldValue, aNewValue) {
-    if (aProperty == kBiffStateAtom &&
+    if (aProperty.toString() == "BiffState" &&
         aNewValue == Ci.nsIMsgFolder.nsMsgBiffState_NewMail) {
       this._gotNewMailBiff = true;
       async_driver();
     }
   }
 };
 
 var tests = [
--- a/mailnews/news/test/unit/test_internalUris.js
+++ b/mailnews/news/test/unit/test_internalUris.js
@@ -53,22 +53,19 @@ function alert(title, text) {}
 function confirmEx(title, text, flags) {  return 0; }
 
 function* test_cancel() {
   // This tests nsMsgNewsFolder::CancelMessage
   let folder = localserver.rootFolder.getChildNamed("test.filter");
   let db = folder.msgDatabase;
   let hdr = db.GetMsgHdrForKey(4);
 
-  let atomService = Cc['@mozilla.org/atom-service;1']
-                      .getService(Ci.nsIAtomService);
-  let kDeleteAtom = atomService.getAtom("DeleteOrMoveMsgCompleted");
   let folderListener = {
     OnItemEvent: function(aEventFolder, aEvent) {
-      if (aEvent == kDeleteAtom) {
+      if (aEvent.toString() == "DeleteOrMoveMsgCompleted") {
         MailServices.mailSession.RemoveFolderListener(this);
       }
     }
   };
   MailServices.mailSession.AddFolderListener(folderListener, Ci.nsIFolderListener.event);
   folder.QueryInterface(Ci.nsIMsgNewsFolder)
         .cancelMessage(hdr, dummyMsgWindow);
   yield false;
--- a/mailnews/test/resources/mailTestUtils.js
+++ b/mailnews/test/resources/mailTestUtils.js
@@ -449,23 +449,19 @@ var mailTestUtils = {
    * @param [aSomeoneElseWillTriggerTheUpdate=false] If this is true, we do not
    *     trigger the updateFolder call and it is assumed someone else is taking
    *     care of that.
    */
   updateFolderAndNotify: function(aFolder, aCallback, aCallbackThis,
       aCallbackArgs, aSomeoneElseWillTriggerTheUpdate) {
     // register for the folder loaded notification ahead of time... even though
     //  we may not need it...
-    let atomService = Cc["@mozilla.org/atom-service;1"]
-                        .getService(Ci.nsIAtomService);
-    let kFolderLoadedAtom = atomService.getAtom("FolderLoaded");
-
     let folderListener = {
       OnItemEvent: function (aEventFolder, aEvent) {
-        if (aEvent == kFolderLoadedAtom && aFolder.URI == aEventFolder.URI) {
+        if (aEvent.toString() == "FolderLoaded" && aFolder.URI == aEventFolder.URI) {
           MailServices.mailSession.RemoveFolderListener(this);
           aCallback.apply(aCallbackThis, aCallbackArgs);
         }
       }
     };
 
     MailServices.mailSession.AddFolderListener(folderListener, Ci.nsIFolderListener.event);