Bug 720632 - Part 4: Use nsISmsRequestManager in Android JNI code. r=cjones
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Mon, 20 Feb 2012 00:44:29 +0100
changeset 87185 7b757f2d70c4ce875e061e31ef8f347db849ff69
parent 87184 b6344097919d78941721d3f2ceba8c0bd66d1586
child 87186 16c4770044a8e360c391e917c4f0e6be327664c5
push id6240
push userpweitershausen@mozilla.com
push dateSun, 19 Feb 2012 23:45:02 +0000
treeherdermozilla-inbound@16c4770044a8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs720632
milestone13.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 720632 - Part 4: Use nsISmsRequestManager in Android JNI code. r=cjones
widget/android/AndroidJNI.cpp
--- a/widget/android/AndroidJNI.cpp
+++ b/widget/android/AndroidJNI.cpp
@@ -60,19 +60,18 @@
 #endif
 
 #include "mozilla/unused.h"
 
 #include "mozilla/dom/sms/SmsMessage.h"
 #include "mozilla/dom/sms/Constants.h"
 #include "mozilla/dom/sms/Types.h"
 #include "mozilla/dom/sms/PSms.h"
-#include "mozilla/dom/sms/SmsRequestManager.h"
-#include "mozilla/dom/sms/SmsRequest.h"
 #include "mozilla/dom/sms/SmsParent.h"
+#include "nsISmsRequestManager.h"
 #include "nsISmsDatabaseService.h"
 
 using namespace mozilla;
 using namespace mozilla::dom::sms;
 
 /* Forward declare all the JNI methods as extern "C" */
 
 extern "C" {
@@ -340,17 +339,21 @@ Java_org_mozilla_gecko_GeckoAppShell_not
         if (!obs) {
           return NS_OK;
         }
 
         nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
         obs->NotifyObservers(message, kSmsSentObserverTopic, nsnull);
 
         if (mProcessId == 0) { // Parent process.
-          SmsRequestManager::GetInstance()->NotifySmsSent(mRequestId, message);
+          nsCOMPtr<nsISmsRequestManager> requestManager
+            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
+          if (requestManager) {
+            requestManager->NotifySmsSent(mRequestId, message);
+          }
         } else { // Content process.
           nsTArray<SmsParent*> spList;
           SmsParent::GetAll(spList);
 
           for (PRUint32 i=0; i<spList.Length(); ++i) {
             unused << spList[i]->SendNotifyRequestSmsSent(mMessageData,
                                                           mRequestId,
                                                           mProcessId);
@@ -414,49 +417,54 @@ Java_org_mozilla_gecko_GeckoAppShell_not
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifySmsSendFailed(JNIEnv* jenv, jclass,
                                                          jint aError,
                                                          jint aRequestId,
                                                          jlong aProcessId)
 {
     class NotifySmsSendFailedRunnable : public nsRunnable {
     public:
-      NotifySmsSendFailedRunnable(SmsRequest::ErrorType aError,
-                                  PRInt32 aRequestId, PRUint64 aProcessId)
+      NotifySmsSendFailedRunnable(PRInt32 aError,
+                                  PRInt32 aRequestId,
+                                  PRUint64 aProcessId)
         : mError(aError)
         , mRequestId(aRequestId)
         , mProcessId(aProcessId)
       {}
 
       NS_IMETHODIMP Run() {
         if (mProcessId == 0) { // Parent process.
-          SmsRequestManager::GetInstance()->NotifySmsSendFailed(mRequestId, mError);
+          nsCOMPtr<nsISmsRequestManager> requestManager
+            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
+          if (requestManager) {
+            requestManager->NotifySmsSendFailed(mRequestId, mError);
+          }
         } else { // Content process.
           nsTArray<SmsParent*> spList;
           SmsParent::GetAll(spList);
 
           for (PRUint32 i=0; i<spList.Length(); ++i) {
             unused << spList[i]->SendNotifyRequestSmsSendFailed(mError,
                                                                 mRequestId,
                                                                 mProcessId);
           }
         }
 
         return NS_OK;
       }
 
     private:
-      SmsRequest::ErrorType mError;
-      PRInt32               mRequestId;
-      PRUint64              mProcessId;
+      PRInt32  mError;
+      PRInt32  mRequestId;
+      PRUint64 mProcessId;
     };
 
 
     nsCOMPtr<nsIRunnable> runnable =
-      new NotifySmsSendFailedRunnable(SmsRequest::ErrorType(aError), aRequestId, aProcessId);
+      new NotifySmsSendFailedRunnable(aError, aRequestId, aProcessId);
     NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifyGetSms(JNIEnv* jenv, jclass,
                                                   jint aId,
                                                   jstring aReceiver,
                                                   jstring aSender,
@@ -472,17 +480,21 @@ Java_org_mozilla_gecko_GeckoAppShell_not
         : mMessageData(aMessageData)
         , mRequestId(aRequestId)
         , mProcessId(aProcessId)
       {}
 
       NS_IMETHODIMP Run() {
         if (mProcessId == 0) { // Parent process.
           nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
-          SmsRequestManager::GetInstance()->NotifyGotSms(mRequestId, message);
+          nsCOMPtr<nsISmsRequestManager> requestManager
+            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
+          if (requestManager) {
+            requestManager->NotifyGotSms(mRequestId, message);
+          }
         } else { // Content process.
           nsTArray<SmsParent*> spList;
           SmsParent::GetAll(spList);
 
           for (PRUint32 i=0; i<spList.Length(); ++i) {
             unused << spList[i]->SendNotifyRequestGotSms(mMessageData,
                                                          mRequestId,
                                                          mProcessId);
@@ -512,49 +524,54 @@ Java_org_mozilla_gecko_GeckoAppShell_not
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifyGetSmsFailed(JNIEnv* jenv, jclass,
                                                         jint aError,
                                                         jint aRequestId,
                                                         jlong aProcessId)
 {
     class NotifyGetSmsFailedRunnable : public nsRunnable {
     public:
-      NotifyGetSmsFailedRunnable(SmsRequest::ErrorType aError,
-                                  PRInt32 aRequestId, PRUint64 aProcessId)
+      NotifyGetSmsFailedRunnable(PRInt32 aError,
+                                 PRInt32 aRequestId,
+                                 PRUint64 aProcessId)
         : mError(aError)
         , mRequestId(aRequestId)
         , mProcessId(aProcessId)
       {}
 
       NS_IMETHODIMP Run() {
         if (mProcessId == 0) { // Parent process.
-          SmsRequestManager::GetInstance()->NotifyGetSmsFailed(mRequestId, mError);
+          nsCOMPtr<nsISmsRequestManager> requestManager
+            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
+          if (requestManager) {
+            requestManager->NotifyGetSmsFailed(mRequestId, mError);
+          }
         } else { // Content process.
           nsTArray<SmsParent*> spList;
           SmsParent::GetAll(spList);
 
           for (PRUint32 i=0; i<spList.Length(); ++i) {
             unused << spList[i]->SendNotifyRequestGetSmsFailed(mError,
                                                                mRequestId,
                                                                mProcessId);
           }
         }
 
         return NS_OK;
       }
 
     private:
-      SmsRequest::ErrorType mError;
-      PRInt32               mRequestId;
-      PRUint64              mProcessId;
+      PRInt32  mError;
+      PRInt32  mRequestId;
+      PRUint64 mProcessId;
     };
 
 
     nsCOMPtr<nsIRunnable> runnable =
-      new NotifyGetSmsFailedRunnable(SmsRequest::ErrorType(aError), aRequestId, aProcessId);
+      new NotifyGetSmsFailedRunnable(aError, aRequestId, aProcessId);
     NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifySmsDeleted(JNIEnv* jenv, jclass,
                                                       jboolean aDeleted,
                                                       jint aRequestId,
                                                       jlong aProcessId)
@@ -565,17 +582,21 @@ Java_org_mozilla_gecko_GeckoAppShell_not
                                PRUint64 aProcessId)
         : mDeleted(aDeleted)
         , mRequestId(aRequestId)
         , mProcessId(aProcessId)
       {}
 
       NS_IMETHODIMP Run() {
         if (mProcessId == 0) { // Parent process.
-          SmsRequestManager::GetInstance()->NotifySmsDeleted(mRequestId, mDeleted);
+          nsCOMPtr<nsISmsRequestManager> requestManager
+            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
+          if (requestManager) {
+            requestManager->NotifySmsDeleted(mRequestId, mDeleted);
+          }
         } else { // Content process.
           nsTArray<SmsParent*> spList;
           SmsParent::GetAll(spList);
 
           for (PRUint32 i=0; i<spList.Length(); ++i) {
             unused << spList[i]->SendNotifyRequestSmsDeleted(mDeleted,
                                                              mRequestId,
                                                              mProcessId);
@@ -600,49 +621,54 @@ Java_org_mozilla_gecko_GeckoAppShell_not
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifySmsDeleteFailed(JNIEnv* jenv, jclass,
                                                            jint aError,
                                                            jint aRequestId,
                                                            jlong aProcessId)
 {
     class NotifySmsDeleteFailedRunnable : public nsRunnable {
     public:
-      NotifySmsDeleteFailedRunnable(SmsRequest::ErrorType aError,
-                                    PRInt32 aRequestId, PRUint64 aProcessId)
+      NotifySmsDeleteFailedRunnable(PRInt32 aError,
+                                    PRInt32 aRequestId,
+                                    PRUint64 aProcessId)
         : mError(aError)
         , mRequestId(aRequestId)
         , mProcessId(aProcessId)
       {}
 
       NS_IMETHODIMP Run() {
         if (mProcessId == 0) { // Parent process.
-          SmsRequestManager::GetInstance()->NotifySmsDeleteFailed(mRequestId, mError);
+          nsCOMPtr<nsISmsRequestManager> requestManager
+            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
+          if (requestManager) {
+            requestManager->NotifySmsDeleteFailed(mRequestId, mError);
+          }
         } else { // Content process.
           nsTArray<SmsParent*> spList;
           SmsParent::GetAll(spList);
 
           for (PRUint32 i=0; i<spList.Length(); ++i) {
             unused << spList[i]->SendNotifyRequestSmsDeleteFailed(mError,
                                                                   mRequestId,
                                                                   mProcessId);
           }
         }
 
         return NS_OK;
       }
 
     private:
-      SmsRequest::ErrorType mError;
-      PRInt32               mRequestId;
-      PRUint64              mProcessId;
+      PRInt32  mError;
+      PRInt32  mRequestId;
+      PRUint64 mProcessId;
     };
 
 
     nsCOMPtr<nsIRunnable> runnable =
-      new NotifySmsDeleteFailedRunnable(SmsRequest::ErrorType(aError), aRequestId, aProcessId);
+      new NotifySmsDeleteFailedRunnable(aError, aRequestId, aProcessId);
     NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifyNoMessageInList(JNIEnv* jenv, jclass,
                                                            jint aRequestId,
                                                            jlong aProcessId)
 {
@@ -650,17 +676,21 @@ Java_org_mozilla_gecko_GeckoAppShell_not
     public:
       NotifyNoMessageInListRunnable(PRInt32 aRequestId, PRUint64 aProcessId)
         : mRequestId(aRequestId)
         , mProcessId(aProcessId)
       {}
 
       NS_IMETHODIMP Run() {
         if (mProcessId == 0) { // Parent process.
-          SmsRequestManager::GetInstance()->NotifyNoMessageInList(mRequestId);
+          nsCOMPtr<nsISmsRequestManager> requestManager
+            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
+          if (requestManager) {
+            requestManager->NotifyNoMessageInList(mRequestId);
+          }
         } else { // Content process.
           nsTArray<SmsParent*> spList;
           SmsParent::GetAll(spList);
 
           for (PRUint32 i=0; i<spList.Length(); ++i) {
             unused << spList[i]->SendNotifyRequestNoMessageInList(mRequestId,
                                                                   mProcessId);
           }
@@ -700,19 +730,23 @@ Java_org_mozilla_gecko_GeckoAppShell_not
         , mMessage(aMessage)
         , mRequestId(aRequestId)
         , mProcessId(aProcessId)
       {}
 
       NS_IMETHODIMP Run() {
         if (mProcessId == 0) { // Parent process.
           nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessage);
-          SmsRequestManager::GetInstance()->NotifyCreateMessageList(mRequestId,
-                                                                    mListId,
-                                                                    message);
+          nsCOMPtr<nsISmsRequestManager> requestManager
+            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
+          if (requestManager) {
+            requestManager->NotifyCreateMessageList(mRequestId,
+                                                    mListId,
+                                                    message);
+          }
         } else { // Content process.
           nsTArray<SmsParent*> spList;
           SmsParent::GetAll(spList);
 
           for (PRUint32 i=0; i<spList.Length(); ++i) {
             unused << spList[i]->SendNotifyRequestCreateMessageList(mListId,
                                                                     mMessage,
                                                                     mRequestId,
@@ -760,18 +794,21 @@ Java_org_mozilla_gecko_GeckoAppShell_not
         : mMessage(aMessage)
         , mRequestId(aRequestId)
         , mProcessId(aProcessId)
       {}
 
       NS_IMETHODIMP Run() {
         if (mProcessId == 0) { // Parent process.
           nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessage);
-          SmsRequestManager::GetInstance()->NotifyGotNextMessage(mRequestId,
-                                                                 message);
+          nsCOMPtr<nsISmsRequestManager> requestManager
+            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
+          if (requestManager) {
+            requestManager->NotifyGotNextMessage(mRequestId, message);
+          }
         } else { // Content process.
           nsTArray<SmsParent*> spList;
           SmsParent::GetAll(spList);
 
           for (PRUint32 i=0; i<spList.Length(); ++i) {
             unused << spList[i]->SendNotifyRequestGotNextMessage(mMessage,
                                                                  mRequestId,
                                                                  mProcessId);
@@ -803,49 +840,54 @@ Java_org_mozilla_gecko_GeckoAppShell_not
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifyReadingMessageListFailed(JNIEnv* jenv, jclass,
                                                                     jint aError,
                                                                     jint aRequestId,
                                                                     jlong aProcessId)
 {
     class NotifyReadListFailedRunnable : public nsRunnable {
     public:
-      NotifyReadListFailedRunnable(SmsRequest::ErrorType aError,
-                                    PRInt32 aRequestId, PRUint64 aProcessId)
+      NotifyReadListFailedRunnable(PRInt32 aError,
+                                   PRInt32 aRequestId,
+                                   PRUint64 aProcessId)
         : mError(aError)
         , mRequestId(aRequestId)
         , mProcessId(aProcessId)
       {}
 
       NS_IMETHODIMP Run() {
         if (mProcessId == 0) { // Parent process.
-          SmsRequestManager::GetInstance()->NotifyReadMessageListFailed(mRequestId, mError);
+          nsCOMPtr<nsISmsRequestManager> requestManager
+            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
+          if (requestManager) {
+            requestManager->NotifyReadMessageListFailed(mRequestId, mError);
+          }
         } else { // Content process.
           nsTArray<SmsParent*> spList;
           SmsParent::GetAll(spList);
 
           for (PRUint32 i=0; i<spList.Length(); ++i) {
             unused << spList[i]->SendNotifyRequestReadListFailed(mError,
                                                                  mRequestId,
                                                                  mProcessId);
           }
         }
 
         return NS_OK;
       }
 
     private:
-      SmsRequest::ErrorType mError;
-      PRInt32               mRequestId;
-      PRUint64              mProcessId;
+      PRInt32  mError;
+      PRInt32  mRequestId;
+      PRUint64 mProcessId;
     };
 
 
     nsCOMPtr<nsIRunnable> runnable =
-      new NotifyReadListFailedRunnable(SmsRequest::ErrorType(aError), aRequestId, aProcessId);
+      new NotifyReadListFailedRunnable(aError, aRequestId, aProcessId);
     NS_DispatchToMainThread(runnable);
 }
 
 #ifdef MOZ_JAVA_COMPOSITOR
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_bindWidgetTexture(JNIEnv* jenv, jclass)
 {