Bug 1023695 - Part 2: Add implementation of .idl/.ipdl. r=vyang.
authorBevis Tseng <btseng@mozilla.com>
Fri, 27 Jun 2014 13:17:47 +0800
changeset 193307 ef9dbb2245c8b1da53e47f6a48892a9df0b63aab
parent 193306 29da1b86af3a7b90f382a6bf940853ed22be89d6
child 193308 5f5ef8d480bfcbc22b94c3e85d921a3e82ec54f6
push id27116
push userryanvm@gmail.com
push dateThu, 10 Jul 2014 22:09:47 +0000
treeherdermozilla-central@0a0348d3f0c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvyang
bugs1023695
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 1023695 - Part 2: Add implementation of .idl/.ipdl. r=vyang.
dom/mobilemessage/src/Constants.cpp
dom/mobilemessage/src/Constants.h
dom/mobilemessage/src/DeletedMessageInfo.cpp
dom/mobilemessage/src/DeletedMessageInfo.h
dom/mobilemessage/src/MobileMessageService.cpp
dom/mobilemessage/src/ipc/SmsChild.cpp
dom/mobilemessage/src/ipc/SmsChild.h
dom/mobilemessage/src/ipc/SmsParent.cpp
dom/mobilemessage/src/moz.build
--- a/dom/mobilemessage/src/Constants.cpp
+++ b/dom/mobilemessage/src/Constants.cpp
@@ -12,12 +12,13 @@ const char* kSmsRetrievingObserverTopic 
 const char* kSmsSendingObserverTopic         = "sms-sending";
 const char* kSmsSentObserverTopic            = "sms-sent";
 const char* kSmsFailedObserverTopic          = "sms-failed";
 const char* kSmsDeliverySuccessObserverTopic = "sms-delivery-success";
 const char* kSmsDeliveryErrorObserverTopic   = "sms-delivery-error";
 const char* kSilentSmsReceivedObserverTopic  = "silent-sms-received";
 const char* kSmsReadSuccessObserverTopic     = "sms-read-success";
 const char* kSmsReadErrorObserverTopic       = "sms-read-error";
+const char* kSmsDeletedObserverTopic         = "sms-deleted";
 
 } // namespace mobilemessage
 } // namespace dom
 } // namespace mozilla
--- a/dom/mobilemessage/src/Constants.h
+++ b/dom/mobilemessage/src/Constants.h
@@ -16,16 +16,17 @@ extern const char* kSmsRetrievingObserve
 extern const char* kSmsSendingObserverTopic;
 extern const char* kSmsSentObserverTopic;
 extern const char* kSmsFailedObserverTopic;
 extern const char* kSmsDeliverySuccessObserverTopic;
 extern const char* kSmsDeliveryErrorObserverTopic;
 extern const char* kSilentSmsReceivedObserverTopic;
 extern const char* kSmsReadSuccessObserverTopic;
 extern const char* kSmsReadErrorObserverTopic;
+extern const char* kSmsDeletedObserverTopic;
 
 #define DELIVERY_RECEIVED       NS_LITERAL_STRING("received")
 #define DELIVERY_SENDING        NS_LITERAL_STRING("sending")
 #define DELIVERY_SENT           NS_LITERAL_STRING("sent")
 #define DELIVERY_ERROR          NS_LITERAL_STRING("error")
 #define DELIVERY_NOT_DOWNLOADED NS_LITERAL_STRING("not-downloaded")
 
 #define DELIVERY_STATUS_NOT_APPLICABLE NS_LITERAL_STRING("not-applicable")
new file mode 100644
--- /dev/null
+++ b/dom/mobilemessage/src/DeletedMessageInfo.cpp
@@ -0,0 +1,124 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "DeletedMessageInfo.h"
+#include "nsComponentManagerUtils.h"    // for do_CreateInstance
+#include "nsVariant.h"
+
+namespace mozilla {
+namespace dom {
+namespace mobilemessage {
+
+NS_IMPL_ISUPPORTS(DeletedMessageInfo, nsIDeletedMessageInfo)
+
+DeletedMessageInfo::DeletedMessageInfo(const DeletedMessageInfoData& aData)
+  : mData(aData)
+{
+}
+
+DeletedMessageInfo::DeletedMessageInfo(int32_t* aMessageIds,
+                                       uint32_t aMsgCount,
+                                       uint64_t* aThreadIds,
+                                       uint32_t  aThreadCount)
+{
+  mData.deletedMessageIds().AppendElements(aMessageIds, aMsgCount);
+  mData.deletedThreadIds().AppendElements(aThreadIds, aThreadCount);
+}
+
+DeletedMessageInfo::~DeletedMessageInfo()
+{
+}
+
+/* static */ nsresult
+DeletedMessageInfo::Create(int32_t* aMessageIds,
+                           uint32_t aMsgCount,
+                           uint64_t* aThreadIds,
+                           uint32_t  aThreadCount,
+                           nsIDeletedMessageInfo** aDeletedInfo)
+{
+  NS_ENSURE_ARG_POINTER(aDeletedInfo);
+  NS_ENSURE_TRUE(aMsgCount || aThreadCount, NS_ERROR_INVALID_ARG);
+
+  nsCOMPtr<nsIDeletedMessageInfo> deletedInfo =
+    new DeletedMessageInfo(aMessageIds,
+                           aMsgCount,
+                           aThreadIds,
+                           aThreadCount);
+  deletedInfo.forget(aDeletedInfo);
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+DeletedMessageInfo::GetDeletedMessageIds(nsIVariant** aDeletedMessageIds)
+{
+  NS_ENSURE_ARG_POINTER(aDeletedMessageIds);
+
+  if (mDeletedMessageIds) {
+    NS_ADDREF(*aDeletedMessageIds = mDeletedMessageIds);
+    return NS_OK;
+  }
+
+  uint32_t length = mData.deletedMessageIds().Length();
+
+  if (length == 0) {
+    *aDeletedMessageIds = nullptr;
+    return NS_OK;
+  }
+
+  nsresult rv;
+  mDeletedMessageIds = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  rv = mDeletedMessageIds->SetAsArray(nsIDataType::VTYPE_INT32,
+                                      nullptr,
+                                      length,
+                                      mData.deletedMessageIds().Elements());
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  mDeletedMessageIds->SetWritable(false);
+
+  NS_ADDREF(*aDeletedMessageIds = mDeletedMessageIds);
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+DeletedMessageInfo::GetDeletedThreadIds(nsIVariant** aDeletedThreadIds)
+{
+  NS_ENSURE_ARG_POINTER(aDeletedThreadIds);
+
+  if (mDeletedThreadIds) {
+    NS_ADDREF(*aDeletedThreadIds = mDeletedThreadIds);
+    return NS_OK;
+  }
+
+  uint32_t length = mData.deletedThreadIds().Length();
+
+  if (length == 0) {
+    *aDeletedThreadIds = nullptr;
+    return NS_OK;
+  }
+
+  nsresult rv;
+  mDeletedThreadIds = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  rv = mDeletedThreadIds->SetAsArray(nsIDataType::VTYPE_UINT64,
+                                     nullptr,
+                                     length,
+                                     mData.deletedThreadIds().Elements());
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  mDeletedThreadIds->SetWritable(false);
+
+  NS_ADDREF(*aDeletedThreadIds = mDeletedThreadIds);
+
+  return NS_OK;
+}
+
+} // namespace mobilemessage
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/mobilemessage/src/DeletedMessageInfo.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_dom_mobilemessage_DeletedMessageInfo_h
+#define mozilla_dom_mobilemessage_DeletedMessageInfo_h
+
+#include "mozilla/dom/mobilemessage/SmsTypes.h"
+#include "nsIDeletedMessageInfo.h"
+
+class nsIWritableVariant;
+
+namespace mozilla {
+namespace dom {
+namespace mobilemessage {
+
+class DeletedMessageInfo MOZ_FINAL : public nsIDeletedMessageInfo
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIDELETEDMESSAGEINFO
+
+  DeletedMessageInfo(const DeletedMessageInfoData& aData);
+
+  DeletedMessageInfo(int32_t* aMessageIds,
+                     uint32_t aMsgCount,
+                     uint64_t* aThreadIds,
+                     uint32_t  aThreadCount);
+
+  static nsresult Create(int32_t* aMessageIds,
+                         uint32_t aMsgCount,
+                         uint64_t* aThreadIds,
+                         uint32_t  aThreadCount,
+                         nsIDeletedMessageInfo** aDeletedInfo);
+
+  const DeletedMessageInfoData& GetData() const { return mData; }
+
+private:
+  // Don't try to use the default constructor.
+  DeletedMessageInfo();
+
+  ~DeletedMessageInfo();
+
+  DeletedMessageInfoData mData;
+
+  nsCOMPtr<nsIWritableVariant> mDeletedMessageIds;
+  nsCOMPtr<nsIWritableVariant> mDeletedThreadIds;
+
+protected:
+  /* additional members */
+};
+
+} // namespace mobilemessage
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_mobilemessage_DeletedMessageInfo_h
--- a/dom/mobilemessage/src/MobileMessageService.cpp
+++ b/dom/mobilemessage/src/MobileMessageService.cpp
@@ -2,16 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SmsMessage.h"
 #include "MmsMessage.h"
 #include "MobileMessageThread.h"
 #include "MobileMessageService.h"
 #include "SmsSegmentInfo.h"
+#include "DeletedMessageInfo.h"
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
 NS_IMPL_ISUPPORTS(MobileMessageService, nsIMobileMessageService)
 
 /* static */ StaticRefPtr<MobileMessageService> MobileMessageService::sSingleton;
@@ -129,11 +130,25 @@ MobileMessageService::CreateThread(uint6
                                      aLastMessageSubject,
                                      aBody,
                                      aUnreadCount,
                                      aLastMessageType,
                                      aCx,
                                      aThread);
 }
 
+NS_IMETHODIMP
+MobileMessageService::CreateDeletedMessageInfo(int32_t* aMessageIds,
+                                               uint32_t aMsgCount,
+                                               uint64_t* aThreadIds,
+                                               uint32_t  aThreadCount,
+                                               nsIDeletedMessageInfo** aDeletedInfo)
+{
+  return DeletedMessageInfo::Create(aMessageIds,
+                                    aMsgCount,
+                                    aThreadIds,
+                                    aThreadCount,
+                                    aDeletedInfo);
+}
+
 } // namespace mobilemessage
 } // namespace dom
 } // namespace mozilla
--- a/dom/mobilemessage/src/ipc/SmsChild.cpp
+++ b/dom/mobilemessage/src/ipc/SmsChild.cpp
@@ -1,16 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SmsChild.h"
 #include "SmsMessage.h"
 #include "MmsMessage.h"
 #include "SmsSegmentInfo.h"
+#include "DeletedMessageInfo.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
 #include "MobileMessageThread.h"
 #include "MainThreadUtils.h"
 
 using namespace mozilla;
@@ -127,16 +128,31 @@ SmsChild::RecvNotifyReadSuccessMessage(c
 
 bool
 SmsChild::RecvNotifyReadErrorMessage(const MobileMessageData& aData)
 {
   NotifyObserversWithMobileMessage(kSmsReadErrorObserverTopic, aData);
   return true;
 }
 
+bool
+SmsChild::RecvNotifyDeletedMessageInfo(const DeletedMessageInfoData& aDeletedInfo)
+{
+  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
+  if (!obs) {
+    NS_ERROR("Failed to get nsIObserverService!");
+    return false;
+  }
+
+  nsCOMPtr<nsISupports> info = new DeletedMessageInfo(aDeletedInfo);
+  obs->NotifyObservers(info, kSmsDeletedObserverTopic, nullptr);
+
+  return true;
+}
+
 PSmsRequestChild*
 SmsChild::AllocPSmsRequestChild(const IPCSmsRequest& aRequest)
 {
   MOZ_CRASH("Caller is supposed to manually construct a request!");
 }
 
 bool
 SmsChild::DeallocPSmsRequestChild(PSmsRequestChild* aActor)
--- a/dom/mobilemessage/src/ipc/SmsChild.h
+++ b/dom/mobilemessage/src/ipc/SmsChild.h
@@ -59,16 +59,19 @@ protected:
   RecvNotifyReceivedSilentMessage(const MobileMessageData& aMessage) MOZ_OVERRIDE;
 
   virtual bool
   RecvNotifyReadSuccessMessage(const MobileMessageData& aMessage) MOZ_OVERRIDE;
 
   virtual bool
   RecvNotifyReadErrorMessage(const MobileMessageData& aMessage) MOZ_OVERRIDE;
 
+  virtual bool
+  RecvNotifyDeletedMessageInfo(const DeletedMessageInfoData& aDeletedInfo) MOZ_OVERRIDE;
+
   virtual PSmsRequestChild*
   AllocPSmsRequestChild(const IPCSmsRequest& aRequest) MOZ_OVERRIDE;
 
   virtual bool
   DeallocPSmsRequestChild(PSmsRequestChild* aActor) MOZ_OVERRIDE;
 
   virtual PMobileMessageCursorChild*
   AllocPMobileMessageCursorChild(const IPCMobileMessageCursor& aCursor) MOZ_OVERRIDE;
--- a/dom/mobilemessage/src/ipc/SmsParent.cpp
+++ b/dom/mobilemessage/src/ipc/SmsParent.cpp
@@ -21,16 +21,17 @@
 #include "mozilla/dom/ipc/Blob.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
 #include "nsContentUtils.h"
 #include "nsTArrayHelpers.h"
 #include "nsCxPusher.h"
 #include "xpcpublic.h"
 #include "nsServiceManagerUtils.h"
+#include "DeletedMessageInfo.h"
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
 static JSObject*
 MmsAttachmentDataToJSObject(JSContext* aContext,
                             const MmsAttachmentData& aAttachment)
@@ -174,16 +175,17 @@ SmsParent::SmsParent()
   obs->AddObserver(this, kSmsSendingObserverTopic, false);
   obs->AddObserver(this, kSmsSentObserverTopic, false);
   obs->AddObserver(this, kSmsFailedObserverTopic, false);
   obs->AddObserver(this, kSmsDeliverySuccessObserverTopic, false);
   obs->AddObserver(this, kSmsDeliveryErrorObserverTopic, false);
   obs->AddObserver(this, kSilentSmsReceivedObserverTopic, false);
   obs->AddObserver(this, kSmsReadSuccessObserverTopic, false);
   obs->AddObserver(this, kSmsReadErrorObserverTopic, false);
+  obs->AddObserver(this, kSmsDeletedObserverTopic, false);
 }
 
 void
 SmsParent::ActorDestroy(ActorDestroyReason why)
 {
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   if (!obs) {
     return;
@@ -194,16 +196,17 @@ SmsParent::ActorDestroy(ActorDestroyReas
   obs->RemoveObserver(this, kSmsSendingObserverTopic);
   obs->RemoveObserver(this, kSmsSentObserverTopic);
   obs->RemoveObserver(this, kSmsFailedObserverTopic);
   obs->RemoveObserver(this, kSmsDeliverySuccessObserverTopic);
   obs->RemoveObserver(this, kSmsDeliveryErrorObserverTopic);
   obs->RemoveObserver(this, kSilentSmsReceivedObserverTopic);
   obs->RemoveObserver(this, kSmsReadSuccessObserverTopic);
   obs->RemoveObserver(this, kSmsReadErrorObserverTopic);
+  obs->RemoveObserver(this, kSmsDeletedObserverTopic);
 }
 
 NS_IMETHODIMP
 SmsParent::Observe(nsISupports* aSubject, const char* aTopic,
                    const char16_t* aData)
 {
   ContentParent *parent = static_cast<ContentParent*>(Manager());
 
@@ -319,16 +322,27 @@ SmsParent::Observe(nsISupports* aSubject
       NS_ERROR("Got a 'sms-read-error' topic without a valid message!");
       return NS_OK;
     }
 
     unused << SendNotifyReadErrorMessage(msgData);
     return NS_OK;
   }
 
+  if (!strcmp(aTopic, kSmsDeletedObserverTopic)) {
+    nsCOMPtr<nsIDeletedMessageInfo> deletedInfo = do_QueryInterface(aSubject);
+    if (!deletedInfo) {
+      NS_ERROR("Got a 'sms-deleted' topic without a valid message!");
+      return NS_OK;
+    }
+
+    unused << SendNotifyDeletedMessageInfo(
+      static_cast<DeletedMessageInfo*>(deletedInfo.get())->GetData());
+    return NS_OK;
+  }
 
   return NS_OK;
 }
 
 bool
 SmsParent::RecvAddSilentNumber(const nsString& aNumber)
 {
   if (mSilentNumbers.Contains(aNumber)) {
--- a/dom/mobilemessage/src/moz.build
+++ b/dom/mobilemessage/src/moz.build
@@ -42,16 +42,17 @@ EXPORTS.mozilla.dom += [
     'MobileMessageManager.h',
     'SmsFilter.h',
     'SmsMessage.h',
     'SmsSegmentInfo.h',
 ]
 
 UNIFIED_SOURCES += [
     'Constants.cpp',
+    'DeletedMessageInfo.cpp',
     'DOMMobileMessageError.cpp',
     'ipc/SmsChild.cpp',
     'ipc/SmsIPCService.cpp',
     'ipc/SmsParent.cpp',
     'MmsMessage.cpp',
     'MobileMessageCallback.cpp',
     'MobileMessageCursorCallback.cpp',
     'MobileMessageManager.cpp',