Bug 1077075 - Part 6: Internal architecture (IPC). r=aknow
authorBen Hsu <bhsu@mozilla.com>
Wed, 24 Dec 2014 00:35:00 -0500
changeset 247921 f2f7dc02d217a09d6c2b2f93bc259ebc155b892e
parent 247920 f05cb6eb5ff8cbde5425dfe7094f5b6166388496
child 247922 621cf332663d476f68b359043c816e41b35390f6
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaknow
bugs1077075
milestone37.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 1077075 - Part 6: Internal architecture (IPC). r=aknow
dom/telephony/ipc/PTelephony.ipdl
dom/telephony/ipc/TelephonyIPCService.cpp
dom/telephony/ipc/TelephonyParent.cpp
dom/telephony/ipc/TelephonyParent.h
--- a/dom/telephony/ipc/PTelephony.ipdl
+++ b/dom/telephony/ipc/PTelephony.ipdl
@@ -30,22 +30,57 @@ struct USSDRequest
   nsString ussd;
 };
 
 struct HangUpConferenceRequest
 {
   uint32_t clientId;
 };
 
+struct AnswerCallRequest
+{
+  uint32_t clientId;
+  uint32_t callIndex;
+};
+
+struct HangUpCallRequest
+{
+  uint32_t clientId;
+  uint32_t callIndex;
+};
+
+struct RejectCallRequest
+{
+  uint32_t clientId;
+  uint32_t callIndex;
+};
+
+struct HoldCallRequest
+{
+  uint32_t clientId;
+  uint32_t callIndex;
+};
+
+struct ResumeCallRequest
+{
+  uint32_t clientId;
+  uint32_t callIndex;
+};
+
 union IPCTelephonyRequest
 {
   EnumerateCallsRequest;
   DialRequest;
   USSDRequest;
   HangUpConferenceRequest;
+  AnswerCallRequest;
+  HangUpCallRequest;
+  RejectCallRequest;
+  HoldCallRequest;
+  ResumeCallRequest;
 };
 
 sync protocol PTelephony {
   manager PContent;
   manages PTelephonyRequest;
 
 child:
   NotifyCallError(uint32_t aClientId, int32_t aCallIndex, nsString aError);
@@ -71,26 +106,16 @@ parent:
    * Sent when the child makes an asynchronous request to the parent.
    */
   PTelephonyRequest(IPCTelephonyRequest request);
 
   RegisterListener();
 
   UnregisterListener();
 
-  HangUpCall(uint32_t aClientId, uint32_t aCallIndex);
-
-  AnswerCall(uint32_t aClientId, uint32_t aCallIndex);
-
-  RejectCall(uint32_t aClientId, uint32_t aCallIndex);
-
-  HoldCall(uint32_t aClientId, uint32_t aCallIndex);
-
-  ResumeCall(uint32_t aClientId, uint32_t aCallIndex);
-
   ConferenceCall(uint32_t aClientId);
 
   SeparateCall(uint32_t aClientId, uint32_t aCallIndex);
 
   HoldConference(uint32_t aClientId);
 
   ResumeConference(uint32_t aClientId);
 
--- a/dom/telephony/ipc/TelephonyIPCService.cpp
+++ b/dom/telephony/ipc/TelephonyIPCService.cpp
@@ -166,73 +166,73 @@ TelephonyIPCService::Dial(uint32_t aClie
                           nsITelephonyDialCallback *aCallback)
 {
   nsCOMPtr<nsITelephonyCallback> callback = do_QueryInterface(aCallback);
   return SendRequest(nullptr, callback,
                      DialRequest(aClientId, nsString(aNumber), aIsEmergency));
 }
 
 NS_IMETHODIMP
-TelephonyIPCService::HangUp(uint32_t aClientId, uint32_t aCallIndex)
+TelephonyIPCService::AnswerCall(uint32_t aClientId, uint32_t aCallIndex,
+                                nsITelephonyCallback *aCallback)
 {
   if (!mPTelephonyChild) {
     NS_WARNING("TelephonyService used after shutdown has begun!");
     return NS_ERROR_FAILURE;
   }
 
-  mPTelephonyChild->SendHangUpCall(aClientId, aCallIndex);
-  return NS_OK;
+  return SendRequest(nullptr, aCallback, AnswerCallRequest(aClientId, aCallIndex));
 }
 
 NS_IMETHODIMP
-TelephonyIPCService::AnswerCall(uint32_t aClientId, uint32_t aCallIndex)
+TelephonyIPCService::HangUpCall(uint32_t aClientId, uint32_t aCallIndex,
+                                nsITelephonyCallback *aCallback)
 {
   if (!mPTelephonyChild) {
     NS_WARNING("TelephonyService used after shutdown has begun!");
     return NS_ERROR_FAILURE;
   }
 
-  mPTelephonyChild->SendAnswerCall(aClientId, aCallIndex);
-  return NS_OK;
+  return SendRequest(nullptr, aCallback, HangUpCallRequest(aClientId, aCallIndex));
 }
 
 NS_IMETHODIMP
-TelephonyIPCService::RejectCall(uint32_t aClientId, uint32_t aCallIndex)
+TelephonyIPCService::RejectCall(uint32_t aClientId, uint32_t aCallIndex,
+                                nsITelephonyCallback *aCallback)
 {
   if (!mPTelephonyChild) {
     NS_WARNING("TelephonyService used after shutdown has begun!");
     return NS_ERROR_FAILURE;
   }
 
-  mPTelephonyChild->SendRejectCall(aClientId, aCallIndex);
-  return NS_OK;
+  return SendRequest(nullptr, aCallback, RejectCallRequest(aClientId, aCallIndex));
 }
 
 NS_IMETHODIMP
-TelephonyIPCService::HoldCall(uint32_t aClientId, uint32_t aCallIndex)
+TelephonyIPCService::HoldCall(uint32_t aClientId, uint32_t aCallIndex,
+                              nsITelephonyCallback *aCallback)
 {
   if (!mPTelephonyChild) {
     NS_WARNING("TelephonyService used after shutdown has begun!");
     return NS_ERROR_FAILURE;
   }
 
-  mPTelephonyChild->SendHoldCall(aClientId, aCallIndex);
-  return NS_OK;
+  return SendRequest(nullptr, aCallback, HoldCallRequest(aClientId, aCallIndex));
 }
 
 NS_IMETHODIMP
-TelephonyIPCService::ResumeCall(uint32_t aClientId, uint32_t aCallIndex)
+TelephonyIPCService::ResumeCall(uint32_t aClientId, uint32_t aCallIndex,
+                                nsITelephonyCallback *aCallback)
 {
   if (!mPTelephonyChild) {
     NS_WARNING("TelephonyService used after shutdown has begun!");
     return NS_ERROR_FAILURE;
   }
 
-  mPTelephonyChild->SendResumeCall(aClientId, aCallIndex);
-  return NS_OK;
+  return SendRequest(nullptr, aCallback, ResumeCallRequest(aClientId, aCallIndex));
 }
 
 NS_IMETHODIMP
 TelephonyIPCService::ConferenceCall(uint32_t aClientId)
 {
   if (!mPTelephonyChild) {
     NS_WARNING("TelephonyService used after shutdown has begun!");
     return NS_ERROR_FAILURE;
--- a/dom/telephony/ipc/TelephonyParent.cpp
+++ b/dom/telephony/ipc/TelephonyParent.cpp
@@ -32,26 +32,81 @@ TelephonyParent::ActorDestroy(ActorDestr
   RecvUnregisterListener();
 }
 
 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")));
+  }
 
   switch (aRequest.type()) {
-    case IPCTelephonyRequest::TEnumerateCallsRequest:
-      return actor->DoRequest(aRequest.get_EnumerateCallsRequest());
-    case IPCTelephonyRequest::TDialRequest:
-      return actor->DoRequest(aRequest.get_DialRequest());
-    case IPCTelephonyRequest::TUSSDRequest:
-      return actor->DoRequest(aRequest.get_USSDRequest());
-    case IPCTelephonyRequest::THangUpConferenceRequest:
-      return actor->DoRequest(aRequest.get_HangUpConferenceRequest());
+    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);
+      return true;
+    }
+
+    case IPCTelephonyRequest::TUSSDRequest: {
+      const USSDRequest& request = aRequest.get_USSDRequest();
+      service->SendUSSD(request.clientId(), request.ussd(), actor);
+      return true;
+    }
+
+    case IPCTelephonyRequest::THangUpConferenceRequest: {
+      const HangUpConferenceRequest& request = aRequest.get_HangUpConferenceRequest();
+      service->HangUpConference(request.clientId(), actor);
+      return true;
+    }
+
+    case IPCTelephonyRequest::TAnswerCallRequest: {
+      const AnswerCallRequest& request = aRequest.get_AnswerCallRequest();
+      service->AnswerCall(request.clientId(), request.callIndex(), actor);
+      return true;
+    }
+
+    case IPCTelephonyRequest::THangUpCallRequest: {
+      const HangUpCallRequest& request = aRequest.get_HangUpCallRequest();
+      service->HangUpCall(request.clientId(), request.callIndex(), actor);
+      return true;
+    }
+
+    case IPCTelephonyRequest::TRejectCallRequest: {
+      const RejectCallRequest& request = aRequest.get_RejectCallRequest();
+      service->RejectCall(request.clientId(), request.callIndex(), actor);
+      return true;
+    }
+
+    case IPCTelephonyRequest::THoldCallRequest: {
+      const HoldCallRequest& request = aRequest.get_HoldCallRequest();
+      service->HoldCall(request.clientId(), request.callIndex(), actor);
+      return true;
+    }
+
+    case IPCTelephonyRequest::TResumeCallRequest: {
+      const ResumeCallRequest& request = aRequest.get_ResumeCallRequest();
+      service->ResumeCall(request.clientId(), request.callIndex(), actor);
+      return true;
+    }
+
     default:
       MOZ_CRASH("Unknown type!");
   }
 
   return false;
 }
 
 PTelephonyRequestParent*
@@ -101,76 +156,16 @@ TelephonyParent::RecvUnregisterListener(
     do_GetService(TELEPHONY_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(service, true);
 
   mRegistered = !NS_SUCCEEDED(service->UnregisterListener(this));
   return true;
 }
 
 bool
-TelephonyParent::RecvHangUpCall(const uint32_t& aClientId,
-                                const uint32_t& aCallIndex)
-{
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(service, true);
-
-  service->HangUp(aClientId, aCallIndex);
-  return true;
-}
-
-bool
-TelephonyParent::RecvAnswerCall(const uint32_t& aClientId,
-                                const uint32_t& aCallIndex)
-{
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(service, true);
-
-  service->AnswerCall(aClientId, aCallIndex);
-  return true;
-}
-
-bool
-TelephonyParent::RecvRejectCall(const uint32_t& aClientId,
-                                const uint32_t& aCallIndex)
-{
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(service, true);
-
-  service->RejectCall(aClientId, aCallIndex);
-  return true;
-}
-
-bool
-TelephonyParent::RecvHoldCall(const uint32_t& aClientId,
-                              const uint32_t& aCallIndex)
-{
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(service, true);
-
-  service->HoldCall(aClientId, aCallIndex);
-  return true;
-}
-
-bool
-TelephonyParent::RecvResumeCall(const uint32_t& aClientId,
-                                const uint32_t& aCallIndex)
-{
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(service, true);
-
-  service->ResumeCall(aClientId, aCallIndex);
-  return true;
-}
-
-bool
 TelephonyParent::RecvConferenceCall(const uint32_t& aClientId)
 {
   nsCOMPtr<nsITelephonyService> service =
     do_GetService(TELEPHONY_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(service, true);
 
   service->ConferenceCall(aClientId);
   return true;
@@ -401,77 +396,16 @@ 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
   // an error here to avoid sending a message to the dead process.
   mActorDestroyed = true;
 }
 
-bool
-TelephonyRequestParent::DoRequest(const EnumerateCallsRequest& aRequest)
-{
-  nsresult rv = NS_ERROR_FAILURE;
-
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  if (service) {
-    rv = service->EnumerateCalls(this);
-  }
-
-  if (NS_FAILED(rv)) {
-    return NS_SUCCEEDED(EnumerateCallStateComplete());
-  }
-
-  return true;
-}
-
-bool
-TelephonyRequestParent::DoRequest(const DialRequest& aRequest)
-{
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  if (service) {
-    service->Dial(aRequest.clientId(), aRequest.number(),
-                  aRequest.isEmergency(), this);
-  } else {
-    return NS_SUCCEEDED(NotifyError(NS_LITERAL_STRING("InvalidStateError")));
-  }
-
-  return true;
-}
-
-bool
-TelephonyRequestParent::DoRequest(const USSDRequest& aRequest)
-{
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  if (service) {
-    service->SendUSSD(aRequest.clientId(), aRequest.ussd(), this);
-  } else {
-    return NS_SUCCEEDED(NotifyError(NS_LITERAL_STRING("InvalidStateError")));
-  }
-
-  return true;
-}
-
-bool
-TelephonyRequestParent::DoRequest(const HangUpConferenceRequest& aRequest)
-{
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  if (service) {
-    service->HangUpConference(aRequest.clientId(), this);
-  } else {
-    return NS_SUCCEEDED(NotifyError(NS_LITERAL_STRING("InvalidStateError")));
-  }
-
-  return true;
-}
-
 nsresult
 TelephonyRequestParent::SendResponse(const IPCTelephonyResponse& aResponse)
 {
   NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
 
   return Send__delete__(this, aResponse) ? NS_OK : NS_ERROR_FAILURE;
 }
 
--- a/dom/telephony/ipc/TelephonyParent.h
+++ b/dom/telephony/ipc/TelephonyParent.h
@@ -42,31 +42,16 @@ protected:
 
   virtual bool
   RecvRegisterListener() MOZ_OVERRIDE;
 
   virtual bool
   RecvUnregisterListener() MOZ_OVERRIDE;
 
   virtual bool
-  RecvHangUpCall(const uint32_t& aClientId, const uint32_t& aCallIndex) MOZ_OVERRIDE;
-
-  virtual bool
-  RecvAnswerCall(const uint32_t& aClientId, const uint32_t& aCallIndex) MOZ_OVERRIDE;
-
-  virtual bool
-  RecvRejectCall(const uint32_t& aClientId, const uint32_t& aCallIndex) MOZ_OVERRIDE;
-
-  virtual bool
-  RecvHoldCall(const uint32_t& aClientId, const uint32_t& aCallIndex) MOZ_OVERRIDE;
-
-  virtual bool
-  RecvResumeCall(const uint32_t& aClientId, const uint32_t& aCallIndex) MOZ_OVERRIDE;
-
-  virtual bool
   RecvConferenceCall(const uint32_t& aClientId) MOZ_OVERRIDE;
 
   virtual bool
   RecvSeparateCall(const uint32_t& aClientId, const uint32_t& callIndex) MOZ_OVERRIDE;
 
   virtual bool
   RecvHoldConference(const uint32_t& aClientId) MOZ_OVERRIDE;
 
@@ -115,25 +100,13 @@ protected:
   virtual void
   ActorDestroy(ActorDestroyReason why);
 
   nsresult
   SendResponse(const IPCTelephonyResponse& aResponse);
 
 private:
   bool mActorDestroyed;
-
-  bool
-  DoRequest(const EnumerateCallsRequest& aRequest);
-
-  bool
-  DoRequest(const DialRequest& aRequest);
-
-  bool
-  DoRequest(const USSDRequest& aRequest);
-
-  bool
-  DoRequest(const HangUpConferenceRequest& aRequest);
 };
 
 END_TELEPHONY_NAMESPACE
 
 #endif /* mozilla_dom_telephony_TelephonyParent_h */