Bug 735536 - B2G SMS DB: Use new fangled IndexedDB string constants. r=philikon

This commit is contained in:
Fernando Jiménez 2012-03-16 16:34:05 -07:00
parent 2a4304b4b6
commit d92cb6203d

View File

@ -23,6 +23,11 @@ const FILTER_TIMESTAMP = "timestamp";
const FILTER_NUMBERS = "numbers"; const FILTER_NUMBERS = "numbers";
const FILTER_DELIVERY = "delivery"; const FILTER_DELIVERY = "delivery";
const READ_ONLY = "readonly";
const READ_WRITE = "readwrite";
const PREV = "prev";
const NEXT = "next";
XPCOMUtils.defineLazyServiceGetter(this, "gSmsService", XPCOMUtils.defineLazyServiceGetter(this, "gSmsService",
"@mozilla.org/sms/smsservice;1", "@mozilla.org/sms/smsservice;1",
"nsISmsService"); "nsISmsService");
@ -44,13 +49,13 @@ function SmsDatabaseService() {
gIDBManager.initWindowless(GLOBAL_SCOPE); gIDBManager.initWindowless(GLOBAL_SCOPE);
let that = this; let that = this;
this.newTxn(Ci.nsIIDBTransaction.READ_ONLY, function(error, txn, store){ this.newTxn(READ_ONLY, function(error, txn, store){
if (error) { if (error) {
return; return;
} }
// In order to get the highest key value, we open a key cursor in reverse // In order to get the highest key value, we open a key cursor in reverse
// order and get only the first pointed value. // order and get only the first pointed value.
let request = store.openCursor(null, Ci.nsIIDBCursor.PREV); let request = store.openCursor(null, PREV);
request.onsuccess = function onsuccess(event) { request.onsuccess = function onsuccess(event) {
let cursor = event.target.result; let cursor = event.target.result;
if (!cursor) { if (!cursor) {
@ -165,7 +170,7 @@ SmsDatabaseService.prototype = {
* Start a new transaction. * Start a new transaction.
* *
* @param txn_type * @param txn_type
* Type of transaction (e.g. IDBTransaction.READ_WRITE) * Type of transaction (e.g. READ_WRITE)
* @param callback * @param callback
* Function to call when the transaction is available. It will * Function to call when the transaction is available. It will
* be invoked with the transaction and the 'sms' object store. * be invoked with the transaction and the 'sms' object store.
@ -254,7 +259,7 @@ SmsDatabaseService.prototype = {
onMessageListCreated: function onMessageListCreated(messageList, requestId) { onMessageListCreated: function onMessageListCreated(messageList, requestId) {
if (DEBUG) debug("Message list created: " + messageList); if (DEBUG) debug("Message list created: " + messageList);
let self = this; let self = this;
self.newTxn(Ci.nsIIDBTransaction.READ_ONLY, function (error, txn, store) { self.newTxn(READ_ONLY, function (error, txn, store) {
if (error) { if (error) {
gSmsRequestManager.notifyReadMessageListFailed( gSmsRequestManager.notifyReadMessageListFailed(
requestId, Ci.nsISmsRequestManager.INTERNAL_ERROR); requestId, Ci.nsISmsRequestManager.INTERNAL_ERROR);
@ -295,7 +300,7 @@ SmsDatabaseService.prototype = {
this.lastKey += 1; this.lastKey += 1;
message.id = this.lastKey; message.id = this.lastKey;
if (DEBUG) debug("Going to store " + JSON.stringify(message)); if (DEBUG) debug("Going to store " + JSON.stringify(message));
this.newTxn(Ci.nsIIDBTransaction.READ_WRITE, function(error, txn, store) { this.newTxn(READ_WRITE, function(error, txn, store) {
if (error) { if (error) {
return; return;
} }
@ -330,7 +335,7 @@ SmsDatabaseService.prototype = {
getMessage: function getMessage(messageId, requestId) { getMessage: function getMessage(messageId, requestId) {
if (DEBUG) debug("Retrieving message with ID " + messageId); if (DEBUG) debug("Retrieving message with ID " + messageId);
this.newTxn(Ci.nsIIDBTransaction.READ_ONLY, function (error, txn, store) { this.newTxn(READ_ONLY, function (error, txn, store) {
if (error) { if (error) {
if (DEBUG) debug(error); if (DEBUG) debug(error);
gSmsRequestManager.notifyGetSmsFailed( gSmsRequestManager.notifyGetSmsFailed(
@ -383,7 +388,7 @@ SmsDatabaseService.prototype = {
deleteMessage: function deleteMessage(messageId, requestId) { deleteMessage: function deleteMessage(messageId, requestId) {
let self = this; let self = this;
this.newTxn(Ci.nsIIDBTransaction.READ_WRITE, function (error, txn, store) { this.newTxn(READ_WRITE, function (error, txn, store) {
if (error) { if (error) {
gSmsRequestManager.notifySmsDeleteFailed( gSmsRequestManager.notifySmsDeleteFailed(
requestId, Ci.nsISmsRequestManager.INTERNAL_ERROR); requestId, Ci.nsISmsRequestManager.INTERNAL_ERROR);
@ -404,7 +409,7 @@ SmsDatabaseService.prototype = {
// the message. As IndexedDB does not provide the affected records info, // 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 // we need to try to get the message from the database again to check
// that it is actually gone. // that it is actually gone.
self.newTxn(Ci.nsIIDBTransaction.READ_ONLY, function (error, txn, store) { self.newTxn(READ_ONLY, function (error, txn, store) {
let request = store.getAll(messageId); let request = store.getAll(messageId);
request.onsuccess = function onsuccess(event) { request.onsuccess = function onsuccess(event) {
let deleted = (event.target.result.length == 0); let deleted = (event.target.result.length == 0);
@ -478,7 +483,7 @@ SmsDatabaseService.prototype = {
}; };
let self = this; let self = this;
this.newTxn(Ci.nsIIDBTransaction.READ_ONLY, function (error, txn, store) { this.newTxn(READ_ONLY, function (error, txn, store) {
if (error) { if (error) {
errorCb(error); errorCb(error);
return; return;
@ -495,7 +500,7 @@ SmsDatabaseService.prototype = {
} else if (filter.endDate != null) { } else if (filter.endDate != null) {
timeKeyRange = IDBKeyRange.upperBound(filter.endDate.getTime()); timeKeyRange = IDBKeyRange.upperBound(filter.endDate.getTime());
} }
let direction = reverse ? Ci.nsIIDBCursor.PREV : Ci.nsIIDBCursor.NEXT; let direction = reverse ? PREV : NEXT;
let timeRequest = store.index("timestamp").openKeyCursor(timeKeyRange, let timeRequest = store.index("timestamp").openKeyCursor(timeKeyRange,
direction); direction);
@ -573,7 +578,7 @@ SmsDatabaseService.prototype = {
gSmsRequestManager.notifyNoMessageInList(requestId); gSmsRequestManager.notifyNoMessageInList(requestId);
return; return;
} }
this.newTxn(Ci.nsIIDBTransaction.READ_ONLY, function (error, txn, store) { this.newTxn(READ_ONLY, function (error, txn, store) {
if (DEBUG) debug("Fetching message " + messageId); if (DEBUG) debug("Fetching message " + messageId);
let request = store.get(messageId); let request = store.get(messageId);
let message; let message;