Bug 733268 - B2G SMS DB: fix deleteMessage behaviour. r=philikon
authorFernando Jiménez <ferjmoreno@gmail.com>
Fri, 16 Mar 2012 16:38:50 -0700
changeset 89581 23dac9398f21c0f1672ea349bce27ce211bc8782
parent 89580 c0e783b4cc4bca7488d81b6605c18c1932fed333
child 89582 c8eff2808a2f5e774e025df9f42b0c8082713bfe
push id22262
push userpweitershausen@mozilla.com
push dateSat, 17 Mar 2012 00:22:55 +0000
treeherdermozilla-central@8ecce10fe9b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilikon
bugs733268
milestone14.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 733268 - B2G SMS DB: fix deleteMessage behaviour. r=philikon
dom/sms/src/ril/SmsDatabaseService.js
--- a/dom/sms/src/ril/SmsDatabaseService.js
+++ b/dom/sms/src/ril/SmsDatabaseService.js
@@ -382,56 +382,38 @@ SmsDatabaseService.prototype = {
         //TODO look at event.target.errorCode, pick appropriate error constant
         gSmsRequestManager.notifyGetSmsFailed(
           requestId, Ci.nsISmsRequestManager.INTERNAL_ERROR);
       };
     });
   },
 
   deleteMessage: function deleteMessage(messageId, requestId) {
+    let deleted = false;
     let self = this;
     this.newTxn(READ_WRITE, function (error, txn, store) {
       if (error) {
         gSmsRequestManager.notifySmsDeleteFailed(
           requestId, Ci.nsISmsRequestManager.INTERNAL_ERROR);
         return;
       }
-      let request = store.delete(messageId);
+      let request = store.count(messageId);
 
-      request.onerror = function onerror(event) {
-        if (DEBUG) debug("Caught error on request ", event.target.errorCode);
-        //TODO look at event.target.errorCode
-        gSmsRequestManager.notifySmsDeleteFailed(
-          requestId, Ci.nsISmsRequestManager.INTERNAL_ERROR);
+      request.onsuccess = function onsuccess(event) {        
+        let count = event.target.result;
+        if (DEBUG) debug("Count for messageId " + messageId + ": " + count);
+        deleted = (count == 1);
+        if (deleted) {
+          store.delete(messageId);
+        }
       };
 
       txn.oncomplete = function oncomplete(event) {
         if (DEBUG) debug("Transaction " + txn + " completed.");
-        // Once we transaction is done, we need to check if we actually deleted
-        // the message. As IndexedDB does not provide the affected records info,
-        // we need to try to get the message from the database again to check
-        // that it is actually gone.
-        self.newTxn(READ_ONLY, function (error, txn, store) {
-          let request = store.getAll(messageId);
-          request.onsuccess = function onsuccess(event) {
-            let deleted = (event.target.result.length == 0);
-            gSmsRequestManager.notifySmsDeleted(requestId, deleted);
-          };
-          request.onerror = function onerror(event) {
-            if (DEBUG) {
-              debug("Error checking the message deletion " +
-                    event.target.errorCode);
-            }
-            //TODO should we notify here as an internal error? The failed check
-            //     does not mean that the deletion has failed, so maybe we
-            //     should notify successfully.
-            gSmsRequestManager.notifySmsDeleteFailed(
-              requestId, Ci.nsISmsRequestManager.INTERNAL_ERROR);
-          };
-        });
+        gSmsRequestManager.notifySmsDeleted(requestId, deleted);
       };
 
       txn.onerror = function onerror(event) {
         if (DEBUG) debug("Caught error on transaction", event.target.errorCode);
         //TODO look at event.target.errorCode, pick appropriate error constant
         gSmsRequestManager.notifySmsDeleteFailed(
           requestId, Ci.nsISmsRequestManager.INTERNAL_ERROR);
       };