2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-10-06 01:46:31 +00:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2003-10-06 01:46:31 +00:00
|
|
|
#include "nsTransportUtils.h"
|
|
|
|
#include "nsITransport.h"
|
|
|
|
#include "nsProxyRelease.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2003-10-06 01:46:31 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsTransportStatusEvent;
|
|
|
|
|
|
|
|
class nsTransportEventSinkProxy : public nsITransportEventSink {
|
|
|
|
public:
|
2013-07-19 02:24:13 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2003-10-06 01:46:31 +00:00
|
|
|
NS_DECL_NSITRANSPORTEVENTSINK
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
nsTransportEventSinkProxy(nsITransportEventSink *sink, nsIEventTarget *target)
|
|
|
|
: mSink(sink),
|
|
|
|
mTarget(target),
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
mLock("nsTransportEventSinkProxy.mLock"),
|
2012-07-30 14:20:58 +00:00
|
|
|
mLastEvent(nullptr) {
|
2003-10-06 01:46:31 +00:00
|
|
|
NS_ADDREF(mSink);
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-06-24 16:36:44 +00:00
|
|
|
private:
|
2003-10-06 01:46:31 +00:00
|
|
|
virtual ~nsTransportEventSinkProxy() {
|
|
|
|
// our reference to mSink could be the last, so be sure to release
|
|
|
|
// it on the target thread. otherwise, we could get into trouble.
|
2017-06-14 01:27:17 +00:00
|
|
|
NS_ProxyRelease("nsTransportEventSinkProxy::mSink", mTarget,
|
|
|
|
dont_AddRef(mSink));
|
2003-10-06 01:46:31 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-06-24 16:36:44 +00:00
|
|
|
public:
|
2003-10-06 01:46:31 +00:00
|
|
|
nsITransportEventSink *mSink;
|
|
|
|
nsCOMPtr<nsIEventTarget> mTarget;
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
Mutex mLock;
|
2003-10-06 01:46:31 +00:00
|
|
|
nsTransportStatusEvent *mLastEvent;
|
|
|
|
};
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class nsTransportStatusEvent : public Runnable {
|
2003-10-06 01:46:31 +00:00
|
|
|
public:
|
|
|
|
nsTransportStatusEvent(nsTransportEventSinkProxy *proxy,
|
|
|
|
nsITransport *transport, nsresult status,
|
2015-01-08 19:48:52 +00:00
|
|
|
int64_t progress, int64_t progressMax)
|
2017-01-18 00:50:34 +00:00
|
|
|
: Runnable("nsTransportStatusEvent"),
|
|
|
|
mProxy(proxy),
|
2006-05-10 17:30:15 +00:00
|
|
|
mTransport(transport),
|
2003-10-06 01:46:31 +00:00
|
|
|
mStatus(status),
|
|
|
|
mProgress(progress),
|
|
|
|
mProgressMax(progressMax) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-04-30 16:46:04 +00:00
|
|
|
~nsTransportStatusEvent() = default;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-08-08 02:18:10 +00:00
|
|
|
NS_IMETHOD Run() override {
|
2003-10-06 01:46:31 +00:00
|
|
|
// since this event is being handled, we need to clear the proxy's ref.
|
|
|
|
// if not coalescing all, then last event may not equal self!
|
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
MutexAutoLock lock(mProxy->mLock);
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mProxy->mLastEvent == this) mProxy->mLastEvent = nullptr;
|
2003-10-06 01:46:31 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
mProxy->mSink->OnTransportStatus(mTransport, mStatus, mProgress,
|
|
|
|
mProgressMax);
|
2012-07-20 11:16:17 +00:00
|
|
|
return NS_OK;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsTransportEventSinkProxy> mProxy;
|
2003-10-06 01:46:31 +00:00
|
|
|
|
|
|
|
// parameters to OnTransportStatus
|
|
|
|
nsCOMPtr<nsITransport> mTransport;
|
|
|
|
nsresult mStatus;
|
2015-01-08 19:48:52 +00:00
|
|
|
int64_t mProgress;
|
|
|
|
int64_t mProgressMax;
|
2003-10-06 01:46:31 +00:00
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsTransportEventSinkProxy, nsITransportEventSink)
|
2003-10-06 01:46:31 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransportEventSinkProxy::OnTransportStatus(nsITransport *transport,
|
2015-01-08 19:48:52 +00:00
|
|
|
nsresult status, int64_t progress,
|
|
|
|
int64_t progressMax) {
|
2003-10-06 01:46:31 +00:00
|
|
|
nsresult rv = NS_OK;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsTransportStatusEvent> event;
|
2003-10-06 01:46:31 +00:00
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
// try to coalesce events! ;-)
|
2015-09-15 22:12:37 +00:00
|
|
|
if (mLastEvent && (mLastEvent->mStatus == status)) {
|
2003-10-06 01:46:31 +00:00
|
|
|
mLastEvent->mStatus = status;
|
|
|
|
mLastEvent->mProgress = progress;
|
|
|
|
mLastEvent->mProgressMax = progressMax;
|
|
|
|
} else {
|
|
|
|
event = new nsTransportStatusEvent(this, transport, status, progress,
|
|
|
|
progressMax);
|
|
|
|
if (!event) rv = NS_ERROR_OUT_OF_MEMORY;
|
2006-05-10 17:30:15 +00:00
|
|
|
mLastEvent = event; // weak ref
|
2003-10-06 01:46:31 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2003-10-06 01:46:31 +00:00
|
|
|
if (event) {
|
2006-05-10 17:30:15 +00:00
|
|
|
rv = mTarget->Dispatch(event, NS_DISPATCH_NORMAL);
|
2003-10-06 01:46:31 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("unable to post transport status event");
|
2018-11-30 10:46:48 +00:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
MutexAutoLock lock(mLock); // cleanup.. don't reference anymore!
|
2012-07-30 14:20:58 +00:00
|
|
|
mLastEvent = nullptr;
|
2003-10-06 01:46:31 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2003-10-06 01:46:31 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult net_NewTransportEventSinkProxy(nsITransportEventSink **result,
|
|
|
|
nsITransportEventSink *sink,
|
2015-09-15 22:12:37 +00:00
|
|
|
nsIEventTarget *target) {
|
|
|
|
*result = new nsTransportEventSinkProxy(sink, target);
|
2003-10-06 01:46:31 +00:00
|
|
|
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|