Bug 736708 - 1/3: WebSMS - support Replace-Short-Message-Type. Don't return next message id. r=gene
authorVicamo Yang <vyang@mozilla.com>
Wed, 20 Nov 2013 03:46:12 +0800
changeset 156373 5b4b95bde952be5e1d0baef69416ecd2412b6787
parent 156372 4bf339ae43561c8ff31567a340b65ff80dee872c
child 156374 ed0ffb6a9c8f9b74606fab802651499811d6719a
push id25677
push userryanvm@gmail.com
push dateWed, 20 Nov 2013 01:40:17 +0000
treeherdermozilla-central@0587548f1428 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgene
bugs736708
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 736708 - 1/3: WebSMS - support Replace-Short-Message-Type. Don't return next message id. r=gene
dom/mobilemessage/interfaces/nsIRilMobileMessageDatabaseService.idl
dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js
dom/system/gonk/RadioInterfaceLayer.js
--- a/dom/mobilemessage/interfaces/nsIRilMobileMessageDatabaseService.idl
+++ b/dom/mobilemessage/interfaces/nsIRilMobileMessageDatabaseService.idl
@@ -20,17 +20,17 @@ interface nsIRilMobileMessageDatabaseRec
 {
   /**
    * |aMessageRecord| Object: the mobile-message database record
    * |aDomMessage|: the nsIDOMMoz{Mms,Sms}Message. Noted, this value might be null.
    */
   void notify(in nsresult aRv, in jsval aMessageRecord, in nsISupports aDomMessage);
 };
 
-[scriptable, uuid(f6cd671e-f9af-11e2-b64b-1fb87e9c217c)]
+[scriptable, uuid(d5374151-7451-4590-a70e-40c49c1369ce)]
 interface nsIRilMobileMessageDatabaseService : nsIMobileMessageDatabaseService
 {
   /**
    * |aMessage| Object: should contain the following properties for internal use:
    *   - |type| DOMString: "sms" or "mms"
    *   - |sender| DOMString: the phone number of sender
    *   - |timestamp| Number: the timestamp of received message
    *   - |iccId| DOMString: the ICC ID of the SIM for receiving message
@@ -44,34 +44,34 @@ interface nsIRilMobileMessageDatabaseSer
    *     - |deliveryStatus| DOMString Array: the delivery status of received message
    *     - |receivers| DOMString Array: the phone numbers of receivers
    *     - |phoneNumber| DOMString: [optional] my own phone number.
    *     - |transactionId| DOMString: the transaction ID from MMS PDU header.
    *
    * Note: |deliveryStatus| should only contain single string to specify
    *       the delivery status of MMS message for the phone owner self.
    */
-  long saveReceivedMessage(in jsval aMessage,
+  void saveReceivedMessage(in jsval aMessage,
                 [optional] in nsIRilMobileMessageDatabaseCallback aCallback);
 
   /**
    * |aMessage| Object: should contain the following properties for internal use:
    *   - |type| DOMString: "sms" or "mms"
    *   - |sender| DOMString: the phone number of sender
    *   - |timestamp| Number: the timestamp of sending message
    *   - |deliveryStatusRequested| Bool: true when the delivery report is requested.
    *   - |iccId| DOMString: the ICC ID of the SIM for sending message
    *
    *   - If |type| == "sms", we also need:
    *     - |receiver| DOMString: the phone number of receiver
    *
    *   - If |type| == "mms", we also need:
    *     - |receivers| DOMString Array: the phone numbers of receivers
    */
-  long saveSendingMessage(in jsval aMessage,
+  void saveSendingMessage(in jsval aMessage,
                [optional] in nsIRilMobileMessageDatabaseCallback aCallback);
 
   /**
    * |aMessageId| Number: the message's DB record ID.
    * |aReceiver| DOMString: the phone number of receiver (for MMS; can be null).
    * |aDelivery| DOMString: the new delivery value to update (can be null).
    * |aDeliveryStatus| DOMString: the new delivery status to update (can be null).
    * |aEnvelopeId| DOMString: the "message-id" specified in the MMS PDU headers.
--- a/dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js
+++ b/dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js
@@ -1450,60 +1450,62 @@ MobileMessageDatabaseService.prototype =
                 + JSON.stringify(threadRecord));
         }
         aCallback(threadRecord, participantIds);
       };
     });
   },
 
   saveRecord: function saveRecord(aMessageRecord, aAddresses, aCallback) {
-    let isOverriding = (aMessageRecord.id !== undefined);
-    if (!isOverriding) {
-      // Assign a new id.
-      this.lastMessageId += 1;
-      aMessageRecord.id = this.lastMessageId;
-    }
     if (DEBUG) debug("Going to store " + JSON.stringify(aMessageRecord));
 
     let self = this;
-    function notifyResult(rv) {
-      if (!aCallback) {
-        return;
-      }
-      let domMessage = self.createDomMessageFromRecord(aMessageRecord);
-      aCallback.notify(rv, domMessage);
-    }
+    this.newTxn(READ_WRITE, function(error, txn, stores) {
+      let notifyResult = function(rv) {
+        if (aCallback) {
+          aCallback.notify(rv, self.createDomMessageFromRecord(aMessageRecord));
+        }
+      };
 
-    this.newTxn(READ_WRITE, function(error, txn, stores) {
       if (error) {
         // TODO bug 832140 check event.target.errorCode
         notifyResult(Cr.NS_ERROR_FAILURE);
         return;
       }
+
       txn.oncomplete = function oncomplete(event) {
+        if (aMessageRecord.id > self.lastMessageId) {
+          self.lastMessageId = aMessageRecord.id;
+        }
         notifyResult(Cr.NS_OK);
       };
       txn.onabort = function onabort(event) {
         // TODO bug 832140 check event.target.errorCode
         notifyResult(Cr.NS_ERROR_FAILURE);
       };
 
       let messageStore = stores[0];
       let participantStore = stores[1];
       let threadStore = stores[2];
 
       self.findThreadRecordByParticipants(threadStore, participantStore,
                                           aAddresses, true,
                                           function (threadRecord,
                                                     participantIds) {
         if (!participantIds) {
-          notifyResult(Cr.NS_ERROR_FAILURE);
+          txn.abort();
           return;
         }
 
+        let isOverriding = (aMessageRecord.id !== undefined);
+        if (!isOverriding) {
+          // |self.lastMessageId| is only updated in |txn.oncomplete|.
+          aMessageRecord.id = self.lastMessageId + 1;
+        }
+
         let insertMessageRecord = function (threadId) {
           // Setup threadId & threadIdIndex.
           aMessageRecord.threadId = threadId;
           aMessageRecord.threadIdIndex = [threadId, timestamp];
           // Setup participantIdsIndex.
           aMessageRecord.participantIdsIndex = [];
           for each (let id in participantIds) {
             aMessageRecord.participantIdsIndex.push([id, timestamp]);
@@ -1575,18 +1577,16 @@ MobileMessageDatabaseService.prototype =
                          unreadCount: aMessageRecord.read ? 0 : 1,
                          lastMessageType: aMessageRecord.type})
                    .onsuccess = function (event) {
           let threadId = event.target.result;
           insertMessageRecord(threadId);
         };
       });
     }, [MESSAGE_STORE_NAME, PARTICIPANT_STORE_NAME, THREAD_STORE_NAME]);
-    // We return the key that we expect to store in the db
-    return aMessageRecord.id;
   },
 
   forEachMatchedMmsDeliveryInfo:
     function forEachMatchedMmsDeliveryInfo(aDeliveryInfo, aNeedle, aCallback) {
 
     let typedAddress = MMS.Address.resolveType(aNeedle);
     let normalizedAddress, parsedAddress;
     if (typedAddress.type === "PLMN") {
@@ -1884,17 +1884,17 @@ MobileMessageDatabaseService.prototype =
 
       // If |deliveryTimestamp| is not specified, use 0 as default.
       if (aMessage.deliveryTimestamp == undefined) {
         aMessage.deliveryTimestamp = 0;
       }
     }
     aMessage.deliveryIndex = [aMessage.delivery, timestamp];
 
-    return this.saveRecord(aMessage, threadParticipants, aCallback);
+    this.saveRecord(aMessage, threadParticipants, aCallback);
   },
 
   saveSendingMessage: function saveSendingMessage(aMessage, aCallback) {
     if ((aMessage.type != "sms" && aMessage.type != "mms") ||
         (aMessage.type == "sms" && aMessage.receiver == undefined) ||
         (aMessage.type == "mms" && !Array.isArray(aMessage.receivers)) ||
         aMessage.deliveryStatusRequested == undefined ||
         aMessage.timestamp == undefined) {
@@ -1946,17 +1946,17 @@ MobileMessageDatabaseService.prototype =
     aMessage.read = FILTER_READ_READ;
 
     let addresses;
     if (aMessage.type == "sms") {
       addresses = [aMessage.receiver];
     } else if (aMessage.type == "mms") {
       addresses = aMessage.receivers;
     }
-    return this.saveRecord(aMessage, addresses, aCallback);
+    this.saveRecord(aMessage, addresses, aCallback);
   },
 
   setMessageDeliveryByMessageId: function setMessageDeliveryByMessageId(
       messageId, receiver, delivery, deliveryStatus, envelopeId, callback) {
     this.updateMessageDeliveryById(messageId, "messageId",
                                    receiver, delivery, deliveryStatus,
                                    envelopeId, callback);
 
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -1930,28 +1930,28 @@ RadioInterface.prototype = {
         result: (success ? RIL.PDU_FCS_OK
                          : RIL.PDU_FCS_MEMORY_CAPACITY_EXCEEDED)
       });
 
       if (!success) {
         // At this point we could send a message to content to notify the user
         // that storing an incoming SMS failed, most likely due to a full disk.
         if (DEBUG) {
-          this.debug("Could not store SMS " + message.id + ", error code " + rv);
+          this.debug("Could not store SMS, error code " + rv);
         }
         return;
       }
 
       this.broadcastSmsSystemMessage(kSmsReceivedObserverTopic, domMessage);
       Services.obs.notifyObservers(domMessage, kSmsReceivedObserverTopic, null);
     }.bind(this);
 
     if (message.messageClass != RIL.GECKO_SMS_MESSAGE_CLASSES[RIL.PDU_DCS_MSG_CLASS_0]) {
-      message.id = gMobileMessageDatabaseService.saveReceivedMessage(message,
-                                                                     notifyReceived);
+      gMobileMessageDatabaseService.saveReceivedMessage(message,
+                                                        notifyReceived);
     } else {
       message.id = -1;
       message.threadId = 0;
       message.delivery = DOM_MOBILE_MESSAGE_DELIVERY_RECEIVED;
       message.deliveryStatus = RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS;
       message.read = false;
 
       let domMessage =
@@ -3141,18 +3141,18 @@ RadioInterface.prototype = {
                                                "normal", // message class
                                                sendingMessage.timestamp,
                                                0,
                                                false);
       notifyResult(Cr.NS_OK, domMessage);
       return;
     }
 
-    let id = gMobileMessageDatabaseService.saveSendingMessage(
-      sendingMessage, notifyResult);
+    gMobileMessageDatabaseService.saveSendingMessage(sendingMessage,
+                                                     notifyResult);
   },
 
   registerDataCallCallback: function registerDataCallCallback(callback) {
     if (this._datacall_callbacks) {
       if (this._datacall_callbacks.indexOf(callback) != -1) {
         throw new Error("Already registered this callback!");
       }
     } else {