Bug 674725 - Part AJ - Create a message list when getMessages() is called. r=smaug
authorMounir Lamouri <mounir.lamouri@gmail.com>
Tue, 17 Jan 2012 19:42:05 +0100
changeset 84721 3f4e4e0d231249db6b82bdecaf156618eabaeada
parent 84720 48725e4f215ac788f704f6c64ecbc3be034d3efc
child 84722 0da63ad71e41b11e0fd4c98ce52afa5f2db0429c
push id21873
push usermlamouri@mozilla.com
push dateWed, 18 Jan 2012 10:29:07 +0000
treeherdermozilla-central@7538f4d4697c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs674725
milestone12.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 674725 - Part AJ - Create a message list when getMessages() is called. r=smaug
dom/sms/interfaces/nsIDOMSmsManager.idl
dom/sms/interfaces/nsISmsDatabaseService.idl
dom/sms/src/SmsManager.cpp
dom/sms/src/SmsMessage.cpp
dom/sms/src/Types.h
dom/sms/src/android/SmsDatabaseService.cpp
dom/sms/src/fallback/SmsDatabaseService.cpp
dom/sms/src/ipc/PSms.ipdl
dom/sms/src/ipc/SmsIPCService.cpp
dom/sms/src/ipc/SmsParent.cpp
dom/sms/src/ipc/SmsParent.h
--- a/dom/sms/interfaces/nsIDOMSmsManager.idl
+++ b/dom/sms/interfaces/nsIDOMSmsManager.idl
@@ -33,29 +33,32 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsIDOMEventTarget.idl"
 
 interface nsIDOMEventListener;
 interface nsIDOMMozSmsRequest;
+interface nsIDOMMozSmsFilter;
 
-[scriptable, function, uuid(4e628d96-abc9-45e1-b158-8970885a2552)]
+[scriptable, function, uuid(c9916dce-2947-41bb-95c2-818f792a020c)]
 interface nsIDOMMozSmsManager : nsIDOMEventTarget
 {
   unsigned short      getNumberOfMessagesForText(in DOMString text);
 
   // The first parameter can be either a DOMString (only one number) or an array
   // of DOMStrings.
   // The method returns a SmsRequest object if one number has been passed.
   // An array of SmsRequest objects otherwise.
   jsval send(in jsval number, in DOMString message);
 
   [binaryname(GetMessageMoz)] nsIDOMMozSmsRequest getMessage(in long id);
 
   // The parameter can be either a message id or a SmsMessage.
   nsIDOMMozSmsRequest delete(in jsval param);
 
+  nsIDOMMozSmsRequest getMessages(in nsIDOMMozSmsFilter filter, in boolean reverse);
+
   attribute nsIDOMEventListener onreceived;
   attribute nsIDOMEventListener onsent;
   attribute nsIDOMEventListener ondelivered;
 };
--- a/dom/sms/interfaces/nsISmsDatabaseService.idl
+++ b/dom/sms/interfaces/nsISmsDatabaseService.idl
@@ -33,22 +33,26 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 %{C++
 #define SMS_DATABASE_SERVICE_CID \
-{ 0xcc939280, 0x36ba, 0x4a03,    \
-{ 0xbe, 0x20, 0xd1, 0xfa, 0x7e, 0xb0, 0x44, 0x1e } }
+{ 0xcb971459, 0xe85a, 0x49b3,    \
+{ 0xbc, 0x1c, 0x10, 0x40, 0x27, 0x1e, 0x04, 0x6c } }
 #define SMS_DATABASE_SERVICE_CONTRACTID "@mozilla.org/sms/smsdatabaseservice;1"
 %}
 
-[scriptable, function, uuid(8f217fbf-88d9-4e72-8399-8c4d5e5cf7d0)]
+interface nsIDOMMozSmsFilter;
+
+[scriptable, function, uuid(33358749-d1b3-4bd6-835c-ef3869f0e966)]
 interface nsISmsDatabaseService : nsISupports
 {
   // Takes some information required to save the message and returns its id.
   long saveSentMessage(in DOMString aReceiver, in DOMString aBody, in unsigned long long aDate);
 
   [binaryname(GetMessageMoz)] void getMessage(in long messageId, in long requestId, [optional] in unsigned long long processId);
   void deleteMessage(in long messageId, in long requestId, [optional] in unsigned long long processId);
+
+  void createMessageList(in nsIDOMMozSmsFilter filter, in boolean reverse, in long requestId, [optional] in unsigned long long processId);
 };
--- a/dom/sms/src/SmsManager.cpp
+++ b/dom/sms/src/SmsManager.cpp
@@ -30,16 +30,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "SmsFilter.h"
 #include "SmsManager.h"
 #include "nsIDOMClassInfo.h"
 #include "nsISmsService.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "Constants.h"
 #include "SmsEvent.h"
 #include "nsIDOMSmsMessage.h"
@@ -261,16 +262,39 @@ SmsManager::Delete(const jsval& aParam, 
   NS_ENSURE_TRUE(message, NS_ERROR_INVALID_ARG);
 
   PRInt32 id;
   message->GetId(&id);
 
   return Delete(id, aRequest);
 }
 
+NS_IMETHODIMP
+SmsManager::GetMessages(nsIDOMMozSmsFilter* aFilter, bool aReverse,
+                        nsIDOMMozSmsRequest** aRequest)
+{
+  nsCOMPtr<nsIDOMMozSmsFilter> filter = aFilter;
+
+  if (!filter) {
+    filter = new SmsFilter();
+  }
+
+  int requestId =
+    SmsRequestManager::GetInstance()->CreateRequest(mOwner, mScriptContext, aRequest);
+  NS_ASSERTION(*aRequest, "The request object must have been created!");
+
+  nsCOMPtr<nsISmsDatabaseService> smsDBService =
+    do_GetService(SMS_DATABASE_SERVICE_CONTRACTID);
+  NS_ENSURE_TRUE(smsDBService, NS_ERROR_FAILURE);
+
+  smsDBService->CreateMessageList(filter, aReverse, requestId, 0);
+
+  return NS_OK;
+}
+
 NS_IMPL_EVENT_HANDLER(SmsManager, received)
 NS_IMPL_EVENT_HANDLER(SmsManager, sent)
 NS_IMPL_EVENT_HANDLER(SmsManager, delivered)
 
 nsresult
 SmsManager::DispatchTrustedSmsEventToSelf(const nsAString& aEventName, nsIDOMMozSmsMessage* aMessage)
 {
   nsRefPtr<nsDOMEvent> event = new SmsEvent(nsnull, nsnull);
--- a/dom/sms/src/SmsMessage.cpp
+++ b/dom/sms/src/SmsMessage.cpp
@@ -139,18 +139,19 @@ SmsMessage::GetDelivery(nsAString& aDeli
   switch (mData.delivery()) {
     case eDeliveryState_Received:
       aDelivery = DELIVERY_RECEIVED;
       break;
     case eDeliveryState_Sent:
       aDelivery = DELIVERY_SENT;
       break;
     case eDeliveryState_Unknown:
+    case eDeliveryState_EndGuard:
     default:
-      NS_ASSERTION(true, "We shouldn't get an unknown delivery state!");
+      NS_ASSERTION(true, "We shouldn't get any other delivery state!");
       return NS_ERROR_UNEXPECTED;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SmsMessage::GetSender(nsAString& aSender)
--- a/dom/sms/src/Types.h
+++ b/dom/sms/src/Types.h
@@ -43,31 +43,32 @@
 namespace mozilla {
 namespace dom {
 namespace sms {
 
 // For SmsMessageDate.delivery.
 enum DeliveryState {
   eDeliveryState_Sent,
   eDeliveryState_Received,
+  eDeliveryState_Unknown,
   // This state should stay at the end.
-  eDeliveryState_Unknown
+  eDeliveryState_EndGuard
 };
 
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
 
 namespace IPC {
 
 /**
  * Delivery state serializer.
  */
 template <>
 struct ParamTraits<mozilla::dom::sms::DeliveryState>
   : public EnumSerializer<mozilla::dom::sms::DeliveryState,
                           mozilla::dom::sms::eDeliveryState_Sent,
-                          mozilla::dom::sms::eDeliveryState_Unknown>
+                          mozilla::dom::sms::eDeliveryState_EndGuard>
 {};
 
 } // namespace IPC
 
 #endif // mozilla_dom_sms_Types_h
--- a/dom/sms/src/android/SmsDatabaseService.cpp
+++ b/dom/sms/src/android/SmsDatabaseService.cpp
@@ -78,11 +78,20 @@ SmsDatabaseService::DeleteMessage(PRInt3
   if (!AndroidBridge::Bridge()) {
     return NS_OK;
   }
 
   AndroidBridge::Bridge()->DeleteMessage(aMessageId, aRequestId, aProcessId);
   return NS_OK;
 }
 
+NS_IMETHODIMP
+SmsDatabaseService::CreateMessageList(nsIDOMMozSmsFilter* aFilter,
+                                      bool aReverse, PRInt32 aRequestId,
+                                      PRUint64 aProcessId)
+{
+  // TODO: implement
+  return NS_OK;
+}
+
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
--- a/dom/sms/src/fallback/SmsDatabaseService.cpp
+++ b/dom/sms/src/fallback/SmsDatabaseService.cpp
@@ -64,11 +64,20 @@ SmsDatabaseService::GetMessageMoz(PRInt3
 NS_IMETHODIMP
 SmsDatabaseService::DeleteMessage(PRInt32 aMessageId, PRInt32 aRequestId,
                                   PRUint64 aProcessId)
 {
   NS_ERROR("We should not be here!");
   return NS_OK;
 }
 
+NS_IMETHODIMP
+SmsDatabaseService::CreateMessageList(nsIDOMMozSmsFilter* aFilter,
+                                      bool aReverse, PRInt32 aRequestId,
+                                      PRUint64 aProcessId)
+{
+  NS_ERROR("We should not be here!");
+  return NS_OK;
+}
+
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
--- a/dom/sms/src/ipc/PSms.ipdl
+++ b/dom/sms/src/ipc/PSms.ipdl
@@ -102,14 +102,16 @@ parent:
 
     sync SaveSentMessage(nsString aReceiver, nsString aBody, PRUint64 aDate)
         returns (PRInt32 aId);
 
     GetMessage(PRInt32 aMessageId, PRInt32 aRequestId, PRUint64 aProcessId);
 
     DeleteMessage(PRInt32 aMessageId, PRInt32 aRequestId, PRUint64 aProcessId);
 
+    CreateMessageList(SmsFilterData aFilter, bool aReverse, PRInt32 aRequestId, PRUint64 aProcessId);
+
     __delete__();
 };
 
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
--- a/dom/sms/src/ipc/SmsIPCService.cpp
+++ b/dom/sms/src/ipc/SmsIPCService.cpp
@@ -36,16 +36,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/dom/ContentChild.h"
 #include "SmsIPCService.h"
 #include "nsXULAppAPI.h"
 #include "jsapi.h"
 #include "mozilla/dom/sms/SmsChild.h"
 #include "mozilla/dom/sms/SmsMessage.h"
+#include "SmsFilter.h"
 
 namespace mozilla {
 namespace dom {
 namespace sms {
 
 PSmsChild* SmsIPCService::sSmsChild = nsnull;
 
 NS_IMPL_ISUPPORTS2(SmsIPCService, nsISmsService, nsISmsDatabaseService)
@@ -130,11 +131,22 @@ NS_IMETHODIMP
 SmsIPCService::DeleteMessage(PRInt32 aMessageId, PRInt32 aRequestId,
                              PRUint64 aProcessId)
 {
   GetSmsChild()->SendDeleteMessage(aMessageId, aRequestId,
                                    ContentChild::GetSingleton()->GetID());
   return NS_OK;
 }
 
+NS_IMETHODIMP
+SmsIPCService::CreateMessageList(nsIDOMMozSmsFilter* aFilter, bool aReverse,
+                                 PRInt32 aRequestId, PRUint64 aProcessId)
+{
+  SmsFilter* filter = static_cast<SmsFilter*>(aFilter);
+  GetSmsChild()->SendCreateMessageList(filter->GetData(), aReverse, aRequestId,
+                                       ContentChild::GetSingleton()->GetID());
+
+  return NS_OK;
+}
+
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
--- a/dom/sms/src/ipc/SmsParent.cpp
+++ b/dom/sms/src/ipc/SmsParent.cpp
@@ -39,16 +39,17 @@
 #include "nsISmsService.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "Constants.h"
 #include "nsIDOMSmsMessage.h"
 #include "mozilla/unused.h"
 #include "SmsMessage.h"
 #include "nsISmsDatabaseService.h"
+#include "SmsFilter.h"
 
 namespace mozilla {
 namespace dom {
 namespace sms {
 
 nsTArray<SmsParent*>* SmsParent::gSmsParents = nsnull;
 
 NS_IMPL_ISUPPORTS1(SmsParent, nsIObserver)
@@ -211,11 +212,27 @@ SmsParent::RecvDeleteMessage(const PRInt
   nsCOMPtr<nsISmsDatabaseService> smsDBService =
     do_GetService(SMS_DATABASE_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(smsDBService, true);
 
   smsDBService->DeleteMessage(aMessageId, aRequestId, aProcessId);
   return true;
 }
 
+bool
+SmsParent::RecvCreateMessageList(const SmsFilterData& aFilter,
+                                 const bool& aReverse,
+                                 const PRInt32& aRequestId,
+                                 const PRUint64& aProcessId)
+{
+  nsCOMPtr<nsISmsDatabaseService> smsDBService =
+    do_GetService(SMS_DATABASE_SERVICE_CONTRACTID);
+  NS_ENSURE_TRUE(smsDBService, true);
+
+  nsCOMPtr<nsIDOMMozSmsFilter> filter = new SmsFilter(aFilter);
+  smsDBService->CreateMessageList(filter, aReverse, aRequestId, aProcessId);
+
+  return true;
+}
+
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
--- a/dom/sms/src/ipc/SmsParent.h
+++ b/dom/sms/src/ipc/SmsParent.h
@@ -57,16 +57,17 @@ public:
   SmsParent();
 
   NS_OVERRIDE virtual bool RecvHasSupport(bool* aHasSupport);
   NS_OVERRIDE virtual bool RecvGetNumberOfMessagesForText(const nsString& aText, PRUint16* aResult);
   NS_OVERRIDE virtual bool RecvSendMessage(const nsString& aNumber, const nsString& aMessage, const PRInt32& aRequestId, const PRUint64& aProcessId);
   NS_OVERRIDE virtual bool RecvSaveSentMessage(const nsString& aRecipient, const nsString& aBody, const PRUint64& aDate, PRInt32* aId);
   NS_OVERRIDE virtual bool RecvGetMessage(const PRInt32& aMessageId, const PRInt32& aRequestId, const PRUint64& aProcessId);
   NS_OVERRIDE virtual bool RecvDeleteMessage(const PRInt32& aMessageId, const PRInt32& aRequestId, const PRUint64& aProcessId);
+  NS_OVERRIDE virtual bool RecvCreateMessageList(const SmsFilterData& aFilter, const bool& aReverse, const PRInt32& aRequestId, const PRUint64& aProcessId);
 
 protected:
   virtual void ActorDestroy(ActorDestroyReason why);
 
 private:
   static nsTArray<SmsParent*>* gSmsParents;
 };