From 812d03b96a19e70e3cba19e83790a1a929e289bb Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Sun, 19 Aug 2018 14:43:38 -0700 Subject: [PATCH] #512: M1480092 M1466577 --- media/libvpx/vp8/common/postproc.c | 2 +- .../protocol/websocket/WebSocketChannel.cpp | 136 ++++++++++++------ netwerk/protocol/websocket/WebSocketChannel.h | 3 + 3 files changed, 93 insertions(+), 48 deletions(-) diff --git a/media/libvpx/vp8/common/postproc.c b/media/libvpx/vp8/common/postproc.c index 9899c844a..4ca3bc96e 100644 --- a/media/libvpx/vp8/common/postproc.c +++ b/media/libvpx/vp8/common/postproc.c @@ -330,7 +330,7 @@ void vp8_deblock(VP8_COMMON *cm, double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065; int ppl = (int)(level + .5); - const MODE_INFO *mode_info_context = cm->show_frame_mi; + const MODE_INFO *mode_info_context = cm->mi; int mbr, mbc; /* The pixel thresholds are adjusted according to if or not the macroblock diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index 52b02c634..1243aaf0b 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -1173,6 +1173,7 @@ WebSocketChannel::WebSocketChannel() : mDynamicOutput(nullptr), mPrivateBrowsing(false), mConnectionLogService(nullptr), + mMutex("WebSocketChannel::mMutex"), mCountRecv(0), mCountSent(0), mAppId(NECKO_NO_APP_ID), @@ -2158,7 +2159,7 @@ WebSocketChannel::PrimeNewOutgoingMessage() if (NS_FAILED(rv)) { LOG(("WebSocketChannel::PrimeNewOutgoingMessage(): " "GenerateRandomBytes failure %x\n", rv)); - StopSession(rv); + AbortSession(rv); return; } mask = * reinterpret_cast(buffer); @@ -2308,10 +2309,26 @@ WebSocketChannel::StopSession(nsresult reason) { LOG(("WebSocketChannel::StopSession() %p [%x]\n", this, reason)); + { + MutexAutoLock lock(mMutex); + if (mStopped) { + return; + } + mStopped = 1; + } + + DoStopSession(reason); +} + +void +WebSocketChannel::DoStopSession(nsresult reason) +{ + LOG(("WebSocketChannel::DoStopSession() %p [%x]\n", this, reason)); + // normally this should be called on socket thread, but it is ok to call it // from OnStartRequest before the socket thread machine has gotten underway - mStopped = 1; + MOZ_ASSERT(mStopped); if (!mOpenedHttpChannel) { // The HTTP channel information will never be used in this case @@ -2378,7 +2395,7 @@ WebSocketChannel::StopSession(nsresult reason) // is set when the server close arrives without waiting for the timeout to // expire. - LOG(("WebSocketChannel::StopSession: Wait for Server TCP close")); + LOG(("WebSocketChannel::DoStopSession: Wait for Server TCP close")); nsresult rv; mLingeringCloseTimer = do_CreateInstance("@mozilla.org/timer;1", &rv); @@ -2414,6 +2431,8 @@ WebSocketChannel::AbortSession(nsresult reason) LOG(("WebSocketChannel::AbortSession() %p [reason %x] stopped = %d\n", this, reason, !!mStopped)); + MOZ_ASSERT(NS_FAILED(reason), "reason must be a failure!"); + // normally this should be called on socket thread, but it is ok to call it // from the main thread before StartWebsocketData() has completed @@ -2428,20 +2447,26 @@ WebSocketChannel::AbortSession(nsresult reason) return; } - if (mStopped) - return; - mStopped = 1; + { + MutexAutoLock lock(mMutex); + if (mStopped) { + return; + } - if (mTransport && reason != NS_BASE_STREAM_CLOSED && !mRequestedClose && - !mClientClosed && !mServerClosed && mConnecting == NOT_CONNECTING) { - mRequestedClose = 1; - mStopOnClose = reason; - mSocketThread->Dispatch( - new OutboundEnqueuer(this, new OutboundMessage(kMsgTypeFin, nullptr)), - nsIEventTarget::DISPATCH_NORMAL); - } else { - StopSession(reason); + if (mTransport && reason != NS_BASE_STREAM_CLOSED && !mRequestedClose && + !mClientClosed && !mServerClosed && mDataStarted) { + mRequestedClose = 1; + mStopOnClose = reason; + mSocketThread->Dispatch( + new OutboundEnqueuer(this, new OutboundMessage(kMsgTypeFin, nullptr)), + nsIEventTarget::DISPATCH_NORMAL); + return; + } + + mStopped = 1; } + + DoStopSession(reason); } // ReleaseSession is called on orderly shutdown @@ -2452,8 +2477,6 @@ WebSocketChannel::ReleaseSession() this, !!mStopped)); MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread, "not socket thread"); - if (mStopped) - return; StopSession(NS_OK); } @@ -2802,9 +2825,19 @@ WebSocketChannel::StartWebsocketData() NS_DISPATCH_NORMAL); } - LOG(("WebSocketChannel::StartWebsocketData() %p", this)); - MOZ_ASSERT(!mDataStarted, "StartWebsocketData twice"); - mDataStarted = 1; + { + MutexAutoLock lock(mMutex); + LOG(("WebSocketChannel::StartWebsocketData() %p", this)); + MOZ_ASSERT(!mDataStarted, "StartWebsocketData twice"); + + if (mStopped) { + LOG(("WebSocketChannel::StartWebsocketData channel already closed, not " + "starting data")); + return NS_ERROR_NOT_AVAILABLE; + } + + mDataStarted = 1; + } LOG(("WebSocketChannel::StartWebsocketData Notifying Listener %p\n", mListenerMT ? mListenerMT->mListener.get() : nullptr)); @@ -3416,35 +3449,46 @@ WebSocketChannel::Close(uint16_t code, const nsACString & reason) // save the networkstats (bug 855949) SaveNetworkStats(true); - if (mRequestedClose) { - return NS_OK; - } + { + MutexAutoLock lock(mMutex); - // The API requires the UTF-8 string to be 123 or less bytes - if (reason.Length() > 123) - return NS_ERROR_ILLEGAL_VALUE; - - mRequestedClose = 1; - mScriptCloseReason = reason; - mScriptCloseCode = code; - - if (!mTransport || mConnecting != NOT_CONNECTING) { - nsresult rv; - if (code == CLOSE_GOING_AWAY) { - // Not an error: for example, tab has closed or navigated away - LOG(("WebSocketChannel::Close() GOING_AWAY without transport.")); - rv = NS_OK; - } else { - LOG(("WebSocketChannel::Close() without transport - error.")); - rv = NS_ERROR_NOT_CONNECTED; + if (mRequestedClose) { + return NS_OK; } - StopSession(rv); - return rv; + + if (mStopped) { + return NS_ERROR_NOT_AVAILABLE; + } + + // The API requires the UTF-8 string to be 123 or less bytes + if (reason.Length() > 123) + return NS_ERROR_ILLEGAL_VALUE; + + mRequestedClose = 1; + mScriptCloseReason = reason; + mScriptCloseCode = code; + + if (mDataStarted) { + return mSocketThread->Dispatch( + new OutboundEnqueuer(this, new OutboundMessage(kMsgTypeFin, nullptr)), + nsIEventTarget::DISPATCH_NORMAL); + } + + mStopped = 1; } - return mSocketThread->Dispatch( - new OutboundEnqueuer(this, new OutboundMessage(kMsgTypeFin, nullptr)), - nsIEventTarget::DISPATCH_NORMAL); + nsresult rv; + if (code == CLOSE_GOING_AWAY) { + // Not an error: for example, tab has closed or navigated away + LOG(("WebSocketChannel::Close() GOING_AWAY without transport.")); + rv = NS_OK; + } else { + LOG(("WebSocketChannel::Close() without transport - error.")); + rv = NS_ERROR_NOT_CONNECTED; + } + + DoStopSession(rv); + return rv; } NS_IMETHODIMP @@ -3773,13 +3817,11 @@ WebSocketChannel::OnInputStreamReady(nsIAsyncInputStream *aStream) } if (NS_FAILED(rv)) { - mTCPClosed = true; AbortSession(rv); return rv; } if (count == 0) { - mTCPClosed = true; AbortSession(NS_BASE_STREAM_CLOSED); return NS_OK; } diff --git a/netwerk/protocol/websocket/WebSocketChannel.h b/netwerk/protocol/websocket/WebSocketChannel.h index de9fed706..c3484ed61 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.h +++ b/netwerk/protocol/websocket/WebSocketChannel.h @@ -160,6 +160,7 @@ private: void ReportConnectionTelemetry(); void StopSession(nsresult reason); + void DoStopSession(nsresult reason); void AbortSession(nsresult reason); void ReleaseSession(); void CleanupConnection(); @@ -295,6 +296,8 @@ private: nsCOMPtr mConnectionLogService; + mozilla::Mutex mMutex; + // These members are used for network per-app metering (bug 855949) // Currently, they are only available on gonk. Atomic mCountRecv;