#512: M1480092 M1466577

This commit is contained in:
Cameron Kaiser 2018-08-19 14:43:38 -07:00
parent c469554e9e
commit 812d03b96a
3 changed files with 93 additions and 48 deletions

View File

@ -330,7 +330,7 @@ void vp8_deblock(VP8_COMMON *cm,
double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065; double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065;
int ppl = (int)(level + .5); 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; int mbr, mbc;
/* The pixel thresholds are adjusted according to if or not the macroblock /* The pixel thresholds are adjusted according to if or not the macroblock

View File

@ -1173,6 +1173,7 @@ WebSocketChannel::WebSocketChannel() :
mDynamicOutput(nullptr), mDynamicOutput(nullptr),
mPrivateBrowsing(false), mPrivateBrowsing(false),
mConnectionLogService(nullptr), mConnectionLogService(nullptr),
mMutex("WebSocketChannel::mMutex"),
mCountRecv(0), mCountRecv(0),
mCountSent(0), mCountSent(0),
mAppId(NECKO_NO_APP_ID), mAppId(NECKO_NO_APP_ID),
@ -2158,7 +2159,7 @@ WebSocketChannel::PrimeNewOutgoingMessage()
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
LOG(("WebSocketChannel::PrimeNewOutgoingMessage(): " LOG(("WebSocketChannel::PrimeNewOutgoingMessage(): "
"GenerateRandomBytes failure %x\n", rv)); "GenerateRandomBytes failure %x\n", rv));
StopSession(rv); AbortSession(rv);
return; return;
} }
mask = * reinterpret_cast<uint32_t *>(buffer); mask = * reinterpret_cast<uint32_t *>(buffer);
@ -2308,10 +2309,26 @@ WebSocketChannel::StopSession(nsresult reason)
{ {
LOG(("WebSocketChannel::StopSession() %p [%x]\n", this, 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 // 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 // from OnStartRequest before the socket thread machine has gotten underway
mStopped = 1; MOZ_ASSERT(mStopped);
if (!mOpenedHttpChannel) { if (!mOpenedHttpChannel) {
// The HTTP channel information will never be used in this case // 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 // is set when the server close arrives without waiting for the timeout to
// expire. // expire.
LOG(("WebSocketChannel::StopSession: Wait for Server TCP close")); LOG(("WebSocketChannel::DoStopSession: Wait for Server TCP close"));
nsresult rv; nsresult rv;
mLingeringCloseTimer = do_CreateInstance("@mozilla.org/timer;1", &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", LOG(("WebSocketChannel::AbortSession() %p [reason %x] stopped = %d\n",
this, reason, !!mStopped)); 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 // normally this should be called on socket thread, but it is ok to call it
// from the main thread before StartWebsocketData() has completed // from the main thread before StartWebsocketData() has completed
@ -2428,20 +2447,26 @@ WebSocketChannel::AbortSession(nsresult reason)
return; return;
} }
if (mStopped) {
return; MutexAutoLock lock(mMutex);
mStopped = 1; if (mStopped) {
return;
}
if (mTransport && reason != NS_BASE_STREAM_CLOSED && !mRequestedClose && if (mTransport && reason != NS_BASE_STREAM_CLOSED && !mRequestedClose &&
!mClientClosed && !mServerClosed && mConnecting == NOT_CONNECTING) { !mClientClosed && !mServerClosed && mDataStarted) {
mRequestedClose = 1; mRequestedClose = 1;
mStopOnClose = reason; mStopOnClose = reason;
mSocketThread->Dispatch( mSocketThread->Dispatch(
new OutboundEnqueuer(this, new OutboundMessage(kMsgTypeFin, nullptr)), new OutboundEnqueuer(this, new OutboundMessage(kMsgTypeFin, nullptr)),
nsIEventTarget::DISPATCH_NORMAL); nsIEventTarget::DISPATCH_NORMAL);
} else { return;
StopSession(reason); }
mStopped = 1;
} }
DoStopSession(reason);
} }
// ReleaseSession is called on orderly shutdown // ReleaseSession is called on orderly shutdown
@ -2452,8 +2477,6 @@ WebSocketChannel::ReleaseSession()
this, !!mStopped)); this, !!mStopped));
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread, "not socket thread"); MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread, "not socket thread");
if (mStopped)
return;
StopSession(NS_OK); StopSession(NS_OK);
} }
@ -2802,9 +2825,19 @@ WebSocketChannel::StartWebsocketData()
NS_DISPATCH_NORMAL); NS_DISPATCH_NORMAL);
} }
LOG(("WebSocketChannel::StartWebsocketData() %p", this)); {
MOZ_ASSERT(!mDataStarted, "StartWebsocketData twice"); MutexAutoLock lock(mMutex);
mDataStarted = 1; 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", LOG(("WebSocketChannel::StartWebsocketData Notifying Listener %p\n",
mListenerMT ? mListenerMT->mListener.get() : nullptr)); mListenerMT ? mListenerMT->mListener.get() : nullptr));
@ -3416,35 +3449,46 @@ WebSocketChannel::Close(uint16_t code, const nsACString & reason)
// save the networkstats (bug 855949) // save the networkstats (bug 855949)
SaveNetworkStats(true); SaveNetworkStats(true);
if (mRequestedClose) { {
return NS_OK; MutexAutoLock lock(mMutex);
}
// The API requires the UTF-8 string to be 123 or less bytes if (mRequestedClose) {
if (reason.Length() > 123) return NS_OK;
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;
} }
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( nsresult rv;
new OutboundEnqueuer(this, new OutboundMessage(kMsgTypeFin, nullptr)), if (code == CLOSE_GOING_AWAY) {
nsIEventTarget::DISPATCH_NORMAL); // 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 NS_IMETHODIMP
@ -3773,13 +3817,11 @@ WebSocketChannel::OnInputStreamReady(nsIAsyncInputStream *aStream)
} }
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
mTCPClosed = true;
AbortSession(rv); AbortSession(rv);
return rv; return rv;
} }
if (count == 0) { if (count == 0) {
mTCPClosed = true;
AbortSession(NS_BASE_STREAM_CLOSED); AbortSession(NS_BASE_STREAM_CLOSED);
return NS_OK; return NS_OK;
} }

View File

@ -160,6 +160,7 @@ private:
void ReportConnectionTelemetry(); void ReportConnectionTelemetry();
void StopSession(nsresult reason); void StopSession(nsresult reason);
void DoStopSession(nsresult reason);
void AbortSession(nsresult reason); void AbortSession(nsresult reason);
void ReleaseSession(); void ReleaseSession();
void CleanupConnection(); void CleanupConnection();
@ -295,6 +296,8 @@ private:
nsCOMPtr<nsIDashboardEventNotifier> mConnectionLogService; nsCOMPtr<nsIDashboardEventNotifier> mConnectionLogService;
mozilla::Mutex mMutex;
// These members are used for network per-app metering (bug 855949) // These members are used for network per-app metering (bug 855949)
// Currently, they are only available on gonk. // Currently, they are only available on gonk.
Atomic<uint64_t, Relaxed> mCountRecv; Atomic<uint64_t, Relaxed> mCountRecv;