Bug 958782 - 2.a/3: refactoring, alignments. f=Ms2ger,r=khuey
☠☠ backed out by dfd721d38a74 ☠ ☠
authorVicamo Yang <vyang@mozilla.com>
Mon, 23 Jun 2014 20:55:56 +0800
changeset 190187 15a281081b971ecd72584f70dc58f56c89018b36
parent 190186 033708b53979aebce204af0a77bd85a3e9e36f12
child 190188 731f37afb6498ae303de3276476aaaa07230b640
push id27003
push userkwierso@gmail.com
push dateTue, 24 Jun 2014 01:56:11 +0000
treeherdermozilla-central@e86b84998b18 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs958782
milestone33.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 958782 - 2.a/3: refactoring, alignments. f=Ms2ger,r=khuey
dom/mobilemessage/src/MobileMessageManager.cpp
dom/mobilemessage/src/MobileMessageManager.h
--- a/dom/mobilemessage/src/MobileMessageManager.cpp
+++ b/dom/mobilemessage/src/MobileMessageManager.cpp
@@ -122,52 +122,51 @@ MobileMessageManager::GetSegmentInfoForT
   nsresult rv = smsService->GetSegmentInfoForText(aText, msgCallback);
   NS_ENSURE_SUCCESS(rv, rv);
 
   request.forget(aRequest);
   return NS_OK;
 }
 
 nsresult
-MobileMessageManager::Send(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
+MobileMessageManager::Send(JSContext* aCx,
+                           JS::Handle<JSObject*> aGlobal,
+                           nsISmsService* aSmsService,
                            uint32_t aServiceId,
                            JS::Handle<JSString*> aNumber,
-                           const nsAString& aMessage,
+                           const nsAString& aText,
                            JS::MutableHandle<JS::Value> aRequest)
 {
-  nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
-
   nsDependentJSString number;
   number.init(aCx, aNumber);
 
   nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
   nsCOMPtr<nsIMobileMessageCallback> msgCallback =
     new MobileMessageCallback(request);
 
   // By default, we don't send silent messages via MobileMessageManager.
-  nsresult rv = smsService->Send(aServiceId, number, aMessage,
-                                 false, msgCallback);
+  nsresult rv = aSmsService->Send(aServiceId, number, aText,
+                                  false, msgCallback);
   NS_ENSURE_SUCCESS(rv, rv);
 
   js::AssertSameCompartment(aCx, aGlobal);
   rv = nsContentUtils::WrapNative(aCx,
                                   static_cast<nsIDOMDOMRequest*>(request.get()),
                                   aRequest);
   if (NS_FAILED(rv)) {
     NS_ERROR("Failed to create the js value!");
     return rv;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 MobileMessageManager::Send(JS::Handle<JS::Value> aNumber,
-                           const nsAString& aMessage,
+                           const nsAString& aText,
                            JS::Handle<JS::Value> aSendParams,
                            JSContext* aCx,
                            uint8_t aArgc,
                            JS::MutableHandle<JS::Value> aReturn)
 {
   if (!aNumber.isString() && !JS_IsArrayObject(aCx, aNumber)) {
     return NS_ERROR_INVALID_ARG;
   }
@@ -185,33 +184,35 @@ MobileMessageManager::Send(JS::Handle<JS
     ac.construct(aCx, global);
   }
 
   nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
 
   // Use the default one unless |aSendParams.serviceId| is available.
   uint32_t serviceId;
-  rv = smsService->GetSmsDefaultServiceId(&serviceId);
-  NS_ENSURE_SUCCESS(rv, rv);
+  RootedDictionary<SmsSendParameters> sendParams(aCx);
 
-  if (aArgc == 1) {
+  if (aArgc >= 1) {
     JS::Rooted<JS::Value> param(aCx, aSendParams);
-    RootedDictionary<SmsSendParameters> sendParams(aCx);
     if (!sendParams.Init(aCx, param)) {
       return NS_ERROR_TYPE_ERR;
     }
-    if (sendParams.mServiceId.WasPassed()) {
-      serviceId = sendParams.mServiceId.Value();
-    }
+  }
+
+  if (sendParams.mServiceId.WasPassed()) {
+    serviceId = sendParams.mServiceId.Value();
+  } else {
+    rv = smsService->GetSmsDefaultServiceId(&serviceId);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (aNumber.isString()) {
     JS::Rooted<JSString*> str(aCx, aNumber.toString());
-    return Send(aCx, global, serviceId, str, aMessage, aReturn);
+    return Send(aCx, global, smsService, serviceId, str, aText, aReturn);
   }
 
   // Must be an array then.
   JS::Rooted<JSObject*> numbers(aCx, &aNumber.toObject());
 
   uint32_t size;
   if (!JS_GetArrayLength(aCx, numbers, &size)) {
     return NS_ERROR_FAILURE;
@@ -229,17 +230,17 @@ MobileMessageManager::Send(JS::Handle<JS
       return NS_ERROR_INVALID_ARG;
     }
 
     str = JS::ToString(aCx, number);
     if (!str) {
       return NS_ERROR_FAILURE;
     }
 
-    nsresult rv = Send(aCx, global, serviceId, str, aMessage, requests[i]);
+    nsresult rv = Send(aCx, global, smsService, serviceId, str, aText, requests[i]);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   JS::Rooted<JSObject*> obj(aCx);
   obj = JS_NewArrayObject(aCx, requests);
   if (!obj) {
     return NS_ERROR_FAILURE;
   }
@@ -255,49 +256,53 @@ MobileMessageManager::SendMMS(JS::Handle
                               uint8_t aArgc,
                               nsIDOMDOMRequest** aRequest)
 {
   nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(mmsService, NS_ERROR_FAILURE);
 
   // Use the default one unless |aSendParams.serviceId| is available.
   uint32_t serviceId;
-  nsresult rv = mmsService->GetMmsDefaultServiceId(&serviceId);
-  NS_ENSURE_SUCCESS(rv, rv);
+  RootedDictionary<MmsSendParameters> sendParams(aCx);
+  nsresult rv;
 
-  if (aArgc == 1) {
+  if (aArgc >= 1) {
     JS::Rooted<JS::Value> param(aCx, aSendParams);
-    RootedDictionary<MmsSendParameters> sendParams(aCx);
     if (!sendParams.Init(aCx, param)) {
       return NS_ERROR_TYPE_ERR;
     }
-    if (sendParams.mServiceId.WasPassed()) {
-      serviceId = sendParams.mServiceId.Value();
-    }
+  }
+
+  if (sendParams.mServiceId.WasPassed()) {
+    serviceId = sendParams.mServiceId.Value();
+  } else {
+    rv = mmsService->GetMmsDefaultServiceId(&serviceId);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
   nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
   rv = mmsService->Send(serviceId, aParams, msgCallback);
   NS_ENSURE_SUCCESS(rv, rv);
 
   request.forget(aRequest);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-MobileMessageManager::GetMessageMoz(int32_t aId, nsIDOMDOMRequest** aRequest)
+MobileMessageManager::GetMessageMoz(int32_t aId,
+                                    nsIDOMDOMRequest** aRequest)
 {
-  nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
+  nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
     do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
 
   nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
   nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
-  nsresult rv = mobileMessageDBService->GetMessageMoz(aId, msgCallback);
+  nsresult rv = dbService->GetMessageMoz(aId, msgCallback);
   NS_ENSURE_SUCCESS(rv, rv);
 
   request.forget(aRequest);
   return NS_OK;
 }
 
 nsresult
 MobileMessageManager::GetMessageId(JSContext* aCx,
@@ -314,17 +319,18 @@ MobileMessageManager::GetMessageId(JSCon
   if (mmsMessage) {
     return mmsMessage->GetId(aId);
   }
 
   return NS_ERROR_INVALID_ARG;
 }
 
 NS_IMETHODIMP
-MobileMessageManager::Delete(JS::Handle<JS::Value> aParam, JSContext* aCx,
+MobileMessageManager::Delete(JS::Handle<JS::Value> aParam,
+                             JSContext* aCx,
                              nsIDOMDOMRequest** aRequest)
 {
   // We expect Int32, SmsMessage, MmsMessage, Int32[], SmsMessage[], MmsMessage[]
   if (!aParam.isObject() && !aParam.isInt32()) {
     return NS_ERROR_INVALID_ARG;
   }
 
   nsresult rv = NS_OK;
@@ -409,29 +415,29 @@ MobileMessageManager::GetMessages(nsIDOM
 
   cursorCallback->mDOMCursor = new DOMCursor(GetOwner(), continueCallback);
   NS_ADDREF(*aCursor = cursorCallback->mDOMCursor);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-MobileMessageManager::MarkMessageRead(int32_t aId, bool aValue,
+MobileMessageManager::MarkMessageRead(int32_t aId,
+                                      bool aValue,
                                       bool aSendReadReport,
                                       nsIDOMDOMRequest** aRequest)
 {
-  nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
+  nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
     do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
 
   nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
   nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
-  nsresult rv = mobileMessageDBService->MarkMessageRead(aId, aValue,
-                                                        aSendReadReport,
-                                                        msgCallback);
+  nsresult rv = dbService->MarkMessageRead(aId, aValue, aSendReadReport,
+                                           msgCallback);
   NS_ENSURE_SUCCESS(rv, rv);
 
   request.forget(aRequest);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 MobileMessageManager::GetThreads(nsIDOMDOMCursor** aCursor)
@@ -450,30 +456,30 @@ MobileMessageManager::GetThreads(nsIDOMD
 
   cursorCallback->mDOMCursor = new DOMCursor(GetOwner(), continueCallback);
   NS_ADDREF(*aCursor = cursorCallback->mDOMCursor);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-MobileMessageManager::RetrieveMMS(int32_t id,
+MobileMessageManager::RetrieveMMS(int32_t aId,
                                   nsIDOMDOMRequest** aRequest)
 {
-    nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
-    NS_ENSURE_TRUE(mmsService, NS_ERROR_FAILURE);
+  nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
+  NS_ENSURE_TRUE(mmsService, NS_ERROR_FAILURE);
 
-    nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
-    nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
+  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
+  nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
 
-    nsresult rv = mmsService->Retrieve(id, msgCallback);
-    NS_ENSURE_SUCCESS(rv, rv);
+  nsresult rv = mmsService->Retrieve(aId, msgCallback);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-    request.forget(aRequest);
-    return NS_OK;
+  request.forget(aRequest);
+  return NS_OK;
 }
 
 nsresult
 MobileMessageManager::DispatchTrustedSmsEventToSelf(const char* aTopic,
                                                     const nsAString& aEventName,
                                                     nsISupports* aMsg)
 {
   nsCOMPtr<nsIDOMMozSmsMessage> sms = do_QueryInterface(aMsg);
@@ -547,24 +553,25 @@ MobileMessageManager::Observe(nsISupport
   if (!strcmp(aTopic, kSmsReadErrorObserverTopic)) {
     return DispatchTrustedSmsEventToSelf(aTopic, READ_ERROR_EVENT_NAME, aSubject);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-MobileMessageManager::GetSmscAddress(uint32_t aServiceId, uint8_t aArgc,
+MobileMessageManager::GetSmscAddress(uint32_t aServiceId,
+                                     uint8_t aArgc,
                                      nsIDOMDOMRequest** aRequest)
 {
   nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
 
   nsresult rv;
-  if (aArgc != 1) {
+  if (aArgc == 0) {
     rv = smsService->GetSmsDefaultServiceId(&aServiceId);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
   nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
   rv = smsService->GetSmscAddress(aServiceId, msgCallback);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/dom/mobilemessage/src/MobileMessageManager.h
+++ b/dom/mobilemessage/src/MobileMessageManager.h
@@ -5,16 +5,17 @@
 
 #ifndef mozilla_dom_mobilemessage_MobileMessageManager_h
 #define mozilla_dom_mobilemessage_MobileMessageManager_h
 
 #include "mozilla/DOMEventTargetHelper.h"
 #include "nsIDOMMobileMessageManager.h"
 #include "nsIObserver.h"
 
+class nsISmsService;
 class nsIDOMMozSmsMessage;
 class nsIDOMMozMmsMessage;
 
 namespace mozilla {
 namespace dom {
 
 class MobileMessageManager : public DOMEventTargetHelper
                            , public nsIDOMMozMobileMessageManager
@@ -29,29 +30,35 @@ public:
 
   void Init(nsPIDOMWindow *aWindow);
   void Shutdown();
 
 private:
   /**
    * Internal Send() method used to send one message.
    */
-  nsresult Send(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
-                uint32_t aServiceId,
-                JS::Handle<JSString*> aNumber,
-                const nsAString& aMessage,
-                JS::MutableHandle<JS::Value> aRequest);
+  nsresult
+  Send(JSContext* aCx,
+       JS::Handle<JSObject*> aGlobal,
+       nsISmsService* aSmsService,
+       uint32_t aServiceId,
+       JS::Handle<JSString*> aNumber,
+       const nsAString& aText,
+       JS::MutableHandle<JS::Value> aRequest);
 
-  nsresult DispatchTrustedSmsEventToSelf(const char* aTopic,
-                                         const nsAString& aEventName,
-                                         nsISupports* aMsg);
+  nsresult
+  DispatchTrustedSmsEventToSelf(const char* aTopic,
+                                const nsAString& aEventName,
+                                nsISupports* aMsg);
 
   /**
    * Helper to get message ID from SMS/MMS Message object
    */
-  nsresult GetMessageId(JSContext* aCx, const JS::Value& aMessage,
-                        int32_t* aId);
+  nsresult
+  GetMessageId(JSContext* aCx,
+               const JS::Value& aMessage,
+               int32_t* aId);
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_mobilemessage_MobileMessageManager_h