Bug 849739 3/4: IPC. r=bent
authorVicamo Yang <vyang@mozilla.com>
Wed, 10 Apr 2013 00:37:58 +0800
changeset 128176 625fef901d65e55bff093cc53d2b96ce3fbb5911
parent 128175 109cadb6d2e221535b4373ad064ffbf374f77672
child 128177 75cd6e698bec494e93198ff8209e833e2d7d94f6
push id26179
push uservyang@mozilla.com
push dateTue, 09 Apr 2013 16:38:25 +0000
treeherdermozilla-inbound@75cd6e698bec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs849739
milestone23.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 849739 3/4: IPC. r=bent
dom/mobilemessage/src/ipc/SmsChild.cpp
dom/mobilemessage/src/ipc/SmsChild.h
dom/mobilemessage/src/ipc/SmsIPCService.cpp
dom/mobilemessage/src/ipc/SmsParent.cpp
dom/mobilemessage/src/ipc/SmsParent.h
--- a/dom/mobilemessage/src/ipc/SmsChild.cpp
+++ b/dom/mobilemessage/src/ipc/SmsChild.cpp
@@ -4,16 +4,17 @@
 
 #include "SmsChild.h"
 #include "SmsMessage.h"
 #include "Constants.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "mozilla/dom/ContentChild.h"
 #include "SmsRequest.h"
+#include "MobileMessageThread.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::dom::mobilemessage;
 
 namespace {
 
 void
@@ -92,17 +93,17 @@ SmsChild::AllocPSmsRequest(const IPCSmsR
 bool
 SmsChild::DeallocPSmsRequest(PSmsRequestChild* aActor)
 {
   delete aActor;
   return true;
 }
 
 PMobileMessageCursorChild*
-SmsChild::AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest)
+SmsChild::AllocPMobileMessageCursor(const IPCMobileMessageCursor& aCursor)
 {
   MOZ_NOT_REACHED("Caller is supposed to manually construct a cursor!");
   return nullptr;
 }
 
 bool
 SmsChild::DeallocPMobileMessageCursor(PMobileMessageCursorChild* aActor)
 {
@@ -157,24 +158,16 @@ SmsRequestChild::Recv__delete__(const Me
       mReplyRequest->NotifyMessageDeleted(aReply.get_ReplyMessageDeleteFail().error());
       break;
     case MessageReply::TReplyMarkeMessageRead:
       mReplyRequest->NotifyMessageMarkedRead(aReply.get_ReplyMarkeMessageRead().read());
       break;
     case MessageReply::TReplyMarkeMessageReadFail:
       mReplyRequest->NotifyMarkMessageReadFailed(aReply.get_ReplyMarkeMessageReadFail().error());
       break;
-    case MessageReply::TReplyThreadList: {
-      SmsRequestForwarder* forwarder = static_cast<SmsRequestForwarder*>(mReplyRequest.get());
-      SmsRequest* request = static_cast<SmsRequest*>(forwarder->GetRealRequest());
-      request->NotifyThreadList(aReply.get_ReplyThreadList().items());
-    } break;
-    case MessageReply::TReplyThreadListFail:
-      mReplyRequest->NotifyThreadListFailed(aReply.get_ReplyThreadListFail().error());
-      break;
     default:
       MOZ_NOT_REACHED("Received invalid response parameters!");
       return false;
   }
 
   return true;
 }
 
@@ -193,21 +186,33 @@ MobileMessageCursorChild::MobileMessageC
 
 void
 MobileMessageCursorChild::ActorDestroy(ActorDestroyReason aWhy)
 {
   // Nothing needed here.
 }
 
 bool
-MobileMessageCursorChild::RecvNotifyResult(const SmsMessageData& aMessageData)
+MobileMessageCursorChild::RecvNotifyResult(const MobileMessageCursorData& aData)
 {
   MOZ_ASSERT(mCursorCallback);
 
-  nsCOMPtr<nsISupports> result = new SmsMessage(aMessageData);
+  nsCOMPtr<nsISupports> result;
+  switch(aData.type()) {
+    case MobileMessageCursorData::TSmsMessageData:
+      result = new SmsMessage(aData.get_SmsMessageData());
+      break;
+    case MobileMessageCursorData::TThreadData:
+      result = new MobileMessageThread(aData.get_ThreadData());
+      break;
+    default:
+      MOZ_NOT_REACHED("Received invalid response parameters!");
+      return false;
+  }
+
   mCursorCallback->NotifyCursorResult(result);
   return true;
 }
 
 bool
 MobileMessageCursorChild::Recv__delete__(const int32_t& aError)
 {
   MOZ_ASSERT(mCursorCallback);
--- a/dom/mobilemessage/src/ipc/SmsChild.h
+++ b/dom/mobilemessage/src/ipc/SmsChild.h
@@ -54,17 +54,17 @@ protected:
 
   virtual PSmsRequestChild*
   AllocPSmsRequest(const IPCSmsRequest& aRequest) MOZ_OVERRIDE;
 
   virtual bool
   DeallocPSmsRequest(PSmsRequestChild* aActor) MOZ_OVERRIDE;
 
   virtual PMobileMessageCursorChild*
-  AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest) MOZ_OVERRIDE;
+  AllocPMobileMessageCursor(const IPCMobileMessageCursor& aCursor) MOZ_OVERRIDE;
 
   virtual bool
   DeallocPMobileMessageCursor(PMobileMessageCursorChild* aActor) MOZ_OVERRIDE;
 };
 
 class SmsRequestChild : public PSmsRequestChild
 {
   friend class SmsChild;
@@ -105,17 +105,17 @@ protected:
   {
     MOZ_COUNT_DTOR(MobileMessageCursorChild);
   }
 
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
 
   virtual bool
-  RecvNotifyResult(const SmsMessageData& aMessageData) MOZ_OVERRIDE;
+  RecvNotifyResult(const MobileMessageCursorData& aData) MOZ_OVERRIDE;
 
   virtual bool
   Recv__delete__(const int32_t& aError) MOZ_OVERRIDE;
 };
 
 } // namespace mobilemessage
 } // namespace dom
 } // namespace mozilla
--- a/dom/mobilemessage/src/ipc/SmsIPCService.cpp
+++ b/dom/mobilemessage/src/ipc/SmsIPCService.cpp
@@ -45,17 +45,17 @@ SendRequest(const IPCSmsRequest& aReques
 
   SmsRequestChild* actor = new SmsRequestChild(aRequestReply);
   smsChild->SendPSmsRequestConstructor(actor, aRequest);
 
   return NS_OK;
 }
 
 nsresult
-SendCursorRequest(const CreateMessageCursorRequest& aRequest,
+SendCursorRequest(const IPCMobileMessageCursor& aRequest,
                   nsIMobileMessageCursorCallback* aRequestReply,
                   nsICursorContinueCallback** aResult)
 {
   PSmsChild* smsChild = GetSmsChild();
   NS_ENSURE_TRUE(smsChild, NS_ERROR_FAILURE);
 
   nsRefPtr<MobileMessageCursorChild> actor =
     new MobileMessageCursorChild(aRequestReply);
@@ -149,12 +149,14 @@ NS_IMETHODIMP
 SmsIPCService::MarkMessageRead(int32_t aMessageId,
                                bool aValue,
                                nsIMobileMessageCallback* aRequest)
 {
   return SendRequest(MarkMessageReadRequest(aMessageId, aValue), aRequest);
 }
 
 NS_IMETHODIMP
-SmsIPCService::GetThreadList(nsIMobileMessageCallback* aRequest)
+SmsIPCService::CreateThreadCursor(nsIMobileMessageCursorCallback* aCursorCallback,
+                                  nsICursorContinueCallback** aResult)
 {
-  return SendRequest(GetThreadListRequest(), aRequest);
+  return SendCursorRequest(CreateThreadCursorRequest(), aCursorCallback,
+                           aResult);
 }
--- a/dom/mobilemessage/src/ipc/SmsParent.cpp
+++ b/dom/mobilemessage/src/ipc/SmsParent.cpp
@@ -10,16 +10,17 @@
 #include "Constants.h"
 #include "nsIDOMMozSmsMessage.h"
 #include "mozilla/unused.h"
 #include "SmsMessage.h"
 #include "nsIMobileMessageDatabaseService.h"
 #include "SmsFilter.h"
 #include "SmsRequest.h"
 #include "SmsSegmentInfo.h"
+#include "MobileMessageThread.h"
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
 NS_IMPL_ISUPPORTS1(SmsParent, nsIObserver)
 
 SmsParent::SmsParent()
@@ -178,24 +179,21 @@ SmsParent::RecvPSmsRequestConstructor(PS
     case IPCSmsRequest::TSendMessageRequest:
       return actor->DoRequest(aRequest.get_SendMessageRequest());
     case IPCSmsRequest::TGetMessageRequest:
       return actor->DoRequest(aRequest.get_GetMessageRequest());
     case IPCSmsRequest::TDeleteMessageRequest:
       return actor->DoRequest(aRequest.get_DeleteMessageRequest());
     case IPCSmsRequest::TMarkMessageReadRequest:
       return actor->DoRequest(aRequest.get_MarkMessageReadRequest());
-    case IPCSmsRequest::TGetThreadListRequest:
-      return actor->DoRequest(aRequest.get_GetThreadListRequest());
     default:
       MOZ_NOT_REACHED("Unknown type!");
-      return false;
+      break;
   }
 
-  MOZ_NOT_REACHED("Should never get here!");
   return false;
 }
 
 PSmsRequestParent*
 SmsParent::AllocPSmsRequest(const IPCSmsRequest& aRequest)
 {
   return new SmsRequestParent();
 }
@@ -204,26 +202,36 @@ bool
 SmsParent::DeallocPSmsRequest(PSmsRequestParent* aActor)
 {
   delete aActor;
   return true;
 }
 
 bool
 SmsParent::RecvPMobileMessageCursorConstructor(PMobileMessageCursorParent* aActor,
-                                               const CreateMessageCursorRequest& aRequest)
+                                               const IPCMobileMessageCursor& aRequest)
 {
   MobileMessageCursorParent* actor =
     static_cast<MobileMessageCursorParent*>(aActor);
 
-  return actor->DoRequest(aRequest);
+  switch (aRequest.type()) {
+    case IPCMobileMessageCursor::TCreateMessageCursorRequest:
+      return actor->DoRequest(aRequest.get_CreateMessageCursorRequest());
+    case IPCMobileMessageCursor::TCreateThreadCursorRequest:
+      return actor->DoRequest(aRequest.get_CreateThreadCursorRequest());
+    default:
+      MOZ_NOT_REACHED("Unknown type!");
+      break;
+  }
+
+  return false;
 }
 
 PMobileMessageCursorParent*
-SmsParent::AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest)
+SmsParent::AllocPMobileMessageCursor(const IPCMobileMessageCursor& aRequest)
 {
   MobileMessageCursorParent* actor = new MobileMessageCursorParent();
   // Add an extra ref for IPDL. Will be released in
   // SmsParent::DeallocPMobileMessageCursor().
   actor->AddRef();
 
   return actor;
 }
@@ -322,31 +330,16 @@ SmsRequestParent::DoRequest(const MarkMe
   mSmsRequest = SmsRequest::Create(this);
   nsCOMPtr<nsIMobileMessageCallback> forwarder = new SmsRequestForwarder(mSmsRequest);
   nsresult rv = mobileMessageDBService->MarkMessageRead(aRequest.messageId(), aRequest.value(), forwarder);
   NS_ENSURE_SUCCESS(rv, false);
 
   return true;
 }
 
-bool
-SmsRequestParent::DoRequest(const GetThreadListRequest& aRequest)
-{
-  nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
-    do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
-
-  NS_ENSURE_TRUE(mobileMessageDBService, true);
-  mSmsRequest = SmsRequest::Create(this);
-  nsCOMPtr<nsIMobileMessageCallback> forwarder = new SmsRequestForwarder(mSmsRequest);
-  nsresult rv = mobileMessageDBService->GetThreadList(forwarder);
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
 /*******************************************************************************
  * MobileMessageCursorParent
  ******************************************************************************/
 
 NS_IMPL_ISUPPORTS1(MobileMessageCursorParent, nsIMobileMessageCursorCallback)
 
 void
 MobileMessageCursorParent::ActorDestroy(ActorDestroyReason aWhy)
@@ -388,16 +381,35 @@ MobileMessageCursorParent::DoRequest(con
 
   if (NS_FAILED(rv)) {
     return NS_SUCCEEDED(NotifyCursorError(nsIMobileMessageCallback::INTERNAL_ERROR));
   }
 
   return true;
 }
 
+bool
+MobileMessageCursorParent::DoRequest(const CreateThreadCursorRequest& aRequest)
+{
+  nsresult rv = NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
+    do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
+  if (dbService) {
+    rv = dbService->CreateThreadCursor(this,
+                                       getter_AddRefs(mContinueCallback));
+  }
+
+  if (NS_FAILED(rv)) {
+    return NS_SUCCEEDED(NotifyCursorError(nsIMobileMessageCallback::INTERNAL_ERROR));
+  }
+
+  return true;
+}
+
 // nsIMobileMessageCursorCallback
 
 NS_IMETHODIMP
 MobileMessageCursorParent::NotifyCursorError(int32_t aError)
 {
   // The child process could die before this asynchronous notification, in which
   // case ActorDestroy() was called and mContinueCallback is now null. Return an
   // error here to avoid sending a message to the dead process.
@@ -411,18 +423,32 @@ MobileMessageCursorParent::NotifyCursorE
 NS_IMETHODIMP
 MobileMessageCursorParent::NotifyCursorResult(nsISupports* aResult)
 {
   // The child process could die before this asynchronous notification, in which
   // case ActorDestroy() was called and mContinueCallback is now null. Return an
   // error here to avoid sending a message to the dead process.
   NS_ENSURE_TRUE(mContinueCallback, NS_ERROR_FAILURE);
 
-  SmsMessage* message = static_cast<SmsMessage*>(aResult);
-  return SendNotifyResult(message->GetData()) ? NS_OK : NS_ERROR_FAILURE;
+  nsCOMPtr<nsIDOMMozSmsMessage> iMessage = do_QueryInterface(aResult);
+  if (iMessage) {
+    SmsMessage* message = static_cast<SmsMessage*>(aResult);
+    return SendNotifyResult(MobileMessageCursorData(message->GetData()))
+      ? NS_OK : NS_ERROR_FAILURE;
+  }
+
+  nsCOMPtr<nsIDOMMozMobileMessageThread> iThread = do_QueryInterface(aResult);
+  if (iThread) {
+    MobileMessageThread* thread = static_cast<MobileMessageThread*>(aResult);
+    return SendNotifyResult(MobileMessageCursorData(thread->GetData()))
+      ? NS_OK : NS_ERROR_FAILURE;
+  }
+
+  MOZ_NOT_REACHED("Received invalid response parameters!");
+  return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 MobileMessageCursorParent::NotifyCursorDone()
 {
   return NotifyCursorError(nsIMobileMessageCallback::SUCCESS_NO_ERROR);
 }
 
--- a/dom/mobilemessage/src/ipc/SmsParent.h
+++ b/dom/mobilemessage/src/ipc/SmsParent.h
@@ -53,20 +53,20 @@ protected:
   virtual PSmsRequestParent*
   AllocPSmsRequest(const IPCSmsRequest& aRequest) MOZ_OVERRIDE;
 
   virtual bool
   DeallocPSmsRequest(PSmsRequestParent* aActor) MOZ_OVERRIDE;
 
   virtual bool
   RecvPMobileMessageCursorConstructor(PMobileMessageCursorParent* aActor,
-                                      const CreateMessageCursorRequest& aRequest) MOZ_OVERRIDE;
+                                      const IPCMobileMessageCursor& aCursor) MOZ_OVERRIDE;
 
   virtual PMobileMessageCursorParent*
-  AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest) MOZ_OVERRIDE;
+  AllocPMobileMessageCursor(const IPCMobileMessageCursor& aCursor) MOZ_OVERRIDE;
 
   virtual bool
   DeallocPMobileMessageCursor(PMobileMessageCursorParent* aActor) MOZ_OVERRIDE;
 };
 
 class SmsRequestParent : public PSmsRequestParent
 {
   friend class SmsParent;
@@ -90,19 +90,16 @@ protected:
   bool
   DoRequest(const GetMessageRequest& aRequest);
 
   bool
   DoRequest(const DeleteMessageRequest& aRequest);
 
   bool
   DoRequest(const MarkMessageReadRequest& aRequest);
-
-  bool
-  DoRequest(const GetThreadListRequest& aRequest);
 };
 
 class MobileMessageCursorParent : public PMobileMessageCursorParent
                                 , public nsIMobileMessageCursorCallback
 {
   friend class SmsParent;
 
   nsCOMPtr<nsICursorContinueCallback> mContinueCallback;
@@ -125,15 +122,18 @@ protected:
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
 
   virtual bool
   RecvContinue() MOZ_OVERRIDE;
 
   bool
   DoRequest(const CreateMessageCursorRequest& aRequest);
+
+  bool
+  DoRequest(const CreateThreadCursorRequest& aRequest);
 };
 
 } // namespace mobilemessage
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_mobilemessage_SmsParent_h