Bug 674725 - Part AR - Handle reception of the next message in SmsRequestManager. r=smaug
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 14 Dec 2011 17:17:53 +0100
changeset 84729 b045d642ed32cb932e9352c262496643ec917762
parent 84728 cd7e8a34d4f39c89741250d6d576d02872d5eba9
child 84730 d20eabae9a7fb9c45b4d8ff232268c8b7456196a
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 AR - Handle reception of the next message in SmsRequestManager. r=smaug
dom/sms/src/SmsCursor.cpp
dom/sms/src/SmsCursor.h
dom/sms/src/SmsRequest.cpp
dom/sms/src/SmsRequest.h
dom/sms/src/SmsRequestManager.cpp
--- a/dom/sms/src/SmsCursor.cpp
+++ b/dom/sms/src/SmsCursor.cpp
@@ -70,16 +70,25 @@ SmsCursor::SmsCursor(nsIDOMMozSmsFilter*
 
 SmsCursor::SmsCursor(PRInt32 aListId, nsIDOMMozSmsFilter* aFilter, nsIDOMMozSmsRequest* aRequest)
   : mListId(aListId)
   , mFilter(aFilter)
   , mRequest(aRequest)
 {
 }
 
+void
+SmsCursor::Disconnect()
+{
+  NS_ASSERTION(!mMessage, "mMessage shouldn't be set!");
+
+  mRequest = nsnull;
+  mListId = -1;
+}
+
 NS_IMETHODIMP
 SmsCursor::GetFilter(nsIDOMMozSmsFilter** aFilter)
 {
   NS_ADDREF(*aFilter = mFilter);
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/dom/sms/src/SmsCursor.h
+++ b/dom/sms/src/SmsCursor.h
@@ -58,16 +58,18 @@ public:
 
   NS_DECL_CYCLE_COLLECTION_CLASS(SmsCursor)
 
   SmsCursor(nsIDOMMozSmsFilter* aFilter);
   SmsCursor(PRInt32 aListId, nsIDOMMozSmsFilter* aFilter, nsIDOMMozSmsRequest* aRequest);
 
   void SetMessage(nsIDOMMozSmsMessage* aMessage);
 
+  void Disconnect();
+
 private:
   PRInt32                       mListId;
   nsCOMPtr<nsIDOMMozSmsFilter>  mFilter;
   nsCOMPtr<nsIDOMMozSmsRequest> mRequest;
   nsCOMPtr<nsIDOMMozSmsMessage> mMessage;
 };
 
 inline void
--- a/dom/sms/src/SmsRequest.cpp
+++ b/dom/sms/src/SmsRequest.cpp
@@ -50,26 +50,28 @@ namespace sms {
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(SmsRequest)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SmsRequest,
                                                   nsDOMEventTargetWrapperCache)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
   NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(success)
   NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(error)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCursor)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SmsRequest,
                                                 nsDOMEventTargetWrapperCache)
   if (tmp->mResultRooted) {
     tmp->mResult = JSVAL_VOID;
     tmp->UnrootResult();
   }
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(success)
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(error)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCursor)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(SmsRequest,
                                                nsDOMEventTargetWrapperCache)
   if (JSVAL_IS_GCTHING(tmp->mResult)) {
     void *gcThing = JSVAL_TO_GCTHING(tmp->mResult);
     NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mResult")
   }
@@ -151,17 +153,26 @@ SmsRequest::SetSuccess(bool aResult)
 
   mResult.setBoolean(aResult);
   mDone = true;
 }
 
 void
 SmsRequest::SetSuccess(nsIDOMMozSmsCursor* aCursor)
 {
-  SetSuccessInternal(aCursor);
+  if (!SetSuccessInternal(aCursor)) {
+    return;
+  }
+
+  NS_ASSERTION(!mCursor || mCursor == aCursor,
+               "SmsRequest can't change it's cursor!");
+
+  if (!mCursor) {
+    mCursor = aCursor;
+  }
 }
 
 bool
 SmsRequest::SetSuccessInternal(nsISupports* aObject)
 {
   NS_PRECONDITION(!mDone, "mDone shouldn't have been set to true already!");
   NS_PRECONDITION(mError == eNoError, "mError shouldn't have been set!");
   NS_PRECONDITION(mResult == JSVAL_VOID, "mResult shouldn't have been set!");
--- a/dom/sms/src/SmsRequest.h
+++ b/dom/sms/src/SmsRequest.h
@@ -115,22 +115,36 @@ private:
 
   /**
    * Set the object in a success state with the result being the nsISupports
    * object in parameter.
    * @return whether setting the object was a success
    */
   bool SetSuccessInternal(nsISupports* aObject);
 
+  /**
+   * Return the internal cursor that is saved when
+   * SetSuccess(nsIDOMMozSmsCursor*) is used.
+   * Returns null if this request isn't associated to an cursor.
+   */
+  nsIDOMMozSmsCursor* GetCursor();
+
   jsval     mResult;
   bool      mResultRooted;
   ErrorType mError;
   bool      mDone;
+  nsCOMPtr<nsIDOMMozSmsCursor> mCursor;
 
   NS_DECL_EVENT_HANDLER(success)
   NS_DECL_EVENT_HANDLER(error)
 };
 
+inline nsIDOMMozSmsCursor*
+SmsRequest::GetCursor()
+{
+  return mCursor;
+}
+
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_sms_SmsRequest_h
--- a/dom/sms/src/SmsRequestManager.cpp
+++ b/dom/sms/src/SmsRequestManager.cpp
@@ -207,17 +207,24 @@ SmsRequestManager::NotifySmsDeleteFailed
 {
   NotifyError(aRequestId, aError);
 }
 
 void
 SmsRequestManager::NotifyNoMessageInList(PRInt32 aRequestId)
 {
   // TODO: use Filter!
-  nsCOMPtr<nsIDOMMozSmsCursor> cursor = new SmsCursor(nsnull);
+  SmsRequest* request = GetRequest(aRequestId);
+
+  nsCOMPtr<nsIDOMMozSmsCursor> cursor = request->GetCursor();
+  if (!cursor) {
+    cursor = new SmsCursor(nsnull);
+  } else {
+    static_cast<SmsCursor*>(cursor.get())->Disconnect();
+  }
 
   NotifySuccess<nsIDOMMozSmsCursor*>(aRequestId, cursor);
 }
 
 void
 SmsRequestManager::NotifyCreateMessageList(PRInt32 aRequestId, PRInt32 aListId,
                                            nsIDOMMozSmsMessage* aMessage)
 {
@@ -228,15 +235,20 @@ SmsRequestManager::NotifyCreateMessageLi
   cursor->SetMessage(aMessage);
 
   NotifySuccess<nsIDOMMozSmsCursor*>(aRequestId, cursor);
 }
 
 void
 SmsRequestManager::NotifyGotNextMessage(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage)
 {
-  // TODO: implement
-  printf_stderr("\nHERE\n\n");
+  SmsRequest* request = GetRequest(aRequestId);
+
+  nsCOMPtr<SmsCursor> cursor = static_cast<SmsCursor*>(request->GetCursor());
+  NS_ASSERTION(cursor, "Request should have an cursor in that case!");
+  cursor->SetMessage(aMessage);
+
+  NotifySuccess<nsIDOMMozSmsCursor*>(aRequestId, cursor);
 }
 
 } // namespace sms
 } // namespace dom
 } // namespace mozilla