Bug 1254888 - Part 2: Add log to PresentationSessionInfo and Transport. r=schien
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Sun, 13 Mar 2016 17:05:00 -0400
changeset 288553 06033c2f79c430dd6649f894d153d76894fefd83
parent 288552 bccc70a79ae1ed30eadd59d018be4e57f6818222
child 288554 74282731c3d1dfcdbe182b7ba0919f408df2bf33
push id73452
push userryanvm@gmail.com
push dateMon, 14 Mar 2016 15:53:03 +0000
treeherdermozilla-inbound@bbaa07377c47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersschien
bugs1254888
milestone48.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 1254888 - Part 2: Add log to PresentationSessionInfo and Transport. r=schien
dom/presentation/PresentationLog.h
dom/presentation/PresentationSessionInfo.cpp
dom/presentation/PresentationSessionTransport.cpp
--- a/dom/presentation/PresentationLog.h
+++ b/dom/presentation/PresentationLog.h
@@ -11,12 +11,16 @@
  * NSPR_LOG_MODULES=Presentation:5
  * For detail, see PresentationService.cpp
  */
 namespace mozilla {
 namespace dom {
 extern mozilla::LazyLogModule gPresentationLog;
 }
 }
+
+#undef PRES_ERROR
+#define PRES_ERROR(...) MOZ_LOG(mozilla::dom::gPresentationLog, mozilla::LogLevel::Error, (__VA_ARGS__))
+
 #undef PRES_DEBUG
 #define PRES_DEBUG(...) MOZ_LOG(mozilla::dom::gPresentationLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
 
 #endif // mozilla_dom_PresentationLog_h
--- a/dom/presentation/PresentationSessionInfo.cpp
+++ b/dom/presentation/PresentationSessionInfo.cpp
@@ -17,39 +17,33 @@
 #include "nsIFrameLoader.h"
 #include "nsIMutableArray.h"
 #include "nsINetAddr.h"
 #include "nsISocketTransport.h"
 #include "nsISupportsPrimitives.h"
 #include "nsNetCID.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
+#include "PresentationLog.h"
 #include "PresentationService.h"
 #include "PresentationSessionInfo.h"
 
 #ifdef MOZ_WIDGET_ANDROID
 #include "nsIPresentationNetworkHelper.h"
 #endif // MOZ_WIDGET_ANDROID
 
 #ifdef MOZ_WIDGET_GONK
 #include "nsINetworkInterface.h"
 #include "nsINetworkManager.h"
 #endif
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::services;
 
-
-static LazyLogModule gPresentationSessionInfoLog("PresentationSessionInfo");
-
-#undef LOG
-#define LOG(...) MOZ_LOG(gPresentationSessionInfoLog, mozilla::LogLevel::Error, (__VA_ARGS__))
-
-
 /*
  * Implementation of PresentationChannelDescription
  */
 
 namespace mozilla {
 namespace dom {
 
 #ifdef MOZ_WIDGET_ANDROID
@@ -100,17 +94,17 @@ PresentationNetworkHelper::GetWifiIPAddr
   }
 
   return networkHelper->GetWifiIPAddress(this);
 }
 
 NS_IMETHODIMP
 PresentationNetworkHelper::OnError(const nsACString & aReason)
 {
-  LOG("PresentationNetworkHelper::OnError: %s",
+  PRES_ERROR("PresentationNetworkHelper::OnError: %s",
     nsPromiseFlatCString(aReason).get());
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresentationNetworkHelper::OnGetWifiIPAddress(const nsACString& aIPAddress)
 {
   MOZ_ASSERT(mInfo);
@@ -455,16 +449,22 @@ PresentationControllingInfo::Init(nsIPre
     return rv;
   }
 
   rv = mServerSocket->AsyncListen(this);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
+  int32_t port;
+  rv = mServerSocket->GetPort(&port);
+  if (!NS_WARN_IF(NS_FAILED(rv))) {
+    PRES_DEBUG("%s:ServerSocket created.port[%d]\n",__func__, port);
+  }
+
   return NS_OK;
 }
 
 void
 PresentationControllingInfo::Shutdown(nsresult aReason)
 {
   PresentationSessionInfo::Shutdown(aReason);
 
@@ -525,16 +525,24 @@ PresentationControllingInfo::GetAddress(
   RefPtr<PresentationNetworkHelper> networkHelper =
     new PresentationNetworkHelper(this,
                                   &PresentationControllingInfo::OnGetAddress);
   nsresult rv = networkHelper->GetWifiIPAddress();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
+#elif defined(MOZ_MULET)
+  // In simulator,we need to use the "127.0.0.1" as target address.
+  NS_DispatchToMainThread(
+    NS_NewRunnableMethodWithArg<nsCString>(
+      this,
+      &PresentationControllingInfo::OnGetAddress,
+      "127.0.0.1"));
+
 #else
   // TODO Get host IP via other platforms.
 
   NS_DispatchToMainThread(
     NS_NewRunnableMethodWithArg<nsCString>(
       this,
       &PresentationControllingInfo::OnGetAddress,
       EmptyCString()));
@@ -623,25 +631,31 @@ PresentationControllingInfo::NotifyClose
   return NS_OK;
 }
 
 // nsIServerSocketListener
 NS_IMETHODIMP
 PresentationControllingInfo::OnSocketAccepted(nsIServerSocket* aServerSocket,
                                             nsISocketTransport* aTransport)
 {
+  int32_t port;
+  nsresult rv = aTransport->GetPort(&port);
+  if (!NS_WARN_IF(NS_FAILED(rv))) {
+    PRES_DEBUG("%s:receive from port[%d]\n",__func__, port);
+  }
+
   MOZ_ASSERT(NS_IsMainThread());
 
   // Initialize |mTransport| and use |this| as the callback.
   mTransport = do_CreateInstance(PRESENTATION_SESSION_TRANSPORT_CONTRACTID);
   if (NS_WARN_IF(!mTransport)) {
     return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
-  nsresult rv = mTransport->InitWithSocketTransport(aTransport, this);
+  rv = mTransport->InitWithSocketTransport(aTransport, this);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Enable data notification if the listener has been registered.
   if (mListener) {
     return mTransport->EnableDataNotification();
   }
--- a/dom/presentation/PresentationSessionTransport.cpp
+++ b/dom/presentation/PresentationSessionTransport.cpp
@@ -14,16 +14,17 @@
 #include "nsIScriptableInputStream.h"
 #include "nsISocketTransport.h"
 #include "nsISocketTransportService.h"
 #include "nsISupportsPrimitives.h"
 #include "nsNetUtil.h"
 #include "nsServiceManagerUtils.h"
 #include "nsStreamUtils.h"
 #include "nsThreadUtils.h"
+#include "PresentationLog.h"
 #include "PresentationSessionTransport.h"
 
 #define BUFFER_SIZE 65536
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 class CopierCallbacks final : public nsIRequestObserver
@@ -149,16 +150,18 @@ PresentationSessionTransport::InitWithCh
   }
 
   nsAutoCString serverHost;
   supportStr->GetData(serverHost);
   if (serverHost.IsEmpty()) {
     return NS_ERROR_INVALID_ARG;
   }
 
+  PRES_DEBUG("%s:ServerHost[%s],ServerPort[%d]\n", __func__, serverHost.get(), serverPort);
+
   SetReadyState(CONNECTING);
 
   nsCOMPtr<nsISocketTransportService> sts =
     do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID);
   if (NS_WARN_IF(!sts)) {
     return NS_ERROR_NOT_AVAILABLE;
   }
   rv = sts->CreateTransport(nullptr, 0, serverHost, serverPort, nullptr,
@@ -355,16 +358,18 @@ PresentationSessionTransport::Send(nsIIn
   EnsureCopying();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresentationSessionTransport::Close(nsresult aReason)
 {
+  PRES_DEBUG("%s:reason[%x]\n", __func__, aReason);
+
   if (mReadyState == CLOSED || mReadyState == CLOSING) {
     return NS_OK;
   }
 
   mCloseStatus = aReason;
   SetReadyState(CLOSING);
 
   uint32_t count = 0;
@@ -396,16 +401,18 @@ PresentationSessionTransport::SetReadySt
 
 // nsITransportEventSink
 NS_IMETHODIMP
 PresentationSessionTransport::OnTransportStatus(nsITransport* aTransport,
                                                 nsresult aStatus,
                                                 int64_t aProgress,
                                                 int64_t aProgressMax)
 {
+  PRES_DEBUG("%s:aStatus[%x]\n", __func__, aStatus);
+
   MOZ_ASSERT(NS_IsMainThread());
 
   if (aStatus != NS_NET_STATUS_CONNECTED_TO) {
     return NS_OK;
   }
 
   SetReadyState(OPEN);
 
@@ -444,16 +451,18 @@ PresentationSessionTransport::OnStartReq
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresentationSessionTransport::OnStopRequest(nsIRequest* aRequest,
                                             nsISupports* aContext,
                                             nsresult aStatusCode)
 {
+  PRES_DEBUG("%s:aStatusCode[%x]\n", __func__, aStatusCode);
+
   MOZ_ASSERT(NS_IsMainThread());
 
   uint32_t count;
   nsresult rv = mMultiplexStream->GetCount(&count);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }