Bug 1179089 - Let TelephonyRequestParent hold the callback objects. r=hsinyi
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Tue, 28 Jul 2015 18:41:59 +0800
changeset 286616 55abf3c44b106692fe1295d075754095755675d8
parent 286478 d08100cfaf4dc368806e988629cf195718f12109
child 286617 12d2a457d34d15e96eaa0147495acd2db19b1bce
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi
bugs1179089
milestone42.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 1179089 - Let TelephonyRequestParent hold the callback objects. r=hsinyi
dom/telephony/ipc/TelephonyParent.cpp
dom/telephony/ipc/TelephonyParent.h
--- a/dom/telephony/ipc/TelephonyParent.cpp
+++ b/dom/telephony/ipc/TelephonyParent.cpp
@@ -36,115 +36,115 @@ TelephonyParent::ActorDestroy(ActorDestr
 bool
 TelephonyParent::RecvPTelephonyRequestConstructor(PTelephonyRequestParent* aActor,
                                                   const IPCTelephonyRequest& aRequest)
 {
   TelephonyRequestParent* actor = static_cast<TelephonyRequestParent*>(aActor);
   nsCOMPtr<nsITelephonyService> service = do_GetService(TELEPHONY_SERVICE_CONTRACTID);
 
   if (!service) {
-    return NS_SUCCEEDED(actor->NotifyError(NS_LITERAL_STRING("InvalidStateError")));
+    return NS_SUCCEEDED(actor->GetCallback()->NotifyError(NS_LITERAL_STRING("InvalidStateError")));
   }
 
   switch (aRequest.type()) {
     case IPCTelephonyRequest::TEnumerateCallsRequest: {
       nsresult rv = service->EnumerateCalls(actor);
       if (NS_FAILED(rv)) {
         return NS_SUCCEEDED(EnumerateCallStateComplete());
       } else {
         return true;
       }
     }
 
     case IPCTelephonyRequest::TDialRequest: {
       const DialRequest& request = aRequest.get_DialRequest();
       service->Dial(request.clientId(), request.number(),
-                    request.isEmergency(), actor);
+                    request.isEmergency(), actor->GetDialCallback());
       return true;
     }
 
     case IPCTelephonyRequest::TSendUSSDRequest: {
       const SendUSSDRequest& request = aRequest.get_SendUSSDRequest();
-      service->SendUSSD(request.clientId(), request.ussd(), actor);
+      service->SendUSSD(request.clientId(), request.ussd(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::TCancelUSSDRequest: {
       const CancelUSSDRequest& request = aRequest.get_CancelUSSDRequest();
-      service->CancelUSSD(request.clientId(), actor);
+      service->CancelUSSD(request.clientId(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::TConferenceCallRequest: {
       const ConferenceCallRequest& request = aRequest.get_ConferenceCallRequest();
-      service->ConferenceCall(request.clientId(), actor);
+      service->ConferenceCall(request.clientId(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::TSeparateCallRequest: {
       const SeparateCallRequest& request = aRequest.get_SeparateCallRequest();
-      service->SeparateCall(request.clientId(), request.callIndex(), actor);
+      service->SeparateCall(request.clientId(), request.callIndex(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::THangUpConferenceRequest: {
       const HangUpConferenceRequest& request = aRequest.get_HangUpConferenceRequest();
-      service->HangUpConference(request.clientId(), actor);
+      service->HangUpConference(request.clientId(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::THoldConferenceRequest: {
       const HoldConferenceRequest& request = aRequest.get_HoldConferenceRequest();
-      service->HoldConference(request.clientId(), actor);
+      service->HoldConference(request.clientId(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::TResumeConferenceRequest: {
       const ResumeConferenceRequest& request = aRequest.get_ResumeConferenceRequest();
-      service->ResumeConference(request.clientId(), actor);
+      service->ResumeConference(request.clientId(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::TAnswerCallRequest: {
       const AnswerCallRequest& request = aRequest.get_AnswerCallRequest();
-      service->AnswerCall(request.clientId(), request.callIndex(), actor);
+      service->AnswerCall(request.clientId(), request.callIndex(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::THangUpCallRequest: {
       const HangUpCallRequest& request = aRequest.get_HangUpCallRequest();
-      service->HangUpCall(request.clientId(), request.callIndex(), actor);
+      service->HangUpCall(request.clientId(), request.callIndex(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::TRejectCallRequest: {
       const RejectCallRequest& request = aRequest.get_RejectCallRequest();
-      service->RejectCall(request.clientId(), request.callIndex(), actor);
+      service->RejectCall(request.clientId(), request.callIndex(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::THoldCallRequest: {
       const HoldCallRequest& request = aRequest.get_HoldCallRequest();
-      service->HoldCall(request.clientId(), request.callIndex(), actor);
+      service->HoldCall(request.clientId(), request.callIndex(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::TResumeCallRequest: {
       const ResumeCallRequest& request = aRequest.get_ResumeCallRequest();
-      service->ResumeCall(request.clientId(), request.callIndex(), actor);
+      service->ResumeCall(request.clientId(), request.callIndex(), actor->GetCallback());
       return true;
     }
 
     case IPCTelephonyRequest::TSendTonesRequest: {
       const SendTonesRequest& request = aRequest.get_SendTonesRequest();
       service->SendTones(request.clientId(),
                          request.dtmfChars(),
                          request.pauseDuration(),
                          request.toneDuration(),
-                         actor);
+                         actor->GetCallback());
       return true;
     }
 
     default:
       MOZ_CRASH("Unknown type!");
   }
 
   return false;
@@ -342,22 +342,22 @@ TelephonyParent::SupplementaryServiceNot
       ? NS_OK : NS_ERROR_FAILURE;
 }
 
 /*******************************************************************************
  * TelephonyRequestParent
  ******************************************************************************/
 
 NS_IMPL_ISUPPORTS(TelephonyRequestParent,
-                  nsITelephonyListener,
-                  nsITelephonyCallback,
-                  nsITelephonyDialCallback)
+                  nsITelephonyListener)
 
 TelephonyRequestParent::TelephonyRequestParent()
-  : mActorDestroyed(false)
+  : mActorDestroyed(false),
+    mCallback(new Callback(*this)),
+    mDialCallback(new DialCallback(*this))
 {
 }
 
 void
 TelephonyRequestParent::ActorDestroy(ActorDestroyReason why)
 {
   // The child process could die before this asynchronous notification, in which
   // case ActorDestroy() was called and mActorDestroyed is set to true. Return
@@ -423,96 +423,114 @@ TelephonyRequestParent::NotifyConference
 NS_IMETHODIMP
 TelephonyRequestParent::SupplementaryServiceNotification(uint32_t aClientId,
                                                          int32_t aCallIndex,
                                                          uint16_t aNotification)
 {
   MOZ_CRASH("Not a TelephonyParent!");
 }
 
-// nsITelephonyDialCallback
+/*******************************************************************************
+ * TelephonyRequestParent::Callback
+ ******************************************************************************/
 
-NS_IMETHODIMP
-TelephonyRequestParent::NotifyDialMMI(const nsAString& aServiceCode)
+NS_IMPL_ISUPPORTS(TelephonyRequestParent::Callback,
+                  nsITelephonyCallback)
+
+nsresult TelephonyRequestParent::Callback::SendResponse(const IPCTelephonyResponse& aResponse)
 {
-  NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
-
-  return SendNotifyDialMMI(nsAutoString(aServiceCode)) ? NS_OK : NS_ERROR_FAILURE;
+  return mParent.SendResponse(aResponse);
 }
 
 NS_IMETHODIMP
-TelephonyRequestParent::NotifySuccess()
+TelephonyRequestParent::Callback::NotifySuccess()
 {
   return SendResponse(SuccessResponse());
 }
 
 NS_IMETHODIMP
-TelephonyRequestParent::NotifyError(const nsAString& aError)
+TelephonyRequestParent::Callback::NotifyError(const nsAString& aError)
 {
   return SendResponse(ErrorResponse(nsAutoString(aError)));
 }
 
+/*******************************************************************************
+ * TelephonyRequestParent::DialCallback
+ ******************************************************************************/
+
+NS_IMPL_ISUPPORTS_INHERITED(TelephonyRequestParent::DialCallback,
+                            TelephonyRequestParent::Callback,
+                            nsITelephonyDialCallback)
+
 NS_IMETHODIMP
-TelephonyRequestParent::NotifyDialCallSuccess(uint32_t aClientId,
-                                              uint32_t aCallIndex,
-                                              const nsAString& aNumber)
+TelephonyRequestParent::DialCallback::NotifyDialMMI(const nsAString& aServiceCode)
+{
+  NS_ENSURE_TRUE(!mParent.mActorDestroyed, NS_ERROR_FAILURE);
+
+  return mParent.SendNotifyDialMMI(nsAutoString(aServiceCode)) ? NS_OK : NS_ERROR_FAILURE;
+}
+
+NS_IMETHODIMP
+TelephonyRequestParent::DialCallback::NotifyDialCallSuccess(uint32_t aClientId,
+                                                            uint32_t aCallIndex,
+                                                            const nsAString& aNumber)
 {
   return SendResponse(DialResponseCallSuccess(aClientId, aCallIndex,
                                               nsAutoString(aNumber)));
 }
 
 NS_IMETHODIMP
-TelephonyRequestParent::NotifyDialMMISuccess(const nsAString& aStatusMessage)
+TelephonyRequestParent::DialCallback::NotifyDialMMISuccess(const nsAString& aStatusMessage)
 {
   return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
                                              AdditionalInformation(mozilla::void_t())));
 }
 
 NS_IMETHODIMP
-TelephonyRequestParent::NotifyDialMMISuccessWithInteger(const nsAString& aStatusMessage,
-                                                        uint16_t aAdditionalInformation)
+TelephonyRequestParent::DialCallback::NotifyDialMMISuccessWithInteger(const nsAString& aStatusMessage,
+                                                                      uint16_t aAdditionalInformation)
 {
   return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
                                              AdditionalInformation(aAdditionalInformation)));
 }
 
 NS_IMETHODIMP
-TelephonyRequestParent::NotifyDialMMISuccessWithStrings(const nsAString& aStatusMessage,
-                                                        uint32_t aCount,
-                                                        const char16_t** aAdditionalInformation)
+TelephonyRequestParent::DialCallback::NotifyDialMMISuccessWithStrings(const nsAString& aStatusMessage,
+                                                                      uint32_t aCount,
+                                                                      const char16_t** aAdditionalInformation)
 {
   nsTArray<nsString> additionalInformation;
   for (uint32_t i = 0; i < aCount; i++) {
     additionalInformation.AppendElement(nsDependentString(aAdditionalInformation[i]));
   }
 
   return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
                                              AdditionalInformation(additionalInformation)));
 }
 
 NS_IMETHODIMP
-TelephonyRequestParent::NotifyDialMMISuccessWithCallForwardingOptions(const nsAString& aStatusMessage,
-                                                                      uint32_t aCount,
-                                                                      nsIMobileCallForwardingOptions** aAdditionalInformation)
+TelephonyRequestParent::DialCallback::NotifyDialMMISuccessWithCallForwardingOptions(const nsAString& aStatusMessage,
+                                                                                    uint32_t aCount,
+                                                                                    nsIMobileCallForwardingOptions** aAdditionalInformation)
 {
   nsTArray<nsIMobileCallForwardingOptions*> additionalInformation;
   for (uint32_t i = 0; i < aCount; i++) {
     additionalInformation.AppendElement(aAdditionalInformation[i]);
   }
 
   return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
                                              AdditionalInformation(additionalInformation)));
 }
 
 NS_IMETHODIMP
-TelephonyRequestParent::NotifyDialMMIError(const nsAString& aError)
+TelephonyRequestParent::DialCallback::NotifyDialMMIError(const nsAString& aError)
 {
   return SendResponse(DialResponseMMIError(nsAutoString(aError),
                                            AdditionalInformation(mozilla::void_t())));
 }
 
 NS_IMETHODIMP
-TelephonyRequestParent::NotifyDialMMIErrorWithInfo(const nsAString& aError,
-                                                   uint16_t aInfo)
+TelephonyRequestParent::DialCallback::NotifyDialMMIErrorWithInfo(const nsAString& aError,
+                                                                 uint16_t aInfo)
 {
   return SendResponse(DialResponseMMIError(nsAutoString(aError),
                                            AdditionalInformation(aInfo)));
 }
--- a/dom/telephony/ipc/TelephonyParent.h
+++ b/dom/telephony/ipc/TelephonyParent.h
@@ -67,35 +67,74 @@ protected:
 
 private:
   bool mActorDestroyed;
   bool mRegistered;
 };
 
 class TelephonyRequestParent : public PTelephonyRequestParent
                              , public nsITelephonyListener
-                             , public nsITelephonyDialCallback
 {
   friend class TelephonyParent;
 
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSITELEPHONYLISTENER
-  NS_DECL_NSITELEPHONYCALLBACK
-  NS_DECL_NSITELEPHONYDIALCALLBACK
+
+  class Callback : public nsITelephonyCallback {
+    friend class TelephonyRequestParent;
+
+  public:
+    NS_DECL_ISUPPORTS
+    NS_DECL_NSITELEPHONYCALLBACK
+
+  protected:
+    explicit Callback(TelephonyRequestParent& aParent): mParent(aParent) {}
+    virtual ~Callback() {}
+
+  private:
+    nsresult SendResponse(const IPCTelephonyResponse& aResponse);
+    TelephonyRequestParent& mParent;
+  };
+
+  class DialCallback final : public Callback
+                           , public nsITelephonyDialCallback {
+    friend class TelephonyRequestParent;
+
+  public:
+    NS_DECL_ISUPPORTS_INHERITED
+    NS_DECL_NSITELEPHONYDIALCALLBACK
+    NS_FORWARD_NSITELEPHONYCALLBACK(Callback::)
+
+  private:
+    explicit DialCallback(TelephonyRequestParent& aParent): Callback(aParent) {}
+    ~DialCallback() {}
+  };
 
 protected:
   TelephonyRequestParent();
   virtual ~TelephonyRequestParent() {}
 
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) override;
 
   nsresult
   SendResponse(const IPCTelephonyResponse& aResponse);
 
+  Callback*
+  GetCallback() {
+    return mCallback;
+  }
+
+  DialCallback*
+  GetDialCallback() {
+    return mDialCallback;
+  }
+
 private:
   bool mActorDestroyed;
+  nsRefPtr<Callback> mCallback;
+  nsRefPtr<DialCallback> mDialCallback;
 };
 
 END_TELEPHONY_NAMESPACE
 
 #endif /* mozilla_dom_telephony_TelephonyParent_h */